encoding

package
Version: v0.0.0-...-f0ea040 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2015 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeBytes

func DecodeBytes(b []byte, r []byte) ([]byte, []byte, error)

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

func DecodeBytesDecreasing(b []byte, r []byte) ([]byte, []byte, error)

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 DecodeFloat

func DecodeFloat(buf []byte, tmp []byte) ([]byte, float64, error)

DecodeFloat returns the remaining byte slice after decoding and the decoded float64 from buf.

func DecodeIfNotNull

func DecodeIfNotNull(b []byte) ([]byte, bool)

DecodeIfNotNull decodes a not-NULL value from the input buffer. If the input buffer contains a not-NULL marker at the start of the buffer then it is removed from the buffer and true is returned for the second result. Otherwise, the buffer is returned unchanged and false is returned for the second result. Note that the not-NULL marker is identical to the empty string encoding, so do not use this routine where it is necessary to distinguish not-NULL from the empty string.

func DecodeIfNull

func DecodeIfNull(b []byte) ([]byte, bool)

DecodeIfNull decodes a NULL value from the input buffer. If the input buffer contains a null at the start of the buffer then it is removed from the buffer and true is returned for the second result. Otherwise, the buffer is returned unchanged and false is returned for the second result. Since the NULL value encoding is guaranteed to never occur as the prefix for the EncodeVarint, EncodeFloat, EncodeBytes and EncodeString encodings, it is safe to call DecodeIfNull on their encoded values.

func DecodeString

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

DecodeString decodes a string value from the input buffer which was encoded using EncodeString or EncodeBytes. The r []byte is used as a temporary buffer in order to avoid memory allocations. The remainder of the input buffer and the decoded string are returned.

func DecodeStringDecreasing

func DecodeStringDecreasing(b []byte, r []byte) ([]byte, string, error)

DecodeStringDecreasing decodes a string value from the input buffer which was encoded using EncodeStringDecreasing or EncodeBytesDecreasing. The r []byte is used as a temporary buffer in order to avoid memory allocations. The remainder of the input buffer and the decoded string are returned.

func DecodeTime

func DecodeTime(b []byte) ([]byte, time.Time, error)

DecodeTime decodes a time.Time value which was encoded using EncodeTime. The remainder of the input buffer and the decoded time.Time are returned.

func DecodeUint32

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

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, error)

DecodeUint32Decreasing decodes a uint32 value which was encoded using EncodeUint32Decreasing.

func DecodeUint64

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

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, error)

DecodeUint64Decreasing decodes a uint64 value which was encoded using EncodeUint64Decreasing.

func DecodeUvarint

func DecodeUvarint(b []byte) ([]byte, uint64, error)

DecodeUvarint decodes a varint encoded uint64 from the input buffer. The remainder of the input buffer and the decoded uint64 are returned.

func DecodeUvarintDecreasing

func DecodeUvarintDecreasing(b []byte) ([]byte, uint64, error)

DecodeUvarintDecreasing decodes a uint64 value which was encoded using EncodeUvarintDecreasing.

func DecodeVarint

func DecodeVarint(b []byte) ([]byte, int64, error)

DecodeVarint decodes a varint encoded int64 from the input buffer. The remainder of the input buffer and the decoded int64 are returned.

func DecodeVarintDecreasing

func DecodeVarintDecreasing(b []byte) ([]byte, int64, error)

DecodeVarintDecreasing decodes a uint64 value which was encoded using EncodeVarintDecreasing.

func EncodeBytes

func EncodeBytes(b []byte, data []byte) []byte

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.

func EncodeBytesDecreasing

func EncodeBytesDecreasing(b []byte, data []byte) []byte

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 EncodeFloat

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

EncodeFloat 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.

func EncodeNotNull

func EncodeNotNull(b []byte) []byte

EncodeNotNull encodes a value that is larger than the NULL marker encoded by EncodeNull but less than any encoded value returned by EncodeVarint, EncodeFloat, EncodeBytes or EncodeString.

func EncodeNull

func EncodeNull(b []byte) []byte

EncodeNull encodes a NULL value. The encodes bytes are appended to the supplied buffer and the final buffer is returned. The encoded value for a NULL is guaranteed to not be a prefix for the EncodeVarint, EncodeFloat, EncodeBytes and EncodeString encodings.

func EncodeString

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

EncodeString encodes the string value using an escape-based encoding. See EncodeBytes for details. The encoded bytes are append to the supplied buffer and the resulting buffer is returned.

func EncodeStringDecreasing

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

EncodeStringDecreasing encodes the string value using an escape-based encoding. See EncodeBytesDecreasing for details. The encoded bytes are append to the supplied buffer and the resulting buffer is returned.

func EncodeTime

func EncodeTime(b []byte, t time.Time) []byte

EncodeTime encodes a time value, appends it to the supplied buffer, and returns the final buffer. The encoding is guaranteed to be ordered Such that if t1.Before(t2) then after EncodeTime(b1, t1), and EncodeTime(b2, t1), Compare(b1, b2) < 0. The time zone offset not included in the encoding.

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 EncodeUvarint

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

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

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

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

func EncodeVarint

func EncodeVarint(b []byte, v int64) []byte

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

func EncodeVarintDecreasing(b []byte, v int64) []byte

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

Types

type Type

type Type int

Type represents the type of a value encoded by Encode{Null,NotNull,Varint,Uvarint,Float,Bytes}.

const (
	Unknown Type = iota
	Null
	NotNull
	Int
	Float
	Bytes
	Time
)

Type values.

func PeekType

func PeekType(b []byte) Type

PeekType peeks at the type of the value encoded at the start of b.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL