codec

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2018 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TagSize    = 1
	LengthSize = 4
)

Variables

This section is empty.

Functions

func NewDecodeError

func NewDecodeError(decoder, msg string) error

NewDecodeError create instance of DecodeError with specified error message.

func NewEncodeError

func NewEncodeError(encoder, msg string) error

NewEncodeError create instance of EncodeError with specified error message.

Types

type ApolloConfig

type ApolloConfig struct {
	TLVConfig
	// contains filtered or unexported fields
}

func (*ApolloConfig) RegisterEntity

func (c *ApolloConfig) RegisterEntity(constructor func() ApolloEntity)

type ApolloEntity

type ApolloEntity interface {
	TypeCode() uint16
}

type ApolloFrameDecoder

type ApolloFrameDecoder struct {
	Config ApolloConfig
	// contains filtered or unexported fields
}

ApolloFrameDecoder is a bytes to ApolloEntity decode implementation of FrameDecode based on TLVFrameDecoder using MessagePack for payload data deserialization.

+----------+-----------+---------------------------+
|    TAG   |  LENGTH   |           VALUE           |
| (1 byte) | (4 bytes) |   2 bytes   | serialized  |
|          |           |  type code  |    data     |
+----------+-----------+---------------------------+

Decode:

[]byte → ApolloEntity(*pointer)

func (*ApolloFrameDecoder) Decode

func (d *ApolloFrameDecoder) Decode(in buffer.ByteBuf) (interface{}, error)

type ApolloFrameEncoder

type ApolloFrameEncoder struct {
	Config ApolloConfig
	// contains filtered or unexported fields
}

ApolloFrameEncoder is a ApolloEntity to bytes encoder implementation of FrameEncode based on TLVFrameEncoder using MessagePack for payload data serialization.

+----------+-----------+---------------------------+
|    TAG   |  LENGTH   |           VALUE           |
| (1 byte) | (4 bytes) |   2 bytes   | serialized  |
|          |           |  type code  |    data     |
+----------+-----------+---------------------------+

Encode:

ApolloEntity(*pointer) → []byte

func (*ApolloFrameEncoder) Encode

func (e *ApolloFrameEncoder) Encode(msg interface{}) ([]byte, error)

type DecodeError

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

DecodeError is a error implementation with detail error string output include decoder name and cause for decode exception. The format of complete error string is '$DECODER decode error cause $CAUSE'.

func (*DecodeError) Error

func (e *DecodeError) Error() string

type EncodeError

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

EncodeError is a error implementation with detail error string output include encoder name and cause for encode exception. The format of complete error string is '$ENCODER encode error cause $CAUSE'.

func (*EncodeError) Error

func (e *EncodeError) Error() string

type FrameCodec

type FrameCodec interface {
	FrameDecoder
	FrameEncoder
}

FrameCodec is the interface that wraps the basic method for both encode and decode.

type FrameDecoder

type FrameDecoder interface {
	Decode(in buffer.ByteBuf) (result interface{}, err error)
}

FrameDecoder is the interface that wraps the basic method for decode tcp stream. A FrameDecoder will be instantiated and init by PipelineInitializer in Pipeline initializing.

Model:

+-------------------------+
|     (src)↓              |
|  Decode(in) → (result)  |
+-------------------------+

func NewApolloFrameDecoder

func NewApolloFrameDecoder(config ApolloConfig) FrameDecoder

NewApolloFrameDecoder create a new ApolloFrameDecoder instance with configuration.

func NewStringFrameDecoder

func NewStringFrameDecoder() FrameDecoder

NewStringFrameDecoder create a new StringFrameDecoder instance.

func NewTLVFrameDecoder

func NewTLVFrameDecoder(config TLVConfig) FrameDecoder

NewTLVFrameDecoder create instance of TLVFrameDecoder with specified configuration.

type FrameEncoder

type FrameEncoder interface {
	Encode(msg interface{}) (result []byte, err error)
}

FrameDecoder is the interface that wraps the basic method for encode tcp stream. A FrameEncoder will be instantiated and init by PipelineInitializer in Pipeline initializing.

Model:

+-------------------------+
|     (src)↓              |
|  Encode(in) → (result)  |
+-------------------------+

func NewApolloFrameEncoder

func NewApolloFrameEncoder(config ApolloConfig) FrameEncoder

NewApolloFrameEncoder create a new ApolloFrameEncoder instance with configuration.

func NewStringFrameEncoder

func NewStringFrameEncoder() FrameEncoder

NewStringFrameEncoder create a new StringFrameEncoder instance.

func NewTLVFrameEncoder

func NewTLVFrameEncoder(config TLVConfig) FrameEncoder

NewTLVFrameEncoder create instance of TLVFrameEncoder with specified configuration.

type StringFrameDecoder

type StringFrameDecoder struct {
}

StringFrameDecoder is a bytes to string decoder implementation of FrameDecoder interface that transform inbound data from []byte to string.

Example:

+-----------------------------------------------------------+            +----------------+
|0x48|0x65|0x6c|0x6c|0x6f|0x20|0x57|0x6f|0x72|0x6c|0x64|0x2e| → decode → | "Hello World." |
+-----------------------------------------------------------+            +----------------+

func (*StringFrameDecoder) Decode

func (d *StringFrameDecoder) Decode(in buffer.ByteBuf) (interface{}, error)

type StringFrameEncoder

type StringFrameEncoder struct {
}

StringFrameEncoder is a string to bytes encoder implementation of FrameEncoder interface that transform outbound data from string to []byte.

Example:

+----------------+            +-----------------------------------------------------------+
| "Hello World." | → encode → |0x48|0x65|0x6c|0x6c|0x6f|0x20|0x57|0x6f|0x72|0x6c|0x64|0x2e|
+----------------+            +-----------------------------------------------------------+

func (*StringFrameEncoder) Encode

func (e *StringFrameEncoder) Encode(msg interface{}) ([]byte, error)

type TLVConfig

type TLVConfig struct {
	TagValue   uint8
	FrameLimit uint32
}

TLVConfig is a data struct provide configuration properties for both TLVFrameDecoder and TLVFrameEncoder.

+----------+-----------+-----------+
|    TAG   |  LENGTH   |   VALUE   |
| (1 byte) | (4 bytes) | (payload) |
+----------+-----------+-----------+
     ↑
  TagValue

type TLVFrameDecoder

type TLVFrameDecoder struct {
	Config TLVConfig
	// contains filtered or unexported fields
}

TLVFrameDecoder is a bytes to bytes decoder implementation of FrameDecoder with TLV format.

+----------+-----------+-----------+
|    TAG   |  LENGTH   |   VALUE   |
| (1 byte) | (4 bytes) | (payload) |
+----------+-----------+-----------+
     ↑
  TagValue

Notes:

Decode []byte → []byte.

func (*TLVFrameDecoder) Decode

func (c *TLVFrameDecoder) Decode(in buffer.ByteBuf) (interface{}, error)

type TLVFrameEncoder

type TLVFrameEncoder struct {
	Config TLVConfig
}

TLVFrameEncoder is a bytes to bytes encoder implementation of FrameEncoder with TLV format.

+----------+-----------+-----------+
|    TAG   |  LENGTH   |   VALUE   |
| (1 byte) | (4 bytes) | (payload) |
+----------+-----------+-----------+
     ↑
  TagValue

Notes:

Encode []byte → []byte.

func (*TLVFrameEncoder) Encode

func (c *TLVFrameEncoder) Encode(msg interface{}) ([]byte, error)

Jump to

Keyboard shortcuts

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