proto

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: May 7, 2015 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CtrlErrCode  = 0x1 // Response Error Code
	CtrlCas      = 0x2 // Compare And Switch
	CtrlColSpace = 0x4
	CtrlValue    = 0x8
	CtrlScore    = 0x10
)

CtrlFlag

View Source
const (
	ColSpaceDefault = 0 // Default column space
	ColSpaceScore1  = 1 // rowKey+score+colKey => value
	ColSpaceScore2  = 2 // rowKey+colKey => value+score
)
View Source
const (
	// Common flags
	FlagZop = 0x1 // if set, it is a "Z" op

	// (Z)Scan flags
	FlagScanAsc      = 0x4  // if set, Scan in ASC order, else DESC order
	FlagScanKeyStart = 0x8  // if set, Scan start from MIN/MAX key
	FlagScanEnd      = 0x10 // if set, Scan finished, stop now

	// Dump flags
	FlagDumpTable     = 0x4  // if set, Dump only one table, else Dump current DB(dbId)
	FlagDumpUnitStart = 0x8  // if set, Dump start from new UnitId, else from pivot record
	FlagDumpEnd       = 0x10 // if set, Dump finished, stop now
)

PkgFlag

View Source
const (
	// Front CTRL
	CmdAuth = 0x9

	// Front Read
	CmdPing = 0x10
	CmdGet  = 0x11
	CmdMGet = 0x12
	CmdScan = 0x13
	CmdDump = 0x14

	// Front Write
	CmdSet   = 0x60
	CmdMSet  = 0x61
	CmdDel   = 0x62
	CmdMDel  = 0x63
	CmdIncr  = 0x64
	CmdMIncr = 0x65

	// Inner SYNC
	CmdSync   = 0xB0 // Sync data
	CmdSyncSt = 0xB1 // Sync status

	// Inner CTRL
	CmdSlaveOf = 0xD0
	CmdMigrate = 0xD1 // Start/Stop migration
	CmdSlaveSt = 0xD2 // Get migration/slave status
	CmdDelUnit = 0xD3 // Delete unit data
)
View Source
const (
	AdminDbId   = 255
	HeadSize    = 14
	MaxUint8    = 255
	MaxUint16   = 65535
	MaxValueLen = 1024 * 1024     // 1MB
	MaxPkgLen   = 1024 * 1024 * 2 // 2MB
)

Variables

View Source
var (
	ErrPkgLen     = errors.New("pkg length out of range")
	ErrRowKeyLen  = errors.New("row key length out of range")
	ErrColKeyLen  = errors.New("col key length out of range")
	ErrKvArrayLen = errors.New("key/value array length out of range")
)

Functions

func OverWriteLen

func OverWriteLen(pkg []byte, pkgLen int)

func OverWriteSeq

func OverWriteSeq(pkg []byte, seq uint64)

func ReadPkg

func ReadPkg(r *bufio.Reader, headBuf []byte, head *PkgHead,
	pkgBuf []byte) (pkg []byte, err error)

Types

type KeyValue

type KeyValue struct {
	CtrlFlag uint8
	ErrCode  int8  // default: 0 if missing
	ColSpace uint8 // default: 0 if missing
	TableId  uint8
	RowKey   []byte
	ColKey   []byte
	Value    []byte // default: nil if missing
	Score    int64  // default: 0 if missing
	Cas      uint32 // default: 0 if missing
}

KeyValue=cCtrlFlag+cTableId+[cErrCode]+[cColSpace]

+cRowKeyLen+sRowKey+wColKeyLen+sColKey
+[dwValueLen+sValue]+[ddwScore]+[dwCas]

func (*KeyValue) Decode

func (kv *KeyValue) Decode(pkg []byte) (int, error)

func (*KeyValue) Encode

func (kv *KeyValue) Encode(pkg []byte) (int, error)

func (*KeyValue) Length

func (kv *KeyValue) Length() int

func (*KeyValue) SetCas

func (kv *KeyValue) SetCas(cas uint32)

func (*KeyValue) SetColSpace

func (kv *KeyValue) SetColSpace(colSpace uint8)

func (*KeyValue) SetErrCode

