Skip to main content

clasp_core/
lib.rs

1//! CLASP Core
2//!
3//! Core types, encoding, and protocol primitives for CLASP v3.
4//! Creative Low-Latency Application Streaming Protocol.
5//!
6//! # Wire Format v3
7//!
8//! CLASP v3 uses an efficient binary encoding that is ~54% smaller and ~5x faster
9//! than the v2 MessagePack-with-named-keys format. The decoder auto-detects v2
10//! format for backward compatibility.
11//!
12//! This crate provides:
13//! - Protocol message types ([`Message`], [`SignalType`])
14//! - Binary frame encoding/decoding ([`Frame`], [`codec`])
15//! - Address parsing and wildcard matching ([`Address`])
16//! - State management primitives ([`ParamState`])
17//! - Timing utilities ([`Timestamp`])
18
19#![cfg_attr(not(feature = "std"), no_std)]
20
21#[cfg(feature = "alloc")]
22extern crate alloc;
23
24pub mod address;
25pub mod codec;
26pub mod error;
27pub mod frame;
28#[cfg(feature = "std")]
29pub mod p2p;
30#[cfg(feature = "std")]
31pub mod security;
32pub mod state;
33pub mod time;
34#[cfg(feature = "std")]
35pub mod timeline;
36pub mod types;
37
38pub use address::Address;
39pub use codec::{decode, encode};
40pub use error::{Error, Result};
41pub use frame::Frame;
42#[cfg(feature = "std")]
43pub use p2p::{
44    extract_target_session, is_p2p_address, is_p2p_signal_address, signal_address, P2PAnnounce,
45    P2PConfig, P2PConnectionState, P2PSignal, RoutingMode, TurnServer, P2P_ANNOUNCE, P2P_NAMESPACE,
46    P2P_SIGNAL_PREFIX,
47};
48#[cfg(feature = "std")]
49pub use security::{
50    Action, CpskValidator, Scope, SecurityMode, TokenInfo, TokenValidator, ValidationResult,
51    ValidatorChain,
52};
53pub use state::ParamState;
54pub use time::Timestamp;
55#[cfg(feature = "std")]
56pub use timeline::{PlaybackState, TimelinePlayer};
57pub use types::*;
58
59/// Protocol version (used in HELLO messages)
60pub const PROTOCOL_VERSION: u8 = 1;
61
62/// Magic byte for frame identification
63pub const MAGIC_BYTE: u8 = 0x53; // 'S' for Streaming
64
65/// Default WebSocket port
66pub const DEFAULT_WS_PORT: u16 = 7330;
67
68/// Default UDP discovery port
69pub const DEFAULT_DISCOVERY_PORT: u16 = 7331;
70
71/// WebSocket subprotocol identifier
72pub const WS_SUBPROTOCOL: &str = "clasp";
73
74/// mDNS service type
75pub const MDNS_SERVICE_TYPE: &str = "_clasp._tcp.local.";