Syntax
class MutableData;
template <DataLengthType kDataLengthType>
class Data : public Clearable<Data<kDataLengthType>>, public Unequatable<Data<kDataLengthType>>, private DataUtils
{
friend class MutableData<kDataLengthType>;
public:
using LengthType = typename TypeTraits::Conditional<kDataLengthType == kWithUint8Length, uint8_t, uint16_t>::Type;
void Init(const void *aBuffer, LengthType aLength)
{
mBuffer = static_cast<const uint8_t *>(aBuffer);
mLength = aLength;
}
void InitFromRange(const uint8_t *aStart, const uint8_t *aEnd)
{
Init(aStart, static_cast<LengthType>(aEnd - aStart));
}
template <typename ObjectType> void InitFrom(const ObjectType &aObject)
{
static_assert(!TypeTraits::IsPointer<ObjectType>::kValue, "ObjectType MUST not be a pointer");
Init(&aObject, sizeof(aObject));
}
const uint8_t *GetBytes(void) const { return mBuffer; }
LengthType GetLength(void) const { return mLength; }
void SetLength(LengthType aLength) { mLength = aLength; }
void CopyBytesTo(void *aBuffer) const { memcpy(aBuffer, mBuffer, mLength); }
bool MatchesBytesIn(const void *aBuffer) const { return memcmp(mBuffer, aBuffer, mLength) == 0; }
bool MatchesBytesIn(const void *aBuffer, ByteMatcher aMatcher)
{
return MatchBytes(mBuffer, static_cast<const uint8_t *>(aBuffer), mLength, aMatcher);
}
bool operator==(const Data &aOtherData) const
{
return (mLength == aOtherData.mLength) && MatchesBytesIn(aOtherData.mBuffer);
}
bool StartsWith(const Data &aOtherData) const
{
return (mLength >= aOtherData.mLength) && aOtherData.MatchesBytesIn(mBuffer);
}
private:
const uint8_t *mBuffer;
LengthType mLength;
};
template <DataLengthType kDataLengthType> class MutableData : public Data;
![]()
template <DataLengthType kDataLengthType> class MutableData : public Data<kDataLengthType>![]()
using Base = MutableData<kWithUint16Length>;![]()
friend class MutableData<kDataLengthType>;![]()
MutableData<kWithUint16Length> txtData;![]()
using Base = MutableData<kWithUint16Length>;