encoding

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TombstoneValue byte = 0

	// Null
	NullValue byte = 2

	// Booleans
	FalseValue byte = 5
	TrueValue  byte = 6

	// Negative integers
	Int64Value byte = 12
	Int32Value byte = 13
	Int16Value byte = 14
	Int8Value  byte = 15

	// Contiguous block of 64 integers.
	// Types from 16 to 79 represent
	// values from -32 to 31
	IntSmallValue byte = 16

	// Positive integers
	Uint8Value  byte = 80
	Uint16Value byte = 81
	Uint32Value byte = 82
	Uint64Value byte = 83

	// Floating point numbers
	Float64Value byte = 90

	// Text
	TextValue byte = 98

	// Binary
	BlobValue byte = 103

	// Arrays
	ArrayValue byte = 110

	// Objects
	ObjectValue byte = 120

	// DESC_ prefix means that the value is encoded in reverse order.
	DESC_ObjectValue   byte = 255 - ObjectValue
	DESC_ArrayValue    byte = 255 - ArrayValue
	DESC_BlobValue     byte = 255 - BlobValue
	DESC_TextValue     byte = 255 - TextValue
	DESC_Float64Value  byte = 255 - Float64Value
	DESC_Uint64Value   byte = 255 - Uint64Value
	DESC_Uint32Value   byte = 255 - Uint32Value
	DESC_Uint16Value   byte = 255 - Uint16Value
	DESC_Uint8Value    byte = 255 - Uint8Value
	DESC_IntSmallValue byte = 255 - IntSmallValue
	DESC_Int8Value     byte = 255 - Int8Value
	DESC_Int16Value    byte = 255 - Int16Value
	DESC_Int32Value    byte = 255 - Int32Value
	DESC_Int64Value    byte = 255 - Int64Value
	DESC_TrueValue     byte = 255 - TrueValue
	DESC_FalseValue    byte = 255 - FalseValue
	DESC_NullValue     byte = 255 - NullValue
)

Types used to encode values in the tree. They are sorted from the smallest to largest. Each type is encoded on 1 byte and describes two things: - the type of the field - the sort order of the field (ASC or DESC) The first 128 values are used for ASC order, the last 128 values are used for DESC order. A block of 64 is reserved for small integers in the range [-32, 31]. Gaps are left between each type to allow adding new types in the future.

Variables

This section is empty.

Functions

func AbbreviatedKey

func AbbreviatedKey(key []byte) uint64

AbbreviatedKey returns a shortened version that is used for comparing keys during indexed batch comparisons. The key is not guaranteed to be unique, but it respects the same ordering as the original key. If two abbreviated keys are equal, Pebble will call the Equal function to determine if the original keys are equal. The key is constructed as follows: - 12 bits: the namespace, from 0 to 4096. If bigger than 4096, returns math.MaxUint64. - 4 bits: the Chai type of the first value. - 48 bits: a representation of the first value of the key, depending on its type.

func Compare

func Compare(a, b []byte) int

func ConvertToTimestamp

func ConvertToTimestamp(x int64) time.Time

func DecodeArray

func DecodeArray(b []byte, intAsDouble bool) types.Array

func DecodeBlob

func DecodeBlob(b []byte) ([]byte, int)

func DecodeBoolean

func DecodeBoolean(b []byte) bool

func DecodeFloat

func DecodeFloat(b []byte) (float64, int)

func DecodeFloat64

func DecodeFloat64(b []byte) float64

func DecodeInt

func DecodeInt(b []byte) (int64, int)

func DecodeInt16

func DecodeInt16(b []byte) int16

func DecodeInt32

func DecodeInt32(b []byte) int32

func DecodeInt64

func DecodeInt64(b []byte) int64

func DecodeInt8

func DecodeInt8(b []byte) int8

func DecodeObject

func DecodeObject(b []byte, intAsDouble bool) types.Object

func DecodeText

func DecodeText(b []byte) (string, int)

func DecodeTimestamp

func DecodeTimestamp(b []byte) (time.Time, int)

func DecodeUint16

