rpc

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2020 License: MIT Imports: 12 Imported by: 0

README

rpc.go

编译消息
protoc --go_out=. message.proto

Documentation

Index

Constants

View Source
const (
	MessageTypeData = MessageType(iota)
	MessageTypePing
	MessageTypePong
)

Variables

View Source
var (
	ErrorMessageFormatInvalid = errors.New("message format invalid")
	ErrorConnectIdInvalid     = errors.New("connect id invalid")
	ErrorConnectionInvalid    = errors.New("connection invalid")
)
View Source
var File_message_proto protoreflect.FileDescriptor

Functions

This section is empty.

Types

type AcceptClient

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

type Client

type Client struct {
	OnConnected func()
	OnClose     func()
	OnData      func(tag uint32, payload []byte)
	// contains filtered or unexported fields
}

func NewClient

func NewClient() (*Client, error)

func (*Client) Close

func (c *Client) Close()

func (*Client) DialAndServe

func (c *Client) DialAndServe(address string, password []byte, salt []byte) error

func (*Client) Reconnect

func (c *Client) Reconnect(second time.Duration)

func (*Client) Send

func (c *Client) Send(tag uint32, data []byte) (n int, err error)

type Event

type Event struct {
	ClientId  uint64
	RequestId uint32
	Request   *Request
}

type MessageType

type MessageType uint8

type Request

type Request struct {
	Id   int32  `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`    // 请求 id
	Tag  int32  `protobuf:"varint,2,opt,name=tag,proto3" json:"tag,omitempty"`  // tag
	Body []byte `protobuf:"bytes,3,opt,name=body,proto3" json:"body,omitempty"` // 消息体
	// contains filtered or unexported fields
}

func (*Request) Descriptor deprecated

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

Deprecated: Use Request.ProtoReflect.Descriptor instead.

func (*Request) GetBody

func (x *Request) GetBody() []byte

func (*Request) GetId

func (x *Request) GetId() int32

func (*Request) GetTag

func (x *Request) GetTag() int32

func (*Request) ProtoMessage

func (*Request) ProtoMessage()

func (*Request) ProtoReflect

func (x *Request) ProtoReflect() protoreflect.Message

func (*Request) Reset

func (x *Request) Reset()

func (*Request) String

func (x *Request) String() string

type Response

type Response struct {
	Id     int32  `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`         // 回复对应的请求 id
	Tag    int32  `protobuf:"varint,2,opt,name=tag,proto3" json:"tag,omitempty"`       // tag
	Body   []byte `protobuf:"bytes,3,opt,name=body,proto3" json:"body,omitempty"`      // 消息体
	Status int32  `protobuf:"varint,4,opt,name=status,proto3" json:"status,omitempty"` // 处理消息的状态码
	Type   int32  `protobuf:"varint,5,opt,name=type,proto3" json:"type,omitempty"`     // 消息类型, 0 普通, 1 推送
	// contains filtered or unexported fields
}

func (*Response) Descriptor deprecated

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

Deprecated: Use Response.ProtoReflect.Descriptor instead.

func (*Response) GetBody

func (x *Response) GetBody() []byte

func (*Response) GetId

func (x *Response) GetId() int32

func (*Response) GetStatus

func (x *Response) GetStatus() int32

func (*Response) GetTag

func (x *Response) GetTag() int32

func (*Response) GetType

func (x *Response) GetType() int32

func (*Response) ProtoMessage

func (*Response) ProtoMessage()

func (*Response) ProtoReflect

func (x *Response) ProtoReflect() protoreflect.Message

func (*Response) Reset

func (x *Response) Reset()

func (*Response) String

func (x *Response) String() string

type Server

type Server struct {
	OnNew   func(id uint64)
	OnData  func(id uint64, tag uint32, payload []byte)
	OnClose func(id uint64)
	// contains filtered or unexported fields
}

func NewServer

func NewServer() (*Server, error)

创建服务器

func (*Server) Send

func (s *Server) Send(id uint64, tag uint32, data []byte) (n int, err error)

func (*Server) Serve

func (s *Server) Serve(address string, password []byte, salt []byte) error

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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