Skip to content

File syn_protobuf.h

FileList > src > syntropic > util > syn_protobuf.h

Go to the source code of this file

Zero-Allocation Protocol Buffers Serializer & Deserializer. More...

  • #include "syntropic/common/syn_defs.h"
  • #include <stdbool.h>
  • #include <stddef.h>
  • #include <stdint.h>

Classes

Type Name
struct SYN_PB_Decoder
struct SYN_PB_Encoder
struct SYN_PB_Tag

Public Functions

Type Name
SYN_Status syn_pb_decode_bytes (SYN_PB_Decoder * dec, const uint8_t ** bytes, size_t * len)
Decode a length-delimited byte array field.
SYN_Status syn_pb_decode_fixed32 (SYN_PB_Decoder * dec, uint32_t * value)
Decode a fixed 32-bit integer field value.
SYN_Status syn_pb_decode_tag (SYN_PB_Decoder * dec, SYN_PB_Tag * tag)
Decode the next field tag and wire type.
SYN_Status syn_pb_decode_varint (SYN_PB_Decoder * dec, uint64_t * value)
Decode a raw varint value.
SYN_Status syn_pb_decoder_init (SYN_PB_Decoder * dec, const uint8_t * buf, size_t size)
Initialize a Protobuf decoder instance.
SYN_Status syn_pb_encode_bool (SYN_PB_Encoder * enc, uint32_t field_number, bool value)
Encode a boolean field.
SYN_Status syn_pb_encode_bytes (SYN_PB_Encoder * enc, uint32_t field_number, const uint8_t * bytes, size_t len)
Encode a raw byte array field.
SYN_Status syn_pb_encode_fixed32 (SYN_PB_Encoder * enc, uint32_t field_number, uint32_t value)
Encode a fixed 32-bit integer field.
SYN_Status syn_pb_encode_int32 (SYN_PB_Encoder * enc, uint32_t field_number, int32_t value)
Encode a signed 32-bit integer field.
SYN_Status syn_pb_encode_string (SYN_PB_Encoder * enc, uint32_t field_number, const char * str)
Encode a UTF-8 string field.
SYN_Status syn_pb_encode_tag (SYN_PB_Encoder * enc, uint32_t field_number, uint8_t wire_type)
Encode field tag and wire type.
SYN_Status syn_pb_encode_uint32 (SYN_PB_Encoder * enc, uint32_t field_number, uint32_t value)
Encode an unsigned 32-bit integer field.
SYN_Status syn_pb_encode_varint (SYN_PB_Encoder * enc, uint64_t value)
Encode a raw varint value.
SYN_Status syn_pb_encoder_init (SYN_PB_Encoder * enc, uint8_t * buf, size_t capacity)
Initialize a Protobuf encoder instance.
SYN_Status syn_pb_skip_field (SYN_PB_Decoder * dec, uint8_t wire_type)
Skip unknown field based on wire type.

Macros

Type Name
define SYN_PB_WIRE_FIXED32 5U
define SYN_PB_WIRE_FIXED64 1U
define SYN_PB_WIRE_LENGTH_DELIMITED 2U
define SYN_PB_WIRE_VARINT 0U

Detailed Description

Provides varint (LEB128), fixed32/64, length-delimited string/bytes encoding and decoding for compact binary serialization on microcontrollers.

Public Functions Documentation

function syn_pb_decode_bytes

Decode a length-delimited byte array field.

SYN_Status syn_pb_decode_bytes (
    SYN_PB_Decoder * dec,
    const uint8_t ** bytes,
    size_t * len
) 

Parameters:

  • dec Pointer to decoder instance.
  • bytes Output byte array pointer pointer.
  • len Output byte array length pointer.

Returns:

SYN_OK on success, SYN_INVALID_PARAM or SYN_ERROR on EOF.


function syn_pb_decode_fixed32

Decode a fixed 32-bit integer field value.

SYN_Status syn_pb_decode_fixed32 (
    SYN_PB_Decoder * dec,
    uint32_t * value
) 

Parameters:

  • dec Pointer to decoder instance.
  • value Output 32-bit value pointer.

Returns:

SYN_OK on success, SYN_INVALID_PARAM or SYN_ERROR on EOF.


function syn_pb_decode_tag

Decode the next field tag and wire type.

SYN_Status syn_pb_decode_tag (
    SYN_PB_Decoder * dec,
    SYN_PB_Tag * tag
) 

Parameters:

  • dec Pointer to decoder instance.
  • tag Output tag structure pointer.

Returns:

SYN_OK on success, SYN_INVALID_PARAM or SYN_ERROR on EOF.


function syn_pb_decode_varint

Decode a raw varint value.

SYN_Status syn_pb_decode_varint (
    SYN_PB_Decoder * dec,
    uint64_t * value
) 

Parameters:

  • dec Pointer to decoder instance.
  • value Output 64-bit value pointer.

Returns:

SYN_OK on success, SYN_INVALID_PARAM or SYN_ERROR on EOF.


function syn_pb_decoder_init

Initialize a Protobuf decoder instance.

SYN_Status syn_pb_decoder_init (
    SYN_PB_Decoder * dec,
    const uint8_t * buf,
    size_t size
) 

Parameters:

  • dec Pointer to decoder instance.
  • buf Input byte buffer pointer.
  • size Input byte buffer length.

