Public Member Functions | Static Public Member Functions | Friends | List of all members
ndn::DynamicUInt8ArrayLite Class Reference

A DynamicUInt8ArrayLite holds a pointer to an allocated array, the length of the allocated array, and an optional realloc function which can changes its size. More...

#include <dynamic-uint8-array-lite.hpp>

Inheritance diagram for ndn::DynamicUInt8ArrayLite:
ndn_DynamicUInt8Array

Public Member Functions

 DynamicUInt8ArrayLite (uint8_t *array, size_t length, ndn_ReallocFunction reallocFunction)
 Create a DynamicUInt8ArrayLite with the given array buffer. More...
 
uint8_t * getArray ()
 Get the current allocated array. More...
 
const uint8_t * getArray () const
 
size_t getLength () const
 Get the current length of the allocated array. More...
 
ndn_Error ensureLength (size_t length)
 Ensure that getLength() is greater than or equal to length. More...
 
ndn_Error copy (const uint8_t *value, size_t valueLength, size_t offset)
 Copy value into this object's array at offset, using ensureLength to make sure the array has enough length. More...
 
ndn_Error ensureLengthFromBack (size_t length)
 Ensure that getLength() is greater than or equal to the given length. More...
 
ndn_Error copyFromBack (const uint8_t *value, size_t valueLength, size_t offsetFromBack)
 First call ensureLengthFromBack to make sure this object's array has offsetFromBack bytes. More...
 

Static Public Member Functions

static DynamicUInt8ArrayLitedownCast (ndn_DynamicUInt8Array &dynamicArray)
 Downcast the reference to the ndn_DynamicUInt8ArrayLite struct to a DynamicUInt8ArrayLiteLite. More...
 
static const DynamicUInt8ArrayLitedownCast (const ndn_DynamicUInt8Array &dynamicArray)
 

Friends

class TcpTransportLite
 
class UdpTransportLite
 
class UnixTransportLite
 
class ArduinoYunTcpTransportLite
 
class Tlv0_1_1WireFormatLite
 

Detailed Description

A DynamicUInt8ArrayLite holds a pointer to an allocated array, the length of the allocated array, and an optional realloc function which can changes its size.

Constructor & Destructor Documentation

ndn::DynamicUInt8ArrayLite::DynamicUInt8ArrayLite ( uint8_t *  array,
size_t  length,
ndn_ReallocFunction  reallocFunction 
)

Create a DynamicUInt8ArrayLite with the given array buffer.

Parameters
arrayThe allocated array buffer. It is the caller's responsibility to free this buffer if necessary when finished with it.
lengthThe length of the allocated array buffer.
reallocFunctionSee ensureLength. This may be 0.

Member Function Documentation

ndn_Error ndn::DynamicUInt8ArrayLite::copy ( const uint8_t *  value,
size_t  valueLength,
size_t  offset 
)

Copy value into this object's array at offset, using ensureLength to make sure the array has enough length.

Parameters
valueThe buffer to copy from.
valueLengthThe length of the value buffer.
offsetThe offset in this object's array to copy to.
Returns
0 for success, else an error code if need to reallocate the array but can't.
ndn_Error ndn::DynamicUInt8ArrayLite::copyFromBack ( const uint8_t *  value,
size_t  valueLength,
size_t  offsetFromBack 
)

First call ensureLengthFromBack to make sure this object's array has offsetFromBack bytes.

Then copy value into this object's array starting offsetFromBack bytes from the back of the array.

Parameters
valueThe buffer to copy from.
valueLengthThe length of the value buffer.
offsetFromBackThe offset from the back of the array to start copying.
Returns
0 for success, else an error code if need to reallocate the array but can't.
static DynamicUInt8ArrayLite& ndn::DynamicUInt8ArrayLite::downCast ( ndn_DynamicUInt8Array dynamicArray)
inlinestatic

Downcast the reference to the ndn_DynamicUInt8ArrayLite struct to a DynamicUInt8ArrayLiteLite.

Parameters
dynamicArrayA reference to the ndn_DynamicUInt8ArrayLite struct.
Returns
The same reference as DynamicUInt8ArrayLiteLite.
ndn_Error ndn::DynamicUInt8ArrayLite::ensureLength ( size_t  length)

Ensure that getLength() is greater than or equal to length.

If it is, just return 0 for success. Otherwise, if the reallocFunction given to the constructor is 0, then return an error. If not 0, call reallocFunction to reallocate this object's array, and update the getLength() (which may be greater than the given length).

Parameters
lengthThe needed minimum size for getLength().
Returns
0 for success, else an error code if need to reallocate the array but can't.
ndn_Error ndn::DynamicUInt8ArrayLite::ensureLengthFromBack ( size_t  length)

Ensure that getLength() is greater than or equal to the given length.

If it is, just return 0 for success. Otherwise, if the the reallocFunction given to the constructor is 0, then return an error. If not 0, call reallocFunction to reallocate this object's array, and update getLength() (which may be greater than the given length).

Parameters
lengththe needed minimum size for self->length
Returns
0 for success, else an error code if need to reallocate the array but can't.
uint8_t* ndn::DynamicUInt8ArrayLite::getArray ( )
inline

Get the current allocated array.

Returns
The array.
size_t ndn::DynamicUInt8ArrayLite::getLength ( ) const
inline

Get the current length of the allocated array.

Returns
The array length.

The documentation for this class was generated from the following files: