nodedb_types/sync/wire/columnar.rs
1// SPDX-License-Identifier: Apache-2.0
2
3//! Columnar insert sync messages (client → server / server → client).
4//!
5//! `ColumnarInsertMsg` carries a batch of typed row values from a Lite
6//! client to Origin. Each row is a MessagePack-serialized `Vec<Value>` in
7//! schema column order, matching the collection's `ColumnarSchema`.
8//!
9//! Wire layout mirrors `TimeseriesPushMsg`: typed payload + schema hint +
10//! a monotonic `batch_id` for dedup / ACK correlation.
11
12use serde::{Deserialize, Serialize};
13
14/// Columnar batch insert (client → server, 0xA0).
15///
16/// Carries one or more rows for a columnar collection. Each entry in
17/// `rows` is a MessagePack-serialized `Vec<nodedb_types::value::Value>`
18/// with entries in schema column order.
19///
20/// `schema_bytes` is a MessagePack-serialized `ColumnarSchema`. Origin uses
21/// it to create the collection if it does not yet exist (definition-sync
22/// guarantees it will already exist in most cases, but the schema hint
23/// lets Origin validate column count and types rather than guessing).
24#[derive(
25 Debug, Clone, Serialize, Deserialize, zerompk::ToMessagePack, zerompk::FromMessagePack,
26)]
27pub struct ColumnarInsertMsg {
28 /// Lite instance ID (for routing and dedup).
29 pub lite_id: String,
30 /// Target collection name.
31 pub collection: String,
32 /// Batch of rows. Each element is MessagePack `Vec<Value>` (schema column order).
33 pub rows: Vec<Vec<u8>>,
34 /// Monotonic batch ID (Lite-assigned, per-collection). Used for ACK correlation.
35 pub batch_id: u64,
36 /// MessagePack-serialized `ColumnarSchema`. May be empty for collections
37 /// that were already synced via definition-sync.
38 #[serde(default)]
39 pub schema_bytes: Vec<u8>,
40}
41
42/// Columnar insert acknowledgment (server → client, 0xA1).
43#[derive(
44 Debug, Clone, Serialize, Deserialize, zerompk::ToMessagePack, zerompk::FromMessagePack,
45)]
46pub struct ColumnarInsertAckMsg {
47 /// Collection acknowledged.
48 pub collection: String,
49 /// Batch ID from the originating `ColumnarInsertMsg`.
50 pub batch_id: u64,
51 /// Number of rows successfully inserted.
52 pub accepted: u64,
53 /// Number of rows rejected (schema mismatch, constraint violation, etc.).
54 pub rejected: u64,
55 /// Optional rejection detail for the first rejected row.
56 #[serde(default)]
57 pub reject_reason: Option<String>,
58}