protocol

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: May 13, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package protocol implements Olric Binary Protocol.

Index

Constants

View Source
const (
	OpPut                   = OpCode(iota) + 1
	OpPutEx                 // 2
	OpPutIf                 // 3
	OpPutIfEx               // 4
	OpGet                   // 5
	OpDelete                // 6
	OpDestroy               // 7
	OpLock                  // 8
	OpLockWithTimeout       // 9
	OpUnlock                // 10
	OpIncr                  // 11
	OpDecr                  // 12
	OpGetPut                // 13
	OpUpdateRouting         // 14
	OpPutReplica            // 15
	OpPutIfReplica          // 16
	OpPutExReplica          // 17
	OpPutIfExReplica        // 18
	OpDeletePrev            // 19
	OpGetPrev               // 20
	OpGetReplica            // 21
	OpDeleteReplica         // 22
	OpDestroyDMapInternal   // 23
	OpMoveFragment          // 24
	OpLengthOfPart          // 25
	OpPipeline              // 26
	OpPing                  // 27
	OpStats                 // 28
	OpExpire                // 29
	OpExpireReplica         // 30
	OpQuery                 // 31
	OpLocalQuery            // 32
	OpPublishDTopicMessage  // 33
	OpDestroyDTopicInternal // 34
	OpDTopicPublish         // 35
	OpDTopicAddListener     // 36
	OpDTopicRemoveListener  // 37
	OpDTopicDestroy         // 38
	OpCreateStream          // 39
	OpStreamCreated         // 40
	OpStreamMessage         // 41
	OpStreamPing            // 42
	OpStreamPong            // 43
)

Operations

View Source
const (
	StatusOK                  = StatusCode(iota) + 1
	StatusErrInternalFailure  // 2
	StatusErrKeyNotFound      // 3
	StatusErrNoSuchLock       // 4
	StatusErrLockNotAcquired  // 5
	StatusErrWriteQuorum      // 6
	StatusErrReadQuorum       // 7
	StatusErrOperationTimeout // 8
	StatusErrKeyFound         // 9
	StatusErrClusterQuorum    // 10
	StatusErrUnknownOperation // 11
	StatusErrEndOfQuery       // 12
	StatusErrServerGone       // 13
	StatusErrInvalidArgument  // 14
	StatusErrKeyTooLarge      // 15
	StatusErrNotImplemented   // 16
)

Status Codes

View Source
const DMapMessageHeaderSize uint32 = 7

DMapMessageHeaderSize defines total count of bytes in a DMapMessage

View Source
const DTopicMessageHeaderSize uint32 = 5

DTopicMessageHeaderSize defines total count of bytes in a DTopicMessage

View Source
const HeaderLength int64 = 6
View Source
const PipelineMessageHeaderSize uint32 = 3

PipelineMessageHeaderSize defines total count of bytes in a PipelineMessage

View Source
const StreamMessageHeaderSize uint32 = 3

StreamMessageHeaderSize defines total count of bytes in a StreamMessage

View Source
const SystemMessageHeaderSize uint32 = 3

Variables

View Source
var ErrConnClosed = errors.New("connection closed")

ErrConnClosed means that the underlying TCP connection has been closed by the client or operating system.

View Source
var Version1 uint8 = 1

Version1 denotes the first public version of Olric Binary Protocol.

Functions

This section is empty.

Types

type AtomicExtra

type AtomicExtra struct {
	Timestamp int64
}

AtomicExtra defines extra values for this operation.

type BytesToConn added in v0.3.0

type BytesToConn struct {
	*bytes.Buffer
}

BytesToConn translates bytes.Buffer into io.ReadWriteCloser interface. It's useful to implement pipeline in OBP.

func NewBytesToConn added in v0.3.0

func NewBytesToConn(data []byte) *BytesToConn

NewBytesToConn returns a new BytesToConn. The underlying bytes.Buffer retrieves from the pool.

func (*BytesToConn) Close added in v0.3.0

func (b *BytesToConn) Close() error

Close resets and recycles underlying bytes.Buffer.

type DMapMessage added in v0.3.0

