Documentation ¶
Overview ¶
Package framing provides a prefix length framed net.Conn connection.
It implements a wrapper around net.Conn that frames each packet with a size prefix of length 1, 2 or 4 bytes of either little or big endianess.
Original author: Adam Lindberg
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrPrefixLength is returned when an invalid prefix length is given. ErrPrefixLength = errors.New("Invalid frame prefix length") // ErrFrameTooLarge is returned from Write(b []byte) when b is larger than // MaxFrameSize. ErrFrameTooLarge = errors.New("Frame too large for buffer size") )
Errors returned by framed connections.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct { // The inner net.Conn net.Conn // The frame size: 1, 2 or 4. PrefixLength byte // The endianess of the length prefix. Endianess binary.ByteOrder // The maximum size of a frame for the current prefix size. MaxFrameSize uint // contains filtered or unexported fields }
Conn wraps a net.Conn making it aware about frames and their size.
func NewConn ¶
NewConn returns a framing.Conn that acts like a net.Conn. prefixLength should be one of 1, 2 or 4. endianess should be one of binary.BigEndian or binary.LittleEndian.
The difference to a normal net.Conn is that Write(b []byte) prefixes each packet with a size and Read(b []byte) reads that size and waits for that many bytes.
A complementary ReadFrame() function can be used to read and wait for a full frame.