fix44_forge_helpers/
lib.rs

1//! # fix44-forge-helpers
2//!
3//! High-performance helper functions for FIX 4.4 protocol parsing and serialization.
4//!
5//! This crate provides zero-allocation, minimal-branching functions for reading and writing
6//! FIX protocol data types. It's designed for hot-path performance in financial applications
7//! where every nanosecond counts.
8//!
9//! ## Platform Support
10//!
11//! **Unix/Linux Only** - This crate requires Unix-like systems and will NOT compile on Windows.
12//! Uses `libc::clock_gettime` and other Unix-specific system calls for maximum performance.
13//!
14//! ## Performance Philosophy
15//!
16//! - Zero allocations in hot paths
17//! - Minimal branching for maximum performance
18//! - Early termination on invalid input
19//! - Wrapping arithmetic semantics for overflow handling
20//! - Direct buffer manipulation for optimal cache usage
21//!
22//! # Example
23//!
24//! ```rust
25//! use fix44_forge_helpers::*;
26//!
27//! // Reading from bytes
28//! let value = read_u32(b"12345");
29//! assert_eq!(value, 12345);
30//!
31//! // Writing with pre-initialized forge buffer
32//! let mut buffer = forge_out_buffer("FIX.4.4");
33//! let mut pos = FORGE_WRITE_START; // Header "8=FIX.4.4\x019=0000\x0135=" already there!
34//!
35//! // Write MsgType value (tag "35=" already present)
36//! buffer[pos] = b'D'; pos += 1;
37//! buffer[pos] = 0x01; pos += 1; // SOH
38//!
39//! // Continue with other fields
40//! pos += write_tag_and_u32(&mut buffer, pos, b"34=", 123);
41//!
42//! // Update BodyLength with actual length
43//! update_body_length(&mut buffer, pos);
44//! // Result: "8=FIX.4.4\x019=0012\x0135=D\x0134=123\x01"
45//! ```
46
47// Compile-time platform check
48#[cfg(not(unix))]
49compile_error!(
50    "fix44-forge-helpers requires a Unix-like operating system (Linux, macOS, BSD). Windows is not supported due to the use of Unix-specific system calls like libc::clock_gettime. Consider using WSL2 or a containerized Linux environment for Windows development."
51);
52
53pub mod buffer;
54pub mod errors;
55pub mod reading;
56pub mod special;
57pub mod writing;
58
59// Re-export all public items for convenience
60pub use buffer::*;
61pub use errors::*;
62pub use reading::*;
63pub use special::*;
64pub use writing::*;
65
66// Common constants used across modules
67pub(crate) const DIGIT_PAIRS: &[u8; 200] = &[
68    48, 48, 48, 49, 48, 50, 48, 51, 48, 52, 48, 53, 48, 54, 48, 55, 48, 56, 48, 57, 49, 48, 49, 49,
69    49, 50, 49, 51, 49, 52, 49, 53, 49, 54, 49, 55, 49, 56, 49, 57, 50, 48, 50, 49, 50, 50, 50, 51,
70    50, 52, 50, 53, 50, 54, 50, 55, 50, 56, 50, 57, 51, 48, 51, 49, 51, 50, 51, 51, 51, 52, 51, 53,
71    51, 54, 51, 55, 51, 56, 51, 57, 52, 48, 52, 49, 52, 50, 52, 51, 52, 52, 52, 53, 52, 54, 52, 55,
72    52, 56, 52, 57, 53, 48, 53, 49, 53, 50, 53, 51, 53, 52, 53, 53, 53, 54, 53, 55, 53, 56, 53, 57,
73    54, 48, 54, 49, 54, 50, 54, 51, 54, 52, 54, 53, 54, 54, 54, 55, 54, 56, 54, 57, 55, 48, 55, 49,
74    55, 50, 55, 51, 55, 52, 55, 53, 55, 54, 55, 55, 55, 56, 55, 57, 56, 48, 56, 49, 56, 50, 56, 51,
75    56, 52, 56, 53, 56, 54, 56, 55, 56, 56, 56, 57, 57, 48, 57, 49, 57, 50, 57, 51, 57, 52, 57, 53,
76    57, 54, 57, 55, 57, 56, 57, 57,
77];