|
CX Framework
Cross-platform C utility framework
|
Functions | |
| SerWriter * | serJsonWriterCreate (StreamBuffer *sb, flags_t flags) |
| SerReader * | serJsonReaderCreate (StreamBuffer *sb, flags_t flags) |
JSON cannot represent the data model losslessly, so the projection is defined rather than improvised. Each rule below is the behaviour, not a suggestion:
null; under SER_Strict they are an error instead.[key, value] arrays. The backend does not advertise SER_Cap_NonStringKeys, so the traverser projects it.float32 is written in the shortest form that reads back as the same float32.SER_EmitDefaults writes them anyway.SER_Strict it is an error.The transport is a StreamBuffer the caller owns and registers a consumer or producer on, the same as the rest of cx's JSON support. The backend only borrows the stream buffer: it neither ends nor releases it, so several documents may go into the same one.
| SerReader * serJsonReaderCreate | ( | StreamBuffer * | sb, |
| flags_t | flags | ||
| ) |
Creates a reader that parses JSON from a stream buffer.
| 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 * serJsonWriterCreate | ( | StreamBuffer * | sb, |
| flags_t | flags | ||
| ) |
Creates a writer that emits JSON 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_JSON_Pretty indents by 4 and breaks lines, SER_JSON_Compact strips every optional space; the default is one line with spaces after punctuation. Pretty wins if both are given. |