twig

package
v0.0.0-...-133031b Latest Latest
Warning

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

Go to latest
Published: May 30, 2023 License: Apache-2.0 Imports: 2 Imported by: 4

Documentation

Overview

Package twig implements the twig key-value data format.

Twig is a simple text key-value format. Keys and values are separated by NULL bytes (bytes of value 0). Keys and values may not contain a NULL byte. All other characters are allowed.

Keys have an additional constraint. Each key must contain a "name" and a "version" number. These describe the semantics of the data stored for that key, and the precise meaning is left to the user. The key and name are separated (in the binary format) by a delimiter, which is currently '/'.

The key name may not be empty.

In practice, twig keys look like (the final slash is the delimiter between key and version):

anexample/235 // name: anexample, version: 235
heres one with spaces/9 // name: heres one with spaces, version: 9
heres/one/with/slashes/9 // name: heres/one/with/slashes, version: 9

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data struct {
	Values map[Key][]byte
}

Data represents a collection of twig key-value pairs. It provides methods for converting them to/from binary

func New

func New() *Data

New allocates an empty twig key-value Data

func (*Data) Contains

func (d *Data) Contains(name string, version uint) bool

Contains checks whether or not a key exists in the data values by name and version

func (*Data) Get

func (d *Data) Get(name string, version uint) ([]byte, bool)

Get fetches a value from the value store by key name and version, and whether or not the key was in the values

func (*Data) MarshalBinary

func (d *Data) MarshalBinary() ([]byte, error)

MarshalBinary converts this Data into twig binary form.

func (*Data) Set

func (d *Data) Set(name string, version uint, value []byte) (*Data, error)

Set sets a twig key-version data entry. If the entry does not exist, it is created

func (*Data) UnmarshalBinary

func (d *Data) UnmarshalBinary(b []byte) error

UnmarshalBinary populates a Data from raw binary in Twig format

type Key

type Key struct {
	Name    string
	Version uint
}

Key represents a key within the twig data

func FromString

func FromString(s string) (Key, error)

FromString converts a string into a Key struct by separating the name and version

func (Key) String

func (k Key) String() string

String converts a key back into its string representation

Jump to

Keyboard shortcuts

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