Skip to content

ZeroCopyReader

[Source]

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.

class ref ZeroCopyReader

Constructors

create

[Source]

new ref create()
: ZeroCopyReader ref^

Returns


Public Functions

size

[Source]

Return the number of available bytes.

fun box size()
: USize val

Returns


append

[Source]

Add a chunk of data. The reader holds a val reference to the chunk's underlying array. No copy is performed.

fun ref append(
  data: (String val | Array[U8 val] val))
: None val

Parameters

Returns


block

[Source]

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).

fun ref block(
  len: USize val)
: Array[U8 val] val ?

Parameters

Returns


skip

[Source]

Skip n bytes. Errors if fewer than n bytes are available.

fun ref skip(
  n: USize val)
: None val ?

Parameters

Returns


u8

[Source]

Get a U8. Errors if there isn't enough data.

fun ref u8()
: U8 val ?

Returns

  • U8 val ?

i8

[Source]

Get an I8.

fun ref i8()
: I8 val ?

Returns

  • I8 val ?

u16_be

[Source]

Get a big-endian U16.

fun ref u16_be()
: U16 val ?

Returns


i16_be

[Source]

Get a big-endian I16.

fun ref i16_be()
: I16 val ?

Returns


u32_be

[Source]

Get a big-endian U32.

fun ref u32_be()
: U32 val ?

Returns


i32_be

[Source]

Get a big-endian I32.

fun ref i32_be()
: I32 val ?

Returns


u64_be

[Source]

Get a big-endian U64.

fun ref u64_be()
: U64 val ?

Returns


i64_be

[Source]

Get a big-endian I64.

fun ref i64_be()
: I64 val ?

Returns


f32_be

[Source]

Get a big-endian F32.

fun ref f32_be()
: F32 val ?

Returns


f64_be

[Source]

Get a big-endian F64.

fun ref f64_be()
: F64 val ?

Returns


peek_u8

[Source]

Peek at a U8 at the given offset without consuming it. Errors if there isn't enough data.

fun box peek_u8(
  offset: USize val = 0)
: U8 val ?

Parameters

Returns

  • U8 val ?

peek_u16_be

[Source]

Peek at a big-endian U16 at the given offset without consuming it.

fun box peek_u16_be(
  offset: USize val = 0)
: U16 val ?

Parameters

Returns


peek_u32_be

[Source]

Peek at a big-endian U32 at the given offset without consuming it.

fun box peek_u32_be(
  offset: USize val = 0)
: U32 val ?

Parameters

Returns