Skip to content

yggdrasil.pickle.ser.header

header

Header

Header(
    tag: int,
    codec: int,
    size: int,
    meta_size: int,
    start: int,
    metadata: Metadata = None,
    *,
    _meta_blob: bytes | None = None
)

Binary header for a serialized payload.

Layout

tag:u16 codec:u16 size:u32 meta_size:u32 metadata:meta_size bytes payload:size bytes

build classmethod

build(
    *,
    tag: int,
    codec: int,
    size: int,
    metadata: Mapping[bytes, bytes] | None = None,
    start: int = 0
) -> "Header"

Build a header from semantic fields.

read_from classmethod

read_from(buffer: IO, *, pos: int | None = None) -> 'Header'

Parse a header from a buffer without materializing the payload.

payload_view

payload_view(buffer: 'IO | _ScratchBuf') -> 'IO | _ScratchBuf'

Return a buffer over the payload sub-range [start, start+size).

A :class:_ScratchBuf slices in place (its own zero-copy view); a yggdrasil :class:IO is read directly (pread) into a fresh :class:_ScratchBuf — the pickle module's lightweight read surface — which is exactly what the bounded IO.view did before.

write_to

write_to(
    data: bytes | bytearray | memoryview,
    *,
    buffer: "IO | TypingIO[bytes] | None" = None
) -> "IO | TypingIO[bytes]"

Write header + payload into a buffer and return that buffer.

Streams via the universal :class:IO[bytes].write method so a stdlib io.BytesIO or any open file handle works as a sink — not just the yggdrasil :class:IO. Avoids the extra to_bytes() materialization that previous shapes incurred.

encode_metadata

encode_metadata(metadata: Mapping[bytes, bytes] | None) -> bytes

Encode metadata as length-prefixed key/value pairs.

Format:

[k_len:u32][key][v_len:u32][value]...