level

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package level defines the bounded, versioned data envelope stored in a Karty level cartridge. It is shared contract code, not generated project output.

Index

Constants

View Source
const (
	EnvelopeVersion  = uint16(1)
	HeaderSize       = 32
	EntryHeaderSize  = 12
	MaxEnvelopeSize  = 16 * 1024 * 1024
	MaxMetadataSize  = 16 * 1024
	MaxEntryCount    = 4096
	MaxEntryNameSize = 1024
	MaxEntrySize     = 8 * 1024 * 1024
)

Variables

View Source
var (
	ErrEnvelopeSize = errors.New("level envelope size is invalid")
	ErrHeader       = errors.New("level envelope header is invalid")
	ErrVersion      = errors.New("level envelope version is unsupported")
	ErrMetadata     = errors.New("level metadata is invalid")
	ErrEntry        = errors.New("level data entry is invalid")
	ErrEntryOrder   = errors.New("level data entries are not in canonical order")
	ErrEntryRange   = errors.New("level data entry range is invalid")
)

Functions

func Encode

func Encode(metadata []byte, source []SourceEntry) ([]byte, error)

Encode creates a deterministic envelope. Entries are ordered by logical name; callers do not control table or payload order.

func TextureAssetID

func TextureAssetID(name string) (uint32, bool)

TextureAssetID recognizes a reserved texture payload name.

func TextureEntryName

func TextureEntryName(assetID uint32) string

TextureEntryName returns the reserved envelope name for a nonzero, level-local texture ID.

func WrapModule

func WrapModule(envelope []byte) ([]byte, error)

WrapModule places a validated KTYL envelope in a minimal passive core-Wasm module exposing the three level-cartridge ABI functions and memory.

Types

type Entry

type Entry struct {
	Name   string
	Kind   EntryKind
	Offset uint32
	Length uint32
}

Entry describes a validated named payload in an Envelope.

type EntryKind

type EntryKind uint8

EntryKind identifies a named payload's schema family.

const (
	EntryData    EntryKind = 1
	EntryTexture EntryKind = 2
)

type Envelope

type Envelope struct {
	Raw      []byte
	Metadata []byte
	Entries  []Entry
	// contains filtered or unexported fields
}

Envelope is a validated view over immutable envelope bytes. Metadata and payload slices alias Raw and remain valid only while Raw is retained.

func Decode

func Decode(encoded []byte) (Envelope, error)

Decode validates a complete canonical envelope before exposing any entry.

func (Envelope) Read

func (envelope Envelope) Read(name string, offset, maximum uint32) ([]byte, uint32, bool)

Read returns a bounded view of a named payload. The returned bytes alias Raw.

type SourceEntry

type SourceEntry struct {
	Name string
	Kind EntryKind
	Data []byte
}

SourceEntry is an authoring-time named payload passed to Encode.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL