encoding

package
v0.0.0-...-9741dc9 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2014 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxIntSize is the maximum encoded integer size in bytes.
	MaxIntSize = 12
)

Maximum sizes for allocating buffers to hold encoded values.

Variables

This section is empty.

Functions

func Decode

func Decode(k []byte, wrappedValue []byte) (interface{}, error)

Decode decodes a Go datatype from a value stored in the key-value store. It returns either an error or a variable of the decoded value.

func DecodeBinary

func DecodeBinary(buf []byte) ([]byte, []byte)

DecodeBinary decodes the given key-encoded byte slice, returning the unencoded byte slice value. (see documentation for EncodeBinary for more details). The first return argument is the remainder of the input buffer, after decoding the binary value.

func DecodeBinaryFinal

func DecodeBinaryFinal(buf []byte) []byte

DecodeBinaryFinal decodes a byte slice and returns the result presuming that it is the last part of the buffer (see documentation for EncodeBinary for more details).

func DecodeInt

func DecodeInt(buf []byte) ([]byte, int64)

DecodeInt returns the remaining byte slice after decoding and the decoded int64 from buf.

func DecodeIntDecreasing

func DecodeIntDecreasing(buf []byte) ([]byte, int64)

DecodeIntDecreasing returns the remaining byte slice after decoding and the decoded int64 in decreasing order from buf.

func DecodeString

func DecodeString(b []byte) ([]byte, string)

DecodeString returns the remaining byte slice after decoding and the decoded string from b.

func DecodeUint32

func DecodeUint32(b []byte) ([]byte, uint32)

DecodeUint32 decodes a uint32 from the input buffer, treating the input as a big-endian 8 byte uint32 representation. The remainder of the input buffer and the decoded uint32 are returned.

func DecodeUint32Decreasing

func DecodeUint32Decreasing(b []byte) ([]byte, uint32)

DecodeUint32Decreasing decodes a uint32 value which was encoded using EncodeUint32Decreasing.

func DecodeUint64

func DecodeUint64(b []byte) ([]byte, uint64)

DecodeUint64 decodes a uint64 from the input buffer, treating the input as a big-endian 8 byte uint64 representation. The remainder of the input buffer and the decoded uint64 are returned.

func DecodeUint64Decreasing

func DecodeUint64Decreasing(b []byte) ([]byte, uint64)

DecodeUint64Decreasing decodes a uint64 value which was encoded using EncodeUint64Decreasing.

func DecodeVarUint64

func DecodeVarUint64(b []byte) ([]byte, uint64)

DecodeVarUint64 decodes a uint64 from the input buffer, treating the input as a big-endian 8 byte uint64 representation. The remainder of the input buffer and the decoded uint64 are returned.

func DecodeVarUint64Decreasing

func DecodeVarUint64Decreasing(b []byte) ([]byte, uint64)

DecodeVarUint64Decreasing decodes a uint64 value which was encoded using EncodeVarUint64Decreasing.

func Encode

func Encode(k []byte, v interface{}) ([]byte, error)

Encode translates the given value into a byte representation used to store it in the underlying key-value store. It typically applies to user-level keys, but not to keys operated on internally, such as accounting keys. It returns a byte slice containing, in order, the internal representation of v and a checksum of (k+v).

func EncodeBinary

func EncodeBinary(b []byte, i []byte) []byte

EncodeBinary returns the resulting byte slice with i encoded and appended to b.

The encoding of binaries fields is different depending on whether or not the value to be encoded is the last value (the right-most value) in the key.

Each value that is BINARY that is not the last value of the key begins with a single byte of 0x25 and ends with a single terminator byte of 0x00. There are zero or more intervening bytes that encode the binary value. None of the intervening bytes may be zero. Each of the intervening bytes contains 7 bits of blob content with a 1 in the high-order bit (the 0x80 bit). Each encoded byte thereafter consists of a high-order bit followed by 7 bits of payload. An empty input value is encoded as the header byte immediately followed by a termination byte 0x00.

When the very last value of a key is BINARY, then it is encoded as a single byte of 0x26 and is followed by a byte-for-byte copy of the BINARY value. This alternative encoding is more efficient, but it only works if there are no subsequent values in the key, since there is no termination mark on the BLOB being encoded.

The initial byte of a binary value, 0x25 or 0x26, is larger than the initial byte of a text value, 0x24, ensuring that every binary value will sort after every text value.

func EncodeBinaryFinal

func EncodeBinaryFinal(b []byte) []byte

EncodeBinaryFinal encodes a byte slice and returns the result presuming that the byte slice is the last portion of the buffer (see the comment for EncodeBinary).

func EncodeFloat

func EncodeFloat(b []byte, f float64) []byte

EncodeFloat returns the resulting byte slice with the encoded float64 and appended to b.

Values are classified as large, medium, or small according to the value of E. If E is 11 or more, the value is large. For E between 0 and 10, the value is medium. For E less than zero, the value is small.

