DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
bytes.h File Reference

Shared byte-cursor mechanics for the binary codecs (one source of truth). More...

#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Functions

template<typename W >
void det_bw_init (W *w, uint8_t *buf, size_t cap)
 Bind a write cursor to buf (capacity cap) and reset it.
 
template<typename W >
size_t det_bw_len (const W *w)
 Bytes the payload needs so far (keeps counting past cap on overflow).
 
template<typename W >
bool det_bw_ok (const W *w)
 True while every write has fit in the buffer.
 
template<typename W >
void det_bw_put (W *w, uint8_t b)
 Append one byte; on overflow set the flag but keep counting pos.
 
template<typename W >
void det_bw_put_be (W *w, uint64_t val, int nbytes)
 Append the low nbytes of val, big-endian (network order).
 
template<typename R >
void det_br_init (R *r, const uint8_t *buf, size_t len)
 Bind a read cursor to buf (length len) at offset 0.
 
template<typename R >
bool det_br_ok (const R *r)
 True while no malformed / out-of-bounds read has occurred.
 
template<typename R >
bool det_br_take_be (R *r, size_t nbytes, uint64_t *out)
 Read nbytes big-endian immediately after the tag byte at pos, advancing past the tag and the argument (pos += 1 + nbytes).
 

Detailed Description

Shared byte-cursor mechanics for the binary codecs (one source of truth).

CBOR and MessagePack (and any future binary codec) kept their own copies of the exact same write cursor ({buf, cap, pos, overflow} with bounds-checked put + big-endian put) and read cursor ({buf, len, pos, err} with a big-endian take). The subtle invariants - keep counting pos past cap on overflow so the caller can size the buffer; sticky err; network (big-endian) byte order - now live here once, so a bug is fixed in one place and every codec inherits it.

Header-only and templated on the cursor type, so each codec keeps its own public struct (CborWriter, MsgpackReader, ...) - these helpers just require the matching field names. No .cpp to wire into the per-env test src filters.

Author
Douglas Quigg (dstroy0)
Date
2026

Definition in file bytes.h.

Function Documentation

◆ det_bw_init()

template<typename W >
void det_bw_init ( W *  w,
uint8_t *  buf,
size_t  cap 
)
inline

Bind a write cursor to buf (capacity cap) and reset it.

Definition at line 32 of file bytes.h.

◆ det_bw_len()

template<typename W >
size_t det_bw_len ( const W *  w)
inline

Bytes the payload needs so far (keeps counting past cap on overflow).

Definition at line 41 of file bytes.h.

◆ det_bw_ok()

template<typename W >
bool det_bw_ok ( const W *  w)
inline

True while every write has fit in the buffer.

Definition at line 47 of file bytes.h.

◆ det_bw_put()

template<typename W >
void det_bw_put ( W *  w,
uint8_t  b 
)
inline

Append one byte; on overflow set the flag but keep counting pos.

Definition at line 53 of file bytes.h.

Referenced by det_bw_put_be().

◆ det_bw_put_be()

template<typename W >
void det_bw_put_be ( W *  w,
uint64_t  val,
int  nbytes 
)
inline

Append the low nbytes of val, big-endian (network order).

Definition at line 63 of file bytes.h.

References det_bw_put().

◆ det_br_init()

template<typename R >
void det_br_init ( R *  r,
const uint8_t *  buf,
size_t  len 
)
inline

Bind a read cursor to buf (length len) at offset 0.

Definition at line 72 of file bytes.h.

◆ det_br_ok()

template<typename R >
bool det_br_ok ( const R *  r)
inline

True while no malformed / out-of-bounds read has occurred.

Definition at line 81 of file bytes.h.

◆ det_br_take_be()

template<typename R >
bool det_br_take_be ( R *  r,
size_t  nbytes,
uint64_t *  out 
)
inline

Read nbytes big-endian immediately after the tag byte at pos, advancing past the tag and the argument (pos += 1 + nbytes).

Both CBOR heads and MessagePack format bytes are a 1-byte tag followed by a big-endian argument, so this consumes the tag + argument in one step. Sets the sticky err and returns false if the read would run past the buffer.

Definition at line 94 of file bytes.h.