type DMapMessage struct {
	Header
	DMapMessageHeader
	// contains filtered or unexported fields
}

DMapMessage is a message type in OBP. It can be used to access and modify DMap data structure.

func NewDMapMessage added in v0.3.0

func NewDMapMessage(opcode OpCode) *DMapMessage

NewDMapMessage returns a new DMapMessage with the given operation code.

func NewDMapMessageFromRequest added in v0.3.0

func NewDMapMessageFromRequest(buf *bytes.Buffer) *DMapMessage

NewDMapMessageFromRequest returns a new DMapMessage for the given bytes.Buffer. The caller can use Decode method to read message from the raw data.

func (*DMapMessage) Buffer added in v0.3.0

func (d *DMapMessage) Buffer() *bytes.Buffer

Buffer returns the underlying bytes.Buffer

func (*DMapMessage) DMap added in v0.3.0

func (d *DMapMessage) DMap() string

Returns the DMap name.

func (*DMapMessage) Decode added in v0.3.0

func (d *DMapMessage) Decode() error

Decode decodes message from byte form into DMapMessage.

func (*DMapMessage) Encode added in v0.3.0

func (d *DMapMessage) Encode() error

Encode encodes the message into byte form.

func (*DMapMessage) Extra added in v0.3.0

func (d *DMapMessage) Extra() interface{}

Extra returns the extra section of the message, if there is any.

func (*DMapMessage) Key added in v0.3.0

func (d *DMapMessage) Key() string

Key returns the key for this DMap message.

func (*DMapMessage) OpCode added in v0.3.0

func (d *DMapMessage) OpCode() OpCode

OpCode returns operation code of the message

func (*DMapMessage) Response added in v0.3.0

func (d *DMapMessage) Response(buf *bytes.Buffer) EncodeDecoder

Response generates a response message for the request. This is a shortcut function to reduce boilerplate code.

func (*DMapMessage) SetBuffer added in v0.3.0

func (d *DMapMessage) SetBuffer(buf *bytes.Buffer)

SetBuffer sets the underlying bytes.Buffer. It should be recycled by the caller.

func (*DMapMessage) SetDMap added in v0.3.0

func (d *DMapMessage) SetDMap(dmap string)

SetDMap sets the DMap name for this message.

func (*DMapMessage) SetExtra added in v0.3.0

func (d *DMapMessage) SetExtra(extra interface{})

SetExtra sets the extra section for the message, if there is any.

func (*DMapMessage) SetKey added in v0.3.0

func (d *DMapMessage) SetKey(key string)

SetKey sets the key for this DMap message.

func (*DMapMessage) SetStatus added in v0.3.0

func (d *DMapMessage) SetStatus(code StatusCode)

SetStatus sets a status code for the message.

func (*DMapMessage) SetValue added in v0.3.0

func (d *DMapMessage) SetValue(value []byte)

SetValue writes the given byte slice into the underlying bytes.Buffer

func (*DMapMessage) Status added in v0.3.0

func (d *DMapMessage) Status() StatusCode

Status returns status code.

func (*DMapMessage) Value added in v0.3.0

func (d *DMapMessage) Value() []byte

Value returns the value

type DMapMessageHeader added in v0.3.0

type DMapMessageHeader struct {
	Op         OpCode     // 1
	DMapLen    uint16     // 2
	KeyLen     uint16     // 2
	ExtraLen   uint8      // 1
	StatusCode StatusCode // 1
}

Header defines a message header for both request and response.

type DTopicAddListenerExtra added in v0.3.0

type DTopicAddListenerExtra struct {
	StreamID   uint64
	ListenerID uint64
}

type DTopicMessage added in v0.3.0

type DTopicMessage struct {
	Header
	DTopicMessageHeader
	// contains filtered or unexported fields
}

DTopicMessage is a message type in OBP. It can be used to access and modify DTopic data structure.

func NewDTopicMessage added in v0.3.0

func NewDTopicMessage(opcode OpCode) *DTopicMessage

NewDTopicMessage returns a new DTopicMessage with the given operation code.

func NewDTopicMessageFromRequest added in v0.3.0

func NewDTopicMessageFromRequest(buf *bytes.Buffer) *DTopicMessage

