|
CX Framework
Cross-platform C utility framework
|
Enumerations | |
| enum | SerBinHeaderFlagsEnum { SER_BinHdr_SelfDescribing = (1 << 0) , SER_BinHdr_StringDedup = (1 << 1) , SER_BinHdr_Refs = (1 << 2) } |
| Header flag bits, recording how the body was encoded. More... | |
Functions | |
| SerWriter * | serBinaryWriterCreate (StreamBuffer *sb, flags_t flags) |
| SerReader * | serBinaryReaderCreate (StreamBuffer *sb, flags_t flags) |
A compact, lossless binary format. It advertises SER_Cap_Bytes, SER_Cap_ExactInt, and SER_Cap_Sizes, so nothing is lost or approximated the way it can be with JSON.
Documents are written and read strictly front-to-back, which makes this format a good fit for a socket or pipe. It is not meant for reading a large file at random; use a different backend for that.
A few notes on the encoding, useful if you need to inspect or debug a document:
SER_Bin_NoStringDedup is set) string values are deduplicated into a shared dictionary, so a repeated string only costs a few bytes after the first time it appears.Compact mode (SER_Bin_Compact) makes documents smaller by dropping the tag byte on values whose type the schema already pins down (integers, reals, byte runs). The trade-off: a compact document can only be read back with the exact schema it was written with, and an unrecognized field is an error rather than something that can be skipped. Use the default, self-describing mode if documents need to keep reading after the schema changes.
The reader detects the mode from the document itself, so you don't need to know how a document was written in order to read it.
Header flag bits, recording how the body was encoded.
| Enumerator | |
|---|---|
| SER_BinHdr_SelfDescribing | values carry tag bytes |
| SER_BinHdr_StringDedup | string values intern into the dictionary |
| SER_BinHdr_Refs | document may contain reference nodes |
Definition at line 59 of file serbinary.h.
| SerReader * serBinaryReaderCreate | ( | StreamBuffer * | sb, |
| flags_t | flags | ||
| ) |
Creates a reader that decodes binary from a stream buffer.
The document's header decides whether it is self-describing or compact and whether string values were interned; none of that has to be supplied here.
| sb | Stream buffer with a producer registered in pull mode. The reader registers as the consumer, taking a reference of its own; destroying it ends the consumer side and drops that reference, which spends the stream. The caller's own reference is untouched and still has to be released. |
| flags | SerFlagsEnum options |
Example:
| SerWriter * serBinaryWriterCreate | ( | StreamBuffer * | sb, |
| flags_t | flags | ||
| ) |
Creates a writer that emits binary to a stream buffer.
| sb | Stream buffer with a consumer registered in push mode. The writer registers as the producer, taking a reference of its own; finishing or destroying it ends the producer side and drops that reference, which spends the stream. The caller's own reference is untouched and still has to be released. |
| flags | SerFlagsEnum options. SER_Bin_Compact omits the tags the schema makes redundant, SER_Bin_NoStringDedup writes string values inline instead of interning them. |