Documentation ¶
Index ¶
- Constants
- Variables
- func ContextWithSession(ctx context.Context, session Session) context.Context
- func DeregisterMarshaler(typ MarshalType)
- func RegisterCodec(proto string, server, client Codec)
- func RegisterMarshaler(typ MarshalType, marshaler Marshaler)
- func RegisterSessionBuilder(proto string, builder SessionBuilder)
- type BaseSession
- type Codec
- type CompressType
- type Compressor
- type GZipCompressor
- type MarshalType
- type Marshaler
- type PBMarshaler
- type Session
- type SessionBuilder
Constants ¶
const ( MarshalTypePB = MarshalType(iota) MarshalTypeJSON )
const (
CompressGZip = CompressType(iota)
)
Variables ¶
var MarshalInvalidPBErr = errors.New("pkg isn't proto.Message")
Functions ¶
func ContextWithSession ¶
ContextWithSession return new context carrying value `session`
func DeregisterMarshaler ¶
func DeregisterMarshaler(typ MarshalType)
DeregisterMarshaler deregisters the marshaler of specific MarshalType, this is concurrent-safe.
func RegisterCodec ¶
register the client and server codec to framework
func RegisterMarshaler ¶
func RegisterMarshaler(typ MarshalType, marshaler Marshaler)
RegisterMarshaler registers a new marshaler implemention of specific MarshalType, this is concurrent-safe.
func RegisterSessionBuilder ¶
func RegisterSessionBuilder(proto string, builder SessionBuilder)
RegisterSessionBuilder register extended SessionBuilder for protocol `proto`
Types ¶
type BaseSession ¶
type BaseSession struct { ReqHead interface{} RspHead interface{} }
BaseSession implements some basic methods defined in `Session`
func (*BaseSession) Request ¶
func (r *BaseSession) Request() interface{}
func (*BaseSession) Response ¶
func (r *BaseSession) Response() interface{}
func (*BaseSession) SetResponse ¶
func (r *BaseSession) SetResponse(rsp interface{})
type Codec ¶
type Codec interface { // codec name Name() string // Encode encode 'pkg' into []byte, here 'pkg' must be []byte, // which is marshaled and compressed data. Encode(pkg interface{}) (data []byte, err error) // Decode decode []byte, return decoded body data and length, // which is marshaled and compressed data. Decode(data []byte) (req interface{}, n int, err error) }
encode * decode client and server side should impl the codec
type Compressor ¶
type GZipCompressor ¶
type GZipCompressor struct{}
func (*GZipCompressor) Decompress ¶
func (r *GZipCompressor) Decompress(data []byte) ([]byte, error)
type MarshalType ¶
type MarshalType int
type Marshaler ¶
type Marshaler interface { // Marshal serializes 'pkg' to []byte, return the data, // return error if any error encountered. Marshal(pkg interface{}) (data []byte, err error) // Unmarhshal deserializes []byte to pkg, which must be a pointer, // return error if any error encountered. Unmarshal(data []byte, pkg interface{}) error }
Marshaler defines how to serialize/deserialize
type PBMarshaler ¶
type PBMarshaler struct{}
PBMarshaler google protocolbuffers marshaling
func (*PBMarshaler) Marshal ¶
func (m *PBMarshaler) Marshal(pkg interface{}) (data []byte, err error)
Marshal marshal pkg in protocolbuffers manner
func (*PBMarshaler) Unmarshal ¶
func (m *PBMarshaler) Unmarshal(data []byte, pkg interface{}) error
Unmarshal unmarshal data into pkg, which must be proto.Message
type Session ¶
type Session interface { RPCName() string Request() interface{} Response() interface{} SetResponse(rsp interface{}) SetError(err error) }
define the rpc context for a request the session init instally in client side when server side receive the requset, session init in server side maybe call `RpcContext`
func SessionFromContext ¶
SessionFromContext return Session carried by `ctx`
type SessionBuilder ¶
SessionBuilder when extending protocols, SessionBuilder should be implemented and registered to help build the `Session`.
func GetSessionBuilder ¶
func GetSessionBuilder(proto string) SessionBuilder
GetSessionBuilder return SessionBuilder for protocol `proto`