Skip to main content

nautilus_serialization/capnp/
mod.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! Cap'n Proto serialization for Nautilus types.
17//!
18//! This module provides Cap'n Proto serialization support for Nautilus domain types.
19//! The generated schema modules are available at the crate root for proper cross-referencing.
20//!
21//! **Warning:** The Cap'n Proto wire format is not yet stable and may change without notice
22//! between releases. Do not depend on wire compatibility across versions.
23//!
24//! # Generated Modules
25//!
26//! The following modules are generated from Cap'n Proto schemas:
27//! - `crate::base_capnp` - Base types (UUID4, UnixNanos, StringMap)
28//! - `crate::identifiers_capnp` - Identifier types
29//! - `crate::types_capnp` - Value types (Price, Quantity, Money, etc.)
30//! - `crate::enums_capnp` - Enumerations
31//! - `crate::trading_capnp` - Trading commands
32//! - `crate::data_capnp` - Data commands and responses
33//! - `crate::order_capnp` - Order events
34//! - `crate::position_capnp` - Position events
35//! - `crate::account_capnp` - Account events
36//! - `crate::market_capnp` - Market data types
37
38pub mod conversions;
39
40// Re-export generated modules for convenience.
41// Re-export conversion functions for use by other crates
42pub use conversions::order_side_to_capnp;
43
44pub use crate::{
45    account_capnp, base_capnp, data_capnp, enums_capnp, identifiers_capnp, market_capnp,
46    order_capnp, position_capnp, trading_capnp, types_capnp,
47};
48
49/// Trait for converting Rust types to Cap'n Proto builders.
50pub trait ToCapnp<'a> {
51    /// The Cap'n Proto builder type for this Rust type.
52    type Builder;
53
54    /// Convert this Rust value to a Cap'n Proto builder.
55    fn to_capnp(&self, builder: Self::Builder);
56}
57
58/// Trait for converting Cap'n Proto readers to Rust types.
59pub trait FromCapnp<'a> {
60    /// The Cap'n Proto reader type for this Rust type.
61    type Reader;
62
63    /// Convert a Cap'n Proto reader to this Rust type.
64    ///
65    /// # Errors
66    ///
67    /// Returns an error if the Cap'n Proto data is invalid or cannot be converted.
68    fn from_capnp(reader: Self::Reader) -> Result<Self, Box<dyn std::error::Error>>
69    where
70        Self: Sized;
71}