Documentation
¶
Index ¶
- func ExtractRouteSeq(buf buffer.Buffer) (int32, int32, error)
- func NewPacker(opts ...Option) *defaultPacker
- func PackHeartbeat(server ...bool) buffer.Buffer
- func PackMessage(message *Message) (buffer.Buffer, error)
- func Read(reader io.Reader) (bool, int64, buffer.Buffer, error)
- func SetPacker(packer Packer)
- func UnpackMessage(buf buffer.Buffer) (int32, int32, buffer.Buffer, error)
- type Message
- type Option
- type Packer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractRouteSeq ¶ added in v2.6.0
ExtractRouteSeq extracts the route and sequence number from the message buffer buf. It returns the route, the sequence number and any unpacking error.
func NewPacker ¶
func NewPacker(opts ...Option) *defaultPacker
NewPacker returns a new default packer.
It validates the options and prebuilds the heartbeat packet. The program terminates when the given options are invalid.
func PackHeartbeat ¶ added in v2.1.0
PackHeartbeat packs a heartbeat.
The returned heartbeat buffer must neither be modified nor released. Pass server as true to pack a server-side heartbeat.
func PackMessage ¶ added in v2.1.0
PackMessage packs message as a buffer and returns the packed buffer or a packing error.
func Read ¶ added in v2.6.0
Read reads a message as a buffer. It reports whether the message is a heartbeat, the server-side timestamp in nanoseconds, the message buffer and any read error.
Types ¶
type Message ¶
type Message struct {
Seq int32 // Sequence number
Route int32 // Route ID
Buffer []byte // Message content
}
Message is a message.
It is used to pass plain data messages between encoding and decoding.
type Option ¶
type Option func(o *options)
func WithBufferBytes ¶
WithBufferBytes returns an Option that sets the number of message bytes, that is, the maximum allowed message size.
func WithByteOrder ¶
WithByteOrder returns an Option that sets the byte order.
func WithHeartbeatTime ¶ added in v2.1.0
WithHeartbeatTime returns an Option that sets whether the heartbeat time is carried.
func WithRouteBytes ¶
WithRouteBytes returns an Option that sets the number of route bytes.
The number of route bytes must be 1, 2 or 4.
func WithSeqBytes ¶
WithSeqBytes returns an Option that sets the number of sequence-number bytes.
It may be 0, 1, 2 or 4; sequence-number encoding is disabled when it is 0.
type Packer ¶
type Packer interface {
// Read reads a message as a buffer. It reports whether the message is a heartbeat, the
// server-side timestamp in nanoseconds, the message buffer and any read error.
Read(reader io.Reader) (bool, int64, buffer.Buffer, error)
// PackMessage packs message as a buffer and returns the packed buffer or a packing error.
PackMessage(message *Message) (buffer.Buffer, error)
// ExtractRouteSeq extracts the route and sequence number from the message buffer buf. It
// returns the route, the sequence number and any unpacking error.
ExtractRouteSeq(buf buffer.Buffer) (int32, int32, error)
// UnpackMessage unpacks the message buffer buf. It returns the route, the sequence number,
// the message buffer and any unpacking error.
UnpackMessage(buf buffer.Buffer) (int32, int32, buffer.Buffer, error)
// PackHeartbeat packs a heartbeat. Pass server as true to pack a server-side heartbeat.
PackHeartbeat(server ...bool) buffer.Buffer
}
Packer defines the encoding and decoding capabilities of messages.