ProtoCore
v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
cbor.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 cbor.h
6
* @brief Layer 6 (Presentation) - zero-heap CBOR (RFC 8949) encoder.
7
*
8
* A streaming encoder that writes directly into a caller-provided buffer (no
9
* heap), the binary counterpart to the JSON writer. Emit definite-length arrays
10
* and maps by writing the header (Cbor.put_array / Cbor.put_map with the item count) then
11
* that many items (twice that for a map: key, value, key, value, ...).
12
*
13
* Overflow is tracked, not crashed on: writes past the buffer set the overflow
14
* flag and stop, while the span's pos keeps counting the bytes the full payload would
15
* need, so a caller can size the buffer and check spat.ok().
16
*
17
* @author Douglas Quigg (dstroy0)
18
* @date 2026
19
*/
20
21
#ifndef PROTOCORE_CBOR_H
22
#define PROTOCORE_CBOR_H
23
24
#include "
network_drivers/presentation/codec/codec.h
"
// protocore_codec_type - one item vocabulary
25
#include "spatium/spatium.h"
// mmgr_span / mmgr_cspan - the region, bound with spat.from()
26
27
#include "
protocore_config.h
"
28
29
EMBED_BEGIN_DECLS
30
31
#if PROTOCORE_ENABLE_CBOR
32
33
// The encoder writes into a mmgr_span and the decoder reads from a mmgr_cspan. There is no CBOR-specific
34
// cursor type: this codec declared one field-identical to mmgr_span, MessagePack declared another, and
35
// the byte verbs were templated only to bind them by field name. Bind with spat.from(),
36
// check with spat.ok(), and take the encoded length from the span's pos.
37
38
/**
39
* @brief CBOR (RFC 8949) as an instance of the codec interface.
40
*
41
* The operations, their order and their signatures are protocore_codec's; this is the
42
* format that supplies them. The one symbol this module exports.
43
*/
44
extern
const
protocore_codec
Cbor;
45
46
#endif
// PROTOCORE_ENABLE_CBOR
47
48
EMBED_END_DECLS
49
50
#endif
// PROTOCORE_CBOR_H
codec.h
One binary codec interface; a wire encoding is an instance of it.
protocore_config.h
protocore_codec
A wire encoding: the ten writes, the peek, and the nine reads.
Definition
codec.h:52
src
network_drivers
presentation
codec
cbor
cbor.h
Generated by
1.15.0