encoding

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2018 License: Apache-2.0 Imports: 7 Imported by: 3

Documentation

Index

Constants

View Source
const (
	VTypeBytes        byte = 0x01
	VTypeString       byte = 0x02
	VTypeInt8         byte = 0x03
	VTypeInt16        byte = 0x04
	VTypeInt32        byte = 0x05
	VTypeInt64        byte = 0x06
	VTypeUint8        byte = 0x07
	VTypeUint16       byte = 0x08
	VTypeUint32       byte = 0x09
	VTypeUint64       byte = 0x0a
	VTypeMap          byte = 0x0b
	VTypeQueue        byte = 0x0c
	VTypeBorrowRecord byte = 0x30
	VTypeLimiterMeta  byte = 0x31
)

Variables

This section is empty.

Functions

func BytesToString

func BytesToString(b []byte) string

func RegistSerializerGenerator

func RegistSerializerGenerator(vType byte, f SerializerGenerator) error

注册Serializer生成器

func StringToBytes

func StringToBytes(v string) ([]byte, error)

Types

type Bytes

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

func NewBytes

func NewBytes(v []byte) *Bytes

func (*Bytes) Cap

func (bt *Bytes) Cap() int

func (*Bytes) Decode

func (bt *Bytes) Decode(b []byte) ([]byte, error)

func (*Bytes) Encode

func (bt *Bytes) Encode() ([]byte, error)

Encode encode byte slice to format which used to binary persist Encoded Format: > [1 byte] data type > [4 bytes] data len > [N bytes] data content

func (*Bytes) Grow

func (bt *Bytes) Grow(n int) *Bytes

func (*Bytes) Hex

func (bt *Bytes) Hex() string

func (*Bytes) Len

func (bt *Bytes) Len() int

func (*Bytes) Set

func (bt *Bytes) Set(idx int, bv byte)

func (*Bytes) Value

func (bt *Bytes) Value() []byte

type Int64

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

func NewInt64

func NewInt64(v int64) *Int64

func (*Int64) Decode

func (i *Int64) Decode(b []byte) ([]byte, error)

func (*Int64) Encode

func (i *Int64) Encode() ([]byte, error)

Encode encode int64 to format which used to binary persist Encoded Format: > [1 byte] data type > [8 bytes] data content

func (*Int64) Incr

func (i *Int64) Incr(delta int64)

func (*Int64) Value

func (i *Int64) Value() int64

type KVPair

type KVPair struct {
	K string
	V Serializer
}

type Map

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

func NewMap

func NewMap() *Map

func (*Map) Decode

func (m *Map) Decode(b []byte) ([]byte, error)

func (*Map) Delete

func (m *Map) Delete(k string)

func (*Map) Encode

func (m *Map) Encode() ([]byte, error)

Encode encode map to format which used to binary persist Encoded Format: > [1 byte] data type > [4 bytes] pair's count of the map > -------------------------------------------- > [1 byte] type of the key > [4 bytes] byte count of key's encoded result > [N bytes] content of encoded key > [1 byte] type of value > [4 bytes] byte count of value's encoded result > [N bytes] content of encoded value > -------------------------------------------- > ... > ... > ...

func (*Map) Get

func (m *Map) Get(k string) (Serializer, bool)

func (*Map) Range

func (m *Map) Range(quit <-chan struct{}) <-chan *KVPair

Range 遍历map,上层禁止关闭*KVPair channel

func (*Map) Set

func (m *Map) Set(k string, v Serializer)

type Queue

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

Queue implement of Serializer interface{}

func NewQueue

func NewQueue() *Queue

func (*Queue) Decode

func (q *Queue) Decode(b []byte) ([]byte, error)

func (*Queue) Encode

func (q *Queue) Encode() ([]byte, error)

Encode encode queue to format which used to binary persist Encoded Format: > [1 byte] data type > [4 bytes] element's count of the queue > -------------------------------------------- > [1 byte] type of the first element > [4 bytes] byte count of the first element's encoded result > [N bytes] the first element's encoded result > -------------------------------------------- > ... > ... > ...

func (*Queue) Front

func (q *Queue) Front() QueueElement

func (*Queue) Init

func (q *Queue) Init()

Init initializes or clears queue q.

func (*Queue) Len

func (q *Queue) Len() int

func (*Queue) PopFront

func (q *Queue) PopFront() (interface{}, bool)

PopFront pop the first element from queue, if not found, then false will be returned

func (*Queue) PushBack

func (q *Queue) PushBack(v Serializer)

func (*Queue) PushBackQueue

func (q *Queue) PushBackQueue(q2 *Queue)

func (*Queue) Remove

func (q *Queue) Remove(e QueueElement)

type QueueElement

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

QueueElement is an element of a queue

func (QueueElement) IsNil

func (e QueueElement) IsNil() bool

func (QueueElement) Next

func (e QueueElement) Next() QueueElement

func (QueueElement) Value

func (e QueueElement) Value() interface{}

type Serializer

type Serializer interface {
	// Encode encode object to []byte
	Encode() ([]byte, error)

	// Decode decode from []byte to object
	// If decode success, byte sequeue will be removed from input []byte and then return
	Decode([]byte) ([]byte, error)
}

func SerializerFactory

func SerializerFactory(vType byte) (Serializer, error)

Serializer工厂函数,生成Serializer实例

type SerializerGenerator

type SerializerGenerator func() Serializer

Serializer生成器

type String

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

func NewString

func NewString(v string) *String

func (*String) Decode

func (s *String) Decode(b []byte) ([]byte, error)

func (*String) Encode

func (s *String) Encode() ([]byte, error)

Encode encode string to format which used to binary persist Encoded Format: > [1 byte] data type > [4 bytes] data len > [N bytes] data content

func (*String) Value

func (s *String) Value() string

type Uint32

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

func NewUint32

func NewUint32(v uint32) *Uint32

func (*Uint32) Decode

func (u *Uint32) Decode(b []byte) ([]byte, error)

func (*Uint32) Decr

func (u *Uint32) Decr(delta uint32)

func (*Uint32) Encode

func (u *Uint32) Encode() ([]byte, error)

Encode encode uint32 to format which used to binary persist Encoded Format: > [1 byte] data type > [4 bytes] data content

func (*Uint32) Incr

func (u *Uint32) Incr(delta uint32)

func (*Uint32) Value

func (u *Uint32) Value() uint32

Jump to

Keyboard shortcuts

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