Skip to main content

snapcast_proto/
lib.rs

1#![forbid(unsafe_code)]
2#![warn(clippy::redundant_closure)]
3#![warn(clippy::implicit_clone)]
4#![warn(clippy::uninlined_format_args)]
5#![warn(missing_docs)]
6
7//! Snapcast binary protocol implementation.
8//!
9//! This crate implements the Snapcast binary wire protocol, providing
10//! serialization and deserialization for all message types exchanged
11//! between snapclient and snapserver.
12//!
13//! # Protocol Overview
14//!
15//! Every message consists of a [`BaseMessage`] header followed by a typed payload.
16//! All multi-byte integers are little-endian.
17//!
18//! See the [protocol documentation](https://github.com/snapcast/snapcast/blob/master/doc/binary_protocol.md)
19//! for the full specification.
20
21pub mod message;
22pub mod sample_format;
23pub mod status;
24pub mod types;
25
26#[cfg(feature = "custom-protocol")]
27pub use message::CustomMessage;
28pub use message::MessageType;
29pub use message::base::{BaseMessage, ProtoError};
30pub use sample_format::SampleFormat;
31pub use types::Timeval;
32
33/// Default TCP port for binary protocol (streaming clients).
34pub const DEFAULT_STREAM_PORT: u16 = 1704;
35/// Default TCP port for JSON-RPC control.
36pub const DEFAULT_CONTROL_PORT: u16 = 1705;
37/// Default HTTP port for JSON-RPC + Snapweb.
38pub const DEFAULT_HTTP_PORT: u16 = 1780;
39/// Default WebSocket Secure port.
40pub const DEFAULT_WSS_PORT: u16 = 1788;
41/// Snapcast binary protocol version.
42pub const PROTOCOL_VERSION: u32 = 2;
43/// Default sample format: 48000 Hz, 16-bit, stereo.
44pub const DEFAULT_SAMPLE_FORMAT: SampleFormat = SampleFormat::new(48000, 16, 2);
45
46/// Default pre-shared key for f32lz4e (encrypted f32lz4) codec.
47///
48/// Used when the `f32lz4e` codec is selected without an explicit PSK.
49/// Provides transport obfuscation out of the box — not a substitute for
50/// real key management in security-sensitive deployments.
51pub const DEFAULT_ENCRYPTION_PSK: &str = "snapcast-f32lz4e-default-psk-v1";