Skip to main content

nautilus_serialization/
lib.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//! Data serialization and format conversion for [NautilusTrader](http://nautilustrader.io).
17//!
18//! The `nautilus-serialization` crate provides comprehensive data serialization capabilities for converting
19//! trading data between different formats including Apache Arrow and Cap'n Proto.
20//! This enables efficient data storage, retrieval, and interoperability across different systems:
21//!
22//! - **Apache Arrow integration**: Schema definitions and encoding/decoding for market data types.
23//! - **Parquet file operations**: High-performance columnar storage for historical data analysis.
24//! - **Record batch processing**: Efficient batch operations for time-series data.
25//! - **Schema management**: Type-safe schema definitions with metadata preservation.
26//! - **Cross-format conversion**: Seamless data interchange between Arrow, Cap'n Proto, and native types.
27//! - **Cap'n Proto serialization**: Zero-copy, schema-based serialization for efficient data interchange (requires `capnp` feature).
28//! - **SBE decode utilities**: Zero-copy cursor and shared decode errors for SBE parsers (requires `sbe` feature).
29//!
30//! # Platform
31//!
32//! [NautilusTrader](http://nautilustrader.io) is an open-source, high-performance, production-grade
33//! algorithmic trading platform, providing quantitative traders with the ability to backtest
34//! portfolios of automated trading strategies on historical data with an event-driven engine,
35//! and also deploy those same strategies live, with no code changes.
36//!
37//! NautilusTrader's design, architecture, and implementation philosophy prioritizes software correctness and safety at the
38//! highest level, with the aim of supporting mission-critical, trading system backtesting and live deployment workloads.
39//!
40//! # Feature Flags
41//!
42//! This crate provides feature flags to control source code inclusion during compilation,
43//! depending on the intended use case, i.e. whether to provide Python bindings
44//! for the [nautilus_trader](https://pypi.org/project/nautilus_trader) Python package,
45//! or as part of a Rust only build.
46//!
47//! - `arrow`: Enables Apache Arrow schema definitions and RecordBatch encoding/decoding.
48//! - `python`: Enables Python bindings from [PyO3](https://pyo3.rs).
49//! - `high-precision`: Enables [high-precision mode](https://nautilustrader.io/docs/nightly/getting_started/installation#precision-mode) to use 128-bit value types.
50//! - `extension-module`: Builds the crate as a Python extension module.
51//! - `capnp`: Enables [Cap'n Proto](https://capnproto.org/) serialization support.
52//! - `sbe`: Enables generic SBE (Simple Binary Encoding) decode utilities.
53
54#![warn(rustc::all)]
55#![deny(unsafe_code)]
56#![deny(unsafe_op_in_unsafe_fn)]
57#![deny(nonstandard_style)]
58#![deny(missing_debug_implementations)]
59#![deny(clippy::missing_errors_doc)]
60#![deny(clippy::missing_panics_doc)]
61#![deny(rustdoc::broken_intra_doc_links)]
62
63#[cfg(feature = "arrow")]
64pub mod arrow;
65
66#[cfg(feature = "capnp")]
67pub mod capnp;
68
69#[cfg(feature = "sbe")]
70pub mod sbe;
71
72/// Re-export MsgPack serialization helpers for consumers expecting to configure codecs via this crate.
73pub use nautilus_core::serialization::msgpack;
74
75#[cfg(feature = "capnp")]
76macro_rules! include_capnp_module {
77    ($name:ident, $path:expr) => {
78        #[cfg(all(feature = "capnp", not(docsrs)))]
79        #[allow(
80            clippy::all,
81            clippy::missing_errors_doc,
82            clippy::missing_panics_doc,
83            warnings,
84            dead_code,
85            missing_debug_implementations
86        )]
87        pub mod $name {
88            include!(concat!(env!("OUT_DIR"), $path));
89        }
90
91        #[cfg(all(feature = "capnp", docsrs))]
92        #[allow(
93            clippy::all,
94            clippy::missing_errors_doc,
95            clippy::missing_panics_doc,
96            warnings,
97            dead_code,
98            missing_debug_implementations
99        )]
100        pub mod $name {
101            include!(concat!(
102                env!("CARGO_MANIFEST_DIR"),
103                "/generated/capnp",
104                $path
105            ));
106        }
107    };
108}
109
110#[cfg(feature = "capnp")]
111include_capnp_module!(base_capnp, "/common/base_capnp.rs");
112#[cfg(feature = "capnp")]
113include_capnp_module!(identifiers_capnp, "/common/identifiers_capnp.rs");
114#[cfg(feature = "capnp")]
115include_capnp_module!(types_capnp, "/common/types_capnp.rs");
116#[cfg(feature = "capnp")]
117include_capnp_module!(enums_capnp, "/common/enums_capnp.rs");
118#[cfg(feature = "capnp")]
119include_capnp_module!(trading_capnp, "/commands/trading_capnp.rs");
120#[cfg(feature = "capnp")]
121include_capnp_module!(data_capnp, "/commands/data_capnp.rs");
122#[cfg(feature = "capnp")]
123include_capnp_module!(order_capnp, "/events/order_capnp.rs");
124#[cfg(feature = "capnp")]
125include_capnp_module!(position_capnp, "/events/position_capnp.rs");
126#[cfg(feature = "capnp")]
127include_capnp_module!(account_capnp, "/events/account_capnp.rs");
128#[cfg(feature = "capnp")]
129include_capnp_module!(market_capnp, "/data/market_capnp.rs");
130
131#[cfg(feature = "python")]
132pub mod python;