rpc

package
v0.0.0-...-ff803ae Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2020 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LittleEndian bool
View Source
var NilError = reflect.Zero(reflect.TypeOf((*error)(nil)).Elem())

Functions

func AppendProcessor

func AppendProcessor(rpcProcessor IRpcProcessor)

func GetProcessorType

func GetProcessorType(param interface{}) (RpcProcessorType, IRpcProcessor)

func ReleaseCall

func ReleaseCall(call *Call)

func ReleaseRpcRequest

func ReleaseRpcRequest(rpcRequest *RpcRequest)

Types

type AdditionParam

type AdditionParam struct {
	// Types that are valid to be assigned to AdditionOneof:
	//	*AdditionParam_SParam
	//	*AdditionParam_UParam
	//	*AdditionParam_StrParam
	//	*AdditionParam_BParam
	AdditionOneof        isAdditionParam_AdditionOneof `protobuf_oneof:"addition_oneof"`
	XXX_NoUnkeyedLiteral struct{}                      `json:"-"`
	XXX_unrecognized     []byte                        `json:"-"`
	XXX_sizecache        int32                         `json:"-"`
}

func (*AdditionParam) Descriptor

func (*AdditionParam) Descriptor() ([]byte, []int)

func (*AdditionParam) GetAdditionOneof

func (m *AdditionParam) GetAdditionOneof() isAdditionParam_AdditionOneof

func (*AdditionParam) GetBParam

func (m *AdditionParam) GetBParam() []byte

func (*AdditionParam) GetSParam

func (m *AdditionParam) GetSParam() int64

func (*AdditionParam) GetStrParam

func (m *AdditionParam) GetStrParam() string

func (*AdditionParam) GetUParam

func (m *AdditionParam) GetUParam() uint64

func (*AdditionParam) ProtoMessage

func (*AdditionParam) ProtoMessage()

func (*AdditionParam) Reset

func (m *AdditionParam) Reset()

func (*AdditionParam) String

func (m *AdditionParam) String() string

func (*AdditionParam) XXX_DiscardUnknown

func (m *AdditionParam) XXX_DiscardUnknown()

func (*AdditionParam) XXX_Marshal

func (m *AdditionParam) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*AdditionParam) XXX_Merge

func (m *AdditionParam) XXX_Merge(src proto.Message)

func (*AdditionParam) XXX_OneofFuncs

func (*AdditionParam) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{})

XXX_OneofFuncs is for the internal use of the proto package.

func (*AdditionParam) XXX_Size

func (m *AdditionParam) XXX_Size() int

func (*AdditionParam) XXX_Unmarshal

func (m *AdditionParam) XXX_Unmarshal(b []byte) error

type AdditionParam_BParam

type AdditionParam_BParam struct {
	BParam []byte `protobuf:"bytes,13,opt,name=BParam,oneof"`
}

type AdditionParam_SParam

type AdditionParam_SParam struct {
	SParam int64 `protobuf:"varint,10,opt,name=SParam,oneof"`
}

type AdditionParam_StrParam

type AdditionParam_StrParam struct {
	StrParam string `protobuf:"bytes,12,opt,name=StrParam,oneof"`
}

type AdditionParam_UParam

type AdditionParam_UParam struct {
	UParam uint64 `protobuf:"varint,11,opt,name=UParam,oneof"`
}

type Call

type Call struct {
	Seq           uint64
	ServiceMethod string
	Reply         interface{}
	Response      *RpcResponse
	Err           error
	// contains filtered or unexported fields
}

func MakeCall

func MakeCall() *Call

func (*Call) Clear

func (call *Call) Clear() *Call

func (*Call) Done

func (call *Call) Done() *Call

type Client

type Client struct {
	network.TCPClient
	// contains filtered or unexported fields
}

func (*Client) AddPending

func (client *Client) AddPending(call *Call)

func (*Client) AsyncCall

func (client *Client) AsyncCall(rpcHandler IRpcHandler, serviceMethod string, callback reflect.Value, args interface{}, replyParam interface{}) error

func (*Client) Connect

func (client *Client) Connect(id int, addr string) error

func (*Client) FindPending

func (client *Client) FindPending(seq uint64) *Call

func (*Client) GetId

func (client *Client) GetId() int

func (*Client) Go

func (client *Client) Go(noReply bool, serviceMethod string, args interface{}, reply interface{}) *Call

func (*Client) IsConnected

func (client *Client) IsConnected() bool

func (*Client) NewClientAgent