func DecodeUint16(b []byte) uint16

func DecodeUint32

func DecodeUint32(b []byte) uint32

func DecodeUint64

func DecodeUint64(b []byte) uint64

func DecodeUint8

func DecodeUint8(b []byte) uint8

func DecodeValue

func DecodeValue(b []byte, intAsDouble bool) (types.Value, int)

func Desc

func Desc(dst []byte, n int) ([]byte, int)

Desc changes the type of the encoded value to its descending counterpart. It is meant to be used in combination with one of the Encode* functions.

var buf []byte
buf, n = encoding.Desc(encoding.EncodeInt(buf, 10))

func EncodeArray

func EncodeArray(dst []byte, a types.Array) ([]byte, error)

func EncodeArrayLength

func EncodeArrayLength(dst []byte, l int) []byte

func EncodeBlob

func EncodeBlob(dst []byte, x []byte) []byte

func EncodeBoolean

func EncodeBoolean(dst []byte, x bool) []byte

func EncodeFloat

func EncodeFloat(dst []byte, x float64) []byte

func EncodeFloat64

func EncodeFloat64(dst []byte, x float64) []byte

func EncodeInt

func EncodeInt(dst []byte, n int64) []byte

func EncodeInt16

func EncodeInt16(dst []byte, n int16) []byte

func EncodeInt32

func EncodeInt32(dst []byte, n int32) []byte

func EncodeInt64

func EncodeInt64(dst []byte, n int64) []byte

func EncodeInt8

func EncodeInt8(dst []byte, n int8) []byte

func EncodeNull

func EncodeNull(dst []byte) []byte

func EncodeObject

func EncodeObject(dst []byte, d types.Object) ([]byte, error)

func EncodeObjectLength

func EncodeObjectLength(dst []byte, l int) []byte

func EncodeText

func EncodeText(dst []byte, x string) []byte

func EncodeTimestamp

func EncodeTimestamp(dst []byte, t time.Time) []byte

func EncodeUint

func EncodeUint(dst []byte, n uint64) []byte

func EncodeUint16

func EncodeUint16(dst []byte, n uint16) []byte

func EncodeUint32

func EncodeUint32(dst []byte, n uint32) []byte

func EncodeUint64

func EncodeUint64(dst []byte, n uint64) []byte

func EncodeUint8

func EncodeUint8(dst []byte, n uint8) []byte

func EncodeValue

func EncodeValue(dst []byte, v types.Value, desc bool) ([]byte, error)

func Equal

func Equal(a, b []byte) bool

func Separator

func Separator(dst, a, b []byte) []byte

func Skip

func Skip(b []byte) int

func SkipArray

func SkipArray(b []byte) int

func SkipObject

func SkipObject(b []byte) int

func Successor

func Successor(dst, a []byte) []byte

Types

type EncodedArray

type EncodedArray struct {
	// contains filtered or unexported fields
}

An EncodedArray implements the types.Array interface on top of an encoded representation of an array. It is useful for avoiding decoding the entire array when only a few values are needed.

func (*EncodedArray) GetByIndex

func (e *EncodedArray) GetByIndex(idx int) (v types.Value, err error)

GetByIndex returns a value by index of the array.

func (*EncodedArray) Iterate

func (e *EncodedArray) Iterate(fn func(i int, value types.Value) error) error

Iterate goes through all the values of the array and calls the given function by passing each one of them. If the given function returns an error, the iteration stops.

func (*EncodedArray) MarshalJSON

func (e *EncodedArray) MarshalJSON() ([]byte, error)

type EncodedObject

type EncodedObject struct {
	Encoded []byte
	// contains filtered or unexported fields
}

func (*EncodedObject) GetByField

func (e *EncodedObject) GetByField(field string) (types.Value, error)

func (*EncodedObject) Iterate

func (e *EncodedObject) Iterate(fn func(k string, v types.Value) error) error

func (*EncodedObject) MarshalJSON

func (e *EncodedObject) MarshalJSON() ([]byte, error)

Jump to

Keyboard shortcuts

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