ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
msgpack.h
Go to the documentation of this file.
1// ProtoCore v1.0.16 - Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file msgpack.h
6 * @brief Layer 6 (Presentation) - zero-heap MessagePack encoder and decoder.
7 *
8 * A streaming encoder that writes directly into a caller-provided buffer (no
9 * heap), the MessagePack-format sibling of the CBOR / JSON writers. Each value is
10 * emitted in the shortest MessagePack form (fixint / fixstr / fixarray / fixmap
11 * where possible). Emit definite-length arrays and maps by writing the header
12 * (MsgPack.put_array / MsgPack.put_map with the item count) then that many items (twice
13 * that for a map: key, value, key, value, ...).
14 *
15 * Overflow is tracked, not crashed on: writes past the buffer set the span's overflow
16 * flag and stop, while the span's pos keeps counting the bytes the full payload
17 * would need, so a caller can size the buffer and check spat.ok().
18 *
19 * The decoder is a cursor: MsgPack.peek() reports the next object's type and the
20 * MsgPack.get_* calls consume it (strings and binary point into the source buffer,
21 * no copy). Any malformed or out-of-bounds read sets a sticky error - check
22 * spat.cok(). ext and the unused 0xc1 byte are reported as INVALID.
23 *
24 * @author Douglas Quigg (dstroy0)
25 * @date 2026
26 */
27
28#ifndef PROTOCORE_MSGPACK_H
29#define PROTOCORE_MSGPACK_H
30
31#include "protocore_config.h" // the entry point: protocore_types.h for the widths
32
33#if PROTOCORE_ENABLE_MSGPACK
34
35#include "network_drivers/presentation/codec/codec.h" // protocore_codec_type - one item vocabulary
36#include "spatium/spatium.h" // mmgr_span / mmgr_cspan - the region, bound with spat.from()
37
39
40// The encoder writes into a mmgr_span and the decoder reads from a mmgr_cspan. Bind with
41// spat.from(), check with spat.ok(), and take the encoded length from the span's pos.
42
43/**
44 * @brief MessagePack as an instance of the codec interface.
45 *
46 * The operations, their order and their signatures are protocore_codec's; this is the
47 * format that supplies them. The one symbol this module exports.
48 */
49extern const protocore_codec MsgPack;
50
52
53#endif // PROTOCORE_ENABLE_MSGPACK
54
55#endif // PROTOCORE_MSGPACK_H
One binary codec interface; a wire encoding is an instance of it.
A wire encoding: the ten writes, the peek, and the nine reads.
Definition codec.h:60
#define PROTOCORE_BEGIN_DECLS
Give a header's declarations C linkage, so their symbol names carry no parameter types.
Definition types.h:96
#define PROTOCORE_END_DECLS
Definition types.h:97