func (client *Client) NewClientAgent(conn *network.TCPConn) network.Agent

func (*Client) OnClose

func (client *Client) OnClose()

func (*Client) RawGo

func (client *Client) RawGo(processor IRpcProcessor, noReply bool, serviceMethod string, args []byte, additionParam interface{}, reply interface{}) *Call

func (*Client) RemovePending

func (client *Client) RemovePending(seq uint64) *Call

func (*Client) ResetPending

func (client *Client) ResetPending()

func (*Client) Run

func (client *Client) Run()

type FuncRpcClient

type FuncRpcClient func(nodeId int, serviceMethod string, client []*Client) (error, int)

type FuncRpcServer

type FuncRpcServer func() *Server

type IRawAdditionParam

type IRawAdditionParam interface {
	GetParamValue() interface{}
}

type IRawInputArgs

type IRawInputArgs interface {
	GetRawData() []byte            //获取原始数据
	GetAdditionParam() interface{} //获取附加数据
	DoGc()                         //处理完成,回收内存
}

type IRpcHandler

type IRpcHandler interface {
	GetName() string
	InitRpcHandler(rpcHandler IRpcHandler, getClientFun FuncRpcClient, getServerFun FuncRpcServer)
	GetRpcHandler() IRpcHandler
	PushRequest(callInfo *RpcRequest) error
	HandlerRpcRequest(request *RpcRequest)
	HandlerRpcResponseCB(call *Call)

	GetRpcRequestChan() chan *RpcRequest
	GetRpcResponseChan() chan *Call
	CallMethod(ServiceMethod string, param interface{}, reply interface{}) error

	AsyncCall(serviceMethod string, args interface{}, callback interface{}) error
	Call(serviceMethod string, args interface{}, reply interface{}) error
	Go(serviceMethod string, args interface{}) error
	AsyncCallNode(nodeId int, serviceMethod string, args interface{}, callback interface{}) error
	CallNode(nodeId int, serviceMethod string, args interface{}, reply interface{}) error
	GoNode(nodeId int, serviceMethod string, args interface{}) error
	RawGoNode(rpcProcessorType RpcProcessorType, nodeId int, serviceMethod string, args IRawInputArgs) error
	IsSingleCoroutine() bool
}

type IRpcProcessor

type IRpcProcessor interface {
	Marshal(v interface{}) ([]byte, error) //b表示自定义缓冲区,可以填nil,由系统自动分配
	Unmarshal(data []byte, v interface{}) error
	MakeRpcRequest(seq uint64, serviceMethod string, noReply bool, inParam []byte, additionParam interface{}) IRpcRequestData
	MakeRpcResponse(seq uint64, err RpcError, reply []byte) IRpcResponseData

	ReleaseRpcRequest(rpcRequestData IRpcRequestData)
	ReleaseRpcResponse(rpcRequestData IRpcResponseData)
	IsParse(param interface{}) bool //是否可解析
	GetProcessorType() RpcProcessorType
}

func GetProcessor

func GetProcessor(processorType uint8) IRpcProcessor

type IRpcRequestData

type IRpcRequestData interface {
	GetSeq() uint64
	GetServiceMethod() string
	GetInParam() []byte
	IsNoReply() bool
	GetAdditionParams() IRawAdditionParam
}

type IRpcResponseData

type IRpcResponseData interface {
	GetSeq() uint64
	GetErr() *RpcError
	GetReply() []byte
}

type JsonProcessor

type JsonProcessor struct {
}

func (*JsonProcessor) GetProcessorType

func (jsonProcessor *JsonProcessor) GetProcessorType() RpcProcessorType

func (*JsonProcessor) IsParse

func (jsonProcessor *JsonProcessor) IsParse(param interface{}) bool

func (*JsonProcessor) MakeRpcRequest

func (jsonProcessor *JsonProcessor) MakeRpcRequest(seq uint64, serviceMethod string, noReply bool, inParam []byte, additionParam interface{}) IRpcRequestData

func (*JsonProcessor) MakeRpcResponse

func (jsonProcessor *JsonProcessor) MakeRpcResponse(seq uint64, err RpcError, reply []byte) IRpcResponseData

func (*JsonProcessor) Marshal

func (jsonProcessor *JsonProcessor) Marshal(v interface{}) ([]byte, error)

func (*JsonProcessor) ReleaseRpcRequest

func (jsonProcessor *JsonProcessor) ReleaseRpcRequest(rpcRequestData IRpcRequestData)

func (*JsonProcessor) ReleaseRpcResponse

func (jsonProcessor *JsonProcessor) ReleaseRpcResponse(rpcResponseData IRpcResponseData)

func (*JsonProcessor) Unmarshal

func (jsonProcessor *JsonProcessor) Unmarshal(data []byte, v interface{}) error

type JsonRpcRequestData

type JsonRpcRequestData struct {
	//packhead
	Seq           uint64 // sequence number chosen by client
	ServiceMethod string // format: "Service.Method"
	NoReply       bool   //是否需要返回
	//packbody
	InParam       []byte
	AdditionParam interface{}
}

func (*JsonRpcRequestData) GetAdditionParams

func (jsonRpcRequestData *JsonRpcRequestData) GetAdditionParams() IRawAdditionParam

func (*JsonRpcRequestData) GetInParam

func (jsonRpcRequestData *JsonRpcRequestData) GetInParam() []byte

func (*JsonRpcRequestData) GetParamValue

func (jsonRpcRequestData *JsonRpcRequestData) GetParamValue() interface{}

func (*JsonRpcRequestData) GetSeq

func (jsonRpcRequestData *JsonRpcRequestData) GetSeq() uint64

func (*JsonRpcRequestData) GetServiceMethod

func (jsonRpcRequestData *JsonRpcRequestData) GetServiceMethod() string

func (*JsonRpcRequestData) IsNoReply

func (jsonRpcRequestData *JsonRpcRequestData) IsNoReply() bool

type JsonRpcResponseData

type JsonRpcResponseData struct {
	//head
	Seq uint64 // sequence number chosen by client
	Err string

	//returns
	Reply []byte
}

func (*JsonRpcResponseData) GetErr

func (jsonRpcResponseData *JsonRpcResponseData) GetErr() *RpcError

func (*JsonRpcResponseData) GetReply

func (jsonRpcResponseData *JsonRpcResponseData) GetReply() []byte

func (*JsonRpcResponseData) GetSeq

func (jsonRpcResponseData *JsonRpcResponseData) GetSeq() uint64

type PBProcessor

type PBProcessor struct {
}

func (*PBProcessor) GetProcessorType

func (slf *PBProcessor) GetProcessorType() RpcProcessorType

func (*PBProcessor) IsParse

func (slf *PBProcessor) IsParse(param interface{}) bool

func (*PBProcessor) MakeRpcRequest

func (slf *PBProcessor) MakeRpcRequest(seq uint64, serviceMethod string, noReply bool, inParam []byte, inAdditionParam interface{}) IRpcRequestData

func (*PBProcessor) MakeRpcResponse

func (slf *PBProcessor) MakeRpcResponse(seq uint64, err RpcError, reply []byte) IRpcResponseData

func (*PBProcessor) Marshal

func (slf *PBProcessor) Marshal(v interface{}) ([]byte, error)

func (*PBProcessor) ReleaseRpcRequest

func (slf *PBProcessor) ReleaseRpcRequest(rpcRequestData IRpcRequestData)

func (*PBProcessor) ReleaseRpcResponse

func (slf *PBProcessor) ReleaseRpcResponse(rpcResponseData IRpcResponseData)

func (*PBProcessor) Unmarshal

func (slf *PBProcessor) Unmarshal(data []byte, msg interface{}) error

type PBRpcRequestData

type PBRpcRequestData struct {
	Seq                  *uint64        `protobuf:"varint,1,opt,name=Seq" json:"Seq,omitempty"`
	ServiceMethod        *string        `protobuf:"bytes,2,opt,name=ServiceMethod" json:"ServiceMethod,omitempty"`
	NoReply              *bool          `protobuf:"varint,3,opt,name=NoReply" json:"NoReply,omitempty"`
	InParam              []byte         `protobuf:"bytes,4,opt,name=InParam" json:"InParam,omitempty"`
	AddtionParam         *AdditionParam `protobuf:"bytes,5,opt,name=addtionParam" json:"addtionParam,omitempty"`
	XXX_NoUnkeyedLiteral struct{}       `json:"-"`
	XXX_unrecognized     []byte         `json:"-"`
	XXX_sizecache        int32          `json:"-"`
}

func (*PBRpcRequestData) Descriptor

func (*PBRpcRequestData) Descriptor() ([]byte, []int)

func (*PBRpcRequestData) GetAdditionParams

func (m *PBRpcRequestData) GetAdditionParams() IRawAdditionParam

func (*PBRpcRequestData) GetAddtionParam

func (m *PBRpcRequestData) GetAddtionParam() *AdditionParam

