Documentation
¶
Index ¶
- func ExtractHandshake(buf buffer.Buffer) ([]byte, error)
- func ExtractMessage(buf buffer.Buffer) (int32, int32, []byte, error)
- func ExtractRouteSeq(buf buffer.Buffer) (int32, int32, error)
- func MessageBufferHeadroom() int
- func NewPacker(opts ...Option) *defaultPacker
- func PackHandshake(payload []byte) (buffer.Buffer, error)
- func PackHeartbeat(server ...bool) buffer.Buffer
- func PackMessage(route, seq int32, data []byte) (buffer.Buffer, error)
- func PackMessageBuffer(route, seq int32, payload *buffer.Bytes) (buffer.Buffer, error)
- func ReadBufferHeadroom() int
- func SetPacker(packer Packer)
- func UnpackMessage(buf buffer.Buffer) (int32, int32, buffer.Buffer, error)
- type FrameType
- type MessageBufferHeadroomPacker
- type MessageBufferPacker
- type MessageExtractor
- type Option
- type Packer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractHandshake ¶ added in v2.6.3
ExtractHandshake extracts the payload of a handshake frame.
func ExtractMessage ¶ added in v2.6.3
ExtractMessage returns the route, the sequence number and the payload of buf without modifying the buffer, so it is safe to call on a shared buffer. The payload may alias buf and must not be used after buf is released or modified.
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 MessageBufferHeadroom ¶ added in v2.6.3
func MessageBufferHeadroom() int
MessageBufferHeadroom returns the space that the global packer can use before a pooled payload. It returns zero when the packer does not support in-place header prepending.
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 PackHandshake ¶ added in v2.6.3
PackHandshake packs a handshake frame.
Handshake frames carry neither a route nor a sequence number, and they are marked by a reserved header bit, so they do not consume a route number.
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 a message payload as a buffer and returns the packed buffer or a packing error.
func PackMessageBuffer ¶ added in v2.6.3
PackMessageBuffer packs a pooled payload, transferring ownership only on success. Packers without MessageBufferPacker support receive a copy so the pooled memory can be released safely.
func ReadBufferHeadroom ¶ added in v2.6.5
func ReadBufferHeadroom() int
ReadBufferHeadroom returns the space reserved before every frame read from the wire. A transport header that fits in this space can be prepended in place without copying the payload.
Types ¶
type FrameType ¶ added in v2.6.3
type FrameType uint8
FrameType is the type of a frame read from the wire.
type MessageBufferHeadroomPacker ¶ added in v2.6.3
type MessageBufferHeadroomPacker interface {
MessageBufferHeadroom() int
}
MessageBufferHeadroomPacker reports how much space a pooled payload can reserve so that PackMessageBuffer can prepend the message header without wrapping the payload in another buffer.
type MessageBufferPacker ¶ added in v2.6.3
type MessageBufferPacker interface {
PackMessageBuffer(route, seq int32, payload *buffer.Bytes) (buffer.Buffer, error)
}
MessageBufferPacker packs a pooled payload without copying it. On success the returned buffer owns payload; on error the caller retains ownership.
type MessageExtractor ¶ added in v2.6.3
type MessageExtractor interface {
// ExtractMessage returns the route, the sequence number and the payload of buf.
ExtractMessage(buf buffer.Buffer) (int32, int32, []byte, error)
}
MessageExtractor is implemented by packers that can extract the payload of a packed message without modifying the buffer.
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 frame as a buffer. It reports the frame type, the server-side timestamp in
// nanoseconds, the frame buffer and any read error. The timestamp is meaningful only for
// heartbeat frames.
Read(reader io.Reader) (FrameType, int64, buffer.Buffer, error)
// PackHandshake packs a handshake frame. A handshake frame carries neither a route nor a
// sequence number, and it is marked by a reserved header bit.
PackHandshake(payload []byte) (buffer.Buffer, error)
// PackHeartbeat packs a heartbeat. Pass server as true to pack a server-side heartbeat.
PackHeartbeat(server ...bool) buffer.Buffer
// PackMessage packs a message payload and returns the packed buffer or a packing error.
PackMessage(route, seq int32, data []byte) (buffer.Buffer, 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)
// ExtractHandshake extracts the payload of a handshake frame. It reports
// [errors.ErrInvalidMessage] when buf is not a handshake frame.
ExtractHandshake(buf buffer.Buffer) ([]byte, 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)
}
Packer defines the encoding and decoding capabilities of messages.