Documentation ¶
Index ¶
- Constants
- Variables
- func Decode(k []byte, wrappedValue []byte) (interface{}, error)
- func DecodeBytes(b []byte, r []byte) ([]byte, []byte)
- func DecodeBytesDecreasing(b []byte, r []byte) ([]byte, []byte)
- func DecodeKey(b []byte, format string, args ...interface{}) []byte
- func DecodeNumericFloat(buf []byte) ([]byte, float64)
- func DecodeNumericInt(buf []byte) ([]byte, int64)
- func DecodeNumericIntDecreasing(buf []byte) ([]byte, int64)
- func DecodeUint32(b []byte) ([]byte, uint32)
- func DecodeUint32Decreasing(b []byte) ([]byte, uint32)
- func DecodeUint64(b []byte) ([]byte, uint64)
- func DecodeUint64Decreasing(b []byte) ([]byte, uint64)
- func DecodeUvarint(b []byte) ([]byte, uint64)
- func DecodeUvarintDecreasing(b []byte) ([]byte, uint64)
- func DecodeVarint(b []byte) ([]byte, int64)
- func DecodeVarintDecreasing(b []byte) ([]byte, int64)
- func Encode(k []byte, v interface{}) ([]byte, error)
- func EncodeBytes(b []byte, data []byte) []byte
- func EncodeBytesDecreasing(b []byte, data []byte) []byte
- func EncodeKey(b []byte, format string, args ...interface{}) []byte
- func EncodeNumericFloat(b []byte, f float64) []byte
- func EncodeNumericInt(b []byte, i int64) []byte
- func EncodeNumericIntDecreasing(b []byte, i int64) []byte
- func EncodeUint32(b []byte, v uint32) []byte
- func EncodeUint32Decreasing(b []byte, v uint32) []byte
- func EncodeUint64(b []byte, v uint64) []byte
- func EncodeUint64Decreasing(b []byte, v uint64) []byte
- func EncodeUvarint(b []byte, v uint64) []byte
- func EncodeUvarintDecreasing(b []byte, v uint64) []byte
- func EncodeVarint(b []byte, v int64) []byte
- func EncodeVarintDecreasing(b []byte, v int64) []byte
- func NewCRC32Checksum(b []byte) hash.Hash32
- func ReleaseCRC32Checksum(crc hash.Hash32)
- func WillOverflow(a, b int64) bool
Constants ¶
const (
// MaxUvarintSize is the maximum size in bytes of an encoded uvarint.
MaxUvarintSize = 9
)
Variables ¶
var ( // Infinity compares greater than every other encoded value. Infinity = []byte{0xff, 0xff} )
Functions ¶
func Decode ¶
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. TODO(petermattis) remove this: the only use is in storage/engine.go:Increment.
func DecodeBytes ¶
DecodeBytes decodes a []byte value from the input buffer which was encoded using EncodeBytes. The decoded bytes are appended to r. The remainder of the input buffer and the decoded []byte are returned.
func DecodeBytesDecreasing ¶
DecodeBytesDecreasing decodes a []byte value from the input buffer which was encoded using EncodeBytesDecreasing. The decoded bytes are appended to r. The remainder of the input buffer and the decoded []byte are returned.
func DecodeKey ¶
DecodeKey decodes values from a byte slice according to the format string. Returns the remainder of the byte slice if it was not completely consumed by the format string. See EncodeKey for details of the format specifiers.
The variadic arguments must be pointers to the types specified by the format string. For example, '%d" requires a '*int64' argument.
func DecodeNumericFloat ¶
DecodeNumericFloat returns the remaining byte slice after decoding and the decoded float64 from buf.
func DecodeNumericInt ¶
DecodeNumericInt returns the remaining byte slice after decoding and the decoded int64 from buf.
func DecodeNumericIntDecreasing ¶
DecodeNumericIntDecreasing returns the remaining byte slice after decoding and the decoded int64 in decreasing order from buf.
func DecodeUint32 ¶
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 ¶
DecodeUint32Decreasing decodes a uint32 value which was encoded using EncodeUint32Decreasing.
func DecodeUint64 ¶
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 ¶
DecodeUint64Decreasing decodes a uint64 value which was encoded using EncodeUint64Decreasing.
func DecodeUvarint ¶
DecodeUvarint decodes a varint encoded uint64 from the input buffer. The remainder of the input buffer and the decoded uint64 are returned.
func DecodeUvarintDecreasing ¶
DecodeUvarintDecreasing decodes a uint64 value which was encoded using EncodeUvarintDecreasing.
func DecodeVarint ¶
DecodeVarint decodes a varint encoded int64 from the input buffer. The remainder of the input buffer and the decoded int64 are returned.
func DecodeVarintDecreasing ¶
DecodeVarintDecreasing decodes a uint64 value which was encoded using EncodeVarintDecreasing.
func Encode ¶
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). TODO(petermattis) remove this: the only use is in storage/engine.go:Increment.
func EncodeBytes ¶
EncodeBytes encodes the []byte value using an escape-based encoding. The encoded value is terminated with the sequence "\x00\x01" which is guaranteed to not occur elsewhere in the encoded value. The encoded bytes are append to the supplied buffer and the resulting buffer is returned.
The encoded data is guaranteed to compare less than the Infinity symbol \xff\xff. This is accomplished by transforming \xff to \xff\x00 when it occurs at the beginning of the bytes to encode.
func EncodeBytesDecreasing ¶
EncodeBytesDecreasing encodes the []byte value using an escape-based encoding and then inverts (ones complement) the result so that it sorts in reverse order, from larger to smaller lexicographically.
func EncodeKey ¶
EncodeKey encodes values to a byte slice according to a format string. Returns the byte slice containing the encoded values.
The format string is printf-style with caveats: the primary being that the "fixed" portion of the format must occur as a prefix to the format. The verbs specify precisely what argument type is expected and no attempt is made to perform type conversion. For example, '%d' specifies an argument type of 'int64'. A panic will occur if any other type is encountered.
The verbs:
%d varint (int64) increasing %-d varint (int64) decreasing %u uvarint (uint64) increasing %-u uvarint (uint64) increasing %32u uint32 increasing %-32u uint32 increasing %64u uint64 increasing %-64u uint64 increasing %s bytes ([]byte,string) increasing %-s bytes ([]byte,string) decreasing
func EncodeNumericFloat ¶
EncodeNumericFloat returns the resulting byte slice with the encoded float64 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.
The resulting numeric encodings are all comparable. That is, the result from EncodeNumericInt is comparable with the result from EncodeNumericFloat. But this flexibility comes at the cost of speed. Prefer the EncodeUvarint{32,64} routines for speed.
func EncodeNumericInt ¶
EncodeNumericInt returns the resulting byte slice with the encoded int64 appended to b. See the notes for EncodeNumericFloat for a complete description.
func EncodeNumericIntDecreasing ¶
EncodeNumericIntDecreasing returns the resulting byte slice with the encoded int64 value in decreasing order appended to b.
func EncodeUint32 ¶
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 ¶
EncodeUint32Decreasing encodes the uint32 value so that it sorts in reverse order, from largest to smallest.
func EncodeUint64 ¶
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 ¶
EncodeUint64Decreasing encodes the uint64 value so that it sorts in reverse order, from largest to smallest.
func EncodeUvarint ¶
EncodeUvarint encodes the uint64 value using a variable length (length-prefixed) representation. The length is encoded as a single byte indicating the number of encoded bytes (-8) to follow. See EncodeVarint for rationale. The encoded bytes are appended to the supplied buffer and the final buffer is returned.
func EncodeUvarintDecreasing ¶
EncodeUvarintDecreasing encodes the uint64 value so that it sorts in reverse order, from largest to smallest.
func EncodeVarint ¶
EncodeVarint encodes the int64 value using a variable length (length-prefixed) representation. The length is encoded as a single byte. If the value to be encoded is negative the length is encoded as 8-numBytes. If the value is positive it is encoded as 8+numBytes. The encoded bytes are appended to the supplied buffer and the final buffer is returned.
func EncodeVarintDecreasing ¶
EncodeVarintDecreasing encodes the uint64 value so that it sorts in reverse order, from largest to smallest.
func NewCRC32Checksum ¶
NewCRC32Checksum returns a CRC32 checksum computed from the input byte slice.
func ReleaseCRC32Checksum ¶
ReleaseCRC32Checksum releases a CRC32 back to the allocation pool.
func WillOverflow ¶
WillOverflow returns true if and only if adding both inputs would under- or overflow the 64 bit integer range.
Types ¶
This section is empty.