ndn-lite
Data Structures | Typedefs | Functions
decoder.h File Reference
#include "encoder.h"

Go to the source code of this file.

Data Structures

struct  ndn_decoder
 The structure to keep the state when doing NDN TLV decoding. More...
 

Typedefs

typedef struct ndn_decoder ndn_decoder_t
 The structure to keep the state when doing NDN TLV decoding. More...
 

Functions

static void decoder_init (ndn_decoder_t *decoder, const uint8_t *block_value, uint32_t block_size)
 Init a decoder by setting the wire format buffer and its size. More...
 
static int decoder_get_var (ndn_decoder_t *decoder, uint32_t *var)
 Get the variable size Type (T) and Length (L). More...
 
static int decoder_get_type (ndn_decoder_t *decoder, uint32_t *type)
 Get the variable size Type (T). More...
 
static int decoder_get_length (ndn_decoder_t *decoder, uint32_t *length)
 Get the variable size Length (L). More...
 
static int decoder_get_raw_buffer_value (ndn_decoder_t *decoder, uint8_t *value, uint32_t size)
 Get the variable size Value (V) to bytes. More...
 
static int decoder_get_byte_value (ndn_decoder_t *decoder, uint8_t *value)
 Get the fixed size Value (V) to a single byte. More...
 
static int decoder_get_uint16_value (ndn_decoder_t *decoder, uint16_t *value)
 Get the fixed size Value (V) to a uint16_t. More...
 
static int decoder_get_uint32_value (ndn_decoder_t *decoder, uint32_t *value)
 Get the fixed size Value (V) to a uint32_t. More...
 
static int decoder_get_uint64_value (ndn_decoder_t *decoder, uint64_t *value)
 Get the fixed size Value (V) to a uint64_t. More...
 
static int decoder_get_uint_value (ndn_decoder_t *decoder, uint32_t length, uint64_t *value)
 Get the non-negative int Value (V) to a uint64_t. More...
 
static int decoder_move_forward (ndn_decoder_t *decoder, uint32_t step)
 Move the decoder's offset forward by. More...
 
static int decoder_move_backward (ndn_decoder_t *decoder, uint32_t step)
 Move the decoder's offset backward by. More...
 
static uint32_t decoder_get_offset (const ndn_decoder_t *decoder)
 Get the offset of the decoder. More...
 

Typedef Documentation

◆ ndn_decoder_t

typedef struct ndn_decoder ndn_decoder_t

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

Function Documentation

◆ decoder_get_byte_value()

static int decoder_get_byte_value ( ndn_decoder_t decoder,
uint8_t *  value 
)
inlinestatic

Get the fixed size Value (V) to a single byte.

This function is supposed to be invoked after decoder_get_length().

Parameters
decoder.Input/Output. The decoder's offset will be updated.
value.Output. The variable to keep the byte value.
Returns
0 if there is no error.

◆ decoder_get_length()

static int decoder_get_length ( ndn_decoder_t decoder,
uint32_t *  length 
)
inlinestatic

Get the variable size Length (L).

This function is supposed to be invoked after decoder_get_type().

Parameters
decoder.Input/Output. The decoder's offset will be updated.
length.Output. The uint32_t to keep the decoded Length (L).
Returns
0 if there is no error.

◆ decoder_get_offset()

static uint32_t decoder_get_offset ( const ndn_decoder_t decoder)
inlinestatic

Get the offset of the decoder.

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

◆ decoder_get_raw_buffer_value()

static int decoder_get_raw_buffer_value ( ndn_decoder_t decoder,
uint8_t *  value,
uint32_t  size 
)
inlinestatic

Get the variable size Value (V) to bytes.

This function is supposed to be invoked after decoder_get_length().

Parameters
decoder.Input/Output. The decoder's offset will be updated.
value.Output. The variable to keep the value. It must have been initialized with an empty uint8_t array.
size.Input. The size should be set to the value obtained from decoder_get_length().
Returns
0 if there is no error.

◆ decoder_get_type()

static int decoder_get_type ( ndn_decoder_t decoder,
uint32_t *  type 
)
inlinestatic

Get the variable size Type (T).

Parameters
decoder.Input/Output. The decoder's offset will be updated.
type.Output. The uint32_t to keep the decoded Type (T).
Returns
0 if there is no error.

◆ decoder_get_uint16_value()

static int decoder_get_uint16_value ( ndn_decoder_t decoder,
uint16_t *  value 
)
inlinestatic

Get the fixed size Value (V) to a uint16_t.

This function is supposed to be invoked after decoder_get_length().

Parameters
decoder.Input/Output. The decoder's offset will be updated.
value.Output. The variable to keep the uint16_t value.
Returns
0 if there is no error.

◆ decoder_get_uint32_value()

static int decoder_get_uint32_value ( ndn_decoder_t decoder,
uint32_t *  value 
)
inlinestatic

Get the fixed size Value (V) to a uint32_t.

This function is supposed to be invoked after decoder_get_length().

Parameters
decoder.Input/Output. The decoder's offset will be updated.
value.Output. The variable to keep the uint32_t value.
Returns
0 if there is no error.

◆ decoder_get_uint64_value()

static int decoder_get_uint64_value ( ndn_decoder_t decoder,
uint64_t *  value 
)
inlinestatic

Get the fixed size Value (V) to a uint64_t.

This function is supposed to be invoked after decoder_get_length().

Parameters
decoder.Input/Output. The decoder's offset will be updated.
value.Output. The variable to keep the uint64_t value.
Returns
0 if there is no error.

◆ decoder_get_uint_value()

static int decoder_get_uint_value ( ndn_decoder_t decoder,
uint32_t  length,
uint64_t *  value 
)
inlinestatic

Get the non-negative int Value (V) to a uint64_t.

This function is supposed to be invoked after decoder_get_length(). 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
decoder.Input/Output. The decoder's offset will be updated.
length.Input. The Length (L) obtained from decoder_get_length().
value.Output. The variable to keep the non-negative int value.
Returns
0 if there is no error.

◆ decoder_get_var()

static int decoder_get_var ( ndn_decoder_t decoder,
uint32_t *  var 
)
inlinestatic

Get the variable size Type (T) and Length (L).

Parameters
decoder.Input/Output. The decoder's offset will be updated.
var.Output. The uint32_t to keep the decoded Type (T) or Length (L).
Returns
0 if there is no error.

◆ decoder_init()

static void decoder_init ( ndn_decoder_t decoder,
const uint8_t *  block_value,
uint32_t  block_size 
)
inlinestatic

Init a decoder by setting the wire format buffer and its size.

Parameters
decoder.Output. The decoder to be inited.
block_value.Input. The wire format buffer.
block_size.Input. The size of wire format buffer.

◆ decoder_move_backward()

static int decoder_move_backward ( ndn_decoder_t decoder,
uint32_t  step 
)
inlinestatic

Move the decoder's offset backward by.

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

◆ decoder_move_forward()

static int decoder_move_forward ( ndn_decoder_t decoder,
uint32_t  step 
)
inlinestatic

Move the decoder's offset forward by.

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