Documentation ¶
Overview ¶
Package packet provides convenience methods to read/write packets to a net.Conn. A selection of different functions are available to specify timeouts and to provide either raw bytes or custom values that are en-/decoded with custom codec.Codecs.
Packets ¶
A packet is a very simple network data format used to transmit data over a network. It consists of two parts, a header and the payload.
The header must be present and has a fixed size of 4 bytes. It only contains the size of the payload.
The payload is of variable size (as indicated by the header) and is a stream of bytes. The maximum possible size is restricted by the available bytes for the header, and is therefore currently 2^32 - 1.
In case an empty payload should be transmitted, the packet consists of solely a header with value 0.
Index ¶
Constants ¶
const (
MaxSize = math.MaxUint32
)
Variables ¶
var ErrZeroData = errors.New("zero data")
Functions ¶
func Read ¶
Read reads a packet from the connection and returns the raw bytes of it.
A timeout must be specified, where a timeout <= 0 means no timeout.
If buffer is set and is big enough to fit the packet, then the buffer is used. Otherwise a new buffer is allocated. Returns an empty byte slice when no data was send. Returns ErrZeroData, if a packet with length 0 is received.
func ReadDecode ¶
ReadDecode reads the packet from the connection using Read() and decodes it into the value, using the provided codec. Ensure to pass a pointer value.
Types ¶
This section is empty.