codec

package
v0.0.0-...-5dc8409 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2018 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package codec is an interface for encoding messages

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCodecMap

func GetCodecMap() map[string]Codec

GetCodecMap is to get the codec map

func InstallPlugin

func InstallPlugin(t string, f func() Codec)

InstallPlugin to install the codec plugins

Types

type ClientCodec

type ClientCodec interface {
	ReadResponseHeader(*Response) error
	ReadResponseBody(interface{}) error
	// WriteRequest must be safe for concurrent use by multiple goroutines.
	// don't return bytes
	WriteRequest(*Request) error
	Close() error
}

ClientCodec writes RPC requests and reads RPC responses in the client side of an RPC session. ReadResponseHeader and ReadResponseBody are called in pairs to read requests. WriteRequest writes a request to the connection ReadResponseBody could be called with a nil param to force the body of the response to be read and then discarded.

type Codec

type Codec interface {
	// 编码函数.
	Marshal(v interface{}) ([]byte, error)
	// 解码函数.
	Unmarshal(data []byte, v interface{}) error
}

Codec 编解码接口

func NewJSONCodec

func NewJSONCodec() Codec

NewJSONCodec 创建JSON编解码对象实例

func NewPBCodec

func NewPBCodec() Codec

NewPBCodec 创建PB编解码对象实例

type MessageType

type MessageType int

MessageType is gives the info about message type

type NewClientCodec

type NewClientCodec func(io.ReadWriteCloser) ClientCodec

NewClientCodec takes in a connection/buffer and returns a new client codec

type NewServerCodec

type NewServerCodec func(io.ReadWriteCloser) ServerCodec

NewServerCodec takes in a connection/buffer and returns a new server codec

type Request

type Request struct {
	ID          uint64
	SchemaID    string
	OperationID string
	Error       string
	Header      map[string]string
	Arg         interface{}
}

Request Message represents detailed information about the communication, likely followed by the body. In the case of an error, body may be nil

type Response

type Response struct {
	ID          uint64
	SchemaID    string
	OperationID string
	Error       string
	Header      map[string]string
	// contains filtered or unexported fields
}

Response Message represents detailed information about the communication, likely followed by the body. In the case of an error, body may be nil

type ServerCodec

type ServerCodec interface {
	ReadRequestHeader(*Request) error
	ReadRequestBody(interface{}) error
	// WriteResponse must be safe for concurrent use by multiple goroutines.
	WriteResponse(r *Response) error
	Close() error
}

ServerCodec reads RPC requests and writes RPC responses in the server side of an RPC session. ReadRequestHeader and ReadRequestBody are called in pairs to read requests from the connection. WriteResponse writes a response back. ReadRequestBody could be called with a nil param to force the body of the request to be read and discarded.

Jump to

Keyboard shortcuts

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