Documentation
¶
Index ¶
- Constants
- Variables
- func ParseHeaderLen(bs []byte) (l uint16)
- type Codec
- func (c *Codec) ClientCall(ctx context.Context, channel, callID uint16, req, res Msg) (done <-chan error, err error)
- func (c *Codec) Close() (err error)
- func (c *Codec) Handler(ctx context.Context, caller Method, header Header, req Msg) (resp Msg, err error)
- func (c *Codec) Heartbeat(ctx context.Context, cancel context.CancelFunc)
- func (c *Codec) IsClosed() (yes bool)
- func (c *Codec) ReadLoop(ctx context.Context, cancel context.CancelFunc)
- func (c *Codec) Send(ctx context.Context, wbuf []byte, ver, channel, callID uint16, callSN uint32) (err error)
- func (c *Codec) SendCloseMsg(ctx context.Context) (err error)
- func (c *Codec) SendCmd(ctx context.Context, channel uint16, req *base.CmdReq) (res *base.CmdRsp, err error)
- func (c *Codec) SendHeartbeatMsg(ctx context.Context) (err error)
- func (c *Codec) SendMsg(ctx context.Context, ver, channel, callID uint16, callSN uint32, msg Msg) (err error)
- func (c *Codec) Stream(ctx context.Context, channel uint16, callID uint16, caller Method, sync bool) (stream *Stream, err error)
- func (c *Codec) StreamCall(ctx context.Context, ver, channel, callID uint16, callSN uint32, req Msg) (err error)
- func (c *Codec) VerCallReq(ctx context.Context, header Header, bsBody []byte) (err error)
- func (c *Codec) VerCallResp(ctx context.Context, header Header, bsBody []byte) (err error)
- func (c *Codec) VerCmdReq(ctx context.Context, header Header, bsBody []byte) (err error)
- func (c *Codec) VerStreamReq(ctx context.Context, header Header, bsBody []byte) (err error)
- func (c *Codec) VerStreamResp(ctx context.Context, header Header, bsBody []byte) (err error)
- type Header
- type Method
- type Msg
- type Stream
Constants ¶
View Source
const ( VerHeartbeat = 0 VerRaw = 1 VerCallReq = 2 VerCallResp = 3 VerClose = 4 VerCmdReq = 5 // 发送控制命令 VerCmdResp = 6 // 响应控制命令 VerStreamReq = 7 VerStreamResp = 8 )
View Source
const ( HeaderSizeRaw = 6 HeaderSize = 16 MaxBuffSize = HeaderSize + math.MaxUint16 )
Variables ¶
View Source
var ErrHasBeenClosed = errors.NewCode(0, 0x1111, "has been closed")
Functions ¶
func ParseHeaderLen ¶
Types ¶
type Codec ¶
type Codec struct {
// contains filtered or unexported fields
}
func NewCodec ¶
func NewCodec(ctx context.Context, cancel context.CancelFunc, rwc io.ReadWriteCloser, callers []Method, needHeartbeat bool) (c *Codec, err error)
func (*Codec) ClientCall ¶
func (*Codec) StreamCall ¶
func (*Codec) VerCallReq ¶
收到 Req
func (*Codec) VerCallResp ¶
收到 Resp
func (*Codec) VerStreamReq ¶
type Header ¶
type Header struct { Len uint16 // 版本号, 0:raw bytes, 1:CallReq, 2:CallResp; size: 2 Channel uint16 // 通道,通道见彼此独立, size: 2 Ver uint16 // 消息长度, size: 2 // Len != 0 才需要 SegmentCount uint16 // 大包拆包总数量, size: 2 SegmentIdx uint16 // 大包拆包编号, size: 2 CallID uint16 // 调用ID, size: 4; 连接建立后,将 caller func name 与id映射一次 CallSN uint32 // 调用序列号, size: 4; stream 的 callSN 和 Call 要保持独立, 因为stream回头有可能会碰撞 }
func ParseHeader ¶
func ReadPack ¶
func ReadPack(ctx context.Context, r io.Reader, buf []byte) (header Header, bsBody []byte, err error)
ReadPack 读一个裸消息
func (*Header) FormatCall ¶
type Method ¶
type Method interface { ReqType() reflect.Type RespType() reflect.Type NewReq() Msg NewResp() Msg SvcInvoke(ctx context.Context, req Msg) (resp Msg, err error) FuncName() string }
Method 表示一个 struct 的可以调用的方法
Click to show internal directories.
Click to hide internal directories.