Returns:

SYN_OK on success, SYN_INVALID_PARAM if NULL.


function syn_pb_encode_bool

Encode a boolean field.

SYN_Status syn_pb_encode_bool (
    SYN_PB_Encoder * enc,
    uint32_t field_number,
    bool value
) 

Parameters:

  • enc Pointer to encoder instance.
  • field_number Field tag number.
  • value Boolean value.

Returns:

SYN_OK on success, SYN_INVALID_PARAM or SYN_ERROR on overflow.


function syn_pb_encode_bytes

Encode a raw byte array field.

SYN_Status syn_pb_encode_bytes (
    SYN_PB_Encoder * enc,
    uint32_t field_number,
    const uint8_t * bytes,
    size_t len
) 

Parameters:

  • enc Pointer to encoder instance.
  • field_number Field tag number.
  • bytes Pointer to input byte array.
  • len Length of byte array.

Returns:

SYN_OK on success, SYN_INVALID_PARAM or SYN_ERROR on overflow.


function syn_pb_encode_fixed32

Encode a fixed 32-bit integer field.

SYN_Status syn_pb_encode_fixed32 (
    SYN_PB_Encoder * enc,
    uint32_t field_number,
    uint32_t value
) 

Parameters:

  • enc Pointer to encoder instance.
  • field_number Field tag number.
  • value Fixed 32-bit integer value.

Returns:

SYN_OK on success, SYN_INVALID_PARAM or SYN_ERROR on overflow.


function syn_pb_encode_int32

Encode a signed 32-bit integer field.

SYN_Status syn_pb_encode_int32 (
    SYN_PB_Encoder * enc,
    uint32_t field_number,
    int32_t value
) 

Parameters:

  • enc Pointer to encoder instance.
  • field_number Field tag number.
  • value Signed 32-bit integer value.

Returns:

SYN_OK on success, SYN_INVALID_PARAM or SYN_ERROR on overflow.


function syn_pb_encode_string

Encode a UTF-8 string field.

SYN_Status syn_pb_encode_string (
    SYN_PB_Encoder * enc,
    uint32_t field_number,
    const char * str
) 

Parameters:

  • enc Pointer to encoder instance.
  • field_number Field tag number.
  • str Null-terminated string pointer.

Returns:

SYN_OK on success, SYN_INVALID_PARAM or SYN_ERROR on overflow.


function syn_pb_encode_tag

Encode field tag and wire type.

SYN_Status syn_pb_encode_tag (
    SYN_PB_Encoder * enc,
    uint32_t field_number,
    uint8_t wire_type
) 

Parameters:

  • enc Pointer to encoder instance.
  • field_number Field tag number.
  • wire_type Protobuf wire type (0, 1, 2, 5).

Returns:

SYN_OK on success, SYN_INVALID_PARAM or SYN_ERROR on overflow.


function syn_pb_encode_uint32

Encode an unsigned 32-bit integer field.

SYN_Status syn_pb_encode_uint32 (
    SYN_PB_Encoder * enc,
    uint32_t field_number,
    uint32_t value
) 

Parameters:

  • enc Pointer to encoder instance.
  • field_number Field tag number.
  • value Unsigned 32-bit integer value.

Returns:

SYN_OK on success, SYN_INVALID_PARAM or SYN_ERROR on overflow.


function syn_pb_encode_varint

Encode a raw varint value.

SYN_Status syn_pb_encode_varint (
    SYN_PB_Encoder * enc,
    uint64_t value
) 

Parameters:

  • enc Pointer to encoder instance.
  • value 64-bit value to encode.

Returns:

SYN_OK on success, SYN_INVALID_PARAM or SYN_ERROR on overflow.


function syn_pb_encoder_init

Initialize a Protobuf encoder instance.

SYN_Status syn_pb_encoder_init (
    SYN_PB_Encoder * enc,
    uint8_t * buf,
    size_t capacity
) 

Parameters:

  • enc Pointer to encoder instance.
  • buf Output byte buffer.
  • capacity Maximum buffer size in bytes.

Returns:

SYN_OK on success, SYN_INVALID_PARAM if NULL or zero.


function syn_pb_skip_field

Skip unknown field based on wire type.

SYN_Status syn_pb_skip_field (
    SYN_PB_Decoder * dec,
    uint8_t wire_type
) 

Parameters:

  • dec Pointer to decoder instance.
  • wire_type Wire type of field to skip.

Returns:

SYN_OK on success, SYN_INVALID_PARAM or SYN_ERROR on failure.


Macro Definition Documentation

define SYN_PB_WIRE_FIXED32

#define SYN_PB_WIRE_FIXED32 `5U`

fixed32, sfixed32, float


define SYN_PB_WIRE_FIXED64

#define SYN_PB_WIRE_FIXED64 `1U`

fixed64, sfixed64, double


define SYN_PB_WIRE_LENGTH_DELIMITED

#define SYN_PB_WIRE_LENGTH_DELIMITED `2U`

string, bytes, embedded messages


define SYN_PB_WIRE_VARINT

#define SYN_PB_WIRE_VARINT `0U`

Protobuf Wire Types int32, int64, uint32, uint64, bool, enum



The documentation for this class was generated from the following file src/syntropic/util/syn_protobuf.h