objectpacker

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: GPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustPackSlice

func MustPackSlice(items ...interface{}) []byte

MustPackSlice calls PackAny using items and panics if there was an error.

func PackAny

func PackAny(in interface{}, out io.Writer) error

PackAny packs any JSON-encodable value (ex. structs, also ignores interfaces like encoding.TextMarshaler) to a BSON-similar format suitable for consistent hashing. Spec:

PackAny(nil) => 0x0 PackAny(false) => 0x1 PackAny(true) => 0x2 PackAny(float64(42)) => 0x3 ieee754_binary64_bigendian(42) PackAny("exämple") => 0x4 uint64_bigendian(len([]byte("exämple"))) []byte("exämple") PackAny([]uint8{0x42}) => 0x4 uint64_bigendian(len([]uint8{0x42})) []uint8{0x42} PackAny([1]uint8{0x42}) => 0x4 uint64_bigendian(len([1]uint8{0x42})) [1]uint8{0x42} PackAny([]T{x,y}) => 0x5 uint64_bigendian(len([]T{x,y})) PackAny(x) PackAny(y) PackAny(map[K]V{x:y}) => 0x6 uint64_bigendian(len(map[K]V{x:y})) len(map_key(x)) map_key(x) PackAny(y) PackAny((*T)(nil)) => 0x0 PackAny((*T)(0x42)) => PackAny(*(*T)(0x42)) PackAny(x) => panic()

map_key([1]uint8{0x42}) => [1]uint8{0x42} map_key(x) => []byte(fmt.Sprint(x))

Types

This section is empty.

Jump to

Keyboard shortcuts

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