func (*PBRpcRequestData) GetInParam

func (m *PBRpcRequestData) GetInParam() []byte

func (*PBRpcRequestData) GetNoReply

func (m *PBRpcRequestData) GetNoReply() bool

func (*PBRpcRequestData) GetParamValue

func (m *PBRpcRequestData) GetParamValue() interface{}

func (*PBRpcRequestData) GetSeq

func (m *PBRpcRequestData) GetSeq() uint64

func (*PBRpcRequestData) GetServiceMethod

func (m *PBRpcRequestData) GetServiceMethod() string

func (*PBRpcRequestData) IsNoReply

func (slf *PBRpcRequestData) IsNoReply() bool

func (*PBRpcRequestData) MakeRequest

func (slf *PBRpcRequestData) MakeRequest(seq uint64, serviceMethod string, noReply bool, inParam []byte, inAdditionParam interface{}) *PBRpcRequestData

func (*PBRpcRequestData) ProtoMessage

func (*PBRpcRequestData) ProtoMessage()

func (*PBRpcRequestData) Reset

func (m *PBRpcRequestData) Reset()

func (*PBRpcRequestData) String

func (m *PBRpcRequestData) String() string

func (*PBRpcRequestData) XXX_DiscardUnknown

func (m *PBRpcRequestData) XXX_DiscardUnknown()

func (*PBRpcRequestData) XXX_Marshal

func (m *PBRpcRequestData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*PBRpcRequestData) XXX_Merge

func (m *PBRpcRequestData) XXX_Merge(src proto.Message)

func (*PBRpcRequestData) XXX_Size

func (m *PBRpcRequestData) XXX_Size() int

func (*PBRpcRequestData) XXX_Unmarshal

func (m *PBRpcRequestData) XXX_Unmarshal(b []byte) error

type PBRpcResponseData

