TypeLenVal
Loading...
Searching...
No Matches
tlv.h File Reference

Type-Length-Value (TLV) Data Serializer (Hardware-Agnostic) More...

#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <assert.h>

Go to the source code of this file.

Data Structures

struct  tlv_entry
struct  tlv_buf

Macros

#define TLV_TAGLEN_SIZE   (sizeof(tlv_tag_t) + sizeof(tlv_len_t))

Typedefs

typedef uint8_t tlv_tag_t
typedef uint8_t tlv_len_t

Functions

static void tlv_buf_init (struct tlv_buf *self, uint8_t *mem, const size_t cap)
static void tlv_entry_init (struct tlv_entry *self, const uint8_t tag, const uint8_t len, void *val)
static bool tlv_buf_push (struct tlv_buf *self, struct tlv_entry *entry)
static bool tlv_buf_pop (struct tlv_buf *self, struct tlv_entry *entry)
static void tlv_buf_reset_head (struct tlv_buf *self)
static void tlv_buf_reset (struct tlv_buf *self)
static size_t tlv_buf_get_occupied_mem_size (struct tlv_buf *self)
static size_t tlv_buf_get_free_mem_size (struct tlv_buf *self)

Detailed Description

Type-Length-Value (TLV) Data Serializer (Hardware-Agnostic)

This file contains the software implementation of the TLV logic. The design is hardware-agnostic, requiring an external adaptation layer for hardware interaction.

Conventions: C89, Linux kernel style, MISRA, rule of 10, No hardware specific code, only generic C and some binding layer. Be extra specific about types.

Scientific units where posible at end of the names, for example:

  • timer_10s (timer_10s has a resolution of 10s per bit)
  • power_150w (power 150W per bit or 0.15kw per bit)

Keep variables without units if they're unknown or not specified or hard to define with short notation.

Copyright (c) 2025 furdog <https://github.com/furdog>
SPDX-License-Identifier: 0BSD

Be free, be wise and take care of yourself! With best wishes and respect, furdog

Macro Definition Documentation

◆ TLV_TAGLEN_SIZE

#define TLV_TAGLEN_SIZE   (sizeof(tlv_tag_t) + sizeof(tlv_len_t))

Total size of tlv_tag_t and tlv_len_t

Typedef Documentation

◆ tlv_tag_t

typedef uint8_t tlv_tag_t

TLV tag data type

◆ tlv_len_t

typedef uint8_t tlv_len_t

TLV len data type

Function Documentation

◆ tlv_buf_init()

void tlv_buf_init ( struct tlv_buf * self,
uint8_t * mem,
const size_t cap )
static

Initialize TLV buffer. Provide pointer to uint8_t memory to be used by TLV entries and buffer capacity in bytes

◆ tlv_entry_init()

void tlv_entry_init ( struct tlv_entry * self,
const uint8_t tag,
const uint8_t len,
void * val )
static

Initialize TLV entry to be used by PUSH operation

◆ tlv_buf_push()

bool tlv_buf_push ( struct tlv_buf * self,
struct tlv_entry * entry )
static

Push(FIFO) tag, len and val to TLV buffer. Returns (bool) true on success

◆ tlv_buf_pop()

bool tlv_buf_pop ( struct tlv_buf * self,
struct tlv_entry * entry )
static

Pop(FIFO) entry from TLV buffer, which contains tag, len and val. Returns (bool) true on success

◆ tlv_buf_reset_head()

void tlv_buf_reset_head ( struct tlv_buf * self)
static

Resets TLV buffer head, so tlv_buf_pop will read the same data again

◆ tlv_buf_reset()

void tlv_buf_reset ( struct tlv_buf * self)
static

Resets TLV buffer to its initial state

◆ tlv_buf_get_occupied_mem_size()

size_t tlv_buf_get_occupied_mem_size ( struct tlv_buf * self)
static

Get occupied memory size

◆ tlv_buf_get_free_mem_size()

size_t tlv_buf_get_free_mem_size ( struct tlv_buf * self)
static

Get free(remaining) memory size