rpc

package
v0.0.0-...-a538cea Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2020 License: Apache-2.0 Imports: 16 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 ReleaseCall

func ReleaseCall(call *Call)

func ReleaseRpcRequest

func ReleaseRpcRequest(rpcRequest *RpcRequest)

func ReleaseRpcResponse

func ReleaseRpcResponse(rpcRespone *RpcResponse)

func SetProcessor

func SetProcessor(proc IRpcProcessor)

Types

type Call

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

func MakeCall

func MakeCall() *Call

func (*Call) Clear

func (slf *Call) Clear() *Call

func (*Call) Done

func (slf *Call) Done() *Call

type Client

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

func (*Client) AddPending

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

func (*Client) AsycCall

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

func (*Client) Connect

func (slf *Client) Connect(addr string) error

func (*Client) FindPending

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

func (*Client) Go

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

func (*Client) IsConnected

func (slf *Client) IsConnected() bool

func (*Client) NewClientAgent

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

func (*Client) OnClose

func (slf *Client) OnClose()

func (*Client) RemovePending

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

func (*Client) ResetPending

func (slf *Client) ResetPending()

func (*Client) Run

func (slf *Client) Run()

type FuncRpcClient

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

type FuncRpcServer

type FuncRpcServer func() *Server

type IRpcHandler

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

	GetRpcRequestChan() chan *RpcRequest
	GetRpcResponeChan() 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
}

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) IRpcRequestData
	MakeRpcResponse(seq uint64, err *RpcError, reply []byte) IRpcResponseData

	ReleaseRpcRequest(rpcRequestData IRpcRequestData)
	ReleaseRpcRespose(rpcRequestData IRpcResponseData)
}

type IRpcRequestData

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

type IRpcResponseData

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

type JsonProcessor

type JsonProcessor struct {
}

func (*JsonProcessor) MakeRpcRequest

func (slf *JsonProcessor) MakeRpcRequest(seq uint64, serviceMethod string, noReply bool, inParam []byte) IRpcRequestData

func (*JsonProcessor) MakeRpcResponse

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

func (*JsonProcessor) Marshal

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

func (*JsonProcessor) ReleaseRpcRequest

func (slf *JsonProcessor) ReleaseRpcRequest(rpcRequestData IRpcRequestData)

func (*JsonProcessor) ReleaseRpcRespose

func (slf *JsonProcessor) ReleaseRpcRespose(rpcRequestData IRpcResponseData)

func (*JsonProcessor) Unmarshal

func (slf *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
}

func (*JsonRpcRequestData) GetInParam

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

func (*JsonRpcRequestData) GetSeq

func (slf *JsonRpcRequestData) GetSeq() uint64

func (*JsonRpcRequestData) GetServiceMethod

func (slf *JsonRpcRequestData) GetServiceMethod() string

func (*JsonRpcRequestData) IsNoReply

func (slf *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 (slf *JsonRpcResponseData) GetErr() *RpcError

func (*JsonRpcResponseData) GetReply

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

func (*JsonRpcResponseData) GetSeq

func (slf *JsonRpcResponseData) GetSeq() uint64

type PBProcessor

type PBProcessor struct {
}

func (*PBProcessor) MakeRpcRequest

func (slf *PBProcessor) MakeRpcRequest(seq uint64, serviceMethod string, noReply bool, inParam []byte) 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) ReleaseRpcRespose

func (slf *PBProcessor) ReleaseRpcRespose(rpcRequestData 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"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*PBRpcRequestData) Descriptor

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

func (*PBRpcRequestData) GetInParam

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

func (*PBRpcRequestData) GetNoReply

func (m *PBRpcRequestData) GetNoReply() bool

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) *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 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 (gate *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) WriteRespone

func (agent *RpcAgent) WriteRespone(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 (slf *RpcHandler) AsyncCall(serviceMethod string, args interface{}, callback interface{}) error

func (slf *RpcHandler) asyncCallRpc(serviceMethod string,mutiCoroutine bool,callback interface{},args ...interface{}) error { func (slf *RpcHandler) callRpc(serviceMethod string,reply interface{},mutiCoroutine bool,args ...interface{}) error { func (slf *RpcHandler) goRpc(serviceMethod string,mutiCoroutine bool,args ...interface{}) error { (reply *int,err error) {}

func (*RpcHandler) AsyncCallNode

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

func (*RpcHandler) Call

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

func (*RpcHandler) CallMethod

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

func (*RpcHandler) CallNode

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

func (*RpcHandler) CastGo

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

func (*RpcHandler) GetName

func (slf *RpcHandler) GetName() string

func (*RpcHandler) GetRpcHandler

func (slf *RpcHandler) GetRpcHandler() IRpcHandler

func (*RpcHandler) GetRpcRequestChan

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

func (*RpcHandler) GetRpcResponeChan

func (slf *RpcHandler) GetRpcResponeChan() chan *Call

func (*RpcHandler) Go

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

func (*RpcHandler) GoNode

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

func (*RpcHandler) HandlerRpcRequest

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

func (*RpcHandler) HandlerRpcResponeCB

func (slf *RpcHandler) HandlerRpcResponeCB(call *Call)

func (*RpcHandler) InitRpcHandler

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

func (*RpcHandler) PushRequest

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

func (*RpcHandler) RegisterRpc

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

type RpcMethodInfo

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

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 {
	RpcResponeData IRpcResponseData
}

func MakeRpcResponse

func MakeRpcResponse() *RpcResponse

func (*RpcResponse) Clear

func (slf *RpcResponse) Clear() *RpcResponse

type Server

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

func (*Server) Init

func (slf *Server) Init(rpcHandleFinder RpcHandleFinder)

func (*Server) NewAgent

func (slf *Server) NewAgent(conn *network.TCPConn) network.Agent

func (*Server) Start

func (slf *Server) Start(listenAddr string)

Jump to

Keyboard shortcuts

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