NewDTopicMessageFromRequest returns a new DTopicMessage for the given bytes.Buffer. The caller can use Decode method to read message from the raw data.

func (*DTopicMessage) Buffer added in v0.3.0

func (d *DTopicMessage) Buffer() *bytes.Buffer

Buffer returns the underlying bytes.Buffer

func (*DTopicMessage) DTopic added in v0.3.0

func (d *DTopicMessage) DTopic() string

DTopic returns the DTopic name.

func (*DTopicMessage) Decode added in v0.3.0

func (d *DTopicMessage) Decode() error

Decode decodes message from byte form into DTopicMessage.

func (*DTopicMessage) Encode added in v0.3.0

func (d *DTopicMessage) Encode() error

Encode encodes the message into byte form.

func (*DTopicMessage) Extra added in v0.3.0

func (d *DTopicMessage) Extra() interface{}

Extra returns the extra section of the message, if there is any.

func (*DTopicMessage) OpCode added in v0.3.0

func (d *DTopicMessage) OpCode() OpCode

OpCode returns operation code of the message

func (*DTopicMessage) Response added in v0.3.0

func (d *DTopicMessage) Response(buf *bytes.Buffer) EncodeDecoder

Response generates a response message for the request. This is a shortcut function to reduce boilerplate code.

func (*DTopicMessage) SetBuffer added in v0.3.0

func (d *DTopicMessage) SetBuffer(buf *bytes.Buffer)

SetBuffer sets the underlying bytes.Buffer. It should be recycled by the caller.

func (*DTopicMessage) SetDTopic added in v0.3.0

func (d *DTopicMessage) SetDTopic(dtopic string)

SetDTopic sets the DTopic name for this message.

func (*DTopicMessage) SetExtra added in v0.3.0

func (d *DTopicMessage) SetExtra(extra interface{})

SetExtra sets the extra section for the message, if there is any.

func (*DTopicMessage) SetStatus added in v0.3.0

func (d *DTopicMessage) SetStatus(code StatusCode)

SetStatus sets a status code for the message.

func (*DTopicMessage) SetValue added in v0.3.0

func (d *DTopicMessage) SetValue(value []byte)

SetValue writes the given byte slice into the underlying bytes.Buffer

func (*DTopicMessage) Status added in v0.3.0

func (d *DTopicMessage) Status() StatusCode

Status returns status code.

func (*DTopicMessage) Value added in v0.3.0

func (d *DTopicMessage) Value() []byte

Value returns the value

type DTopicMessageHeader added in v0.3.0

type DTopicMessageHeader struct {
	Op         OpCode     // 1
	DTopicLen  uint16     // 2
	ExtraLen   uint8      // 1
	StatusCode StatusCode // 1
}

Header defines a message header for both request and response.

type DTopicRemoveListenerExtra added in v0.3.0

type DTopicRemoveListenerExtra struct {
	ListenerID uint64
}

type EncodeDecoder added in v0.3.0

type EncodeDecoder interface {
	// Encode encodes the message and writes into a bytes.Buffer.
	Encode() error

	// Decode decodes the message from the given bytes.Buffer.
	Decode() error

	// SetStatus sets a status code for the message.
	SetStatus(StatusCode)

	// Status returns status code.
	Status() StatusCode

	// SetValue writes the given byte slice into the underlying bytes.Buffer
	SetValue([]byte)

	// Value returns the value
	Value() []byte

	// OpCode returns operation code of the message
	OpCode() OpCode

	// SetBuffer sets the underlying bytes.Buffer. It should be recycled by the caller.
	SetBuffer(*bytes.Buffer)

	// Buffer returns the underlying bytes.Buffer
	Buffer() *bytes.Buffer

	// SetExtra sets the extra section for the message, if there is any.
	SetExtra(interface{})

	// Extra returns the extra section of the message, if there is any.
	Extra() interface{}

	// Response generates a response message for the message.
	Response(*bytes.Buffer) EncodeDecoder
}

EncodeDecoder is an interface that defines methods for encoding/decoding a messages in OBP.

type ExpireExtra

