SpydWire Protocol (SPD2)
12-byte binary frame specification, CRC32C checksums, opcodes, 25 typed value tags, and SCRAM-SHA-256 auth.
5 min read Protocols & HTTP API
SpydWire is SpydDB's native framed TCP/TLS protocol (port: 5433 default). Every official native driver connects via spydwire:// or spyddb:// URIs using SpydWire v2 (SPD2) canonical big-endian binary framing with full CRC32C (Castagnoli) frame integrity and transparent SPD1 JSON frame compatibility.
1. Frame Envelope (12-Byte Header)#
Every message on the wire is prefixed by a 12-byte big-endian header:
text
Offset Size Field
0 4 magic: "SPD2" (binary codec) or "SPD1" (UTF-8 JSON)
4 4 body_len: unsigned u32 big-endian payload length (default max 8 MiB)
8 4 crc32c: Castagnoli CRC-32C checksum over payload bytes [12 .. 12 + body_len]
12 n payload bytes- Receivers verify
body_len <= max_frame_bytesbefore allocating buffers and validate CRC32C before decoding. - The server responds in the same frame version (
SPD2->SPD2,SPD1->SPD1), enabling zero-downtime interoperability across client versions. - Incomplete frames or I/O errors fail closed and close the connection without mid-stream resynchronization.
2. Connection URI Specification#
text
spydwire://[user:password@]host[:port][/database][?param=value&...]
spyddb://[user:token@]host[:port][/database][?param=value&...]| Parameter | Description | Example |
|---|---|---|
token / token_env | Static bearer token or environment variable holding token | token_env=SPYD_TOKEN |
user / password / password_env | Username + password for SCRAM-SHA-256 authentication | user=alice&password_env=SPYD_PW |
tls | Force TLS on (true/1) or loopback plaintext off (false/0) | tls=1 |
ca | Explicit CA PEM certificate file path for TLS server verification | ca=/etc/spyd/ca.crt |
server_name | Explicit TLS SNI / hostname override | server_name=db.internal |
client_cert / client_key | Client PEM certificate & private key for mutual TLS (mTLS) | client_cert=/etc/spyd/c.crt |
timeout / connect_timeout | Socket request and connect timeouts | timeout=30000 |
3. SPD2 Opcodes & Payload Format#
All integers and IEEE-754 floats are big-endian. Strings and byte arrays encode as u32 length + raw bytes.
Request Opcodes#
| Opcode | Request | Payload |
|---|---|---|
0x01 | Authenticate | str token |
0x02 | AuthenticatePassword | str user, str password |
0x03 | AuthenticateKerberos | str ap_req |
0x04 | StartScram | str user, str client_first |
0x05 | ScramProof | str proof, str client_final |
0x10 | Ping | (empty) |
0x11 | Cancel | u64 id |
0x12 | Query | u64 id, str sql, u32 param_count, Value... |
0x13 | PrepareStatement | u64 id, str sql |
0x14 | ExecutePrepared | u64 id, u64 statement_id, u32 param_count, Value... |
0x15 | ClosePrepared | u64 id, u64 statement_id |
0x16 | UseDatabase | u64 id, str database |
0x17 | BeginTransaction | u64 id |
0x18 | CommitTransaction | u64 id |
0x19 | RollbackTransaction | u64 id |
0x1A | Catalog | u64 id |
Response Opcodes#
| Opcode | Response | Payload |
|---|---|---|
0x81 | Authenticated | str user |
0x82 | ScramChallenge | str server_first |
0x83 | ScramAuthenticated | str user, str server_final |
0x84 | Pong | (empty) |
0x85 | Cancelled | u64 id, bool found (0 | 1) |
0x86 | Error | u8 has_id, [u64 id], str code, str message |
0x87 | Result | u64 id, u64 affected, u8 has_msg, [str message], u32 col_count, (str name, str data_type)..., u32 row_count, (u32 cell_count, Value...)... |
0x88 | StatementPrepared | u64 id, u64 statement_id, bool read_only, u32 col_count, (str name, str data_type)... |
0x89 | StatementClosed | u64 id, bool closed |
0x8A | DatabaseSelected | u64 id, str database |
0x8B | TransactionState | u64 id, u8 state (1 = Begun, 2 = Committed, 3 = RolledBack) |
0x8C | Catalog | u64 id, str document |
4. Canonical SPD2 Value Tags#
| Tag | Type | Encoding |
|---|---|---|
0x00 | Null | empty |
0x01 | Bool | u8 (0 | 1, strictly validated) |
0x02..0x05 | U8, U16, U32, U64 | unsigned big-endian integer |
0x06..0x09 | I8, I16, I32, I64 | two's-complement signed big-endian integer |
0x0A / 0x0B | F32 / F64 | IEEE-754 big-endian bit pattern |
0x0C | Decimal | i128 mantissa (16B big-endian) + u8 scale (<= 38) |
0x0D / 0x0E | String / Text | u32 byte len + UTF-8 |
0x0F | Bytes | u32 byte len + raw bytes |
0x10 / 0x11 | Timestamp / Date | i64 UTC microseconds / i32 Unix days |
0x12 | Uuid | 16 raw bytes |
0x13 | Json | length-prefixed JSON UTF-8 |
0x14 | Vector | u32 dims + f32 elements |
0x15 | GeoPoint | f64 lat + f64 lng |
0x16 | Enum | u32 ordinal |
0x17 | Array | u32 len + Value... (max depth 32) |
0x18 | JsonFallback | length-prefixed JSON fallback |
5. Security, Cancellation & Fail-Closed Guarantees#
- Authentication first: No query, prepare, database selection, or catalog call is accepted before authentication completes (
Authenticate,AuthenticatePassword,StartScram+ScramProofper RFC 5802 SHA-256, orAuthenticateKerberos). - Prepared Plan Security Binding: Every prepared handle embeds the session's compiled RBAC, row filters, field masks, ABAC attributes, and catalog generation; DDL changes automatically trigger
statement_expiredfor clean client re-preparation. - Cross-Connection Query Cancellation: Because a synchronous socket waits on its active statement, send
Cancel(id)over a second connection authenticated as the exact same user and tenant. - Automatic Tx Cleanup: Disconnecting an open interactive transaction rolls back pending writes automatically.