Documentation ¶
Overview ¶
Package codec implements readers and writers for https://github.com/dominictarr/packet-stream-codec
Packet structure:
( [flags (1byte), length (4 bytes, UInt32BE), req (4 bytes, Int32BE)] # Header [body (length bytes)] ) * [zeros (9 bytes)]
Flags:
[ignored (4 bits), stream (1 bit), end/err (1 bit), type (2 bits)] type = {0 => Buffer, 1 => String, 2 => JSON} # PacketType
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Wrap ¶
func Wrap(l log.Logger, rwc io.ReadWriteCloser) io.ReadWriteCloser
Wrap decodes every packet that passes through it and logs it
Types ¶
type Flag ¶
type Flag byte
Flag is the first byte of the Header
func (Flag) PacketType ¶
func (f Flag) PacketType() PacketType
type Packet ¶
type Packet struct { Stream bool EndErr bool Type PacketType Req int32 Body []byte }
Packet is the decoded high-level representation
type PacketType ¶
type PacketType uint
PacketType are the 2 bits of type in the packet header
const ( Buffer PacketType = iota String JSON )
Enumeration of the possible body types of a packet
func (PacketType) Flag ¶
func (pt PacketType) Flag() Flag
func (PacketType) String ¶
func (i PacketType) String() string
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
func (*Reader) ReadPacket ¶
ReadPacket decodes the header from the underlying writer, and reads as many bytes as specified in it TODO: pass in packet pointer as arg to reduce allocations
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
func (*Writer) Close ¶
Close sends 9 zero bytes and also closes it's underlying writer if it is also an io.Closer
func (*Writer) WritePacket ¶
WritePacket creates an header for the Packet and writes it and the body to the underlying writer