26#ifndef PROTOCORE_BYTES_H
27#define PROTOCORE_BYTES_H
53 for (int32_t s = (nbytes - 1) * 8; s >= 0; s -= 8)
55 pc_bw_put(w,
static_cast<uint8_t
>(val >> s));
71 if (r->
pos + 1 + nbytes > r->
len)
77 for (
size_t i = 0; i < nbytes; i++)
79 v = (v << 8) | r->
buf[r->
pos + 1 + i];
93inline bool pc_rd_u32(
const uint8_t *p,
size_t len,
size_t *off, uint32_t *out)
110inline bool pc_rd_str(
const uint8_t *p,
size_t len,
size_t *off,
const uint8_t **out, uint32_t *slen)
void pc_bw_put_be(pc_span *w, uint64_t val, int32_t nbytes)
Append the low nbytes of val, big-endian (network order).
bool pc_rd_str(const uint8_t *p, size_t len, size_t *off, const uint8_t **out, uint32_t *slen)
Read a u32-length-prefixed blob: out points into p, slen is its length.
bool pc_rd_u32(const uint8_t *p, size_t len, size_t *off, uint32_t *out)
Read a big-endian u32 at *off, advancing it by 4. False if it would run past len.
void pc_bw_put(pc_span *w, uint8_t b)
Append one byte; on overflow set the flag but keep counting pos.
bool pc_br_take_be(pc_cspan *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...
Fixed-width integer serializers into a raw uint8_t* buffer - one source of truth.
uint32_t pc_rd32be(const uint8_t *p)
Read a big-endian u32 at p.
A byte region whose run length is bound in both directions.
const uint8_t * buf
first byte, or nullptr when there is nothing to read
size_t len
readable bytes at buf (0 whenever buf is nullptr)
bool err
sticky: a read ran past len
A writable byte region: the storage, the capacity that belongs to it, and what has been produced into...
bool overflow
set once a write did not fit; pos then reports the size required
uint8_t * buf
first byte, or nullptr when the region could not be obtained
size_t pos
bytes the payload needs so far; keeps counting past cap on overflow
size_t cap
bytes writable at buf (0 whenever buf is nullptr)