codec

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

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

Go to latest
Published: Feb 15, 2018 License: Apache-2.0, 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 {
	// WriteRequest must be safe for concurrent use by multiple goroutines.
	// don't return bytes
	WriteRequest(*Request) error
	ReadResponseHeader(*Response) error
	ReadResponseBody(interface{}) error
	Close() error
}

A ClientCodec implements writing of RPC requests and reading of RPC responses for the client side of an RPC session. The client calls WriteRequest to write a request to the connection and calls ReadResponseHeader and ReadResponseBody in pairs to read responses. The client calls Close when finished with the connection. ReadResponseBody may be called with a nil argument 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
}

A ServerCodec implements reading of RPC requests and writing of RPC responses for the server side of an RPC session. The server calls ReadRequestHeader and ReadRequestBody in pairs to read requests from the connection, and it calls WriteResponse to write a response back. The server calls Close when finished with the connection. ReadRequestBody may be called with a nil argument 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