lrpc

package
v0.0.0-...-e8b5d25 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2019 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MSG_HEAD = []byte("@@@@")

Functions

func AssembleBuffer

func AssembleBuffer(b []byte) (result []byte)

组合成消息

func BytesToIntLittleEndian

func BytesToIntLittleEndian(b []byte) uint

字节转换成整形(小端)

func EncodeCallMsg

func EncodeCallMsg(in *RPCCall) (b []byte)

序列化消息

func EncodeResultMsg

func EncodeResultMsg(in *RPCResult) (b []byte)

序列化消息

func GetMsgBody

func GetMsgBody(b []byte, length uint) []byte

获取body

func GetMsgLen

func GetMsgLen(b []byte) uint

获取长度

func HandleHeader

func HandleHeader(b []byte) (newB []byte)

处理一下消息头

func IntToBytesLittleEndian

func IntToBytesLittleEndian(n int) []byte

整形转换成字节(小端)

Types

type RPCCall

type RPCCall struct {
	Seq    int
	Class  string
	Method string
	Args   []interface{}
}

func DecodeCallMsg

func DecodeCallMsg(b []byte) (rpccall RPCCall)

反序列化消息

type RPCClient

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

func NewRPCClient

func NewRPCClient(addr, port string) *RPCClient

func (*RPCClient) Call

func (this *RPCClient) Call(method string, args []interface{})

远程调用(无返回值) method: class.method

func (*RPCClient) CallReply

func (this *RPCClient) CallReply(method string, args []interface{}, fn RPCFunc)

远程调用(有返回值) method: class.method

func (*RPCClient) Dial

func (this *RPCClient) Dial()

type RPCFunc

type RPCFunc func(arg ...interface{})

type RPCResult

type RPCResult struct {
	Seq    int
	Return []interface{}
}

func DecodeResultMsg

func DecodeResultMsg(b []byte) (rpccall RPCResult)

反序列化消息

type RPCServer

type RPCServer struct {
	Listener *net.TCPListener
	Port     string
	RPCObjs  *sync.Map // rpc注册的对象
}

rpc

func NewRPCServer

func NewRPCServer(port string) *RPCServer

func (*RPCServer) Accept

func (this *RPCServer) Accept()

接受消息

func (*RPCServer) HandleConn

func (this *RPCServer) HandleConn(conn net.Conn)

处理链接

func (*RPCServer) Register

func (this *RPCServer) Register(class interface{})

注册类

Jump to

Keyboard shortcuts

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