ProtoCore v0.0.2
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
codec.h File Reference

One binary codec interface; a wire encoding is an instance of it. More...

#include "protocore_config.h"
#include "shared_primitives/span.h"
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Classes

struct  pc_codec
 A wire encoding: the ten writes, the peek, and the nine reads. More...
 

Enumerations

enum class  pc_codec_type : uint8_t {
  PC_CODEC_UINT = 0 , PC_CODEC_INT , PC_CODEC_BYTES , PC_CODEC_STR ,
  PC_CODEC_ARRAY , PC_CODEC_MAP , PC_CODEC_BOOL , PC_CODEC_NULL ,
  PC_CODEC_FLOAT , PC_CODEC_INVALID
}
 The next item's type, reported by pc_codec::peek without consuming it. More...
 

Detailed Description

One binary codec interface; a wire encoding is an instance of it.

CBOR and MessagePack encode the same ten things - unsigned, signed, bytes, string, bool, null, float, array header, map header - into different bytes. Written out separately they were two parallel APIs over two field-identical cursor structs, and a caller had to pick one at the call site, so SenML-over-CBOR and SenML-over-MessagePack could not be the same code.

They are one interface with two instances. The operations, their order, and their signatures are fixed here; a format supplies the function pointers. Order is load-bearing: it is the field order of the table, so a format whose operations drift out of order fails to compile rather than silently binding the wrong encoder.

Dispatch is a static const table of plain function pointers in rodata, the same shape as ProtoHandler. Not virtual, not RTTI, not std::function (SRCBANNED #22): the set of reachable targets stays a closed list the linker can see whole, so the worst-case path is still a number.

The region types come from span.h and the byte verbs from bytes.h - a codec does no allocation and owns no buffer; it writes into a pc_span the caller bound and reads from a pc_cspan.

Author
Douglas Quigg (dstroy0)
Date
2026

Definition in file codec.h.

Enumeration Type Documentation

◆ pc_codec_type

enum class pc_codec_type : uint8_t
strong

The next item's type, reported by pc_codec::peek without consuming it.

One set of names across every format: CBOR calls a byte string "bytes" and MessagePack calls it "bin"; CBOR has "null" and MessagePack "nil". They are the same item, so they get one name here and the format maps its own tag onto it.

Enumerator
PC_CODEC_UINT 
PC_CODEC_INT 
PC_CODEC_BYTES 
PC_CODEC_STR 
PC_CODEC_ARRAY 
PC_CODEC_MAP 
PC_CODEC_BOOL 
PC_CODEC_NULL 
PC_CODEC_FLOAT 
PC_CODEC_INVALID 

end of buffer, a prior error, or an item this format does not carry

Definition at line 44 of file codec.h.