YAACC - UPNP Client and Server
Loading...
Searching...
No Matches
de.yaacc.snapcast.protocol.SnapcastMessageCodec Class Reference

Encodes and decodes the binary messages of the Snapcast stream protocol (little endian, the layouts of docs/tech.md, "Binary protocol"). More...

Collaboration diagram for de.yaacc.snapcast.protocol.SnapcastMessageCodec:
Collaboration graph

Static Public Member Functions

static byte[] encode (SnapcastBinaryMessage message, int id, int refersTo, int sentSec, int sentUsec, int receivedSec, int receivedUsec)
 One complete frame: the 26 byte header and the typed message.
 
static byte[] encode (SnapcastBinaryMessage message, int id, int refersTo, long sentMicros)
 As above with the send time as microseconds (clamped into the range of 32 bit seconds) and no receive time.
 
static Frame decode (byte[] frame) throws StreamFormatException
 Decodes one complete frame held in a byte array.
 

Detailed Description

Encodes and decodes the binary messages of the Snapcast stream protocol (little endian, the layouts of docs/tech.md, "Binary protocol").

Everything here is a pure function of bytes; the network is FrameReader.

Rules for what comes from the server (design, "Security rules for Phase B"): the size in the header is checked against its cap before a body is read (MessageHeader#parse), every length inside a message is checked against what is left of the message before anything is reserved for it, JSON goes through the depth and token pre-scan of the control client, and the only failure that leaves this class is a StreamFormatException. Types this client does not handle (and the base type 0) are skipped by size, with no message.

Member Function Documentation

◆ decode()

static Frame de.yaacc.snapcast.protocol.SnapcastMessageCodec.decode ( byte[] frame) throws StreamFormatException
static

Decodes one complete frame held in a byte array.

Exceptions
StreamFormatExceptionTRUNCATED when the array ends early, MALFORMED when there are bytes after the frame, and the errors of the header and the body

◆ encode()

static byte[] de.yaacc.snapcast.protocol.SnapcastMessageCodec.encode ( SnapcastBinaryMessage message,
int id,
int refersTo,
int sentSec,
int sentUsec,
int receivedSec,
int receivedUsec )
static

One complete frame: the 26 byte header and the typed message.

Parameters
idthe id of this message (0 to 65535)
refersTothe id of the message this answers (0 when it answers none)
sentSecthe time of sending, filled in by the sender
receivedSecthe time of receiving, filled in by the receiver (0 when we send)

Referenced by de.yaacc.snapcast.protocol.SnapcastMessageCodec.encode(), and de.yaacc.snapcast.protocol.SnapcastConnection.sendClientInfo().

Here is the caller graph for this function:

The documentation for this class was generated from the following file: