52#ifndef PROTOCORE_SPAN_H
53#define PROTOCORE_SPAN_H
95 s.
buf = (p !=
nullptr && cap != 0) ? p :
nullptr;
96 s.
cap = (s.
buf !=
nullptr) ? cap : 0;
106 s.
buf = (p !=
nullptr && len != 0) ? p :
nullptr;
107 s.
len = (s.
buf !=
nullptr) ? len : 0;
122 return s.
buf !=
nullptr;
128 return s.
buf !=
nullptr && !s.
err;
pc_cspan pc_span_produced(const pc_span &s)
A read-only view of what has been produced into s.
pc_span pc_span_from(uint8_t *p, size_t cap)
Bind a span to memory whose extent is only known at run time.
bool pc_cspan_ok(const pc_cspan &s)
True when the read-only span refers to real bytes and no read has run past the end.
pc_cspan pc_cspan_from(const uint8_t *p, size_t len)
Bind a read-only span to memory whose extent is only known at run time.
void pc_span_reset(pc_span *s)
Rewind to empty, keeping the same storage and clearing the overflow flag.
size_t pc_span_room(const pc_span &s)
Writable bytes remaining (0 once the region is full or has overflowed).
pc_span pc_span_after(const pc_span &s, size_t off)
The sub-span starting off bytes into s (a fresh, empty cursor over that tail).
bool pc_span_has_storage(const pc_span &s)
True when the span refers to real storage, whether or not a write has overflowed.
bool pc_span_ok(const pc_span &s)
True when the span refers to real storage and every write so far has fit.
pc_span pc_span_first(const pc_span &s, size_t n)
The first n bytes of s as a fresh span, clamped to what s actually has.
pc_cspan pc_span_read(const pc_span &s, size_t len)
A read-only view of the first len bytes of s, clamped to its capacity.
size_t pc_span_len(const pc_span &s)
Bytes the payload needs - the backward direction.
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)