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 ¶
This section is empty.
Types ¶
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
func (Reader) ReadHeader ¶
ReadHeader only reads the header packet data (flag, len, req id). Use the exposed io.Reader to read the body.
func (Reader) ReadPacket ¶
ReadPacket decodes the header from the underlying reader, 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
Click to show internal directories.
Click to hide internal directories.