func (kv *KeyValue) SetErrCode(errCode int8)

func (*KeyValue) SetScore

func (kv *KeyValue) SetScore(score int64)

func (*KeyValue) SetValue

func (kv *KeyValue) SetValue(value []byte)

type PkgDumpReq

type PkgDumpReq struct {
	StartUnitId uint16 // Dump start unit ID (included)
	EndUnitId   uint16 // Dump finish unit ID (included)
	PkgOneOp
}

Dump PKG=PkgOneOp+wStartUnitId+wEndUnitId

func (*PkgDumpReq) Decode

func (p *PkgDumpReq) Decode(pkg []byte) (int, error)

func (*PkgDumpReq) Encode

func (p *PkgDumpReq) Encode(pkg []byte) (int, error)

func (*PkgDumpReq) Length

func (p *PkgDumpReq) Length() int

type PkgDumpResp

type PkgDumpResp struct {
	StartUnitId uint16
	EndUnitId   uint16
	LastUnitId  uint16 // Last Unit ID tried to dump
	PkgMultiOp
}

Dump PKG=PkgMultiOp+wStartUnitId+wEndUnitId+wLastUnitId

func (*PkgDumpResp) Decode

func (p *PkgDumpResp) Decode(pkg []byte) (int, error)

func (*PkgDumpResp) Encode

func (p *PkgDumpResp) Encode(pkg []byte) (int, error)

func (*PkgDumpResp) Length

func (p *PkgDumpResp) Length() int

type PkgEncoding

type PkgEncoding interface {
	Length() int
	Encode(pkg []byte) (int, error)
	Decode(pkg []byte) (int, error)
}

type PkgHead

type PkgHead struct {
	Cmd    uint8
	DbId   uint8
	Seq    uint64 //normal: request seq; replication: master binlog seq
	PkgLen uint32
}

cCmd+cDbId+ddwSeq+dwPkgLen+sBody

func (*PkgHead) Decode

func (head *PkgHead) Decode(pkg []byte) (int, error)

func (*PkgHead) Encode

func (head *PkgHead) Encode(pkg []byte) (int, error)

type PkgMultiOp

type PkgMultiOp struct {
	PkgFlag uint8
	ErrCode int8
	PkgHead
	Kvs []KeyValue
}

MGet, MSet, MDel, MZGet, MZSet, MZDel PKG=HEAD+cPkgFlag+cErrCode+wNum+KeyValue[wNum]

func (*PkgMultiOp) Decode

func (p *PkgMultiOp) Decode(pkg []byte) (int, error)

func (*PkgMultiOp) Encode

func (p *PkgMultiOp) Encode(pkg []byte) (int, error)

func (*PkgMultiOp) Length

func (p *PkgMultiOp) Length() int

func (*PkgMultiOp) SetErrCode

func (p *PkgMultiOp) SetErrCode(errCode int8)

type PkgOneOp

type PkgOneOp struct {
	PkgHead
	PkgFlag uint8
	KeyValue
}

Get, Set, Del, GetSet, GetDel, ZGet, ZSet, Sync PKG=HEAD+cPkgFlag+KeyValue

func (*PkgOneOp) Decode

func (p *PkgOneOp) Decode(pkg []byte) (int, error)

func (*PkgOneOp) Encode

func (p *PkgOneOp) Encode(pkg []byte) (int, error)

func (*PkgOneOp) Length

func (p *PkgOneOp) Length() int

type PkgResponse

type PkgResponse interface {
	PkgEncoding
	SetErrCode(errCode int8)
}

type PkgScanReq

type PkgScanReq struct {
	Num uint16
	PkgOneOp
}

Scan, ZScan PKG=PkgOneOp+wNum

func (*PkgScanReq) Decode

func (p *PkgScanReq) Decode(pkg []byte) (int, error)

func (*PkgScanReq) Encode

func (p *PkgScanReq) Encode(pkg []byte) (int, error)

func (*PkgScanReq) Length

func (p *PkgScanReq) Length() int

type PkgScanResp

type PkgScanResp struct {
	PkgMultiOp
}

Scan, ZScan

Jump to

Keyboard shortcuts

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