codec

package
v2.1.0-rc.5+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2018 License: Apache-2.0 Imports: 12 Imported by: 3,258

Documentation

Index

Constants

View Source
const (
	NilFlag byte = 0
)

First byte in the encoded value which specifies the encoding type.

Variables

This section is empty.

Functions

func CutOne

func CutOne(b []byte) (data []byte, remain []byte, err error)

CutOne cuts the first encoded value from b. It will return the first encoded item and the remains as byte slice.

func Decode

func Decode(b []byte, size int) ([]types.Datum, error)

Decode decodes values from a byte slice generated with EncodeKey or EncodeValue before. size is the size of decoded datum slice.

func DecodeBytes

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

DecodeBytes decodes bytes which is encoded by EncodeBytes before, returns the leftover bytes and decoded value if no error. `buf` is used to buffer data to avoid the cost of makeslice in decodeBytes when DecodeBytes is called by Decoder.DecodeOne.

func DecodeBytesDesc

func DecodeBytesDesc(b []byte, buf []byte) ([]byte, []byte, error)

DecodeBytesDesc decodes bytes which is encoded by EncodeBytesDesc before, returns the leftover bytes and decoded value if no error.

func DecodeCmpUintToInt

func DecodeCmpUintToInt(u uint64) int64

DecodeCmpUintToInt decodes the u that encoded by EncodeIntToCmpUint

func DecodeCompactBytes

func DecodeCompactBytes(b []byte) ([]byte, []byte, error)

DecodeCompactBytes decodes bytes which is encoded by EncodeCompactBytes before.

func DecodeComparableUvarint

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

DecodeComparableUvarint decodes mem-comparable uvarint.

func DecodeComparableVarint

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

DecodeComparableVarint decodes mem-comparable varint.

func DecodeDecimal

func DecodeDecimal(b []byte) ([]byte, *types.MyDecimal, int, int, error)

DecodeDecimal decodes bytes to decimal.

func DecodeFloat

func DecodeFloat(b []byte) ([]byte, float64, error)

DecodeFloat decodes a float from a byte slice generated with EncodeFloat before.

func DecodeFloatDesc

func DecodeFloatDesc(b []byte) ([]byte, float64, error)

DecodeFloatDesc decodes a float from a byte slice generated with EncodeFloatDesc before.

func DecodeInt

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

DecodeInt decodes value encoded by EncodeInt before. It returns the leftover un-decoded slice, decoded value if no error.

func DecodeIntDesc

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

DecodeIntDesc decodes value encoded by EncodeInt before. It returns the leftover un-decoded slice, decoded value if no error.

func DecodeOne

func DecodeOne(b []byte) (remain []byte, d types.Datum, err error)

DecodeOne decodes on datum from a byte slice generated with EncodeKey or EncodeValue.

func DecodeRange

func DecodeRange(b []byte, size int) ([]types.Datum, error)

DecodeRange decodes the range values from a byte slice that generated by EncodeKey. It handles some special values like `MinNotNull` and `MaxValueDatum`.

func DecodeUint

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

DecodeUint decodes value encoded by EncodeUint before. It returns the leftover un-decoded slice, decoded value if no error.

func DecodeUintDesc

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

DecodeUintDesc decodes value encoded by EncodeInt before. It returns the leftover un-decoded slice, decoded value if no error.

func DecodeUvarint

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

DecodeUvarint decodes value encoded by EncodeUvarint before. It returns the leftover un-decoded slice, decoded value if no error.

func DecodeVarint

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

DecodeVarint decodes value encoded by EncodeVarint before. It returns the leftover un-decoded slice, decoded value if no error.

func EncodeBytes

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

EncodeBytes guarantees the encoded value is in ascending order for comparison, encoding with the following rule:

[group1][marker1]...[groupN][markerN]
group is 8 bytes slice which is padding with 0.
marker is `0xFF - padding 0 count`

For example:

[] -> [0, 0, 0, 0, 0, 0, 0, 0, 247]
[1, 2, 3] -> [1, 2, 3, 0, 0, 0, 0, 0, 250]
[1, 2, 3, 0] -> [1, 2, 3, 0, 0, 0, 0, 0, 251]
[1, 2, 3, 4, 5, 6, 7, 8] -> [1, 2, 3, 4, 5, 6, 7, 8, 255, 0, 0, 0, 0, 0, 0, 0, 0, 247]

Refer: https://github.com/facebook/mysql-5.6/wiki/MyRocks-record-format#memcomparable-format

func EncodeBytesDesc

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

EncodeBytesDesc first encodes bytes using EncodeBytes, then bitwise reverses encoded value to guarantee the encoded value is in descending order for comparison.

func EncodeCompactBytes

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

EncodeCompactBytes joins bytes with its length into a byte slice. It is more efficient in both space and time compare to EncodeBytes. Note that the encoded result is not memcomparable.

func EncodeComparableUvarint

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

EncodeComparableUvarint encodes uint64 into mem-comparable bytes.

func EncodeComparableVarint

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

EncodeComparableVarint encodes an int64 to a mem-comparable bytes.

func EncodeDecimal

func EncodeDecimal(b []byte, dec *types.MyDecimal, precision, frac int) ([]byte, error)

EncodeDecimal encodes a decimal into a byte slice which can be sorted lexicographically later.

func EncodeFloat

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

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

func EncodeFloatDesc(b []byte, v float64) []byte

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

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

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

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

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 EncodeIntToCmpUint

func EncodeIntToCmpUint(v int64) uint64

EncodeIntToCmpUint make int v to comparable uint type

func EncodeKey

func EncodeKey(sc *stmtctx.StatementContext, b []byte, v ...types.Datum) ([]byte, error)

EncodeKey appends the encoded values to byte slice b, returns the appended slice. It guarantees the encoded value is in ascending order for comparison. For Decimal type, datum must set datum's length and frac.

func EncodeUint

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

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

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

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 EncodeUvarint

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

EncodeUvarint appends the encoded value to slice b and returns the appended slice. Note that the encoded result is not memcomparable.

func EncodeValue

func EncodeValue(sc *stmtctx.StatementContext, b []byte, v ...types.Datum) ([]byte, error)

EncodeValue appends the encoded values to byte slice b, returning the appended slice. It does not guarantee the order for comparison.

func EncodeVarint

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

EncodeVarint appends the encoded value to slice b and returns the appended slice. Note that the encoded result is not memcomparable.

func HashChunkRow

func HashChunkRow(sc *stmtctx.StatementContext, b []byte, row chunk.Row, allTypes []*types.FieldType, colIdx []int) ([]byte, error)

HashChunkRow appends the encoded values to byte slice "b", returning the appended slice. If two rows are equal, it will generate the same bytes.

func HashValues

func HashValues(sc *stmtctx.StatementContext, b []byte, v ...types.Datum) ([]byte, error)

HashValues appends the encoded values to byte slice b, returning the appended slice. If two datums are equal, they will generate the same bytes.

func SetRawValues

func SetRawValues(data []byte, values []types.Datum) error

SetRawValues set raw datum values from a row data.

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder is used to decode value to chunk.

func NewDecoder

func NewDecoder(chk *chunk.Chunk, timezone *time.Location) *Decoder

NewDecoder creates a Decoder.

func (*Decoder) DecodeOne

func (decoder *Decoder) DecodeOne(b []byte, colIdx int, ft *types.FieldType) (remain []byte, err error)

DecodeOne decodes one value to chunk and returns the remained bytes.

Jump to

Keyboard shortcuts

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