Client API Reference

Complete reference for NerveClient, NerveConfig, SchemaId, and SdkMetrics.

NerveClient Methods

MethodSignatureDescription
connectasync fn connect(config: NerveConfig) -> NerveResult<Self>TLS 1.3 handshake probe + spawn background worker
send_rawfn send_raw(schema: SchemaId, payload: &[u8]) -> NerveResult<()>Non-blocking send (~50 ns). Spills to disk if queue full.
send_priorityfn send_priority(schema, payload, priority) -> NerveResult<()>Explicit priority: Critical bypasses batching.
sendfn send<T: FlatBufferSerializable>(data: &T) -> NerveResult<()>Typed convenience: auto-extracts schema ID and serializes.
set_command_handlerfn set_command_handler(handler: impl CommandHandler)Register bidirectional command handler.
queue_depthfn queue_depth() -> usizeIn-memory channel depth (excludes spill).
spill_depthfn spill_depth() -> u64Messages persisted on disk.
metricsfn metrics() -> &Arc<SdkMetrics>Access atomic counters.
is_connectedfn is_connected() -> boolFalse after shutdown or worker exit.
shutdownasync fn shutdown(self, timeout: Duration) -> NerveResult<usize>Drain remaining. Returns unflushed count (0 = fully flushed).

NerveConfig

See Transport Layer for the full config table, TLS options, and workload tuning guide.

SchemaId

Content-addressed 32-bit identifier: first 4 bytes of SHA-256 of the schema content.

ConstructorDescription
SchemaId::new(u32)From a known numeric ID
SchemaId::from_bytes(&[u8])Hash arbitrary bytes and truncate to 4 bytes
SchemaId::from_file(&Path)Read file, hash contents

Display format: zero-padded lowercase hex (e.g. "00000002"). Birthday collision: ~65,536 schemas before meaningful probability.

SdkMetrics

Seven atomic u64 counters, accessible from any thread. Use metrics().snapshot() to export all as (name, value) pairs for Prometheus or StatsD.

CounterIncremented when
messages_sentsend_raw succeeds (queued or spilled)
messages_droppedChannel disconnected (worker dead)
messages_spilledChannel full → spilled to disk
bytes_sentCompressed bytes written to QUIC
batch_flushesEach batch written to a QUIC stream
reconnect_countWorker reconnect attempt
circuit_opensCircuit breaker enters Open state

Error Types

ErrorWhenRecovery
QueueFullChannel and spill both at capacityRare — increase queue_capacity or max_disk_bytes
DisconnectedBackground worker terminatedCreate a new NerveClient
HandshakeTimeoutTLS handshake exceeded deadlineCheck network, increase connect_timeout_ms
TlsValidationCertificate verification failedCheck ca_cert_path or use insecure() for dev
ConnectionRefusedServer unreachableCheck endpoint, firewall, server status
StreamClosedQUIC stream resetAuto-reconnects (no user action needed)

Authentication

Two authentication modes:

  • Static API Key: Configured in AuthConfig.api_key. Sent as an auth frame after each QUIC handshake.
  • Token Provider: Implement TokenProvider trait for rotating JWT, HMAC, or HSM-backed auth. Register via QuicConnector::with_auth().

Auth frame wire format:

Text
[magic: u16 LE = 0xA077][token_len: u16][token: bytes][device_id_len: u16][device_id: bytes]

Questions?

Reach out for help with integration, deployment, or custom domain codecs.