type ExpireExtra struct {
	TTL       int64
	Timestamp int64
}

ExpireExtra defines extra values for this operation.

type Header struct {
	Magic         MagicCode // 1 byte
	Version       uint8     // 1 byte
	MessageLength uint32    // 4 bytes
}

Header is a shared message header for all the message types in Olric Binary Protocol.

func ReadMessage added in v0.3.0

func ReadMessage(src io.ReadWriteCloser, dst *bytes.Buffer) (*Header, error)

ReadMessage reads the whole message from src into the given bytes.Buffer. Header can be used to determine message. Then you can pick an appropriate message type and decode it.

type LengthOfPartExtra

type LengthOfPartExtra struct {
	PartID uint64
	Backup bool
}

LengthOfPartExtra defines extra values for this operation.

type LocalQueryExtra

type LocalQueryExtra struct {
	PartID uint64
}

type LockExtra

type LockExtra struct {
	Deadline int64
}

LockExtra defines extra values for this operation.

type LockWithTimeoutExtra

type LockWithTimeoutExtra struct {
	Timeout  int64
	Deadline int64
}

LockWithTimeoutExtra defines extra values for this operation.

type MagicCode

type MagicCode uint8

MagicCode defines an unique code to distinguish a request message from a response message in Olric Binary Protocol.

const (
	// MagicDMapReq is a magic number which denotes DMap message requests on the wire.
	MagicDMapReq MagicCode = 0xE2
	// MagicDMapRes is a magic number which denotes DMap message response on the wire.
	MagicDMapRes MagicCode = 0xE3
)
const (
	// MagicDTopicReq is a magic number which denotes DTopic message requests on the wire.
	MagicDTopicReq MagicCode = 0xEA
	// MagicDTopicRes is a magic number which denotes DTopic message response on the wire.
	MagicDTopicRes MagicCode = 0xEB
)
const (
	// MagicPipelineReq is a magic number which denotes Pipeline message requests on the wire.
	MagicPipelineReq MagicCode = 0xE6
	// MagicPipelineRes is a magic number which denotes Pipeline message response on the wire.
	MagicPipelineRes MagicCode = 0xE7
)
const (
	// MagicStreamReq is a magic number which denotes Stream message requests on the wire.
	MagicStreamReq MagicCode = 0xE4
	// MagicStreamRes is a magic number which denotes Stream message response on the wire.
	MagicStreamRes MagicCode = 0xE5
)
const (
	MagicSystemReq MagicCode = 0xE8
	MagicSystemRes MagicCode = 0xE9
)

type OpCode

type OpCode uint8

type PipelineMessage added in v0.3.0

type PipelineMessage struct {
	Header
	PipelineMessageHeader
	// contains filtered or unexported fields
}

PipelineMessage is a message type in OBP. It can be used to access and modify Pipeline data structure.

func NewPipelineMessage added in v0.3.0

func NewPipelineMessage(opcode OpCode) *PipelineMessage

NewPipelineMessage returns a new PipelineMessage with the given operation code.

func NewPipelineMessageFromRequest added in v0.3.0

func NewPipelineMessageFromRequest(buf *bytes.Buffer) *PipelineMessage

NewPipelineMessageFromRequest returns a new PipelineMessage for the given bytes.Buffer. The caller can use Decode method to read message from the raw data.

func (*PipelineMessage) Buffer added in v0.3.0

func (d *PipelineMessage) Buffer() *bytes.Buffer

Buffer returns the underlying bytes.Buffer

func (*PipelineMessage) Decode added in v0.3.0

func (d *PipelineMessage) Decode() error

Decode decodes message from byte form into PipelineMessage.

func (*PipelineMessage) Encode added in v0.3.0

func (d *PipelineMessage) Encode() error

Encode encodes the message into byte form.

func (*PipelineMessage) Extra added in v0.3.0

func (d *PipelineMessage) Extra() interface{}

Extra returns the extra section of the message, if there is any.

func (*PipelineMessage) OpCode added in v0.3.0

func (d *PipelineMessage) OpCode() OpCode

OpCode returns operation code of the message

func (*PipelineMessage) Response added in v0.3.0

