SofaBuffers C/C++ 0.12.0
API Documentation
Loading...
Searching...
No Matches
istream.h File Reference

SofaBuffers C - Input stream decoder for Sofab messages. More...

#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include "sofab/sofab.h"
Include dependency graph for istream.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  sofab_istream_decoder
 Decoder context used for Sofab sequences. More...
 
struct  sofab_istream
 Internal state of the Sofab input stream. More...
 

Macros

#define SOFAB_ISTREAM_EXTERN   extern
 
#define SOFAB_ISTREAM_OPT_FIELDTYPE(type)   ((type) & 0x07)
 
#define SOFAB_ISTREAM_OPT_FIXLENTYPE(type)   (((type) & 0x07) << 3)
 
#define SOFAB_ISTREAM_OPT_STRINGTERM   (0x40)
 
#define SOFAB_ISTREAM_OPT_BOOLEAN   (0x80)
 

Typedefs

typedef struct sofab_istream sofab_istream_t
 Opaque Sofab input stream context.
 
typedef void(* sofab_istream_field_cb_t) (sofab_istream_t *ctx, sofab_id_t id, size_t size, size_t count, void *usrptr)
 Field callback invoked whenever a new field ID is decoded.
 
typedef struct sofab_istream_decoder sofab_istream_decoder_t
 Decoder context used for Sofab sequences.
 

Functions

void sofab_istream_init (sofab_istream_t *ctx, sofab_istream_field_cb_t field_callback, void *usrptr)
 Initializes a Sofab input stream context.
 
sofab_ret_t sofab_istream_feed (sofab_istream_t *ctx, const void *data, size_t datalen)
 Feeds raw Sofab-encoded bytes into the input stream.
 
void sofab_istream_invalidate (sofab_istream_t *ctx)
 Reject the message in progress from within a field callback.
 
void sofab_istream_read_field (sofab_istream_t *ctx, void *var, size_t varlen, uint8_t opt)
 Number of fields skipped because their wire type contradicted the destination a field callback bound.
 
static void sofab_istream_read_i8 (sofab_istream_t *ctx, int8_t *var)
 Reads an 8-bit signed integer.
 
static void sofab_istream_read_u8 (sofab_istream_t *ctx, uint8_t *var)
 Reads an 8-bit unsigned integer.
 
static void sofab_istream_read_i16 (sofab_istream_t *ctx, int16_t *var)
 Reads a 16-bit signed integer.
 
static void sofab_istream_read_u16 (sofab_istream_t *ctx, uint16_t *var)
 Reads a 16-bit unsigned integer.
 
static void sofab_istream_read_i32 (sofab_istream_t *ctx, int32_t *var)
 Reads a 32-bit signed integer.
 
static void sofab_istream_read_u32 (sofab_istream_t *ctx, uint32_t *var)
 Reads a 32-bit unsigned integer.
 
static void sofab_istream_read_i64 (sofab_istream_t *ctx, int64_t *var)
 Reads a 64-bit signed integer.
 
static void sofab_istream_read_u64 (sofab_istream_t *ctx, uint64_t *var)
 Reads a 64-bit unsigned integer.
 
static void sofab_istream_read_bool (sofab_istream_t *ctx, bool *var)
 Reads a boolean value.
 
static void sofab_istream_read_fp32 (sofab_istream_t *ctx, float *var)
 Reads a 32-bit floating-point value.
 
static void sofab_istream_read_fp64 (sofab_istream_t *ctx, double *var)
 Reads a 64-bit floating-point value.
 
static void sofab_istream_read_string (sofab_istream_t *ctx, char *var, size_t varlen)
 Reads a string of fixed maximum size.
 
static void sofab_istream_read_string_noterm (sofab_istream_t *ctx, char *var, size_t varlen)
 Reads a string of fixed maximum size.
 
static void sofab_istream_read_blob (sofab_istream_t *ctx, void *var, size_t varlen)
 Reads a binary blob of fixed maximum size.
 
void sofab_istream_read_array (sofab_istream_t *ctx, void *var, size_t element_count, size_t element_size, uint8_t opt)
 Reads an array of elements.
 
static void sofab_istream_read_array_of_i8 (sofab_istream_t *ctx, int8_t *var, size_t element_count)
 Reads an array of 8-bit signed integers.
 
static void sofab_istream_read_array_of_u8 (sofab_istream_t *ctx, uint8_t *var, size_t element_count)
 Reads an array of 8-bit unsigned integers.
 
static void sofab_istream_read_array_of_i16 (sofab_istream_t *ctx, int16_t *var, size_t element_count)
 Reads an array of 16-bit signed integers.
 
static void sofab_istream_read_array_of_u16 (sofab_istream_t *ctx, uint16_t *var, size_t element_count)
 Reads an array of 16-bit unsigned integers.
 
static void sofab_istream_read_array_of_i32 (sofab_istream_t *ctx, int32_t *var, size_t element_count)
 Reads an array of 32-bit signed integers.
 
static void sofab_istream_read_array_of_u32 (sofab_istream_t *ctx, uint32_t *var, size_t element_count)
 Reads an array of 32-bit unsigned integers.
 
static void sofab_istream_read_array_of_bool (sofab_istream_t *ctx, bool *var, size_t element_count)
 Reads an array of booleans.
 
static void sofab_istream_read_array_of_i64 (sofab_istream_t *ctx, int64_t *var, size_t element_count)
 Reads an array of 64-bit signed integers.
 
static void sofab_istream_read_array_of_u64 (sofab_istream_t *ctx, uint64_t *var, size_t element_count)
 Reads an array of 64-bit unsigned integers.
 
static void sofab_istream_read_array_of_fp32 (sofab_istream_t *ctx, float *var, size_t element_count)
 Reads an array of 32-bit floating-point values.
 
static void sofab_istream_read_array_of_fp64 (sofab_istream_t *ctx, double *var, size_t element_count)
 Reads an array of 64-bit floating-point values.
 
void sofab_istream_read_sequence (sofab_istream_t *ctx, sofab_istream_decoder_t *decoder, sofab_istream_field_cb_t field_callback, void *usrptr)
 Begins decoding a nested Sofab sequence.
 

Detailed Description

SofaBuffers C - Input stream decoder for Sofab messages.

This module implements a streaming decoder for SofaBuffers (Sofab), a compact, TLV-like (Type-Length-Value) serialization format. The decoder accepts data incrementally through sofab_istream_feed, interprets field headers, and automatically invokes user-provided field callbacks when new fields begin. Within these callbacks, the user must select an appropriate sofab_istream_read_*() function to bind a destination buffer or to start decoding nested sequences.

Typical usage:

  • Initialize a sofab_istream with a user context and a field callback.
  • Feed incoming data incrementally using sofab_istream_feed().
  • Dispatch fields in the callback and select the appropriate sofab_istream_read_*() function for reception.
  • Continue feeding data until the message is fully consumed.
  • After all data has been fed, the message data is available in the user-provided buffers.

SPDX-License-Identifier: MIT

Definition in file istream.h.