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](https://nautilustrader.io).
17//!
18//! The `nautilus-serialization` crate provides data serialization capabilities for converting
19//! trading data between different formats including Apache Arrow, JSON, MessagePack, and SBE.
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**: Data interchange between Arrow and native types.
27//! - **SBE decode utilities**: Zero-copy cursor and shared decode errors for SBE parsers (requires `sbe` feature).
28//!
29//! # NautilusTrader
30//!
31//! [NautilusTrader](https://nautilustrader.io) is an open-source, production-grade, Rust-native
32//! engine for multi-asset, multi-venue trading systems.
33//!
34//! The system spans research, deterministic simulation, and live execution within a single
35//! event-driven architecture, providing research-to-live semantic parity.
36//!
37//! # Feature Flags
38//!
39//! This crate provides feature flags to control source code inclusion during compilation,
40//! depending on the intended use case, i.e. whether to provide Python bindings
41//! for the [nautilus_trader](https://pypi.org/project/nautilus_trader) Python package,
42//! or as part of a Rust only build.
43//!
44//! - `arrow`: Enables Apache Arrow schema definitions and RecordBatch encoding/decoding.
45//! - `arrow-display`: Enables display-friendly Arrow encoders for market data and requires `arrow`.
46//! - `extension-module`: Builds as a Python extension module.
47//! - `high-precision`: Enables
48//!   [high-precision mode](https://nautilustrader.io/docs/nightly/getting_started/installation/#precision-mode)
49//!   to use 128-bit value types.
50//! - `python`: Enables Python bindings from [PyO3](https://pyo3.rs).
51//! - `sbe`: Enables generic SBE (Simple Binary Encoding) decode utilities.
52//!
53//! **Warning:** SBE schemas are not yet stable and may break between releases.
54
55#![warn(rustc::all)]
56#![warn(clippy::pedantic)]
57#![allow(
58    clippy::manual_let_else,
59    clippy::option_if_let_else,
60    clippy::or_fun_call,
61    clippy::redundant_else,
62    clippy::similar_names,
63    clippy::single_match_else,
64    reason = "workspace policy; generated by scripts/update-clippy-allowances.py"
65)]
66#![warn(clippy::clone_on_ref_ptr)]
67#![deny(unsafe_code)]
68#![deny(unsafe_op_in_unsafe_fn)]
69#![deny(nonstandard_style)]
70#![deny(missing_debug_implementations)]
71#![deny(clippy::missing_errors_doc)]
72#![deny(clippy::missing_panics_doc)]
73#![deny(rustdoc::broken_intra_doc_links)]
74#![allow(
75    clippy::doc_markdown,
76    reason = "serialization docs are heavy on Arrow and domain-specific type names where blanket backticks add noise"
77)]
78#![allow(
79    clippy::too_many_lines,
80    reason = "wide encode and decode functions mirror protocol schemas and Arrow record layouts"
81)]
82#![allow(
83    clippy::implicit_hasher,
84    reason = "serialization metadata uses a standardized HashMap<String, String> shape across traits and codecs"
85)]
86#![allow(
87    clippy::cast_possible_truncation,
88    clippy::cast_possible_wrap,
89    clippy::cast_precision_loss,
90    clippy::cast_sign_loss,
91    clippy::cast_lossless,
92    reason = "wire-format and fixed-point conversions in serialization code require explicit numeric casts"
93)]
94#![allow(
95    clippy::assert_is_empty,
96    reason = "`assert!(x.is_empty())` is clearer than comparing against an empty value"
97)]
98#![cfg_attr(
99    test,
100    allow(
101        clippy::float_cmp,
102        reason = "serialization tests assert exact float encodings and decoded values"
103    )
104)]
105
106#[cfg(feature = "arrow")]
107pub mod arrow;
108
109/// Re-export custom data registration for use by persistence and tests.
110#[cfg(feature = "arrow")]
111pub use arrow::custom::ensure_custom_data_registered;
112/// Re-exports MsgPack codecs for consumers configuring serialization through this crate.
113pub use nautilus_core::serialization::msgpack;
114
115#[cfg(feature = "sbe")]
116pub mod sbe;
117
118#[cfg(feature = "sbe")]
119mod numeric;
120
121#[cfg(feature = "python")]
122pub mod python;
123
124/// Generates typed Arrow encoding for custom data.
125#[cfg(feature = "arrow")]
126pub use nautilus_macros::arrow_custom_data;