Classes | Public Member Functions | List of all members
ndn::TlvEncoder Class Reference

A TlvEncoder extends a C ndn_TlvEncoder struct and wraps related functions. More...

#include <tlv-encoder.hpp>

Inheritance diagram for ndn::TlvEncoder:
ndn_TlvEncoder

Public Member Functions

 TlvEncoder (size_t initialLength=16)
 Initialize the base ndn_TlvEncoder struct with the initialLength. More...
 
Blob finish ()
 Resize the output vector to the correct encoding length, transfer the bytes to a Blob and return the Blob. More...
 
void writeTypeAndLength (unsigned int type, size_t length)
 
void writeNonNegativeInteger (uint64_t value)
 
void writeBlobTlv (unsigned int type, struct ndn_Blob *value)
 
void writeRawStringTlv (unsigned int type, const std::string &value)
 Call writeBlobTlv using the raw string bytes. More...
 
void writeNonNegativeIntegerTlv (unsigned int type, uint64_t value)
 
void writeNestedTlv (unsigned int type, ndn_Error(*writeValue)(const void *context, struct ndn_TlvEncoder *encoder), const void *context, bool omitZeroLength=false)
 
void writeNestedTlv (unsigned int type, void(*writeValue)(const void *context, TlvEncoder &encoder), const void *context, bool omitZeroLength=false)
 Call writeNestedTlv so that it calls writeValue(context, *this). More...
 

Additional Inherited Members

- Public Attributes inherited from ndn_TlvEncoder
struct ndn_DynamicUInt8Arrayoutput
 A pointer to a ndn_DynamicUInt8Array which receives the encoded output. More...
 
size_t offset
 The offset into output.array for the next encoding. More...
 
int enableOutput
 If 0, then only advance offset without writing to output. More...
 

Detailed Description

A TlvEncoder extends a C ndn_TlvEncoder struct and wraps related functions.

Constructor & Destructor Documentation

ndn::TlvEncoder::TlvEncoder ( size_t  initialLength = 16)
inline

Initialize the base ndn_TlvEncoder struct with the initialLength.

Use simpleRealloc.

Parameters
initialLengthThe initial size of the output. If omitted, use 16.

Member Function Documentation

Blob ndn::TlvEncoder::finish ( )
inline

Resize the output vector to the correct encoding length, transfer the bytes to a Blob and return the Blob.

This clear the internal pointer to the output vector, and further calls to write to it will throw an exception.

Parameters
sizeThe final size of the allocated vector.
Returns
A new Blob with the bytes from the vector.
void ndn::TlvEncoder::writeNestedTlv ( unsigned int  type,
void(*)(const void *context, TlvEncoder &encoder)  writeValue,
const void *  context,
bool  omitZeroLength = false 
)
inline

Call writeNestedTlv so that it calls writeValue(context, *this).

Parameters
typeThe TLV type for writeNestedTlv.
writeValueThe callback to write the TLV value. This calls writeValue(context, *this).
contextThe context to pass to writeValue.
omitZeroLengthThe omitZeroLength flag for writeNestedTlv.
void ndn::TlvEncoder::writeRawStringTlv ( unsigned int  type,
const std::string &  value 
)
inline

Call writeBlobTlv using the raw string bytes.

Parameters
typeThe type of the TLV.
valueThe raw string.

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