func (d *PipelineMessage) Response(buf *bytes.Buffer) EncodeDecoder

Response generates a response message for the request. This is a shortcut function to reduce boilerplate code.

func (*PipelineMessage) SetBuffer added in v0.3.0

func (d *PipelineMessage) SetBuffer(buf *bytes.Buffer)

SetBuffer sets the underlying bytes.Buffer. It should be recycled by the caller.

func (*PipelineMessage) SetExtra added in v0.3.0

func (d *PipelineMessage) SetExtra(extra interface{})

SetExtra sets the extra section for the message, if there is any.

func (*PipelineMessage) SetStatus added in v0.3.0

func (d *PipelineMessage) SetStatus(code StatusCode)

SetStatus sets a status code for the message.

func (*PipelineMessage) SetValue added in v0.3.0

func (d *PipelineMessage) SetValue(value []byte)

SetValue writes the given byte slice into the underlying bytes.Buffer

func (*PipelineMessage) Status added in v0.3.0

func (d *PipelineMessage) Status() StatusCode

Status returns status code.

func (*PipelineMessage) Value added in v0.3.0

func (d *PipelineMessage) Value() []byte

Value returns the value

type PipelineMessageHeader added in v0.3.0

type PipelineMessageHeader struct {
	Op         OpCode     // 1
	ExtraLen   uint8      // 1
	StatusCode StatusCode // 1
}

PipelineMessageHeader defines a message header for both request and response.

type PutExExtra

type PutExExtra struct {
	TTL       int64
	Timestamp int64
}

PutExExtra defines extra values for this operation.

type PutExtra

type PutExtra struct {
	Timestamp int64
}

PutExtra defines extra values for this operation.

type PutIfExExtra

type PutIfExExtra struct {
	Flags     int16
	Timestamp int64
	TTL       int64
}

PutIfExExtra defines extra values for this operation.

type PutIfExtra

type PutIfExtra struct {
	Flags     int16
	Timestamp int64
}

PutIfExtra defines extra values for this operation.

type QueryExtra

type QueryExtra struct {
	PartID uint64
}

type StatsExtra added in v0.4.0

type StatsExtra struct {
	CollectRuntime bool
}

type StatusCode

type StatusCode uint8

type StreamCreatedExtra added in v0.3.0

type StreamCreatedExtra struct {
	StreamID uint64
}

type StreamMessage added in v0.3.0

type StreamMessage struct {
	Header
	StreamMessageHeader
	// contains filtered or unexported fields
}

StreamMessage is a message type in OBP. It can be used to access and modify Stream data structure.

func ConvertToStreamMessage added in v0.3.0

func ConvertToStreamMessage(msg EncodeDecoder, listenerID uint64) *StreamMessage

func NewStreamMessage added in v0.3.0

func NewStreamMessage(opcode OpCode) *StreamMessage

NewStreamMessage returns a new StreamMessage with the given operation code.

func NewStreamMessageFromRequest added in v0.3.0

func NewStreamMessageFromRequest(buf *bytes.Buffer) *StreamMessage

NewStreamMessageFromRequest returns a new StreamMessage for the given bytes.Buffer. The caller can use Decode method to read message from the raw data.

func (*StreamMessage) Buffer added in v0.3.0

func (d *StreamMessage) Buffer() *bytes.Buffer

Buffer returns the underlying bytes.Buffer

func (*StreamMessage) Close added in v0.3.0

func (d *StreamMessage) Close()

func (*StreamMessage) Conn added in v0.3.0

func (d *StreamMessage) Conn() io.ReadWriteCloser

func (*StreamMessage) Decode added in v0.3.0

func (d *StreamMessage) Decode() error

Decode decodes message from byte form into StreamMessage.

func (*StreamMessage) Encode added in v0.3.0

func (d *StreamMessage) Encode() error

Encode encodes the message into byte form.

func (*StreamMessage) Extra added in v0.3.0

func (d *StreamMessage) Extra() interface{}

Extra returns the extra section of the message, if there is any.

func (*StreamMessage) OpCode added in v0.3.0

func (d *StreamMessage) OpCode() OpCode

OpCode returns operation code of the message

