bytemap

package module
v0.0.0-...-b07440a Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2021 License: Apache-2.0 Imports: 5 Imported by: 8

Documentation

Overview

Package bytemap provides a map[string]interface{} encoded as a byte slice.

Index

Constants

View Source
const (
	TypeNil = iota
	TypeBool
	TypeByte
	TypeUInt16
	TypeUInt32
	TypeUInt64
	TypeInt8
	TypeInt16
	TypeInt32
	TypeInt64
	TypeInt
	TypeFloat32
	TypeFloat64
	TypeString
	TypeTime
	TypeUInt
	TypeBytes
	TypeFloat64s
	TypeInts
)
View Source
const (
	SizeKeyLen      = 2
	SizeValueType   = 1
	SizeValueOffset = 4
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ByteMap

type ByteMap []byte

ByteMap is an immutable map[string]interface{} backed by a byte array.

func Build

func Build(iterate func(func(string, interface{})), valueFor func(string) interface{}, iteratesSorted bool) ByteMap

Build builds a new ByteMap using a function that iterates over all included key/value paris and another function that returns the value for a given key/ index. If iteratesSorted is true, then the iterate order of iterate is considered to be in lexicographically sorted order over the keys and is stable over multiple invocations, and valueFor is not needed.

func FromSortedKeysAndFloats

func FromSortedKeysAndFloats(keys []string, values []float64) ByteMap

FromSortedKeysAndFloats constructs a ByteMap from sorted keys and float values.

func FromSortedKeysAndValues

func FromSortedKeysAndValues(keys []string, values []interface{}) ByteMap

FromSortedKeysAndValues constructs a ByteMap from sorted keys and values.

func New

func New(m map[string]interface{}) ByteMap

New creates a new ByteMap from the given map

func NewFloat

func NewFloat(m map[string]float64) ByteMap

NewFloat creates a new ByteMap from the given map

func (ByteMap) AsMap

func (bm ByteMap) AsMap() map[string]interface{}

AsMap returns a map representation of this ByteMap.

func (ByteMap) Get

func (bm ByteMap) Get(key string) interface{}

Get gets the value for the given key, or nil if the key is not found.

func (ByteMap) GetBytes

func (bm ByteMap) GetBytes(key string) []byte

GetBytes gets the bytes slice for the given key, or nil if the key is not found.

func (ByteMap) Iterate

func (bm ByteMap) Iterate(includeValue bool, includeBytes bool, cb func(key string, value interface{}, valueBytes []byte) bool)

Iterate iterates over the key/value pairs in this ByteMap and calls the given callback with each. If the callback returns false, iteration stops even if there remain unread values. includeValue and includeBytes determine whether to include the value, the bytes or both in the callback.

func (ByteMap) IterateValueBytes

func (bm ByteMap) IterateValueBytes(cb func(key string, valueBytes []byte) bool)

IterateValueBytes iterates over the key/value bytes pairs in this ByteMap and calls the given callback with each. If the callback returns false, iteration stops even if there remain unread values.

func (ByteMap) IterateValues

func (bm ByteMap) IterateValues(cb func(key string, value interface{}) bool)

IterateValues iterates over the key/value pairs in this ByteMap and calls the given callback with each. If the callback returns false, iteration stops even if there remain unread values.

func (ByteMap) Slice

func (bm ByteMap) Slice(includeKeys map[string]bool) ByteMap

Slice creates a new ByteMap that contains only the specified keys from the original.

func (ByteMap) Split

func (bm ByteMap) Split(includeKeys map[string]bool) (ByteMap, ByteMap)

Split returns two byte maps, the first containing all of the specified keys and the second containing all of the other keys.

Jump to

Keyboard shortcuts

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