Documentation
¶
Overview ¶
Protocol package implements a simple framing protocol for sending and receiving data.
Frame format: A CCCC DDD...DDD FFFF Where: A: command byte C: payload length (32 bits, big endian) D: payload (array of bytes) F: checksum (FNV-1a, 32 bits, big endian)
The checksum covers the command byte, payload length, and the data itself.
Index ¶
Examples ¶
Constants ¶
const ( MSG = 0x1 RESIZE = 0x2 )
Frame command bytes. Mirrored in assets/term.js; change both together.
const BufferSize = 262144
BufferSize is the largest payload a frame carries, and the read buffer size used throughout the project.
const MaxPackageSize = BufferSize + Overhead
MaxPackageSize is the largest a whole frame can be.
const Overhead = 9
Overhead is the number of framing bytes around a payload: command (1) + length (4) + checksum (4).
Variables ¶
var ( ErrInvalidSize = errors.New("invalid size") ErrInvalidChecksum = errors.New("invalid checksum") )
Functions ¶
func Decode ¶
Decode reads one frame from src into dest, returning the command byte and the payload length.
Example ¶
out := make([]byte, MaxPackageSize)
n, err := Encode(out, []byte("hello"), 0x01)
if err != nil {
panic(err)
}
data := make([]byte, BufferSize)
cmd, n, err := Decode(data, out[:n])
if err != nil {
panic(err)
}
fmt.Printf("cmd: %02X\n", cmd)
fmt.Printf("data: %v\n", string(data[:n]))
Output: cmd: 01 data: hello
Types ¶
This section is empty.