Documentation ¶
Index ¶
- Variables
- func DecodeBytes(b []byte) ([]byte, []byte, error)
- func DecodeBytesDesc(b []byte) ([]byte, []byte, error)
- func DecodeFloat(b []byte) ([]byte, float64, error)
- func DecodeFloatDesc(b []byte) ([]byte, float64, error)
- func DecodeInt(b []byte) ([]byte, int64, error)
- func DecodeIntDesc(b []byte) ([]byte, int64, error)
- func DecodeKey(b []byte) ([]interface{}, error)
- func DecodeUint(b []byte) ([]byte, uint64, error)
- func DecodeUintDesc(b []byte) ([]byte, uint64, error)
- func EncodeBytes(b []byte, data []byte) []byte
- func EncodeBytesDesc(b []byte, data []byte) []byte
- func EncodeFloat(b []byte, v float64) []byte
- func EncodeFloatDesc(b []byte, v float64) []byte
- func EncodeInt(b []byte, v int64) []byte
- func EncodeIntDesc(b []byte, v int64) []byte
- func EncodeKey(args ...interface{}) ([]byte, error)
- func EncodeUint(b []byte, v uint64) []byte
- func EncodeUintDesc(b []byte, v uint64) []byte
- func Float64ToUint64(f float64) uint64
- func StripEnd(b []byte) ([]byte, error)
- func Uint64ToFloat64(u uint64) float64
Constants ¶
This section is empty.
Variables ¶
var ( // InfiniteValue is the greatest than any other encoded value. InfiniteValue = []byte{0xFF, 0xFF} // NilValue is the smallest than any other encoded value. NilValue = []byte{0x00, 0x00} // SmallestNoneNilValue is smaller than any other encoded value except nil value. SmallestNoneNilValue = []byte{0x00, 0x01} )
Functions ¶
func DecodeBytes ¶
DecodeBytes decodes bytes which is encoded by EncodeBytes before, returns the leftover bytes and decoded value if no error.
func DecodeBytesDesc ¶
DecodeBytesDesc decodes bytes which is encoded by EncodeBytesDesc before, returns the leftover bytes and decoded value if no error.
func DecodeFloat ¶
DecodeFloat decodes a float from a byte slice generated with EncodeFloat before.
func DecodeFloatDesc ¶
DecodeFloatDesc decodes a float from a byte slice generated with EncodeFloatDesc before.
func DecodeInt ¶
DecodeInt decodes value encoded by EncodeInt before. It returns the leftover un-decoded slice, decoded value if no error.
func DecodeIntDesc ¶
DecodeIntDesc decodes value encoded by EncodeInt before. It returns the leftover un-decoded slice, decoded value if no error.
func DecodeUint ¶
DecodeUint decodes value encoded by EncodeUint before. It returns the leftover un-decoded slice, decoded value if no error.
func DecodeUintDesc ¶
DecodeUintDesc decodes value encoded by EncodeInt before. It returns the leftover un-decoded slice, decoded value if no error.
func EncodeBytes ¶
EncodeBytes encodes the slice value using an escape based encoding, with the following rule:
\x00 -> \x00\xFF \xFF -> \xFF\x00 if the first byte is \xFF
EncodeBytes will append \x00\x01 at the end of the encoded value to indicate the termination. EncodeBytes guarantees the encoded value is in ascending order for comparison, The encoded value is >= SmallestNoneNilValue and < InfiniteValue.
func EncodeBytesDesc ¶
EncodeBytesDesc first encodes bytes using EncodeBytes, then bitwise reverses encoded value to guarentee the encoded value is in descending order for comparison, The encoded value is >= SmallestNoneNilValue and < InfiniteValue.
func EncodeFloat ¶
EncodeFloat encodes a float v into a byte slice which can be sorted lexicographically later. EncodeFloat guarantees that the encoded value is in ascending order for comparison.
func EncodeFloatDesc ¶
EncodeFloatDesc encodes a float v into a byte slice which can be sorted lexicographically later. EncodeFloatDesc guarantees that the encoded value is in descending order for comparison.
func EncodeInt ¶
EncodeInt encodes the int64 value with variable length format. The encoded bytes format is: length flag(1 byte) + encoded data. The length flag is calculated with following way
flag Value Range 8 -> [MinInt64, MinInt32) 12 -> [MinInt32, MinInt16) 14 -> [MinInt16, MinInt8) 15 -> [MinInt8, 0) 16 -> 0 17 -> (0, MaxInt8] 18 -> (MaxInt8, MaxInt16] 20 -> (MaxInt16, MaxInt32] 24 -> (MaxInt32, MaxInt64]
EncodeInt appends the encoded value to slice b and returns the appended slice. EncodeInt guarantees that the encoded value is in ascending order for comparison.
func EncodeIntDesc ¶
EncodeIntDesc encodes the int64 value with variable length format. The encoded bytes format is: length flag(1 byte) + encoded data. The length flag is calculated with following way
flag Value Range 24 -> [MinInt64, MinInt32) 20 -> [MinInt32, MinInt16) 18 -> [MinInt16, MinInt8) 17 -> [MinInt8, 0) 16 -> 0 15 -> (0, MaxInt8] 14 -> (MaxInt8, MaxInt16] 12 -> (MaxInt16, MaxInt32] 8 -> (MaxInt32, MaxInt64]
EncodeIntDesc appends the encoded value to slice b and returns the appended slice. EncodeIntDesc guarantees that the encoded value is in descending order for comparison.
func EncodeKey ¶
EncodeKey encodes args to a slice which can be sorted lexicographically later. EncodeKey guarantees the encoded slice is in ascending order for comparison. TODO: we may add more test to check its valiadation, especially for null type and multi indices.
func EncodeUint ¶
EncodeUint encodes the uint64 value with variable length format. The encoded bytes format is: length flag(1 byte) + encoded data. The length flag is calculated with following way:
flag Value Range 16 -> 0 17 -> (0, MaxUint8] 18 -> (MaxUint8, MaxUint16] 20 -> (MaxUint16, MaxUint32] 24 -> (MaxUint32, MaxUint64]
EncodeUint appends the encoded value to slice b and returns the appended slice. EncodeUint guarantees that the encoded value is in ascending order for comparison.
func EncodeUintDesc ¶
EncodeUintDesc encodes the int64 value with variable length format. The encoded bytes format is: length flag(1 byte) + encoded data. The length flag is calculated with following way
flag Value Range 16 -> 0 15 -> (0, MaxUint8] 14 -> (MaxUint8, MaxUint16] 12 -> (MaxUint16, MaxUint32] 8 -> (MaxUint32, MaxUint64]
EncodeUintDesc appends the encoded value to slice b and returns the appended slice. EncodeUintDesc guarantees that the encoded value is in descending order for comparison.
func Float64ToUint64 ¶
Float64ToUint64 converts float to a uint for lexicographical comparation.
func StripEnd ¶
StripEnd splits a slice b into two substrings separated by sepKey and returns a slice byte of the previous substrings.
func Uint64ToFloat64 ¶
Uint64ToFloat64 converts the uint generated with Float64ToUint64 before to a float.
Types ¶
This section is empty.