ndn-lite
Data Structures | Typedefs | Functions
encoder.h File Reference
#include "../ndn-constants.h"
#include "../ndn-error-code.h"
#include "../ndn-enums.h"
#include <inttypes.h>
#include <string.h>

Go to the source code of this file.

Data Structures

struct  ndn_buffer
 
struct  ndn_encoder
 The structure to keep the state when doing NDN TLV encoding. More...
 

Typedefs

typedef struct ndn_buffer ndn_buffer_t
 
typedef struct ndn_encoder ndn_encoder_t
 The structure to keep the state when doing NDN TLV encoding. More...
 

Functions

static void encoder_init (ndn_encoder_t *encoder, uint8_t *block_value, uint32_t block_max_size)
 Init an encoder by setting the buffer to keep the encoding output and its size. More...
 
static uint32_t encoder_get_var_size (uint32_t var)
 Probe the size of a variable-length type (T) or length (L). More...
 
static uint32_t encoder_probe_block_size (uint32_t type, uint32_t payload_size)
 Probe the size of a TLV block. More...
 
static int encoder_append_var (ndn_encoder_t *encoder, uint32_t var)
 Append a variable-length type (T) or length (L) to the wire format buffer. More...
 
static int encoder_append_type (ndn_encoder_t *encoder, uint32_t type)
 Append a variable-length type (T) to the wire format buffer. More...
 
static int encoder_append_length (ndn_encoder_t *encoder, uint32_t length)
 Append a variable-length length (L) to the wire format buffer. More...
 
static int encoder_append_raw_buffer_value (ndn_encoder_t *encoder, const uint8_t *buffer, uint32_t size)
 Append the byte array as the value (V) to the wire format buffer. More...
 
static int encoder_append_byte_value (ndn_encoder_t *encoder, uint8_t value)
 Append a single byte as the value (V) to the wire format buffer. More...
 
static int encoder_append_uint16_value (ndn_encoder_t *encoder, uint16_t value)
 Append a uint16_t as the value (V) to the wire format buffer. More...
 
static int encoder_append_uint32_value (ndn_encoder_t *encoder, uint32_t value)
 Append a uint32_t as the value (V) to the wire format buffer. More...
 
static int encoder_append_uint64_value (ndn_encoder_t *encoder, uint64_t value)
 Append a uint64_t as the value (V) to the wire format buffer. More...
 
static int encoder_probe_uint_length (uint64_t value)
 Probe the length of a non-negative int as the value (V). More...
 
static int encoder_append_uint_value (ndn_encoder_t *encoder, uint64_t value)
 Append a non-negative int as the value (V) to the wire format buffer. More...
 
static int encoder_move_forward (ndn_encoder_t *encoder, uint32_t step)
 Move the encoder's offset forward by. More...
 
static int encoder_move_backward (ndn_encoder_t *encoder, uint32_t step)
 Move the encoder's offset backward by. More...
 
static uint32_t encoder_get_offset (const ndn_encoder_t *encoder)
 Get the offset of the encoder. More...
 

Typedef Documentation

◆ ndn_buffer_t

typedef struct ndn_buffer ndn_buffer_t

◆ ndn_encoder_t

typedef struct ndn_encoder ndn_encoder_t

The structure to keep the state when doing NDN TLV encoding.

Function Documentation

◆ encoder_append_byte_value()

static int encoder_append_byte_value ( ndn_encoder_t encoder,
uint8_t  value 
)
inlinestatic

Append a single byte as the value (V) to the wire format buffer.

Parameters
encoder.Output. The encoder will keep the encoding result and the offset will be updated.
value.Input. The byte to be encoded.
Returns
0 if there is no error.

◆ encoder_append_length()

static int encoder_append_length ( ndn_encoder_t encoder,
uint32_t  length 
)
inlinestatic

Append a variable-length length (L) to the wire format buffer.

Parameters
encoder.Output. The encoder will keep the encoding result and the offset will be updated.
length.Input. The variable-length length (L).
Returns
0 if there is no error.

◆ encoder_append_raw_buffer_value()

static int encoder_append_raw_buffer_value ( ndn_encoder_t encoder,
const uint8_t *  buffer,
uint32_t  size 
)
inlinestatic

Append the byte array as the value (V) to the wire format buffer.

Parameters
encoder.Output. The encoder will keep the encoding result and the offset will be updated.
buffer.Input. The buffer to be encoded.
size.Input. The size of the buffer to be encoded.
Returns
0 if there is no error.

◆ encoder_append_type()

static int encoder_append_type ( ndn_encoder_t encoder,
uint32_t  type 
)
inlinestatic

Append a variable-length type (T) to the wire format buffer.

