apicodec

package
v2.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ModeRaw represent a raw operation in TiKV.
	ModeRaw = iota
	// ModeTxn represent a transaction operation in TiKV.
	ModeTxn
)

Variables

View Source
var (
	// DefaultKeyspaceID is the keyspaceID of the default keyspace.
	DefaultKeyspaceID uint32 = 0
	// DefaultKeyspaceName is the name of the default keyspace.
	DefaultKeyspaceName = "DEFAULT"
)

Functions

func BuildKeyspaceName

func BuildKeyspaceName(name string) string

BuildKeyspaceName builds a keyspace name

func DecodeKey

func DecodeKey(encoded []byte, version kvrpcpb.APIVersion) ([]byte, []byte, error)

DecodeKey split a key to it's keyspace prefix and actual key.

func IsDecodeError

func IsDecodeError(err error) bool

IsDecodeError is used to determine if error is decode error.

Types

type Codec

type Codec interface {
	// GetAPIVersion returns the api version of the codec.
	GetAPIVersion() kvrpcpb.APIVersion
	// GetKeyspace return the keyspace id of the codec in bytes.
	GetKeyspace() []byte
	// GetKeyspaceID return the keyspace id of the codec.
	GetKeyspaceID() KeyspaceID
	// EncodeRequest encodes with the given Codec.
	// NOTE: req is reused on retry. MUST encode on cloned request, other than overwrite the original.
	EncodeRequest(req *tikvrpc.Request) (*tikvrpc.Request, error)
	// DecodeResponse decode the resp with the given codec.
	DecodeResponse(req *tikvrpc.Request, resp *tikvrpc.Response) (*tikvrpc.Response, error)
	// EncodeRegionKey encode region's key.
	EncodeRegionKey(key []byte) []byte
	// DecodeRegionKey decode region's key
	DecodeRegionKey(encodedKey []byte) ([]byte, error)
	// DecodeBucketKeys decode region bucket's key
	DecodeBucketKeys(keys [][]byte) ([][]byte, error)
	// EncodeRegionRange encode region's start and end.
	EncodeRegionRange(start, end []byte) ([]byte, []byte)
	// DecodeRegionRange decode region's start and end.
	DecodeRegionRange(encodedStart, encodedEnd []byte) ([]byte, []byte, error)
	// EncodeRange encode a key range.
	EncodeRange(start, end []byte) ([]byte, []byte)
	// DecodeRange decode a key range.
	DecodeRange(encodedStart, encodedEnd []byte) ([]byte, []byte, error)
	// EncodeKey encode a key.
	EncodeKey(key []byte) []byte
	// DecodeKey decode a key.
	DecodeKey(encoded []byte) ([]byte, error)
}

Codec is responsible for encode/decode requests.

func NewCodecV1

func NewCodecV1(mode Mode) Codec

NewCodecV1 returns a codec that can be used to encode/decode keys and requests to and from APIv1 format.

func NewCodecV2

func NewCodecV2(mode Mode, keyspaceID uint32) (Codec, error)

NewCodecV2 returns a codec that can be used to encode/decode keys and requests to and from APIv2 format.

type KeyspaceID

type KeyspaceID uint32

KeyspaceID denotes the target keyspace of the request.

const (
	// NullspaceID is a special keyspace id that represents no keyspace exist.
	NullspaceID KeyspaceID = 0xffffffff
)

func ParseKeyspaceID

func ParseKeyspaceID(b []byte) (KeyspaceID, error)

ParseKeyspaceID retrieves the keyspaceID from the given keyspace-encoded key. It returns error if the given key is not in proper api-v2 format.

type Mode

type Mode int

Mode represents the operation mode of a request.

Jump to

Keyboard shortcuts

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