types

package
v0.1.1-rc.2 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeOffset

func DecodeOffset(header uint16) int

func EncodeEnd

func EncodeEnd(offset int) uint16

func EncodeHeader

func EncodeHeader(offset int, typeID Type) uint16

func GetAs

func GetAs[U any](om *OrderedMapAny, key string) U

Types

type OrderedMap

type OrderedMap[V any] struct {
	// contains filtered or unexported fields
}

OrderedMap is a generic ordered map keyed by string

func NewOrderedMap

func NewOrderedMap[V any](pairs ...Pair[V]) *OrderedMap[V]

NewOrderedMap creates a new OrderedMap, optionally initialized with pairs.

func (*OrderedMap[V]) Delete

func (om *OrderedMap[V]) Delete(key string)

Delete removes a key

func (*OrderedMap[V]) Equal

func (om *OrderedMap[V]) Equal(other *OrderedMap[V]) bool

func (*OrderedMap[V]) Get

func (om *OrderedMap[V]) Get(key string) (V, bool)

Get retrieves a value

func (*OrderedMap[V]) Items

func (om *OrderedMap[V]) Items() []Pair[V]

Items returns key/value pairs in insertion order

func (*OrderedMap[V]) ItemsIter

func (om *OrderedMap[V]) ItemsIter() iter.Seq2[string, V]

ItemsIter returns an iterator over key/value pairs

func (*OrderedMap[V]) Keys

func (om *OrderedMap[V]) Keys() []string

Keys returns keys in insertion order

func (*OrderedMap[V]) KeysIter

func (om *OrderedMap[V]) KeysIter() iter.Seq[string]

KeysIter returns an iterator over keys

func (*OrderedMap[V]) Len

func (om *OrderedMap[V]) Len() int

Length

func (*OrderedMap[V]) MarshalJSON

func (om *OrderedMap[V]) MarshalJSON() ([]byte, error)

MarshalJSON encodes as JSON object in insertion order

func (*OrderedMap[V]) MoveToEnd

func (om *OrderedMap[V]) MoveToEnd(key string, last bool) error

MoveToEnd moves a key to front or back

func (*OrderedMap[V]) Set

func (om *OrderedMap[V]) Set(key string, value V)

Set inserts or updates a key

func (*OrderedMap[V]) UnmarshalJSON

func (om *OrderedMap[V]) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes JSON object preserving order

func (*OrderedMap[V]) Values

func (om *OrderedMap[V]) Values() []V

Values returns values in insertion order

func (*OrderedMap[V]) ValuesIter

func (om *OrderedMap[V]) ValuesIter() iter.Seq[V]

ValuesIter returns an iterator over values

type OrderedMapAny

type OrderedMapAny = OrderedMap[any]

Alias for OrderedMap with any values

func ConvertUnorderedToOrdered

func ConvertUnorderedToOrdered(m map[string]any, order []string) *OrderedMapAny

ConvertUnorderedToOrdered takes a plain map[string]any and a desired key order, and returns an OrderedMapAny with keys in that order.

func NewOrderedMapAny

func NewOrderedMapAny(pairs ...PairAny) *OrderedMapAny

NewOrderedMapAny creates an OrderedMap[any] initialized with pairs.

type Pair

type Pair[V any] struct {
	Key   string
	Value V
}

Pair represents a key/value pair for initialization

func OP

func OP[V any](k string, v V) Pair[V]

type PairAny

type PairAny = Pair[any]

Alias for Pair[any]

func OPAny

func OPAny(k string, v any) PairAny

OPAny is a helper to construct a Pair[any] inline.

type Type

type Type uint16

Type is a 3-bit tag encoded into a uint16 header

const (
	TypeInvalid              Type = 0
	TypeEnd                  Type = 0
	TypeUnk                  Type = 0 // actually, can be used as arg position is not determined by it
	TypeInteger              Type = 1
	TypeExtendedTagContainer Type = 2
	TypeFloating             Type = 3
	TypeTuple                Type = 4
	TypeNull                 Type = 4
	TypeBool                 Type = 5
	TypeString               Type = 6 // used for both string and []byte small chunks
	TypeByteArray            Type = 6
	TypeSlice                Type = 6
	TypeMap                  Type = 7
)

func DecodeHeader

func DecodeHeader(header uint16) (offset int, typeID Type)

DecodeHeader splits a header entry into offset and type tag

func DecodeType

func DecodeType(header uint16) Type

func (Type) String

func (t Type) String() string

String returns the human-readable name of the type

Jump to

Keyboard shortcuts

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