9 #ifndef NDN_ENCODING_ENCODER_H 10 #define NDN_ENCODING_ENCODER_H 12 #include "../ndn-constants.h" 13 #include "../ndn-error-code.h" 14 #include "../ndn-enums.h" 55 memset(block_value, 0, block_max_size);
66 static inline uint32_t
69 if (var < 253)
return 1;
70 if (var <= 0xFFFF)
return 3;
81 static inline uint32_t
86 return payload_size + type_size + length_size;
99 if (var < 253 && rest_size >= 1) {
103 else if (var <= 0xFFFF && rest_size >= 3) {
109 else if (var <= 0xFFFFFFFF && rest_size >= 5) {
158 if (rest_length < (
int) size) {
210 for (
int i = 0; i < 4; i++) {
228 for (
int i = 0; i < 8; i++) {
248 else if (value <= 0xFFFF) {
251 else if (value <= 0xFFFFFFFF) {
273 else if (value <= 0xFFFF) {
276 else if (value <= 0xFFFFFFFF) {
317 static inline uint32_t
327 #endif // NDN_ENCODING_ENCODER_H static uint32_t encoder_get_var_size(uint32_t var)
Probe the size of a variable-length type (T) or length (L).
Definition: encoder.h:67
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.
Definition: encoder.h:268
uint32_t offset
The actual size used of the buffer to keep the encoding output.
Definition: encoder.h:43
struct ndn_buffer ndn_buffer_t
struct ndn_encoder ndn_encoder_t
The structure to keep the state when doing NDN TLV encoding.
#define NDN_OVERSIZE_VAR
Truncation due to insufficient buffer.
Definition: ndn-error-code.h:62
uint32_t max_size
Definition: encoder.h:25
uint32_t output_max_size
The size of the buffer to keep the encoding output.
Definition: encoder.h:39
static uint32_t encoder_get_offset(const ndn_encoder_t *encoder)
Get the offset of the encoder.
Definition: encoder.h:318
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.
Definition: encoder.h:224
uint8_t * output_value
The buffer to keep the encoding output.
Definition: encoder.h:35
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.
Definition: encoder.h:155
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.
Definition: encoder.h:173
static uint32_t encoder_probe_block_size(uint32_t type, uint32_t payload_size)
Probe the size of a TLV block.
Definition: encoder.h:82
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.
Definition: encoder.h:53
uint32_t size
Definition: encoder.h:24
static int encoder_append_type(ndn_encoder_t *encoder, uint32_t type)
Append a variable-length type (T) to the wire format buffer.
Definition: encoder.h:130
static int encoder_probe_uint_length(uint64_t value)
Probe the length of a non-negative int as the value (V).
Definition: encoder.h:243
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.
Definition: encoder.h:96
#define NDN_OVERSIZE
The object given is larger than expected.
Definition: ndn-error-code.h:33
The structure to keep the state when doing NDN TLV encoding.
Definition: encoder.h:31
static int encoder_move_forward(ndn_encoder_t *encoder, uint32_t step)
Move the encoder's offset forward by.
Definition: encoder.h:291
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.
Definition: encoder.h:189
static int encoder_append_length(ndn_encoder_t *encoder, uint32_t length)
Append a variable-length length (L) to the wire format buffer.
Definition: encoder.h:142
uint8_t * value
Definition: encoder.h:23
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.
Definition: encoder.h:206
static int encoder_move_backward(ndn_encoder_t *encoder, uint32_t step)
Move the encoder's offset backward by.
Definition: encoder.h:306