type PBRpcResponseData struct {
	Seq                  *uint64  `protobuf:"varint,1,opt,name=Seq" json:"Seq,omitempty"`
	Error                *string  `protobuf:"bytes,2,opt,name=Error" json:"Error,omitempty"`
	Reply                []byte   `protobuf:"bytes,3,opt,name=Reply" json:"Reply,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*PBRpcResponseData) Descriptor

func (*PBRpcResponseData) Descriptor() ([]byte, []int)

func (*PBRpcResponseData) GetErr

func (slf *PBRpcResponseData) GetErr() *RpcError

func (*PBRpcResponseData) GetError

func (m *PBRpcResponseData) GetError() string

func (*PBRpcResponseData) GetReply

func (m *PBRpcResponseData) GetReply() []byte

func (*PBRpcResponseData) GetSeq

func (m *PBRpcResponseData) GetSeq() uint64

func (*PBRpcResponseData) MakeRespone

func (slf *PBRpcResponseData) MakeRespone(seq uint64, err RpcError, reply []byte) *PBRpcResponseData

func (*PBRpcResponseData) ProtoMessage

func (*PBRpcResponseData) ProtoMessage()

func (*PBRpcResponseData) Reset

func (m *PBRpcResponseData) Reset()

func (*PBRpcResponseData) String

func (m *PBRpcResponseData) String() string

func (*PBRpcResponseData) XXX_DiscardUnknown

func (m *PBRpcResponseData) XXX_DiscardUnknown()

func (*PBRpcResponseData) XXX_Marshal

func (m *PBRpcResponseData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*PBRpcResponseData) XXX_Merge

func (m *PBRpcResponseData) XXX_Merge(src proto.Message)

func (*PBRpcResponseData) XXX_Size

func (m *PBRpcResponseData) XXX_Size() int

func (*PBRpcResponseData) XXX_Unmarshal

func (m *PBRpcResponseData) XXX_Unmarshal(b []byte) error

type RawAdditionParamNull

type RawAdditionParamNull struct {
}

func (*RawAdditionParamNull) GetParamValue

func (slf *RawAdditionParamNull) GetParamValue() interface{}

type RequestHandler

type RequestHandler func(Returns interface{}, Err RpcError)

type RpcAgent

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

func (*RpcAgent) Close

func (agent *RpcAgent) Close()

func (*RpcAgent) Destroy

func (agent *RpcAgent) Destroy()

func (*RpcAgent) LocalAddr

func (agent *RpcAgent) LocalAddr() net.Addr

func (*RpcAgent) OnClose

func (agent *RpcAgent) OnClose()

func (*RpcAgent) OnDestroy

func (agent *RpcAgent) OnDestroy()

func (*RpcAgent) RemoteAddr

func (agent *RpcAgent) RemoteAddr() net.Addr

func (*RpcAgent) Run

func (agent *RpcAgent) Run()

func (*RpcAgent) WriteMsg

func (agent *RpcAgent) WriteMsg(msg interface{})

func (*RpcAgent) WriteResponse

func (agent *RpcAgent) WriteResponse(processor IRpcProcessor, serviceMethod string, seq uint64, reply interface{}, err RpcError)

type RpcError

type RpcError string

func ConvertError

func ConvertError(e error) RpcError

func Errorf

func Errorf(format string, a ...interface{}) *RpcError

func (RpcError) Error

func (e RpcError) Error() string

type RpcHandleFinder

type RpcHandleFinder interface {
	FindRpcHandler(serviceMethod string) IRpcHandler
}

type RpcHandler

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

func (*RpcHandler) AsyncCall

func (handler *RpcHandler) AsyncCall(serviceMethod string, args interface{}, callback interface{}) error

func (*RpcHandler) AsyncCallNode

func (handler *RpcHandler) AsyncCallNode(nodeId int, serviceMethod string, args interface{}, callback interface{}) error

func (*RpcHandler) Call

func (handler *RpcHandler) Call(serviceMethod string, args interface{}, reply interface{}) error

func (*RpcHandler) CallMethod

func (handler *RpcHandler) CallMethod(ServiceMethod string, param interface{}, reply interface{}) error

func (*RpcHandler) CallNode

func (handler *RpcHandler) CallNode(nodeId int, serviceMethod string, args interface{}, reply interface{}) error

func (*RpcHandler) CastGo

func (handler *RpcHandler) CastGo(serviceMethod string, args interface{})

func (*RpcHandler) GetName

func (handler *RpcHandler) GetName() string

func (*RpcHandler) GetRpcHandler

func (handler *RpcHandler) GetRpcHandler() IRpcHandler

func (*RpcHandler) GetRpcRequestChan

func (handler *RpcHandler) GetRpcRequestChan() chan *RpcRequest

func (*RpcHandler) GetRpcResponseChan

func (handler *RpcHandler) GetRpcResponseChan() chan *Call

func (*RpcHandler) Go

func (handler *RpcHandler) Go(serviceMethod string, args interface{}) error

func (*RpcHandler) GoNode

func (handler *RpcHandler) GoNode(nodeId int, serviceMethod string, args interface{}) error

func (*RpcHandler) HandlerRpcRequest

func (handler *RpcHandler) HandlerRpcRequest(request *RpcRequest)

func (*RpcHandler) HandlerRpcResponseCB

func (handler *RpcHandler) HandlerRpcResponseCB(call *Call)

func (*RpcHandler) InitRpcHandler

func (handler *RpcHandler) InitRpcHandler(rpcHandler IRpcHandler, getClientFun FuncRpcClient, getServerFun FuncRpcServer)

func (*RpcHandler) IsSingleCoroutine

func (handler *RpcHandler) IsSingleCoroutine() bool

func (*RpcHandler) PushRequest

func (handler *RpcHandler) PushRequest(req *RpcRequest) error

func (*RpcHandler) RawGoNode

func (handler *RpcHandler) RawGoNode(rpcProcessorType RpcProcessorType, nodeId int, serviceMethod string, args IRawInputArgs) error

func (*RpcHandler) RegisterRpc

func (handler *RpcHandler) RegisterRpc(rpcHandler IRpcHandler) error

type RpcMethodInfo

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

type RpcProcessorType

type RpcProcessorType uint8
const (
	RpcProcessorJson RpcProcessorType = 0
	RpcProcessorPb   RpcProcessorType = 1
)

type RpcRequest

type RpcRequest struct {
	RpcRequestData IRpcRequestData
	// contains filtered or unexported fields
}

func MakeRpcRequest

func MakeRpcRequest() *RpcRequest

func (*RpcRequest) Clear

func (slf *RpcRequest) Clear() *RpcRequest

type RpcResponse

type RpcResponse struct {
	RpcResponseData IRpcResponseData
}

func (*RpcResponse) Clear

func (rpcResponse *RpcResponse) Clear() *RpcResponse

type Server

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

func (*Server) Init

func (server *Server) Init(rpcHandleFinder RpcHandleFinder)

func (*Server) NewAgent

func (server *Server) NewAgent(c *network.TCPConn) network.Agent

func (*Server) Start

func (server *Server) Start(listenAddr string)

Jump to

Keyboard shortcuts

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