Expand description
CLASP Embedded
Minimal no_std implementation of the standard CLASP binary protocol.
This crate provides both client AND server (mini-router) capabilities for embedded devices like ESP32, Raspberry Pi Pico, etc.
§Protocol Compatibility
Uses the same compact binary protocol as the full CLASP implementation. Messages from embedded devices are fully compatible with desktop/cloud routers.
§Memory Budget
| Component | ESP32 (320KB) | RP2040 (264KB) | Notes |
|---|---|---|---|
| Client | ~2KB | ~2KB | State cache, subscriptions |
| Server | ~4KB | ~4KB | + session management |
| Buffers | ~1KB | ~1KB | TX/RX configurable |
§Features
alloc- Enable heap allocation for dynamic strings (recommended for ESP32)server- Enable mini-router/server modeclient- Enable client mode (default)
Modules§
- msg
- Message type codes (standard CLASP binary format)
- val
- Value type codes (standard CLASP binary format)
Structs§
- Cache
Entry - A cached parameter entry
- Client
- Embedded CLASP client (compact binary protocol)
- State
Cache - Fixed-size parameter cache
Enums§
- Client
State - Client state
- Message
- Decoded message (zero-copy where possible)
- Value
- Simple value type for embedded (core types, no allocation needed)
Constants§
- FLAGS_
BINARY - Frame flags for compact binary encoding Bits: [qos:2][has_ts:1][enc:1][cmp:1][rsv:1][version:2]
- HEADER_
SIZE - Frame header size (without timestamp)
- MAGIC
- Protocol magic byte
- MAX_
ADDRESS_ LEN - Maximum address length
- MAX_
CACHE_ ENTRIES - Maximum cached parameters
- MAX_
PAYLOAD - Maximum payload for embedded (configurable, smaller than full 65535)
- RX_
BUF_ SIZE - TX_
BUF_ SIZE - Buffer size for messages
- VERSION
- Protocol version (used in HELLO messages)
Functions§
- decode_
header - Decode frame header, returns (flags, payload_len) or None
- decode_
message - Decode a message from a frame payload
- decode_
string - Decode a string, returns (str slice, bytes consumed)
- decode_
value - Decode a value, returns (value, bytes_consumed) Note: For String/Bytes types, use decode_value_ext with alloc feature
- encode_
header - Encode frame header with binary encoding flags
- encode_
hello - Encode a HELLO message (binary format) Format: msg_type(1) + version(1) + features(1) + name + token
- encode_
hello_ frame - Encode a HELLO frame
- encode_
ping_ frame - Encode a PING frame
- encode_
pong_ frame - Encode a PONG frame
- encode_
set - Encode a SET message payload (without frame header) Format: msg_type(1) + flags(1) + addr_len(2) + addr + value_data Flags: [has_rev:1][lock:1][unlock:1][has_ttl:1][vtype:4]
- encode_
set_ frame - Encode a complete SET frame (header + payload)
- encode_
string - Encode a string (u16 length prefix)
- encode_
subscribe - Encode a SUBSCRIBE message Format: msg_type(1) + id(4) + pattern + type_mask(1) + opt_flags(1)
- encode_
subscribe_ frame - Encode a SUBSCRIBE frame
- encode_
value - Encode a value, returns bytes written