ZeroCopyReader¶
A reader optimized for zero-copy extraction of byte ranges.
Returns val views into the internal buffer instead of
copying into fresh iso arrays.
Zero-copy succeeds when the requested range falls within a
single internal chunk. When data spans chunk boundaries, the
reader falls back to copying — no worse than buffered.Reader.
This reader is specific to the msgpack package and is not
interoperable with APIs that expect buffered.Reader. Use it
with MessagePackZeroCopyDecoder for zero-copy decoding, or
use MessagePackStreamingDecoder which uses it internally.
Decoded values returned via block() may hold references to
the reader's internal chunks. As long as a decoded value is
live, its source chunk stays in memory. For most use cases
(decode, process, discard) this is not a concern. Callers who
cache decoded values should be aware of this lifetime
relationship.
Constructors¶
create¶
Returns¶
- ZeroCopyReader ref^
Public Functions¶
size¶
Return the number of available bytes.
Returns¶
- USize val
append¶
Add a chunk of data. The reader holds a val reference to
the chunk's underlying array. No copy is performed.
Parameters¶
Returns¶
- None val
block¶
Return len bytes. If the range falls within a single
chunk, returns a trim'd view (zero-copy). If it spans
chunks, copies into a new array (fallback).
Parameters¶
- len: USize val
Returns¶
skip¶
Skip n bytes. Errors if fewer than n bytes are
available.
Parameters¶
- n: USize val
Returns¶
- None val ?
u8¶
Get a U8. Errors if there isn't enough data.
Returns¶
- U8 val ?
i8¶
Get an I8.
Returns¶
- I8 val ?
u16_be¶
Get a big-endian U16.
Returns¶
- U16 val ?
i16_be¶
Get a big-endian I16.
Returns¶
- I16 val ?
u32_be¶
Get a big-endian U32.
Returns¶
- U32 val ?
i32_be¶
Get a big-endian I32.
Returns¶
- I32 val ?
u64_be¶
Get a big-endian U64.
Returns¶
- U64 val ?
i64_be¶
Get a big-endian I64.
Returns¶
- I64 val ?
f32_be¶
Get a big-endian F32.
Returns¶
- F32 val ?
f64_be¶
Get a big-endian F64.
Returns¶
- F64 val ?
peek_u8¶
Peek at a U8 at the given offset without consuming it. Errors if there isn't enough data.
Parameters¶
- offset: USize val = 0
Returns¶
- U8 val ?
peek_u16_be¶
Peek at a big-endian U16 at the given offset without consuming it.
Parameters¶
- offset: USize val = 0
Returns¶
- U16 val ?
peek_u32_be¶
Peek at a big-endian U32 at the given offset without consuming it.
Parameters¶
- offset: USize val = 0
Returns¶
- U32 val ?