Skip to main content

Module protocol

Module protocol 

Source
Expand description

RedDB Wire Protocol — binary TCP, zero JSON overhead.

Frame: [total_len: u32 LE][msg_type: u8][payload…]

Message types (client → server): 0x01 Query [sql_bytes…] 0x04 BulkInsert [coll_len:u16][coll_bytes][n:u32][json_len:u32 + json_bytes]…

Message types (server → client): 0x02 Result [ncols:u16][col_name_len:u16 + col_name]…[nrows:u32][row…] row = [val_type:u8 + val_data]… per column 0x03 Error [error_bytes…] 0x05 BulkOk [count:u64]

Constants§

MSG_BULK_INSERT
MSG_BULK_INSERT_BINARY
MSG_BULK_INSERT_PREVALIDATED
Fast-path bulk insert: payload is [coll_len u16][coll][ncols u16] ([col_name u16 len + bytes])*ncols [nrows u32] ([val_tag u8 + val_data]*ncols)*nrows, IDENTICAL to MSG_BULK_INSERT_BINARY. The only difference from 0x06 is semantic: the caller guarantees every value already matches the declared column type and that contract / uniqueness rules either don’t apply or were already checked client-side. The server skips normalize_row_fields_for_contract, enforce_row_uniqueness and enforce_row_batch_uniqueness on the whole batch, cutting 15-column typed inserts from O(nrows × ncols) contract work down to O(nrows) serialise-and-insert. Intended for typed-bench workloads and driver-generated inserts where types were already validated before the send. Old servers that don’t know 0x08 reply with MSG_ERROR "unknown message type" so clients can fall back to the safe path.
MSG_BULK_OK
MSG_BULK_STREAM_ACK
Intermediate ack sent back for START + ROWS frames so the client can pipeline safely (it always receives a frame per frame sent) without conflating progress with the terminal MSG_BULK_OK at COMMIT time.
MSG_BULK_STREAM_COMMIT
MSG_BULK_STREAM_ROWS
MSG_BULK_STREAM_START
MSG_CLOSE_CURSOR
MSG_CURSOR_BATCH
MSG_CURSOR_OK
MSG_DEALLOCATE
MSG_DECLARE_CURSOR
MSG_ERROR
MSG_EXECUTE_PREPARED
MSG_FETCH
MSG_PREPARE
MSG_PREPARED_OK
MSG_QUERY
MSG_QUERY_BINARY
MSG_RESULT
VAL_BOOL
VAL_F64
VAL_I64
VAL_NULL
VAL_TEXT
VAL_U64

Functions§

decode_value
Decode a Value from wire bytes at the given position.
encode_column_name
Encode a column name to wire format.
encode_value
Encode a Value to wire format bytes, appending to buf.
try_decode_value
write_frame_header
Write a frame header: [total_len: u32 LE][msg_type: u8]