Large positive values are encoded as a single byte 0x22 followed by E as a varint and then M. Medium positive values are a single byte of 0x17+E followed by M. Small positive values are encoded as a single byte 0x16 followed by the ones-complement of the varint for -E followed by M.

Small negative values are encoded as a single byte 0x14 followed by -E as a varint and then the ones-complement of M. Medium negative values are encoded as a byte 0x13-E followed by the ones-complement of M. Large negative values consist of the single byte 0x08 followed by the ones-complement of the varint encoding of E followed by the ones-complement of M.

func EncodeInt

func EncodeInt(b []byte, i int64) []byte

EncodeInt returns the resulting byte slice with the encoded int64 and appended to b. See the notes for EncodeFloat for a complete description.

func EncodeIntDecreasing

func EncodeIntDecreasing(b []byte, i int64) []byte

EncodeIntDecreasing returns the resulting byte slice with the encoded int64 values in decreasing order and appended to b.

func EncodeNil

func EncodeNil() []byte

EncodeNil returns a byte slice containing a nil-encoded value.

func EncodeString

func EncodeString(b []byte, s string) []byte

EncodeString returns the resulting byte slice with s encoded and appended to b. If b is nil, it is treated as an empty byte slice. If s is not a valid utf8-encoded string or contains an intervening 0x00 byte, EncodeString will panic.

Each value that is TEXT begins with a single byte of 0x24 and ends with a single byte of 0x00. There are zero or more intervening bytes that encode the text value. The intervening bytes are chosen so that the encoding will sort in the desired collating order. The default sequence of bytes is simply UTF8. The intervening bytes may not contain a 0x00 character; the only 0x00 byte allowed in a text encoding is the final byte.

Note that all key-encoded text with the BINARY collating sequence is simply UTF8 text. UTF8 not UTF16. Strings must be converted to UTF8 so that equivalent strings in different encodings compare the same and so that the strings contain no embedded 0x00 bytes. In other words, strcmp() should be sufficient for comparing two text keys.

The text encoding ends in 0x00 in order to ensure that when there are two strings where one is a prefix of the other that the shorter string will sort first.

func EncodeUint32

func EncodeUint32(b []byte, v uint32) []byte

EncodeUint32 encodes the uint32 value using a big-endian 8 byte representation. The bytes are appended to the supplied buffer and the final buffer is returned.

func EncodeUint32Decreasing

func EncodeUint32Decreasing(b []byte, v uint32) []byte

EncodeUint32Decreasing encodes the uint32 value so that it sorts in reverse order, from largest to smallest.

func EncodeUint64

func EncodeUint64(b []byte, v uint64) []byte

EncodeUint64 encodes the uint64 value using a big-endian 8 byte representation. The bytes are appended to the supplied buffer and the final buffer is returned.

func EncodeUint64Decreasing

func EncodeUint64Decreasing(b []byte, v uint64) []byte

EncodeUint64Decreasing encodes the uint64 value so that it sorts in reverse order, from largest to smallest.

func EncodeVarUint64

func EncodeVarUint64(b []byte, v uint64) []byte

EncodeVarUint64 encodes the uint64 value using a variable length (length-prefixed) big-endian 8 byte representation. The bytes are appended to the supplied buffer and the final buffer is returned.

func EncodeVarUint64Decreasing

func EncodeVarUint64Decreasing(b []byte, v uint64) []byte

EncodeVarUint64Decreasing encodes the uint64 value so that it sorts in reverse order, from largest to smallest.

func GetUVarint

func GetUVarint(b []byte) (uint64, int)

GetUVarint decodes a varint-encoded byte slice and returns the result and the length of byte slice been used.

func GobDecode

func GobDecode(b []byte) (interface{}, error)

GobDecode is a convenience function to return the unmarshaled value of the given byte slice. If the value implements an interface, it needs to be registered before GobEncode can be used.

func GobEncode

func GobEncode(v interface{}) ([]byte, error)

GobEncode is a convenience function to return the gob representation of the given value. If this value implements an interface, it needs to be registered before GobEncode can be used.

func MustGobDecode

func MustGobDecode(b []byte) interface{}

MustGobDecode calls GobDecode and panics in case of an error.

func MustGobEncode

func MustGobEncode(o interface{}) []byte

MustGobEncode calls GobEncode and panics in case of an error.

func NewCRC32Checksum

func NewCRC32Checksum(b []byte) hash.Hash32

NewCRC32Checksum returns a CRC32 checksum computed from the input byte slice.

func PutUvarint

func PutUvarint(buf []byte, x uint64) int

PutUvarint encodes a uint64 into buf and returns the number of bytes written. If the buffer is too small, a panic will ensue.

func WillOverflow

func WillOverflow(a, b int64) bool

WillOverflow returns true if and only if adding both inputs would under- or overflow the 64 bit integer range.

Types

This section is empty.

Jump to

Keyboard shortcuts

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