Parameters
encoder.Output. The encoder will keep the encoding result and the offset will be updated.
type.Input. The variable-length type (T).
Returns
0 if there is no error.

◆ encoder_append_uint16_value()

static int encoder_append_uint16_value ( ndn_encoder_t encoder,
uint16_t  value 
)
inlinestatic

Append a uint16_t as the value (V) to the wire format buffer.

Parameters
encoder.Output. The encoder will keep the encoding result and the offset will be updated.
value.Input. The uint16_t to be encoded.
Returns
0 if there is no error.

◆ encoder_append_uint32_value()

static int encoder_append_uint32_value ( ndn_encoder_t encoder,
uint32_t  value 
)
inlinestatic

Append a uint32_t as the value (V) to the wire format buffer.

Parameters
encoder.Output. The encoder will keep the encoding result and the offset will be updated.
value.Input. The uint32_t to be encoded.
Returns
0 if there is no error.

◆ encoder_append_uint64_value()

static int encoder_append_uint64_value ( ndn_encoder_t encoder,
uint64_t  value 
)
inlinestatic

Append a uint64_t as the value (V) to the wire format buffer.

Parameters
encoder.Output. The encoder will keep the encoding result and the offset will be updated.
value.Input. The uint64_t to be encoded.
Returns
0 if there is no error.

◆ encoder_append_uint_value()

static int encoder_append_uint_value ( ndn_encoder_t encoder,
uint64_t  value 
)
inlinestatic

Append a non-negative int as the value (V) to the wire format buffer.

TLV-LENGTH of the TLV element MUST be either 1, 2, 4, or 8.

Note
For more details, go https://named-data.net/doc/NDN-packet-spec/current/tlv.html
Parameters
encoder.Output. The encoder will keep the encoding result and the offset will be updated.
value.Input. The uint to be encoded.
Returns
0 if there is no error.

◆ encoder_append_var()

static int encoder_append_var ( ndn_encoder_t encoder,
uint32_t  var 
)
inlinestatic

Append a variable-length type (T) or length (L) to the wire format buffer.

Parameters
encoder.Output. The encoder will keep the encoding result and the offset will be updated.
var.Input. The variable-length type (T) or length (L).
Returns
0 if there is no error.

◆ encoder_get_offset()

static uint32_t encoder_get_offset ( const ndn_encoder_t encoder)
inlinestatic

Get the offset of the encoder.

Parameters
encoder.Input. The encoder's offset will be updated.
Returns
the uint32_t type offset.

◆ encoder_get_var_size()

static uint32_t encoder_get_var_size ( uint32_t  var)
inlinestatic

Probe the size of a variable-length type (T) or length (L).

Parameters
var.Input. The value of the variable-length type (T) or length (L).
Returns
the length of the type (T) or length (L).

◆ encoder_init()

static void encoder_init ( ndn_encoder_t encoder,
uint8_t *  block_value,
uint32_t  block_max_size 
)
inlinestatic

Init an encoder by setting the buffer to keep the encoding output and its size.

Parameters
encoder.Output. The encoder to be inited.
block_value.Input. The buffer to keep the wire format buffer.
block_max_size.Input. The size of wire format buffer.

◆ encoder_move_backward()

static int encoder_move_backward ( ndn_encoder_t encoder,
uint32_t  step 
)
inlinestatic

Move the encoder's offset backward by.

Parameters
step.
encoder.Output. The encoder whose offset will be updated.
step.Input. The step by which the offset will be moved.
Returns
0 if there is no error.

◆ encoder_move_forward()

static int encoder_move_forward ( ndn_encoder_t encoder,
uint32_t  step 
)
inlinestatic

Move the encoder's offset forward by.

Parameters
step.
encoder.Output. The encoder whose offset will be updated.
step.Input. The step by which the offset will be moved.
Returns
0 if there is no error.

◆ encoder_probe_block_size()

static uint32_t encoder_probe_block_size ( uint32_t  type,
uint32_t  payload_size 
)
inlinestatic

Probe the size of a TLV block.

This function is used to check whether the output buffer size is large enough.

Parameters
type.Input. The value of the type (T).
payload_size.Input. The value of length (L).
Returns
the length of the TLV block.

◆ encoder_probe_uint_length()

static int encoder_probe_uint_length ( uint64_t  value)
inlinestatic

Probe the length of a non-negative int as the value (V).

TLV-LENGTH of the TLV element MUST be either 1, 2, 4, or 8.

Note
For more details, go https://named-data.net/doc/NDN-packet-spec/current/tlv.html
Parameters
value.Input. The uint to be checked.
Returns
the length of a non-negative int.