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//! # Generated Modules
22//!
23//! The following modules are generated from Cap'n Proto schemas:
24//! - `crate::base_capnp` - Base types (UUID4, UnixNanos, StringMap)
25//! - `crate::identifiers_capnp` - Identifier types
26//! - `crate::types_capnp` - Value types (Price, Quantity, Money, etc.)
27//! - `crate::enums_capnp` - Enumerations
28//! - `crate::trading_capnp` - Trading commands
29//! - `crate::data_capnp` - Data commands and responses
30//! - `crate::order_capnp` - Order events
31//! - `crate::position_capnp` - Position events
32//! - `crate::account_capnp` - Account events
33//! - `crate::market_capnp` - Market data types
34
35pub mod conversions;
36
37// Re-export generated modules for convenience.
38// Re-export conversion functions for use by other crates
39pub use conversions::order_side_to_capnp;
40
41pub use crate::{
42    account_capnp, base_capnp, data_capnp, enums_capnp, identifiers_capnp, market_capnp,
43    order_capnp, position_capnp, trading_capnp, types_capnp,
44};
45
46/// Trait for converting Rust types to Cap'n Proto builders.
47pub trait ToCapnp<'a> {
48    /// The Cap'n Proto builder type for this Rust type.
49    type Builder;
50
51    /// Convert this Rust value to a Cap'n Proto builder.
52    fn to_capnp(&self, builder: Self::Builder);
53}
54
55/// Trait for converting Cap'n Proto readers to Rust types.
56pub trait FromCapnp<'a> {
57    /// The Cap'n Proto reader type for this Rust type.
58    type Reader;
59
60    /// Convert a Cap'n Proto reader to this Rust type.
61    ///
62    /// # Errors
63    ///
64    /// Returns an error if the Cap'n Proto data is invalid or cannot be converted.
65    fn from_capnp(reader: Self::Reader) -> Result<Self, Box<dyn std::error::Error>>
66    where
67        Self: Sized;
68}