Skip to main content

Module codec

Module codec 

Source
Expand description

Binary codec for vibe-bc-0.1 chunks.

Serializes a Chunk to/from a compact binary format suitable for storage, transmission, or caching. The format is:

┌──────────────────────────────────────────────────────────────┐
│ Header                                                       │
│  magic         4 bytes   "VBC1"                              │
│  version       2 bytes   u16 LE                               │
│  top_locals    2 bytes   u16 LE                               │
│  const_count   2 bytes   u16 LE                               │
│  func_count    2 bytes   u16 LE                               │
│  code_len      2 bytes   u16 LE                               │
├──────────────────────────────────────────────────────────────┤
│ Constants                                                    │
│  For each constant:                                          │
│    tag       1 byte    0=String, 1=Iri                        │
│    len       2 bytes   u16 LE (byte length, UTF-8)            │
│    data      len bytes  UTF-8 string                          │
├──────────────────────────────────────────────────────────────┤
│ Functions                                                    │
│  For each function:                                          │
│    name_len   1 byte                                         │
│    name       name_len bytes                                 │
│    param_ct   1 byte                                         │
│    local_ct   2 bytes   u16 LE                                │
│    code_off   2 bytes   u16 LE                                │
│    budget     8 bytes   u64 LE                                │
├──────────────────────────────────────────────────────────────┤
│ Code                                                         │
│  raw bytes   code_len bytes                                  │
└──────────────────────────────────────────────────────────────┘

Enums§

ChunkDecodeError
Codec error.

Functions§

decode_chunk
Decode a Chunk from binary bytes.
encode_chunk
Encode a Chunk into binary bytes.