func (*StreamMessage) Response added in v0.3.0

func (d *StreamMessage) Response(buf *bytes.Buffer) EncodeDecoder

Response generates a response message for the request. This is a shortcut function to reduce boilerplate code.

func (*StreamMessage) SetBuffer added in v0.3.0

func (d *StreamMessage) SetBuffer(buf *bytes.Buffer)

SetBuffer sets the underlying bytes.Buffer. It should be recycled by the caller.

func (*StreamMessage) SetCancelFunc added in v0.3.0

func (d *StreamMessage) SetCancelFunc(f context.CancelFunc)

func (*StreamMessage) SetConn added in v0.3.0

func (d *StreamMessage) SetConn(conn io.ReadWriteCloser)

func (*StreamMessage) SetExtra added in v0.3.0

func (d *StreamMessage) SetExtra(extra interface{})

SetExtra sets the extra section for the message, if there is any.

func (*StreamMessage) SetStatus added in v0.3.0

func (d *StreamMessage) SetStatus(code StatusCode)

SetStatus sets a status code for the message.

func (*StreamMessage) SetValue added in v0.3.0

func (d *StreamMessage) SetValue(value []byte)

SetValue writes the given byte slice into the underlying bytes.Buffer

func (*StreamMessage) Status added in v0.3.0

func (d *StreamMessage) Status() StatusCode

Status returns status code.

func (*StreamMessage) Value added in v0.3.0

func (d *StreamMessage) Value() []byte

Value returns the value

type StreamMessageExtra added in v0.3.0

type StreamMessageExtra struct {
	ListenerID uint64
}

type StreamMessageHeader added in v0.3.0

type StreamMessageHeader struct {
	Op         OpCode     // 1
	ExtraLen   uint8      // 1
	StatusCode StatusCode // 1
}

Header defines a message header for both request and response.

type SystemMessage added in v0.3.0

type SystemMessage struct {
	Header
	SystemMessageHeader
	// contains filtered or unexported fields
}

func NewSystemMessage added in v0.3.0

func NewSystemMessage(opcode OpCode) *SystemMessage

func NewSystemMessageFromRequest added in v0.3.0

func NewSystemMessageFromRequest(buf *bytes.Buffer) *SystemMessage

func (*SystemMessage) Buffer added in v0.3.0

func (s *SystemMessage) Buffer() *bytes.Buffer

func (*SystemMessage) Decode added in v0.3.0

func (s *SystemMessage) Decode() error

func (*SystemMessage) Encode added in v0.3.0

func (s *SystemMessage) Encode() error

Encode writes a protocol message to given TCP connection by encoding it.

func (*SystemMessage) Extra added in v0.3.0

func (s *SystemMessage) Extra() interface{}

func (*SystemMessage) OpCode added in v0.3.0

func (s *SystemMessage) OpCode() OpCode

func (*SystemMessage) Response added in v0.3.0

func (s *SystemMessage) Response(buf *bytes.Buffer) EncodeDecoder

func (*SystemMessage) SetBuffer added in v0.3.0

func (s *SystemMessage) SetBuffer(buf *bytes.Buffer)

func (*SystemMessage) SetExtra added in v0.3.0

func (s *SystemMessage) SetExtra(extra interface{})

func (*SystemMessage) SetStatus added in v0.3.0

func (s *SystemMessage) SetStatus(code StatusCode)

func (*SystemMessage) SetValue added in v0.3.0

func (s *SystemMessage) SetValue(value []byte)

func (*SystemMessage) Status added in v0.3.0

func (s *SystemMessage) Status() StatusCode

func (*SystemMessage) Value added in v0.3.0

func (s *SystemMessage) Value() []byte

type SystemMessageHeader added in v0.3.0

type SystemMessageHeader struct {
	Op         OpCode     // 1
	ExtraLen   uint8      // 1
	StatusCode StatusCode // 1
}

Header defines a message header for both request and response.

type UpdateRoutingExtra

type UpdateRoutingExtra struct {
	CoordinatorID uint64
}

UpdateRoutingExtra defines extra values for this operation.

Jump to

Keyboard shortcuts

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