55 lines
1.6 KiB
Go
55 lines
1.6 KiB
Go
|
package mq_coder
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"io"
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
errBuildIncomplete = errors.New("coder.Encoder: invalid structure of packet")
|
||
|
errInvalidAdding = errors.New("coder.Encoder: can not add this Packet after StreamPacket has been add")
|
||
|
errNonStreamPacket = errors.New("coder.Packet: this packet is not in node mode")
|
||
|
errWriteFromReader = errors.New("coder.streamV: write from reader error")
|
||
|
errNotNodeMode = errors.New("coder.Encoder: packet should be in node mode can be add other packets as child")
|
||
|
errNilReader = errors.New("coder.Decoder: nil source reader")
|
||
|
)
|
||
|
|
||
|
// Packet 编解码器包
|
||
|
type Packet interface {
|
||
|
// SeqId 返回此数据包的序列Id.
|
||
|
SeqId() int
|
||
|
// Size 返回整个数据包的大小
|
||
|
Size() int
|
||
|
// VSize 返回V的大小.
|
||
|
VSize() int
|
||
|
// Bytes 此数据包的全部字节.
|
||
|
Bytes() []byte
|
||
|
// Reader 返回 io.Reader 字节.
|
||
|
Reader() io.Reader
|
||
|
// VReader 返回 io.Reader 的 流字节.
|
||
|
VReader() io.Reader
|
||
|
// IsStreamMode 是否流模式
|
||
|
IsStreamMode() bool
|
||
|
// IsNodeMode 是否节点模式
|
||
|
IsNodeMode() bool
|
||
|
|
||
|
// BytesV 返回流字节
|
||
|
BytesV() []byte
|
||
|
// UTF8StringV 返回流的utf8字符串值
|
||
|
UTF8StringV() string
|
||
|
// Int32V 返回流的int32值
|
||
|
Int32V() (val int32, err error)
|
||
|
// UInt32V 返回流的uint32值
|
||
|
UInt32V() (val uint32, err error)
|
||
|
// Int64V 返回流的int64值
|
||
|
Int64V() (val int64, err error)
|
||
|
// UInt64V 返回流的uint64值
|
||
|
UInt64V() (val uint64, err error)
|
||
|
// Float32V 返回流的float32值
|
||
|
Float32V() (val float32, err error)
|
||
|
// Float64V 返回流的float64值
|
||
|
Float64V() (val float64, err error)
|
||
|
// BoolV 返回流的bool值
|
||
|
BoolV() (val bool, err error)
|
||
|
}
|