Skip to main content

Crate clasp_embedded

Crate clasp_embedded 

Source
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

ComponentESP32 (320KB)RP2040 (264KB)Notes
Client~2KB~2KBState cache, subscriptions
Server~4KB~4KB+ session management
Buffers~1KB~1KBTX/RX configurable

§Features

  • alloc - Enable heap allocation for dynamic strings (recommended for ESP32)
  • server - Enable mini-router/server mode
  • client - Enable client mode (default)

Modules§

msg
Message type codes (standard CLASP binary format)
val
Value type codes (standard CLASP binary format)

Structs§

CacheEntry
A cached parameter entry
Client
Embedded CLASP client (compact binary protocol)
StateCache
Fixed-size parameter cache

Enums§

ClientState
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