kv3

package
v0.1.73 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package kv3 reads binary KeyValues3 versions 4 and 5 and writes version 5, the format Source 2 compiled resources store their data in.

Decode accepts untrusted input: malformed data returns an error and never panics, and a value budget bounds the work one buffer can demand.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(data []byte) (any, error)

Decode reads binary KeyValues3 data. Objects decode as map[string]any and arrays as []any; the scalars as nil, bool, int64, uint64, float64, string and Blob. Flags are dropped.

func Encode

func Encode(value any) ([]byte, error)

Encode writes value as binary KeyValues3 version 5 with LZ4 compression, the form the resource compiler writes. It takes nil, bool, every integer type, float32, float64, string, []any, Object and map[string]any. An integer is written in the narrowest of int32, uint32, int64 and uint64 that holds it.

Types

type Blob

type Blob struct {
	// Size is the blob's length in bytes.
	Size int
	// Data is the blob's bytes, nil when the payload was unreadable.
	Data []byte
}

Blob is a binary blob: its bytes, or only its size when the payload could not be read.

func (Blob) MarshalJSON added in v0.1.34

func (b Blob) MarshalJSON() ([]byte, error)

MarshalJSON writes a blob as its size, so a dump of a resource stays readable.

type Member

type Member struct {
	// Key names the member.
	Key string
	// Value is the member's value.
	Value any
}

Member is one key and value of an Object.

type Object

type Object []Member

Object is a KeyValues3 object whose members keep their order. Encode also takes a map[string]any, whose members it writes in key order.

Jump to

Keyboard shortcuts

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