23#ifndef DETERMINISTICESPASYNCWEBSERVER_DET_BYTES_H
24#define DETERMINISTICESPASYNCWEBSERVER_DET_BYTES_H
32template <
typename W>
inline void det_bw_init(W *w, uint8_t *buf,
size_t cap)
41template <
typename W>
inline size_t det_bw_len(
const W *w)
47template <
typename W>
inline bool det_bw_ok(
const W *w)
53template <
typename W>
inline void det_bw_put(W *w, uint8_t b)
63template <
typename W>
inline void det_bw_put_be(W *w, uint64_t val,
int nbytes)
65 for (
int s = (nbytes - 1) * 8; s >= 0; s -= 8)
72template <
typename R>
inline void det_br_init(R *r,
const uint8_t *buf,
size_t len)
81template <
typename R>
inline bool det_br_ok(
const R *r)
94template <
typename R>
inline bool det_br_take_be(R *r,
size_t nbytes, uint64_t *out)
96 if (r->pos + 1 + nbytes > r->len)
102 for (
size_t i = 0; i < nbytes; i++)
103 v = (v << 8) | r->buf[r->pos + 1 + i];
105 r->pos += 1 + nbytes;
void det_bw_put_be(W *w, uint64_t val, int nbytes)
Append the low nbytes of val, big-endian (network order).
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...
void det_br_init(R *r, const uint8_t *buf, size_t len)
Bind a read cursor to buf (length len) at offset 0.
void det_bw_put(W *w, uint8_t b)
Append one byte; on overflow set the flag but keep counting pos.
bool det_br_ok(const R *r)
True while no malformed / out-of-bounds read has occurred.
bool det_bw_ok(const W *w)
True while every write has fit in the buffer.
void det_bw_init(W *w, uint8_t *buf, size_t cap)
Bind a write cursor to buf (capacity cap) and reset it.
size_t det_bw_len(const W *w)
Bytes the payload needs so far (keeps counting past cap on overflow).