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

SofaBuffers C - Type definitions and constants. More...

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

Go to the source code of this file.

Macros

#define SOFAB_EXTERN   extern
 
#define SOFAB_API_VERSION   1
 SofaBuffers C API version.
 
#define SOFAB_UNSIGNED_MAX   (UINT64_MAX)
 
#define SOFAB_SIGNED_MAX   (INT64_MAX)
 
#define SOFAB_SIGNED_MIN   (INT64_MIN)
 
#define SOFAB_ID_MAX   (INT32_MAX)
 Largest encodable field id (the (id<<3)|type header must fit in sofab_unsigned_t).
 
#define SOFAB_MAX_DEPTH   (UINT8_MAX)
 Maximum sequence nesting depth.
 
#define SOFAB_MIN_OUTPUT_BUFFER   1
 Smallest output buffer this port accepts for streaming (CORELIB_PLAN §5.1).
 
#define SOFAB_STRICT_UTF8   0
 Wire-construct switches — what a reduced build does on the wire.
 
#define SOFAB_SKIP_COUNTER   0
 Count fields skipped because their wire type contradicted the read bound for them (MESSAGE_SPEC §7.3).
 
#define SOFAB_OBJECT_DESCR_SMALL   1
 Narrow unsigned/signed scalar varint values from 64-bit to 32-bit.
 
#define SOFAB_OBJECT_DESCR_MEDIUM   2
 
#define SOFAB_OBJECT_DESCR_BIG   3
 
#define SOFAB_OBJECT_DESCR_PROFILE   SOFAB_OBJECT_DESCR_MEDIUM
 Selected object descriptor profile (default: MEDIUM).
 
#define SOFAB_OBJECT_DESCR_ID_MAX   (UINT16_MAX)
 
#define SOFAB_OBJECT_DESCR_OFFSET_MAX   (UINT16_MAX)
 
#define SOFAB_OBJECT_DESCR_SIZE_MAX   (UINT16_MAX)
 
Format-wide ceilings (CORELIB_PLAN §6.2)

A declared length or element count above its ceiling is INVALID (§5.2.2), judged where the bytes that declare it are read (§5.2.3) — at the fixlen_word and at the element_count respectively.

§6.2 puts both ceilings at 2,147,483,647 and grants constrained profiles the allowance to lower them to 65,535. **This port takes that allowance exactly where the target forces it, and derives the value from SIZE_MAX rather than restating it per target.** The decoder narrows the declared length and count to size_t (istream.c), so a ceiling above SIZE_MAX would admit a value the target cannot represent and the narrowing would silently truncate it — turning an over-long field into a short or empty one and desynchronising the stream instead of rejecting it. Deriving from SIZE_MAX makes that unrepresentable: the ceiling is, by construction, never wider than what it is narrowed into. istream.c static-asserts exactly that.

The profile choice §6.2 requires be documented: 2,147,483,647 on every target whose size_t is 32-bit or wider, and 65,535 — the value §6.2 sanctions — where size_t is 16 bits (AVR).

Both are overridable (-DSOFAB_FIXLEN_MAX=... ) so a wide host can build with the constrained ceiling; that is how the lowered ceiling is exercised without a 16-bit target (test/c/test_limits.c). An override still has to fit in size_t — the static assertions hold it to that.

Note
The predecessor of this code tested SIZE_MAX == INT16_MAX. A 16-bit size_t has SIZE_MAX == UINT16_MAX (65535), never the signed 32767, so that branch was unreachable on every target and no profile ever got the constrained ceiling.
#define SOFAB_FIXLEN_MAX   (INT32_MAX)
 Maximum fixed-length field size in bytes.
 
#define SOFAB_ARRAY_MAX   (INT32_MAX)
 Maximum number of elements in an array.
 

Typedefs

typedef uint32_t sofab_id_t
 Field identifier type.
 
typedef uint64_t sofab_unsigned_t
 Scalar varint value types.
 
typedef int64_t sofab_signed_t
 Signed value type.
 
typedef uint16_t sofab_object_descr_id_t
 
typedef uint16_t sofab_object_descr_offset_t
 
typedef uint16_t sofab_object_descr_size_t
 
typedef char sofab_check_size_double[(sizeof(double)==8) ? 1 :-1]
 
typedef char sofab_check_size_float[(sizeof(float)==4) ? 1 :-1]
 
typedef char sofab_check_size_char_t[(sizeof(char)==1) ? 1 :-1]
 
typedef char sofab_check_size_uint8_t[(sizeof(uint8_t)==1) ? 1 :-1]
 
typedef char sofab_check_size_int8_t[(sizeof(int8_t)==1) ? 1 :-1]
 
typedef char sofab_check_size_uint16_t[(sizeof(uint16_t)==2) ? 1 :-1]
 
typedef char sofab_check_size_int16_t[(sizeof(int16_t)==2) ? 1 :-1]
 
typedef char sofab_check_size_uint32_t[(sizeof(uint32_t)==4) ? 1 :-1]
 
typedef char sofab_check_size_int32_t[(sizeof(int32_t)==4) ? 1 :-1]
 
typedef char sofab_check_size_uint64_t[(sizeof(uint64_t)==8) ? 1 :-1]
 
typedef char sofab_check_size_int64_t[(sizeof(int64_t)==8) ? 1 :-1]
 

Enumerations

enum  sofab_ret_t {
  SOFAB_RET_OK , SOFAB_RET_INCOMPLETE , SOFAB_RET_E_ARGUMENT , SOFAB_RET_E_BUFFER_FULL ,
  SOFAB_RET_E_INVALID_MSG , SOFAB_RET_E_LIMIT_EXCEEDED
}
 Return status codes. More...
 
enum  sofab_type_t {
  SOFAB_TYPE_VARINT_UNSIGNED = 0x00 , SOFAB_TYPE_VARINT_SIGNED = 0x01 , SOFAB_TYPE_FIXLEN = 0x02 , SOFAB_TYPE_VARINTARRAY_UNSIGNED = 0x03 ,
  SOFAB_TYPE_VARINTARRAY_SIGNED = 0x04 , SOFAB_TYPE_FIXLENARRAY = 0x05 , SOFAB_TYPE_SEQUENCE_START = 0x06 , SOFAB_TYPE_SEQUENCE_END = 0x07
}
 SofaBuffers 3bit field data types. More...
 
enum  sofab_fixlentype_t { SOFAB_FIXLENTYPE_FP32 = 0x00 , SOFAB_FIXLENTYPE_FP64 = 0x01 , SOFAB_FIXLENTYPE_STRING = 0x02 , SOFAB_FIXLENTYPE_BLOB = 0x03 }
 SofaBuffers 3bit fixed-length data types. More...
 

Detailed Description

SofaBuffers C - Type definitions and constants.

SPDX-License-Identifier: MIT

Definition in file sofab.h.