template <DataLengthType kDataLengthType>

class Data

Defined at line 105 of file ../../third_party/openthread/src/core/common/data.hpp

Represents a generic `Data` which is simply a wrapper over a pointer to a buffer with a given data length.

The data length can be either `uint8_t` or `uint16_t` (determined by the template parameter `kDataLengthType`).

While a `Data` instance itself can change (for example, it can be updated to point to another buffer), it always

treats the content of the buffer as immutable.

A `Data` instance MUST be initialized (using any of the `Init()` methods) before calling any other methods on the

instance (e.g., `GetBytes()` or `GetLength()`), otherwise the behavior is undefined.

Template Parameters

kDataLengthType Determines the data length type (`uint8_t` or `uint16_t`).

Public Methods

void Init (const void * aBuffer, LengthType aLength)

Initializes the `Data` to point to a given buffer with a given length.

Parameters

aBuffer [in] A pointer to a buffer containing the data.
aLength [in] The data length (number of bytes in

Defined at line 121 of file ../../third_party/openthread/src/core/common/data.hpp

void InitFromRange (const uint8_t * aStart, const uint8_t * aEnd)

Initializes the `Data` to point to a range of bytes in a given buffer.

The range is specified by the pointers to its start

and its end

`Data` will point to the

bytes in the buffer from

up to but excluding

(i.e., `aStart

<

= bytes

<

aEnd`).

Parameters

aStart [in] Pointer to the start of the range.
aEnd [in] Pointer to the end of the range.

Defined at line 136 of file ../../third_party/openthread/src/core/common/data.hpp

template <typename ObjectType>
void InitFrom (const ObjectType & aObject)

Initializes the `Data` to point to the content of an object.

Parameters

aObject [in] The object to initialize the `Data` with.

Template Parameters

ObjectType The object type (MUST not be a pointer type).

Defined at line 148 of file ../../third_party/openthread/src/core/common/data.hpp

const uint8_t * GetBytes ()

Returns a pointer to the data bytes buffer.

Defined at line 159 of file ../../third_party/openthread/src/core/common/data.hpp

LengthType GetLength ()

Returns the data length.

Defined at line 166 of file ../../third_party/openthread/src/core/common/data.hpp

void SetLength (LengthType aLength)

Sets the data length.

Parameters

aLength [in] The data length (number of bytes).

Defined at line 173 of file ../../third_party/openthread/src/core/common/data.hpp

void CopyBytesTo (void * aBuffer)

Copies the `Data` bytes to a given buffer.

It is up to the caller to ensure that

has enough space for the current data length.

Parameters

aBuffer [out] The buffer to copy the bytes into.

Defined at line 182 of file ../../third_party/openthread/src/core/common/data.hpp

bool MatchesBytesIn (const void * aBuffer)

Compares the `Data` content with the bytes from a given buffer.

It is up to the caller to ensure that

has enough bytes to compare with the current data length.

Parameters

aBuffer [in] A pointer to a buffer to compare with the data.

Defined at line 194 of file ../../third_party/openthread/src/core/common/data.hpp

bool MatchesBytesIn (const void * aBuffer, ByteMatcher aMatcher)

Compares the `Data` content with the bytes from a given buffer using a given `Matcher` function.

It is up to the caller to ensure that

has enough bytes to compare with the current data length.

Parameters

aBuffer [in] A pointer to a buffer to compare with the data.
aMatcher [in] A `ByteMatcher` function to match the bytes. If `nullptr`, bytes are compared directly.

Defined at line 207 of file ../../third_party/openthread/src/core/common/data.hpp

bool operator== (const Data<kDataLengthType> & aOtherData)

Overloads operator `==` to compare the `Data` content with the content from another one.

Parameters

aOtherData [in] The other `Data` to compare with.

Defined at line 220 of file ../../third_party/openthread/src/core/common/data.hpp

bool StartsWith (const Data<kDataLengthType> & aOtherData)

Checks whether the `Data` starts with the same byte content as from another `Data` instance.

Checks that the `Data` instance contains the same bytes as

but allows it to have

additional bytes at the end.

Parameters

aOtherData [in] The other `Data` to compare with.

Defined at line 236 of file ../../third_party/openthread/src/core/common/data.hpp