Documentation ¶
Index ¶
- Constants
- func AddJSONPathTerminator(b []byte) []byte
- func DecodeDecimalAscending(buf []byte, tmp []byte) ([]byte, apd.Decimal, error)
- func DecodeDecimalDescending(buf []byte, tmp []byte) ([]byte, apd.Decimal, error)
- func DecodeFloatAscending(buf []byte) ([]byte, float64, error)
- func DecodeFloatDescending(buf []byte) ([]byte, float64, error)
- func DecodeIntoNonsortingDecimal(dec *apd.Decimal, buf []byte, tmp []byte) error
- func DecodeNonsortingDecimal(buf []byte, tmp []byte) (apd.Decimal, error)
- func DecodeNonsortingStdlibUvarint(buf []byte) (remaining []byte, length int, value uint64, err error)
- func DecodeNonsortingStdlibVarint(b []byte) (remaining []byte, length int, value int64, err error)
- func DecodeNonsortingUvarint(buf []byte) (remaining []byte, length int, value uint64, err error)
- func DecodeUint32Ascending(b []byte) ([]byte, uint32, error)
- func DecodeUint64Ascending(b []byte) ([]byte, uint64, error)
- func DecodeUntaggedDecimalValue(b []byte) (remaining []byte, d apd.Decimal, err error)
- func DecodeUvarintAscending(b []byte) ([]byte, uint64, error)
- func DecodeUvarintDescending(b []byte) ([]byte, uint64, error)
- func EncLenUvarintAscending(v uint64) int
- func EncLenUvarintDescending(v uint64) int
- func EncodeArrayAscending(b []byte) []byte
- func EncodeDecimalAscending(appendTo []byte, d *apd.Decimal) []byte
- func EncodeDecimalDescending(appendTo []byte, d *apd.Decimal) []byte
- func EncodeFalseAscending(b []byte) []byte
- func EncodeFloatAscending(b []byte, f float64) []byte
- func EncodeFloatDescending(b []byte, f float64) []byte
- func EncodeJSONAscending(b []byte) []byte
- func EncodeJSONEmptyArray(b []byte) []byte
- func EncodeJSONEmptyObject(b []byte) []byte
- func EncodeJSONKeyStringAscending(b []byte, s string, end bool) []byte
- func EncodeNonsortingDecimal(b []byte, d *apd.Decimal) []byte
- func EncodeNullAscending(b []byte) []byte
- func EncodeStringAscending(b []byte, s string) []byte
- func EncodeTrueAscending(b []byte) []byte
- func EncodeUint32Ascending(b []byte, v uint32) []byte
- func EncodeUint64Ascending(b []byte, v uint64) []byte
- func EncodeUntaggedDecimalValue(appendTo []byte, d *apd.Decimal) []byte
- func EncodeUvarintAscending(b []byte, v uint64) []byte
- func EncodeUvarintDescending(b []byte, v uint64) []byte
- func GetMultiVarintLen(b []byte, num int) (int, error)
- func IsArrayKeyDone(buf []byte, dir Direction) bool
- func PeekLength(b []byte) (int, error)
- func PutUint32Ascending(b []byte, v uint32, idx int) []byte
- func UnsafeConvertStringToBytes(s string) []byte
- func UpperBoundNonsortingDecimalSize(d *apd.Decimal) int
- func WordLen(nat []big.Word) int
- type Direction
- type Type
Constants ¶
const ( // IntMin is chosen such that the range of int tags does not overlap the // ascii character set that is frequently used in testing. IntMin = 0x80 // 128 // IntMax is the maximum int tag value. IntMax = 0xfd // 253 )
const MaxVarintLen = 9
MaxVarintLen is the maximum length of a value encoded using any of: - EncodeVarintAscending - EncodeVarintDescending - EncodeUvarintAscending - EncodeUvarintDescending
Variables ¶
This section is empty.
Functions ¶
func AddJSONPathTerminator ¶
AddJSONPathTerminator adds a json path terminator to a byte array.
func DecodeDecimalAscending ¶
DecodeDecimalAscending returns the remaining byte slice after decoding and the decoded decimal from buf.
func DecodeDecimalDescending ¶
DecodeDecimalDescending decodes decimals encoded with EncodeDecimalDescending.
func DecodeFloatAscending ¶
DecodeFloatAscending returns the remaining byte slice after decoding and the decoded float64 from buf.
func DecodeFloatDescending ¶
DecodeFloatDescending decodes floats encoded with EncodeFloatDescending.
func DecodeIntoNonsortingDecimal ¶
DecodeIntoNonsortingDecimal is like DecodeNonsortingDecimal, but it operates on the passed-in *apd.Decimal instead of producing a new one.
func DecodeNonsortingDecimal ¶
DecodeNonsortingDecimal returns the decoded decimal from buf encoded with EncodeNonsortingDecimal. buf is assumed to contain only the encoded decimal, as the function does not know from the encoding itself what the length of the encoded value is.
func DecodeNonsortingStdlibUvarint ¶
func DecodeNonsortingStdlibUvarint( buf []byte, ) (remaining []byte, length int, value uint64, err error)
DecodeNonsortingStdlibUvarint decodes a value encoded with binary.PutUvarint. It returns the length of the encoded varint and value.
func DecodeNonsortingStdlibVarint ¶
DecodeNonsortingStdlibVarint decodes a value encoded by EncodeNonsortingVarint. It returns the length of the encoded varint and value.
func DecodeNonsortingUvarint ¶
DecodeNonsortingUvarint decodes a value encoded by EncodeNonsortingUvarint. It returns the length of the encoded varint and value.
func DecodeUint32Ascending ¶
DecodeUint32Ascending decodes a uint32 from the input buffer, treating the input as a big-endian 4 byte uint32 representation. The remainder of the input buffer and the decoded uint32 are returned.
func DecodeUint64Ascending ¶
DecodeUint64Ascending 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 DecodeUntaggedDecimalValue ¶
DecodeUntaggedDecimalValue decodes a value encoded by EncodeUntaggedDecimalValue.
func DecodeUvarintAscending ¶
DecodeUvarintAscending decodes a varint encoded uint64 from the input buffer. The remainder of the input buffer and the decoded uint64 are returned.
func DecodeUvarintDescending ¶
DecodeUvarintDescending decodes a uint64 value which was encoded using EncodeUvarintDescending.
func EncLenUvarintAscending ¶
EncLenUvarintAscending returns the encoding length for EncodeUvarintAscending without actually encoding.
func EncLenUvarintDescending ¶
EncLenUvarintDescending returns the encoding length for EncodeUvarintDescending without actually encoding.
func EncodeArrayAscending ¶
EncodeArrayAscending encodes a value used to signify membership of an array for JSON objects.
func EncodeDecimalAscending ¶
EncodeDecimalAscending returns the resulting byte slice with the encoded decimal appended to the given buffer.
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 0x34 followed by E as a varint and then M. Medium positive values are a single byte of 0x29+E followed by M. Small positive values are encoded as a single byte 0x28 followed by a descending varint encoding for -E followed by M.
Small negative values are encoded as a single byte 0x26 followed by -E as a varint and then the ones-complement of M. Medium negative values are encoded as a byte 0x25-E followed by the ones-complement of M. Large negative values consist of the single byte 0x1a followed by a descending varint encoding of E followed by the ones-complement of M.
func EncodeDecimalDescending ¶
EncodeDecimalDescending is the descending version of EncodeDecimalAscending.
func EncodeFalseAscending ¶
EncodeFalseAscending encodes the boolean value false for use with JSON inverted indexes.
func EncodeFloatAscending ¶
EncodeFloatAscending returns the resulting byte slice with the encoded float64 appended to b. The encoded format for a float64 value f is, for positive f, the encoding of the 64 bits (in IEEE 754 format) re-interpreted as an int64 and encoded using EncodeUint64Ascending. For negative f, we keep the sign bit and invert all other bits, encoding this value using EncodeUint64Descending. This approach was inspired by in github.com/google/orderedcode/orderedcode.go.
One of five single-byte prefix tags are appended to the front of the encoding. These tags enforce logical ordering of keys for both ascending and descending encoding directions. The tags split the encoded floats into five categories: - NaN for an ascending encoding direction - Negative valued floats - Zero (positive and negative) - Positive valued floats - NaN for a descending encoding direction This ordering ensures that NaNs are always sorted first in either encoding direction, and that after them a logical ordering is followed.
func EncodeFloatDescending ¶
EncodeFloatDescending is the descending version of EncodeFloatAscending.
func EncodeJSONAscending ¶
EncodeJSONAscending encodes a JSON Type. The encoded bytes are appended to the supplied buffer and the final buffer is returned.
func EncodeJSONEmptyArray ¶
EncodeJSONEmptyArray returns a byte array b with a byte to signify an empty JSON array.
func EncodeJSONEmptyObject ¶
EncodeJSONEmptyObject returns a byte array b with a byte to signify an empty JSON object.
func EncodeJSONKeyStringAscending ¶
EncodeJSONKeyStringAscending encodes the JSON key string value with a JSON specific escaped terminator. This allows us to encode keys in the same number of bytes as a string, while at the same time giving us a sentinel to identify JSON keys. The end parameter is used to determine if this is the last key in a a JSON path. If it is we don't add a separator after it.
func EncodeNonsortingDecimal ¶
EncodeNonsortingDecimal returns the resulting byte slice with the encoded decimal appended to b. The encoding is limited compared to standard encodings in this package in that
- It will not sort lexicographically
- It does not encode its length or terminate itself, so decoding functions must be provided the exact encoded bytes
The encoding assumes that any number can be written as ±0.xyz... * 10^exp, where xyz is a digit string, x != 0, and the last decimal in xyz is also not 0.
The encoding uses its first byte to split decimals into 7 distinct ordered groups (no NaN or Infinity support yet). The groups can be seen in encoding.go's const definition. Following this, the absolute value of the exponent of the decimal (as defined above) is encoded as an unsigned varint. Second, the absolute value of the digit string is added as a big-endian byte slice.
All together, the encoding looks like:
<marker><uvarint exponent><big-endian encoded big.Int>.
The markers are shared with the sorting decimal encoding as follows:
decimalNaN -> decimalNaN decimalNegativeInfinity -> decimalNegativeInfinity decimalNegLarge -> decimalNegValPosExp decimalNegMedium -> decimalNegValZeroExp decimalNegSmall -> decimalNegValNegExp decimalZero -> decimalZero decimalPosSmall -> decimalPosValNegExp decimalPosMedium -> decimalPosValZeroExp decimalPosLarge -> decimalPosValPosExp decimalInfinity -> decimalInfinity decimalNaNDesc -> decimalNaNDesc
func EncodeNullAscending ¶
EncodeNullAscending 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 EncodeStringAscending ¶
EncodeStringAscending 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 EncodeTrueAscending ¶
EncodeTrueAscending encodes the boolean value true for use with JSON inverted indexes.
func EncodeUint32Ascending ¶
EncodeUint32Ascending encodes the uint32 value using a big-endian 4 byte representation. The bytes are appended to the supplied buffer and the final buffer is returned.
func EncodeUint64Ascending ¶
EncodeUint64Ascending 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 EncodeUntaggedDecimalValue ¶
EncodeUntaggedDecimalValue encodes an apd.Decimal value, appends it to the supplied buffer, and returns the final buffer.
func EncodeUvarintAscending ¶
EncodeUvarintAscending 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 EncodeVarintAscending for rationale. The encoded bytes are appended to the supplied buffer and the final buffer is returned.
func EncodeUvarintDescending ¶
EncodeUvarintDescending encodes the uint64 value so that it sorts in reverse order, from largest to smallest.
func GetMultiVarintLen ¶
GetMultiVarintLen find the length of <num> encoded varints that follow a 1-byte tag.
func IsArrayKeyDone ¶
IsArrayKeyDone returns if the first byte in the input is the array terminator for the input direction.
func PeekLength ¶
PeekLength returns the length of the encoded value at the start of b. Note: if this function succeeds, it's not a guarantee that decoding the value will succeed. PeekLength is meant to be used on key encoded data only.
func PutUint32Ascending ¶
PutUint32Ascending encodes the uint32 value using a big-endian 4 byte representation at the specified index, lengthening the input slice if necessary.
func UnsafeConvertStringToBytes ¶
UnsafeConvertStringToBytes converts a string to a byte array to be used with string encoding functions. Note that the output byte array should not be modified if the input string is expected to be used again - doing so could violate Go semantics.
func UpperBoundNonsortingDecimalSize ¶
func UpperBoundNonsortingDecimalSize(d *apd.Decimal) int
UpperBoundNonsortingDecimalSize returns the upper bound number of bytes that the decimal will need for the non-sorting encoding.
Types ¶
type Direction ¶
type Direction int
Direction for ordering results.
const ( Ascending Direction Descending )
Direction values.
type Type ¶
type Type int
Type represents the type of a value encoded by Encode{Null,NotNull,Varint,Uvarint,Float,Bytes}.
const ( Unknown Type = 0 Null Type = 1 NotNull Type = 2 Int Type = 3 Float Type = 4 Decimal Type = 5 Bytes Type = 6 BytesDesc Type = 7 // Bytes encoded descendingly Time Type = 8 Duration Type = 9 True Type = 10 False Type = 11 UUID Type = 12 Array Type = 13 IPAddr Type = 14 // SentinelType is used for bit manipulation to check if the encoded type // value requires more than 4 bits, and thus will be encoded in two bytes. It // is not used as a type value, and thus intentionally overlaps with the // subsequent type value. The 'Type' annotation is intentionally omitted here. SentinelType = 15 JSON Type = 15 Tuple Type = 16 BitArray Type = 17 BitArrayDesc Type = 18 // BitArray encoded descendingly TimeTZ Type = 19 Geo Type = 20 GeoDesc Type = 21 ArrayKeyAsc Type = 22 // Array key encoding ArrayKeyDesc Type = 23 // Array key encoded descendingly Box2D Type = 24 )
Type values. TODO(dan, arjun): Make this into a proto enum. The 'Type' annotations are necessary for producing stringer-generated values.
func DecodeValueTag ¶
DecodeValueTag decodes a value encoded by EncodeValueTag, used as a prefix in each of the other EncodeFooValue methods.
The tag is structured such that the encoded column id can be dropped from the front by removing the first `typeOffset` bytes. DecodeValueTag, PeekValueLength and each of the DecodeFooValue methods will still work as expected with `b[typeOffset:]`. (Except, obviously, the column id is no longer encoded so if this suffix is passed back to DecodeValueTag, the returned colID should be discarded.)
Concretely:
b := ... typeOffset, _, colID, typ, err := DecodeValueTag(b) _, _, _, typ, err := DecodeValueTag(b[typeOffset:])
will return the same typ and err and
DecodeFooValue(b) DecodeFooValue(b[typeOffset:])
will return the same thing. PeekValueLength works as expected with either of `b` or `b[typeOffset:]`.