simpleRpc

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Request kind = iota
	Response
)

Variables

This section is empty.

Functions

func HeadLength

func HeadLength() int

HeadLength 包头长度

func Magic

func Magic() [2]byte

Magic 魔术字符

func Version

func Version() int

Version 协议版本

Types

type Decoder

type Decoder struct {
	LengthBased *codec.LengthBased
}

Decoder 解码器

func NewDecoder

func NewDecoder() *Decoder

func (*Decoder) Decoder

func (d *Decoder) Decoder(reader *bufio.Reader) (*Message, error)

Decoder 解码

type Encoder

type Encoder struct {
}

func NewEncoder

func NewEncoder() *Encoder

func (*Encoder) Encoder

func (e *Encoder) Encoder(message *Message, writer *bufio.Writer) error

type Handle

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

func NewHandle

func NewHandle() *Handle

func (Handle) Input

func (h Handle) Input(context *event.HandleContext, reader *bufio.Reader) (*Message, bool)

func (Handle) Output

func (h Handle) Output(context *event.HandleContext, message *Message) (any, bool)

type Message

type Message struct {
	Version    int            // 协议版本号
	Length     int            // 消息正文长度
	Serializer SerializerType // 序列化算法
	Kind       kind           // 消息类型, 请求 or 响应

	Sequence int // 消息序号, 四个字节,请求和应答序号一致, 用于支持全双工通讯
	// contains filtered or unexported fields
}

func NewEmpty

func NewEmpty() *Message

NewEmpty 创建一个空的消息

func NewMessage

func NewMessage(data []byte, method kind) *Message

func NewRequest

func NewRequest(data []byte) *Message

NewRequest 请求消息

func NewResponse

func NewResponse(data []byte) *Message

NewResponse 响应消息

func (*Message) Body

func (m *Message) Body() []byte

Body 消息正文

func (*Message) HeadLength

func (m *Message) HeadLength() int

HeadLength 消息头长度

func (*Message) MessageLength

func (m *Message) MessageLength() int

MessageLength 消息总长度

func (*Message) Method

func (m *Message) Method() string

Method 消息方法

func (*Message) SetBody

func (m *Message) SetBody(data []byte)

SetBody 设置消息正文

func (*Message) SetMethod

func (m *Message) SetMethod(name string)

SetMethod 设置方法名

type SerializerType

type SerializerType byte
const (
	Json SerializerType = iota
)

Jump to

Keyboard shortcuts

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