Wirepas SDK
tlv.h File Reference

Library to encode/decode buffers in TLV (Type Length Value) format. More...

Detailed Description

Library to encode/decode buffers in TLV (Type Length Value) format.

Definition in file tlv.h.

Go to the source code of this file.

Functions

void Tlv_init (tlv_record *rcd, uint8_t *buffer, uint8_t length)
 Initialize a TLV record. More...
 
tlv_res_e Tlv_Decode_getNextItem (tlv_record *rcd, tlv_item_t *item)
 Decode the next tlv_item in the tlv_record passed in parameter. More...
 
tlv_res_e Tlv_Encode_addItem (tlv_record *rcd, tlv_item_t *item)
 Add a TLV item to the buffer contained in the TLV record. More...
 
int Tlv_Encode_getBufferSize (tlv_record *rcd)
 Returns the size of the generated buffer by successive calls to Tlv_Encode_addItem. More...
 

Data Structures

struct  tlv_item_t
 Structure describing a Type Length Value item. More...
 
struct  tlv_record
 This structure holds the buffer containing TLV items and data to manage it, max. buffer size and current index. More...
 

Enumerations

enum  tlv_res_e { TLV_RES_OK, TLV_RES_ERROR, TLV_RES_END }
 List of return codes. More...
 

Function Documentation

◆ Tlv_Decode_getNextItem()

tlv_res_e Tlv_Decode_getNextItem ( tlv_record rcd,
tlv_item_t item 
)

Decode the next tlv_item in the tlv_record passed in parameter.

Parameters
[in]rcdPointer to a tlv_record structure to decode items from.
[in]itemPointer to a tlv_item. Updated by the call if return code is TLV_RES_OK
Returns
TLV_RES_OK if OK, see tlv_res_e otherwise.

◆ Tlv_Encode_addItem()

tlv_res_e Tlv_Encode_addItem ( tlv_record rcd,
tlv_item_t item 
)

Add a TLV item to the buffer contained in the TLV record.

Parameters
[in]rcdPointer to a tlv_record structure
[in]itemPointer to a tlv_item to add in the TLV record
Returns
TLV_RES_OK if OK or TLV_RES_ERROR if the buffer is to small to fit the new item.

◆ Tlv_Encode_getBufferSize()

int Tlv_Encode_getBufferSize ( tlv_record rcd)

Returns the size of the generated buffer by successive calls to Tlv_Encode_addItem.

Parameters
[in]rcdPointer to a tlv_record structure.
Returns
Total size of the buffer in bytes.

◆ Tlv_init()

void Tlv_init ( tlv_record rcd,
uint8_t *  buffer,
uint8_t  length 
)

Initialize a TLV record.

Parameters
[in]rcdPointer to the tlv_record structure to initialize.
[in]bufferBuffer used by the tlv_record.
[in]lengthSize in bytes of the buffer.
Note
This funtion must be used before using the Tlv_Decode_getNextItem or Tlv_Encode_addItem functions.

Data Structure Documentation

◆ tlv_item_t

struct tlv_item_t

Structure describing a Type Length Value item.

Definition at line 25 of file tlv.h.

Data Fields
uint8_t length

Length of the value buffer.

uint16_t type

Type of the TLV item.

uint8_t * value

Pointer to the buffer containing the value

◆ tlv_record

struct tlv_record

This structure holds the buffer containing TLV items and data to manage it, max. buffer size and current index.

Definition at line 36 of file tlv.h.

Data Fields
uint8_t * buffer

Pointer to a buffer containing TLV Items.

uint8_t index

Current encode/decode index in the buffer.

uint8_t length

Length of the buffer.

Enumeration Type Documentation

◆ tlv_res_e

enum tlv_res_e

List of return codes.

Enumerator
TLV_RES_OK 

Successfully decoded one TLV item from the buffer.

TLV_RES_ERROR 

Decode error, item is too long or lenth field is 0.

TLV_RES_END 

End of buffer, nothing to decode.

Definition at line 14 of file tlv.h.

15 {
16  TLV_RES_OK,
18  TLV_RES_END,
19 } tlv_res_e;
TLV_RES_ERROR
@ TLV_RES_ERROR
Definition: tlv.h:17
TLV_RES_OK
@ TLV_RES_OK
Definition: tlv.h:16
tlv_res_e
tlv_res_e
List of return codes.
Definition: tlv.h:14
TLV_RES_END
@ TLV_RES_END
Definition: tlv.h:18