Contiguous append-only stream accumulator with a logical read offset and parser scratch state.
More...
|
| | StreamBuffer (std::size_t compact_threshold=4096) |
| | Constructs an empty stream buffer. More...
|
| |
| template<typename D > |
| void | InitAny () |
| | Initialize the parsed data. More...
|
| |
| template<typename D > |
| void | InitAnyB () |
| | Initializes the secondary parser scratch object as D. More...
|
| |
| template<typename D > |
| void | InitAny (uint64_t type) |
| | Initialize the parsed data and type. More...
|
| |
| template<typename D > |
| D & | GetAny () |
| | Get the parsed data. More...
|
| |
| template<typename D > |
| D & | GetAnyB () |
| | Gets the secondary parser scratch object. More...
|
| |
| std::optional< uint64_t > | GetAnyType () |
| | Get the user defined parsed type value. More...
|
| |
| void | SetAnyType (uint64_t type) |
| | Set the user-defined parsed data type value. More...
|
| |
| void | Clear () |
| | Clears unread data and all parser scratch state. More...
|
| |
| void | ResetAny () |
| | Clears both parser scratch objects and the optional parser type without changing stream data. More...
|
| |
| void | ResetAnyB () |
| | Clears only the secondary parser scratch object. More...
|
| |
| template<class D > |
| void | ResetAnyB () |
| | Replaces the secondary parser scratch object with a default-constructed D. More...
|
| |
| bool | AnyHasValue () |
| |
| bool | AnyHasValueB () |
| |
| bool | Empty () const noexcept |
| |
| size_t | Size () noexcept |
| |
| std::span< const T > | Front () noexcept |
| | Get the first data byte in stream buffer. More...
|
| |
| std::span< const T > | Front (std::size_t length) noexcept |
| | Front length number of data bytes. More...
|
| |
| std::span< const T > | Data () noexcept |
| | All readable data bytes in the stream buffer. More...
|
| |
| BufferT | TakeAll () |
| | Surrender everything not yet read, leaving the buffer empty. More...
|
| |
| void | Pop () |
| | Consumes one unread element, or does nothing when empty. More...
|
| |
| void | Pop (std::size_t length) |
| | Consumes up to length unread elements. More...
|
| |
| bool | Available (std::size_t length) const noexcept |
| | Checks if length bytes are available for front. More...
|
| |
| void | Push (const T &value) |
| | Copies one value to the back of the stream. More...
|
| |
| void | Push (T &&value) |
| | Moves one value to the back of the stream. More...
|
| |
| void | Push (std::span< const T > value) |
| | Appends a copy of a contiguous value range. More...
|
| |
| void | PushLengthBytes (std::span< const T > value) |
| | Appends a QUIC variable-length count followed by the supplied values. More...
|
| |
| std::optional< uint64_t > | DecodeUintV (bool pop=true) |
| |
| std::optional< UintVar > | ReadUintV (bool pop=true) |
| |
| std::optional< std::vector< uint8_t > > | DecodeBytes () |
| |
template<typename T, class Allocator = std::allocator<T>>
class quicr::StreamBuffer< T, Allocator >
Contiguous append-only stream accumulator with a logical read offset and parser scratch state.
- Template Parameters
-
| T | Element type; QUIC variable-length decoding requires a byte-compatible integral type. |
| Allocator | Allocator for the underlying vector. |
Pop operations normally advance a logical offset. A later push compacts consumed storage once the offset reaches the configured threshold or exceeds the unread size. The class is not thread-safe. Spans and references returned by accessors are invalidated by compaction, reallocation, clear, or destruction.
template<typename T , class Allocator = std::allocator<T>>
Decodes a variable length array of uint8_t bytes from start of stream buffer
Reads uintV from stream buffer to get the length of the byte array. Then reads byte array from stream buffer after the uintV length. Vector of bytes will be returned if all bytes are available. Otherwise nullopt will be returned to indicate not enough bytes available.
- Returns
- Returns vector<uint8_t> or nullopt if not enough bytes are available
- Note
- The length prefix and payload are consumed only when the complete payload is available.
- Exceptions
-
| Any | exception thrown while constructing the result vector. |
template<typename T , class Allocator = std::allocator<T>>
Decodes a variable length int (uintV) from start of stream buffer
Reads uintV from stream buffer. If all bytes are available, the unsigned 64bit integer will be returned and the buffer will be moved past the uintV. Nullopt will be returned if not enough bytes are available.
- Parameters
-
| pop | True to move the buffer past the uintV. |
- Returns
- Returns uint64 decoded value or nullopt if not enough bytes are available
template<typename T , class Allocator = std::allocator<T>>
Reads a variable length int (uintV) from start of stream buffer
Reads uintV from stream buffer. If all bytes are available, the encoded uintV will be returned and the buffer will be moved past the uintV. Nullopt will be returned if not enough bytes are available.
- Parameters
-
| pop | True to move the buffer past the uintV. |
- Returns
- Returns uintV or nullopt if not enough bytes are available
template<typename T , class Allocator = std::allocator<T>>
Surrender everything not yet read, leaving the buffer empty.
For a caller that takes the whole of what has arrived rather than reading messages out of it one at a time, which costs nothing once it has read what came before. What has been parsed so far is left alone, since that is what says how the stream is being read rather than what is left to read.
- Returns
- The bytes not yet read
When no prefix has been consumed this may transfer the underlying allocation; otherwise it copies unread elements. Parser scratch state is preserved. All previously returned spans are invalidated.
- Exceptions
-
| Any | exception thrown while allocating or copying unread elements. |