SofaBuffers C/C++ 0.12.0
API Documentation
Loading...
Searching...
No Matches
sofab.h
Go to the documentation of this file.
1/*!
2 * @file sofab.h
3 * @brief SofaBuffers C - Type definitions and constants.
4 *
5 * SPDX-License-Identifier: MIT
6 */
7
8#ifndef SOFAB_H
9#define SOFAB_H
10
11/**
12 * @defgroup c_api C API
13 * @{
14 */
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20#ifndef SOFAB_C
21# define SOFAB_EXTERN extern
22#else
23# define SOFAB_EXTERN
24#endif
25
26/* includes *******************************************************************/
27#include <stdint.h>
28#include <stdbool.h>
29
30/* constants ******************************************************************/
31/*! @brief SofaBuffers C API version */
32#define SOFAB_API_VERSION 1
33
34/* macros *********************************************************************/
35
36/* types **********************************************************************/
37/*! @brief Return status codes */
38typedef enum
39{
40 /* Non-error outcomes first — kept low-numbered and contiguous, ahead of the
41 * error codes. INCOMPLETE is a valid (partial) result, not a failure. */
42 SOFAB_RET_OK, //!< OK
43 SOFAB_RET_INCOMPLETE, //!< Consumed bytes end inside a field or with an open
44 //!< sequence: a valid but partial decode. NOT an error —
45 //!< the caller owns end-of-input and may feed more bytes.
46 //!< Distinct from SOFAB_RET_OK (a complete message
47 //!< boundary) and SOFAB_RET_E_INVALID_MSG (malformed).
48 /* Error codes follow. */
49 SOFAB_RET_E_ARGUMENT, //!< The caller handed the library a value it cannot act
50 //!< on: an id above SOFAB_ID_MAX, a destination or
51 //!< descriptor width that is not 1/2/4/8, a descriptor
52 //!< field type that does not exist, or (with strict
53 //!< UTF-8 on) a `string` that is not valid UTF-8.
54 //!< Always a defect in the calling code, never in the
55 //!< data on the wire.
56 SOFAB_RET_E_BUFFER_FULL, //!< Sofab serialization failed due to buffer overflow
57 SOFAB_RET_E_INVALID_MSG, //!< Sofab deserialization failed: the message is malformed, or it
58 //!< carries a wire construct this build was compiled without (the
59 //!< SOFAB_DISABLE_*_SUPPORT switches below). **Terminal**: once
60 //!< sofab_istream_feed returns it, every subsequent feed on that
61 //!< context returns it too and no further callback fires
62 //!< (CORELIB_PLAN §5.2) — only sofab_istream_init resets it.
63 SOFAB_RET_E_LIMIT_EXCEEDED, //!< A configured receiver-side limit (CORELIB_PLAN §6.2.1) was
64 //!< exceeded on a schema-**unbounded** field. The message is
65 //!< well-formed — the same bytes decode under a looser limit — so
66 //!< it is neither SOFAB_RET_E_INVALID_MSG nor the INVALID outcome,
67 //!< but a terminal, receiver-local *policy* rejection (§6.3).
68 //!<
69 //!< **No C API function returns this code.** A receiver limit
70 //!< bounds a field the schema leaves unbounded, and this C API has
71 //!< no such field: every read is handed a destination that already
72 //!< exists, so its capacity is the bound (see @c sofab_object_field_t
73 //!< and sofab_istream_read_string / _read_blob / _read_array, all of
74 //!< which take the destination's own size). The code is declared
75 //!< here because @c sofab_ret_t is the C half of §6.3's shared code
76 //!< table: the C++ wrapper, whose string/blob/array destinations may
77 //!< be growable and therefore *can* be schema-unbounded, enforces the
78 //!< limits and reports them as @c sofab::Error::LimitExceeded, which
79 //!< is this enumerator. Declaring it once here is what keeps the two
80 //!< enums a single numbering.
82
83/*! @brief SofaBuffers 3bit field data types */
95
96/*! @brief SofaBuffers 3bit fixed-length data types */
104
105/*! @brief Field identifier type */
106typedef uint32_t sofab_id_t;
107
108/*! @brief Scalar varint value types.
109 *
110 * By default the unsigned/signed scalar values carried by varint fields are
111 * 64-bit. Defining @ref SOFAB_DISABLE_INT64_SUPPORT narrows them to 32-bit,
112 * which removes the 64-bit varint math (smaller/faster on 32-bit MCUs) at the
113 * cost of the 64-bit value range and wire compatibility for larger values —
114 * see the @c SOFAB_DISABLE_INT64_SUPPORT notes below before enabling it.
115 */
116#if !defined(SOFAB_DISABLE_INT64_SUPPORT)
117/*! @brief Unsigned value type */
118typedef uint64_t sofab_unsigned_t;
119#define SOFAB_UNSIGNED_MAX (UINT64_MAX)
120
121/*! @brief Signed value type */
122typedef int64_t sofab_signed_t;
123#define SOFAB_SIGNED_MAX (INT64_MAX)
124#define SOFAB_SIGNED_MIN (INT64_MIN)
125
126/*! @brief Largest encodable field id (the (id<<3)|type header must fit in
127 * @ref sofab_unsigned_t). */
128#define SOFAB_ID_MAX (INT32_MAX)
129#else
130/*! @brief Unsigned value type (32-bit; see SOFAB_DISABLE_INT64_SUPPORT) */
131typedef uint32_t sofab_unsigned_t;
132#define SOFAB_UNSIGNED_MAX (UINT32_MAX)
133
134/*! @brief Signed value type (32-bit; see SOFAB_DISABLE_INT64_SUPPORT) */
135typedef int32_t sofab_signed_t;
136#define SOFAB_SIGNED_MAX (INT32_MAX)
137#define SOFAB_SIGNED_MIN (INT32_MIN)
138
139/*! @brief Largest encodable field id. The (id<<3)|type header is itself a
140 * varint accumulated in @ref sofab_unsigned_t, so with 32-bit values the id
141 * is capped to what leaves room for the 3 type bits (UINT32_MAX >> 3). */
142#define SOFAB_ID_MAX (UINT32_MAX >> 3)
143#endif /* !defined(SOFAB_DISABLE_INT64_SUPPORT) */
144
145/*! @name Format-wide ceilings (CORELIB_PLAN §6.2)
146 *
147 * A declared length or element count above its ceiling is `INVALID` (§5.2.2),
148 * judged where the bytes that declare it are read (§5.2.3) — at the
149 * @c fixlen_word and at the @c element_count respectively.
150 *
151 * §6.2 puts both ceilings at 2,147,483,647 and grants constrained profiles the
152 * allowance to lower them to 65,535. **This port takes that allowance exactly
153 * where the target forces it, and derives the value from @c SIZE_MAX rather
154 * than restating it per target.** The decoder narrows the declared length and
155 * count to @c size_t (istream.c), so a ceiling above @c SIZE_MAX would admit a
156 * value the target cannot represent and the narrowing would silently truncate
157 * it — turning an over-long field into a short or empty one and desynchronising
158 * the stream instead of rejecting it. Deriving from @c SIZE_MAX makes that
159 * unrepresentable: the ceiling is, by construction, never wider than what it is
160 * narrowed into. istream.c static-asserts exactly that.
161 *
162 * **The profile choice §6.2 requires be documented:** 2,147,483,647 on every
163 * target whose @c size_t is 32-bit or wider, and 65,535 — the value §6.2
164 * sanctions — where @c size_t is 16 bits (AVR).
165 *
166 * Both are overridable (@c -DSOFAB_FIXLEN_MAX=... ) so a wide host can build
167 * with the constrained ceiling; that is how the lowered ceiling is exercised
168 * without a 16-bit target (test/c/test_limits.c). An override still has to fit
169 * in @c size_t — the static assertions hold it to that.
170 *
171 * @note The predecessor of this code tested `SIZE_MAX == INT16_MAX`. A 16-bit
172 * @c size_t has @c SIZE_MAX == @c UINT16_MAX (65535), never the *signed*
173 * 32767, so that branch was unreachable on every target and no profile
174 * ever got the constrained ceiling.
175 * @{
176 */
177
178/*! @brief Maximum fixed-length field size in bytes */
179#if !defined(SOFAB_FIXLEN_MAX)
180# if SIZE_MAX < INT32_MAX
181# define SOFAB_FIXLEN_MAX (SIZE_MAX)
182# else
183# define SOFAB_FIXLEN_MAX (INT32_MAX)
184# endif
185#endif
186
187/*! @brief Maximum number of elements in an array */
188#if !defined(SOFAB_ARRAY_MAX)
189# if SIZE_MAX < INT32_MAX
190# define SOFAB_ARRAY_MAX (SIZE_MAX)
191# else
192# define SOFAB_ARRAY_MAX (INT32_MAX)
193# endif
194#endif
195
196/*! @} */
197
198/*! @brief Maximum sequence nesting depth.
199 *
200 * A message may nest sequences at most @c SOFAB_MAX_DEPTH levels deep; a decode
201 * that would exceed this bound is rejected with @ref SOFAB_RET_E_INVALID_MSG.
202 * The limit governs the skip path — nested sequences the caller does not bind
203 * with @c sofab_istream_read_sequence() — where the depth counter is a
204 * @c uint8_t. Actively-decoded nesting is instead bounded by the number of
205 * caller-provided decoder handles (see @c sofab_object_decoder_t::depth). */
206#define SOFAB_MAX_DEPTH (UINT8_MAX)
207
208/*! @brief Smallest output buffer this port accepts **for streaming**
209 * (CORELIB_PLAN §5.1).
210 *
211 * This port declares **1**. Every writer here reaches the buffer through a
212 * single byte-at-a-time push that flushes and continues when the buffer is
213 * full, so nothing has to land contiguously: a field header varint, a
214 * @c fixlen_word, an @c element_count, an integer value and an fp32/fp64
215 * element may each be split across a flush at any byte. §5.1 calls that
216 * byte-granular case "fully conformant, and the right choice for a footprint
217 * profile" -- a port declaring 1 imposes no requirement on its caller at all.
218 *
219 * **Streaming only.** The minimum binds a buffer installed together with a
220 * flush callback -- at @c sofab_ostream_init() and at every
221 * @c sofab_ostream_buffer_set() -- which must satisfy
222 * @c buflen @c - @c offset @c >= @c SOFAB_MIN_OUTPUT_BUFFER. A buffer installed
223 * *without* a callback is subject to no minimum: no flush can occur, so no unit
224 * can be split, and the buffer either holds the message or reports
225 * @ref SOFAB_RET_E_BUFFER_FULL. That is the case a caller sizes from a
226 * generated @c MAX_SIZE, and it stays exact -- a message that encodes to two
227 * bytes encodes into a two-byte buffer whatever this constant says.
228 *
229 * **Not a build knob.** Unlike @c SOFAB_LAZY_SEQ_DEPTH this states what the
230 * encoder *does*, not what the caller may configure: raising it would not make
231 * any write land contiguously, it would only misinform the caller. Defining it
232 * from the build is therefore an error rather than a silent redefinition.
233 *
234 * **Ceiling 20** (§5.1): a header varint and its value, 2 x 10, which is also
235 * the largest message a schema can bound to a single scalar field. Reserving
236 * further ahead must be handled by flushing, not by raising this declaration.
237 * The check below guards an edit to the value here against that ceiling. */
238#if defined(SOFAB_MIN_OUTPUT_BUFFER)
239# error "SOFAB_MIN_OUTPUT_BUFFER states what this encoder does; it is not configurable"
240#endif
241#define SOFAB_MIN_OUTPUT_BUFFER 1
242
243#if SOFAB_MIN_OUTPUT_BUFFER < 1 || SOFAB_MIN_OUTPUT_BUFFER > 20
244# error "SOFAB_MIN_OUTPUT_BUFFER must be 1..20 (CORELIB_PLAN §5.1)"
245#endif
246
247// disable double support automatically on platforms where double is not 8 bytes
248#if defined(__SIZEOF_DOUBLE__) && __SIZEOF_DOUBLE__ != 8
249# define SOFAB_DISABLE_FP64_SUPPORT
250#endif
251
252/* configuration **************************************************************/
253/*!
254 * @brief Wire-construct switches — what a reduced build does on the wire.
255 *
256 * @warning The @c SOFAB_DISABLE_*_SUPPORT switches below remove a **wire
257 * construct**, not merely the ability to store one. A decoder built without a
258 * construct **rejects** any message that carries it with
259 * @ref SOFAB_RET_E_INVALID_MSG — terminally, per
260 * @ref sofab_istream_feed — even where the field would otherwise have been
261 * skipped: an unknown id, a field the callback declined, or a field inside a
262 * sequence nobody bound. The decoder is schema-agnostic and cannot tell those
263 * apart from a field the caller wanted.
264 *
265 * The consequence is an **interop bound, and it is the caller's to manage**: such
266 * a build only talks to peers that never emit the removed construct, in any field,
267 * ever — including fields added by a later revision of the schema. That rules out
268 * the usual forward-compatibility story, where a reader ignores ids it does not
269 * know (MESSAGE_SPEC §7.3 describes the skip a full build performs). Enable these
270 * when both ends of the link are yours and the wire profile is fixed; do not
271 * enable them on a receiver exposed to messages you do not control.
272 *
273 * Nothing is silently dropped either way: the message is rejected, never
274 * half-accepted. But note that fields *preceding* the offending one have already
275 * been delivered to the callback when the rejection lands — @ref sofab_istream_feed
276 * documents what the caller must do about that.
277 */
278
279/*! @brief Disable support for 64-bit floating point types (if the check above fails).
280 * Rejects any message carrying an fp64 fixlen subtype — see the warning above. */
281// #define SOFAB_DISABLE_FP64_SUPPORT
282
283/*! @brief Disable support for fixed-length fields (floating point types, strings, and blobs).
284 * Rejects any message carrying a fixlen or fixlen-array field — see the warning above. */
285// #define SOFAB_DISABLE_FIXLEN_SUPPORT
286
287/*! @brief Disable support for array fields.
288 * Rejects any message carrying an array field — see the warning above. */
289// #define SOFAB_DISABLE_ARRAY_SUPPORT
290
291/*! @brief Disable support for sequence fields.
292 * Rejects any message carrying a sequence — see the warning above. */
293// #define SOFAB_DISABLE_SEQUENCE_SUPPORT
294
295/*! @brief Disable integer overflow checks when reading integer values. */
296// #define SOFAB_DISABLE_INTEGER_OVERFLOW_CHECK
297
298/*!
299 * @brief Disable the encode-side bound refusal.
300 *
301 * By default @ref sofab_object_encode reads a @c STRING field bounded by its
302 * own storage (@c char[maxlen + 1]) and refuses, with
303 * @ref SOFAB_RET_E_ARGUMENT, a value that fills that storage without a
304 * terminator: it is longer than the field's @c maxlen. Defining this switch
305 * removes the refusal (a compare and a branch per string field) for a caller
306 * that guarantees its strings are terminated within their bound; the read stays
307 * bounded, so such a value is emitted as the whole buffer instead of read past
308 * it. The C++ wrapper reads the same switch as @c sofab::ENCODE_BOUNDS. A
309 * sized blob's length and a sized array's or wrapper holder's element count are
310 * clamped to the capacity in either build (the documented clamp contract), and
311 * decode-side bound checks are not affected.
312 */
313// #define SOFAB_DISABLE_ENCODE_BOUNDS
314
315/*!
316 * @brief Strict UTF-8 validation of @c string fields (default OFF — opt-in).
317 *
318 * A @c string payload is UTF-8 (MESSAGE_SPEC §8); @c blob is the type for
319 * opaque bytes. With strict validation enabled a @c string whose bytes are not
320 * valid UTF-8 is rejected @b symmetrically (CORELIB_PLAN §6.4):
321 * - @b decode: a materialized (read, not skipped) @c string with invalid bytes
322 * makes the message the @ref SOFAB_RET_E_INVALID_MSG outcome — the same
323 * terminal class as any other malformed message. Skipped @c string fields are
324 * never validated (wire validity of unread content is the producer's
325 * responsibility). Cross-chunk: a multi-byte sequence split at end-of-chunk
326 * stays @ref SOFAB_RET_INCOMPLETE; only a sequence still ill-formed once the
327 * complete declared payload has arrived is @c INVALID.
328 * - @b encode: a @c string value that is not valid UTF-8 is refused with
329 * @ref SOFAB_RET_E_ARGUMENT (@c sofab_ostream_write_fixlen with the
330 * @ref SOFAB_FIXLENTYPE_STRING subtype). @c blob bytes are never validated.
331 *
332 * This is a @b validation @b policy, never a wire-format switch: it only decides
333 * accept-vs-reject and never changes how valid data is encoded, so peers with
334 * different settings interoperate on all valid data. It is @b never lossy — an
335 * invalid @c string is rejected, never silently replaced with @c U+FFFD or
336 * truncated, in either direction and in either state.
337 *
338 * This is a @b footprint/embedded corelib (the @c c and @c c-cpp targets), so
339 * the check @b defaults @b OFF and is @b opt-in — the constrained-profile
340 * allowance in CORELIB_PLAN §6.4 (a documented non-strict build; zero
341 * @c .text / @c .rodata cost when OFF, since @c utf8.c and every gated site
342 * compile to nothing). With the check OFF the wire bytes are stored verbatim
343 * (byte-container behavior), never lossy — an invalid @c string is never
344 * silently replaced or dropped, only accepted verbatim.
345 *
346 * The check follows the corelib's opt-in style: it is enabled by defining
347 * @c SOFAB_ENABLE_STRICT_UTF8 (conformance/fuzzer/CI builds do this). A direct
348 * @c -DSOFAB_STRICT_UTF8=1 also works and wins over both knobs. The legacy
349 * @c SOFAB_DISABLE_STRICT_UTF8 opt-out is still honored — it forces the check
350 * OFF, which is now also the default, so it is harmless. The resolved boolean
351 * @ref SOFAB_STRICT_UTF8 (1 when on, 0 when off) is what the corelib and
352 * generated code gate on, so flipping the flag never requires regenerating code.
353 */
354// #define SOFAB_ENABLE_STRICT_UTF8
355#if !defined(SOFAB_STRICT_UTF8)
356# if defined(SOFAB_ENABLE_STRICT_UTF8) && !defined(SOFAB_DISABLE_STRICT_UTF8)
357# define SOFAB_STRICT_UTF8 1
358# else
359# define SOFAB_STRICT_UTF8 0
360# endif
361#endif
362
363/*!
364 * @brief Count fields skipped because their wire type contradicted the read
365 * bound for them (MESSAGE_SPEC §7.3).
366 *
367 * Such a skip is normal traffic, not an error: it is how a reader and a writer
368 * built from different revisions of a schema keep talking. The counter exists
369 * only so an application can *notice* it — a non-zero count after a successful
370 * decode means the two sides disagree about what an id means, which belongs in a
371 * log line or a health metric. Nothing in the decode path reads it.
372 *
373 * Being a pure diagnostic, it follows the same opt-in style as
374 * @ref SOFAB_STRICT_UTF8 and @b defaults @b OFF for this footprint corelib.
375 * Measured cost when ON: 16–24 bytes of @c .text (the saturating increment plus
376 * @ref sofab_istream_skipped), and no @c .data / @c .bss — the counter shares
377 * the alignment padding the context already had. Enable it by defining
378 * @c SOFAB_ENABLE_SKIP_COUNTER; a direct @c -DSOFAB_SKIP_COUNTER=1 also works
379 * and wins. The resolved boolean @ref SOFAB_SKIP_COUNTER is what the corelib and
380 * the C++ wrapper gate on.
381 */
382// #define SOFAB_ENABLE_SKIP_COUNTER
383#if !defined(SOFAB_SKIP_COUNTER)
384# if defined(SOFAB_ENABLE_SKIP_COUNTER) && !defined(SOFAB_DISABLE_SKIP_COUNTER)
385# define SOFAB_SKIP_COUNTER 1
386# else
387# define SOFAB_SKIP_COUNTER 0
388# endif
389#endif
390
391/*!
392 * @brief Narrow unsigned/signed scalar varint values from 64-bit to 32-bit.
393 *
394 * Changes @ref sofab_unsigned_t / @ref sofab_signed_t to 32-bit and removes the
395 * 64-bit integer convenience API (read_u64/read_i64, write/read array_of_u64 and
396 * array_of_i64). Useful on 32-bit MCUs where 64-bit varint math is emulated.
397 *
398 * @warning Change only if you know what you are doing — side effects:
399 * - @b Wire @b compatibility: the format itself is width-agnostic, so messages
400 * whose every value fits in 32 bits stay byte-identical and interoperable.
401 * A value beyond 32-bit range from a 64-bit peer is rejected as a malformed
402 * message (@ref SOFAB_RET_E_INVALID_MSG) and never silently truncated.
403 * - @b ABI: the value types appear in public signatures and context structs, so
404 * 32-bit and 64-bit builds are not ABI-compatible — do not mix them.
405 * - @b Field @b ids: @ref SOFAB_ID_MAX shrinks to @c UINT32_MAX>>3, because the
406 * field header is itself a varint of @c (id<<3)|type.
407 * - @b Conformance: the shipped test vectors include 64-bit values and will not
408 * decode in this mode.
409 */
410// #define SOFAB_DISABLE_INT64_SUPPORT
411
412/* object descriptor configuration ********************************************/
413/*!
414 * @brief Object descriptor size profiles.
415 *
416 * The integer widths used for the @ref sofab_object_descr_field_t members
417 * @c id, @c offset and @c size are selectable so the descriptor footprint can
418 * be tuned to the messages actually in use. Smaller profiles shrink every
419 * descriptor table at the cost of a lower addressable range.
420 *
421 * @c offset and @c size both index into the described object structure, so
422 * they always share the same width; @c id is bounded by the highest field ID
423 * in use. All three follow the selected profile.
424 *
425 * Profiles are ordered ascending by capacity so generated code can verify at
426 * compile time that the corelib is configured wide enough, e.g.
427 * @code
428 * // require at least 16-bit descriptors
429 * #if SOFAB_OBJECT_DESCR_PROFILE < SOFAB_OBJECT_DESCR_MEDIUM
430 * # error "generated descriptors require at least the MEDIUM profile"
431 * #endif
432 *
433 * // or check concrete limits
434 * #if MY_MESSAGE_MAX_FIELD_ID > SOFAB_OBJECT_DESCR_ID_MAX
435 * # error "field IDs exceed the configured descriptor id width"
436 * #endif
437 * @endcode
438 *
439 * A field that does not fit the selected profile is a compile error naming the
440 * ceiling, not a silently truncated offset: every @c SOFAB_OBJECT_FIELD* macro
441 * checks its id, offset and size against the three maxima below
442 * (@c SOFAB_OBJECT_ASSERT_FITS_PROFILE in object.h). The check generates no code.
443 */
444#define SOFAB_OBJECT_DESCR_SMALL 1 /*!< uint8_t id/offset/size (max 255) */
445#define SOFAB_OBJECT_DESCR_MEDIUM 2 /*!< uint16_t id/offset/size (max 65535) */
446#define SOFAB_OBJECT_DESCR_BIG 3 /*!< uint32_t id/offset/size (max 4294967295) */
447
448/*! @brief Selected object descriptor profile (default: MEDIUM). */
449#ifndef SOFAB_OBJECT_DESCR_PROFILE
450# define SOFAB_OBJECT_DESCR_PROFILE SOFAB_OBJECT_DESCR_MEDIUM
451#endif
452
453#if SOFAB_OBJECT_DESCR_PROFILE == SOFAB_OBJECT_DESCR_SMALL
454typedef uint8_t sofab_object_descr_id_t;
455typedef uint8_t sofab_object_descr_offset_t;
456typedef uint8_t sofab_object_descr_size_t;
457# define SOFAB_OBJECT_DESCR_ID_MAX (UINT8_MAX)
458# define SOFAB_OBJECT_DESCR_OFFSET_MAX (UINT8_MAX)
459# define SOFAB_OBJECT_DESCR_SIZE_MAX (UINT8_MAX)
460#elif SOFAB_OBJECT_DESCR_PROFILE == SOFAB_OBJECT_DESCR_MEDIUM
461typedef uint16_t sofab_object_descr_id_t;
464# define SOFAB_OBJECT_DESCR_ID_MAX (UINT16_MAX)
465# define SOFAB_OBJECT_DESCR_OFFSET_MAX (UINT16_MAX)
466# define SOFAB_OBJECT_DESCR_SIZE_MAX (UINT16_MAX)
467#elif SOFAB_OBJECT_DESCR_PROFILE == SOFAB_OBJECT_DESCR_BIG
468typedef uint32_t sofab_object_descr_id_t;
469typedef uint32_t sofab_object_descr_offset_t;
470typedef uint32_t sofab_object_descr_size_t;
471# define SOFAB_OBJECT_DESCR_ID_MAX (UINT32_MAX)
472# define SOFAB_OBJECT_DESCR_OFFSET_MAX (UINT32_MAX)
473# define SOFAB_OBJECT_DESCR_SIZE_MAX (UINT32_MAX)
474#else
475# error "SOFAB_OBJECT_DESCR_PROFILE must be SOFAB_OBJECT_DESCR_SMALL, _MEDIUM or _BIG"
476#endif
477
478/* sanity checks **************************************************************/
479#if !defined(__SIZEOF_DOUBLE__) && !defined(SOFAB_DISABLE_FP64_SUPPORT)
480typedef char sofab_check_size_double[(sizeof(double) == 8) ? 1 : -1];
481#endif
482
483typedef char sofab_check_size_float[(sizeof(float) == 4) ? 1 : -1];
484typedef char sofab_check_size_char_t[(sizeof(char) == 1) ? 1 : -1];
485typedef char sofab_check_size_uint8_t[(sizeof(uint8_t) == 1) ? 1 : -1];
486typedef char sofab_check_size_int8_t[(sizeof(int8_t) == 1) ? 1 : -1];
487typedef char sofab_check_size_uint16_t[(sizeof(uint16_t) == 2) ? 1 : -1];
488typedef char sofab_check_size_int16_t[(sizeof(int16_t) == 2) ? 1 : -1];
489typedef char sofab_check_size_uint32_t[(sizeof(uint32_t) == 4) ? 1 : -1];
490typedef char sofab_check_size_int32_t[(sizeof(int32_t) == 4) ? 1 : -1];
491typedef char sofab_check_size_uint64_t[(sizeof(uint64_t) == 8) ? 1 : -1];
492typedef char sofab_check_size_int64_t[(sizeof(int64_t) == 8) ? 1 : -1];
493
494/* exported vars **************************************************************/
495// SOFAB_EXTERN type sofab_<varname>;
496
497/* prototypes *****************************************************************/
498
499#ifdef __cplusplus
500}
501#endif
502
503/** @} */ // end of defgroup
504
505#endif /* SOFAB_H */
uint16_t sofab_object_descr_offset_t
Definition sofab.h:462
char sofab_check_size_char_t[(sizeof(char)==1) ? 1 :-1]
Definition sofab.h:484
sofab_fixlentype_t
SofaBuffers 3bit fixed-length data types.
Definition sofab.h:98
char sofab_check_size_double[(sizeof(double)==8) ? 1 :-1]
Definition sofab.h:480
char sofab_check_size_int16_t[(sizeof(int16_t)==2) ? 1 :-1]
Definition sofab.h:488
char sofab_check_size_int8_t[(sizeof(int8_t)==1) ? 1 :-1]
Definition sofab.h:486
char sofab_check_size_uint64_t[(sizeof(uint64_t)==8) ? 1 :-1]
Definition sofab.h:491
uint16_t sofab_object_descr_size_t
Definition sofab.h:463
uint32_t sofab_id_t
Field identifier type.
Definition sofab.h:106
uint16_t sofab_object_descr_id_t
Definition sofab.h:461
char sofab_check_size_uint8_t[(sizeof(uint8_t)==1) ? 1 :-1]
Definition sofab.h:485
uint64_t sofab_unsigned_t
Scalar varint value types.
Definition sofab.h:118
char sofab_check_size_float[(sizeof(float)==4) ? 1 :-1]
Definition sofab.h:483
char sofab_check_size_int64_t[(sizeof(int64_t)==8) ? 1 :-1]
Definition sofab.h:492
sofab_ret_t
Return status codes.
Definition sofab.h:39
char sofab_check_size_int32_t[(sizeof(int32_t)==4) ? 1 :-1]
Definition sofab.h:490
char sofab_check_size_uint32_t[(sizeof(uint32_t)==4) ? 1 :-1]
Definition sofab.h:489
int64_t sofab_signed_t
Signed value type.
Definition sofab.h:122
sofab_type_t
SofaBuffers 3bit field data types.
Definition sofab.h:85
char sofab_check_size_uint16_t[(sizeof(uint16_t)==2) ? 1 :-1]
Definition sofab.h:487
@ SOFAB_FIXLENTYPE_FP32
Definition sofab.h:99
@ SOFAB_FIXLENTYPE_STRING
Definition sofab.h:101
@ SOFAB_FIXLENTYPE_FP64
Definition sofab.h:100
@ SOFAB_FIXLENTYPE_BLOB
Definition sofab.h:102
@ SOFAB_RET_INCOMPLETE
Consumed bytes end inside a field or with an open sequence: a valid but partial decode.
Definition sofab.h:43
@ SOFAB_RET_OK
OK.
Definition sofab.h:42
@ SOFAB_RET_E_INVALID_MSG
Sofab deserialization failed: the message is malformed, or it carries a wire construct this build was...
Definition sofab.h:57
@ SOFAB_RET_E_LIMIT_EXCEEDED
A configured receiver-side limit (CORELIB_PLAN §6.2.1) was exceeded on a schema-**unbounded** field.
Definition sofab.h:63
@ SOFAB_RET_E_ARGUMENT
The caller handed the library a value it cannot act on: an id above SOFAB_ID_MAX, a destination or de...
Definition sofab.h:49
@ SOFAB_RET_E_BUFFER_FULL
Sofab serialization failed due to buffer overflow.
Definition sofab.h:56
@ SOFAB_TYPE_FIXLEN
Definition sofab.h:88
@ SOFAB_TYPE_VARINTARRAY_SIGNED
Definition sofab.h:90
@ SOFAB_TYPE_VARINT_SIGNED
Definition sofab.h:87
@ SOFAB_TYPE_SEQUENCE_START
Definition sofab.h:92
@ SOFAB_TYPE_FIXLENARRAY
Definition sofab.h:91
@ SOFAB_TYPE_SEQUENCE_END
Definition sofab.h:93
@ SOFAB_TYPE_VARINT_UNSIGNED
Definition sofab.h:86
@ SOFAB_TYPE_VARINTARRAY_UNSIGNED
Definition sofab.h:89