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_bytes before 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&...]
ParameterDescriptionExample
token / token_envStatic bearer token or environment variable holding tokentoken_env=SPYD_TOKEN
user / password / password_envUsername + password for SCRAM-SHA-256 authenticationuser=alice&password_env=SPYD_PW
tlsForce TLS on (true/1) or loopback plaintext off (false/0)tls=1
caExplicit CA PEM certificate file path for TLS server verificationca=/etc/spyd/ca.crt
server_nameExplicit TLS SNI / hostname overrideserver_name=db.internal
client_cert / client_keyClient PEM certificate & private key for mutual TLS (mTLS)client_cert=/etc/spyd/c.crt
timeout / connect_timeoutSocket request and connect timeoutstimeout=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#

OpcodeRequestPayload
0x01Authenticatestr token
0x02AuthenticatePasswordstr user, str password
0x03AuthenticateKerberosstr ap_req
0x04StartScramstr user, str client_first
0x05ScramProofstr proof, str client_final
0x10Ping(empty)
0x11Cancelu64 id
0x12Queryu64 id, str sql, u32 param_count, Value...
0x13PrepareStatementu64 id, str sql
0x14ExecutePreparedu64 id, u64 statement_id, u32 param_count, Value...
0x15ClosePreparedu64 id, u64 statement_id
0x16UseDatabaseu64 id, str database
0x17BeginTransactionu64 id
0x18CommitTransactionu64 id
0x19RollbackTransactionu64 id
0x1ACatalogu64 id

Response Opcodes#

OpcodeResponsePayload
0x81Authenticatedstr user
0x82ScramChallengestr server_first
0x83ScramAuthenticatedstr user, str server_final
0x84Pong(empty)
0x85Cancelledu64 id, bool found (0 | 1)
0x86Erroru8 has_id, [u64 id], str code, str message
0x87Resultu64 id, u64 affected, u8 has_msg, [str message], u32 col_count, (str name, str data_type)..., u32 row_count, (u32 cell_count, Value...)...
0x88StatementPreparedu64 id, u64 statement_id, bool read_only, u32 col_count, (str name, str data_type)...
0x89StatementClosedu64 id, bool closed
0x8ADatabaseSelectedu64 id, str database
0x8BTransactionStateu64 id, u8 state (1 = Begun, 2 = Committed, 3 = RolledBack)
0x8CCatalogu64 id, str document

4. Canonical SPD2 Value Tags#

TagTypeEncoding
0x00Nullempty
0x01Boolu8 (0 | 1, strictly validated)
0x02..0x05U8, U16, U32, U64unsigned big-endian integer
0x06..0x09I8, I16, I32, I64two's-complement signed big-endian integer
0x0A / 0x0BF32 / F64IEEE-754 big-endian bit pattern
0x0CDecimali128 mantissa (16B big-endian) + u8 scale (<= 38)
0x0D / 0x0EString / Textu32 byte len + UTF-8
0x0FBytesu32 byte len + raw bytes
0x10 / 0x11Timestamp / Datei64 UTC microseconds / i32 Unix days
0x12Uuid16 raw bytes
0x13Jsonlength-prefixed JSON UTF-8
0x14Vectoru32 dims + f32 elements
0x15GeoPointf64 lat + f64 lng
0x16Enumu32 ordinal
0x17Arrayu32 len + Value... (max depth 32)
0x18JsonFallbacklength-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 + ScramProof per RFC 5802 SHA-256, or AuthenticateKerberos).
  • 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_expired for 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.