9.3 Writer
typedef struct peios_mp_writer peios_mp_writer;
peios_mp_writer *;
void ;
void ;
Create a writer, append values, take the bytes, free it (or reset to reuse). All the append calls return void — errors latch.
9.3.0.1 Scalars #
void ;
void ;
void ;
void ;
void ;
void ; /* UTF-8 */
void ;
Use peios_mp_write_int for signed and peios_mp_write_uint for unsigned values; both are stored in the smallest form. peios_mp_write_str takes UTF-8 with an explicit length (no NUL needed); peios_mp_write_bin takes arbitrary bytes.
9.3.0.2 Containers #
void ;
void ;
Write the header, then exactly the promised number of values. A map of count needs 2 * count values — count key/value pairs — written key, value, key, value…. An under- or over-filled container is not caught at the write call; it surfaces at peios_mp_writer_bytes, when the whole structure is validated.
/* {"user": "alice", "ok": true} */
;
; ;
; ;
9.3.0.3 Extensions and raw bytes #
void ;
void ;
peios_mp_write_extwrites a MessagePack extension value with a signed type id.peios_mp_write_rawappends pre-encoded MessagePack bytes verbatim — the escape hatch for splicing in a value you already have encoded. The result is still structurally validated as a whole atpeios_mp_writer_bytes, so you can't smuggle malformed bytes through it.
9.3.0.4 Taking the bytes #
ssize_t ;
int ;
peios_mp_writer_bytes confirms the buffer is exactly one well-formed top-level value, then borrows it: it writes a pointer to the encoded bytes through out (valid until the next mutating call on w) and returns the length. Pass out == NULL to validate and get the length without borrowing. It returns -1 with errno — EINVAL on a latched error or a malformed/under-filled structure, ENOMEM on a prior allocation failure. peios_mp_writer_error returns the latched errno directly, or 0.
Because this call validates, a successful peios_mp_writer_bytes is your guarantee the bytes are emit-ready.