A Rust-based financial protocol code generation and binary codec framework for high-performance trading systems.
This repository provides a comprehensive system for generating Rust code from financial protocol definitions and implementing efficient binary serialization/deserialization for trading messages. 1 The system supports multiple exchange protocols including SZSE (Shenzhen Stock Exchange), SSE (Shanghai Stock Exchange), and sample implementations. 2
graph TB
subgraph "Protocol Definitions"
PDSL["Protocol Definition Files<br/>(.pdsl)"]
SZSE_PROTO["szse_bin_v1.29.pdsl"]
SSE_PROTO["sse_bin_v0.57.pdsl"]
SAMPLE_PROTO["sample.pdsl"]
RISK_PROTO["risk_v0.1.0.pdsl"]
end
subgraph "Code Generation"
FIN_PROTOC["fin-protoc<br/>Code Generator"]
MAKEFILES["Build System<br/>(Makefiles)"]
end
subgraph "Binary Codec Framework"
BINARY_CODEC["binary-codec crate"]
TRAITS["BinaryCodec trait"]
HELPERS["Encoding/Decoding helpers"]
end
subgraph "Generated Implementations"
SZSE_IMPL["szse-binary"]
SSE_IMPL["sse-binary"]
SAMPLE_IMPL["sample-binary"]
RISK_IMPL["risk-binary"]
end
PDSL --> FIN_PROTOC
SZSE_PROTO --> FIN_PROTOC
SSE_PROTO --> FIN_PROTOC
SAMPLE_PROTO --> FIN_PROTOC
RISK_PROTO --> FIN_PROTOC
FIN_PROTOC --> SZSE_IMPL
FIN_PROTOC --> SSE_IMPL
FIN_PROTOC --> SAMPLE_IMPL
FIN_PROTOC --> RISK_IMPL
MAKEFILES --> FIN_PROTOC
BINARY_CODEC --> SZSE_IMPL
BINARY_CODEC --> SSE_IMPL
BINARY_CODEC --> SAMPLE_IMPL
BINARY_CODEC --> RISK_IMPL
TRAITS --> BINARY_CODEC
HELPERS --> BINARY_CODEC
The foundation of the system is the BinaryCodec trait that provides efficient binary serialization: 3
Key features:
- Zero-copy deserialization using
Bytes - Efficient encoding to
BytesMutbuffers - Support for complex data structures and lists 4
The fin-protoc tool transforms protocol definitions into Rust implementations: 5
sequenceDiagram
participant DSL as "Protocol DSL"
participant PROTOC as "fin-protoc"
participant RUST as "Generated Rust"
participant CARGO as "Cargo Tools"
DSL->>PROTOC: "Parse .pdsl/.pdsl files"
PROTOC->>RUST: "Generate structs & impls"
RUST->>CARGO: "cargo fix --allow-dirty"
CARGO->>CARGO: "cargo fmt"
CARGO->>CARGO: "cargo nextest run"
Implements Shenzhen Stock Exchange binary messaging with sophisticated message routing: 6
Key message types:
- Session management (Logon, Logout, Heartbeat)
- Trading messages (NewOrder, ExecutionConfirm, ExecutionReport)
- System messages (BusinessReject, ReportSynchronization)
Shanghai Stock Exchange implementation with similar structure: 7
Provides examples and testing infrastructure: 8
All generated messages follow a consistent pattern:
classDiagram
class BinaryCodec {
<<trait>>
+encode(buf: &mut BytesMut)
+decode(buf: &mut Bytes) Option~Self~
}
class SzseBinary {
+msg_type: u32
+body_length: u32
+body: SzseBinaryBodyEnum
+checksum: i32
}
class MessageBody {
+core_fields: Various
+extensions: ExtensionEnum
}
BinaryCodec <|.. SzseBinary
BinaryCodec <|.. MessageBody
SzseBinary --> MessageBody
Each implementation uses standardized Makefiles with common targets: 9
make compile: Generate code from protocol definitionsmake fmt: Format generated codemake fix: Apply automatic fixesmake test: Run comprehensive tests
- Prerequisites: Install
fin-protocbinary in~/workspace/fin-protoc/bin/ - Build: Run
make allin any implementation directory - Test: Generated code includes comprehensive unit tests 10
The system supports ApplID-based extensions for market-specific functionality: 11
This allows the same message type to have different field structures based on market segment requirements while maintaining protocol consistency.
-
- A comprehensive financial protocol library
- Supports SSE, SZSE, and risk protocols
- Includes Lua dissectors for Wireshark
-
- Native Go implementation of the protocols
- Standardized codec interface
- Modular, exchange-specific architecture
- This repository has been integrated into the
gt-autorepository, an automated testing tool for financial systems(gateway,engine and so on)
-
- Efficient C++ implementation
- Protocol support for SSE, SZSE, risk
- Optimized serialization logic
-
- Binary protocol codec for Java
- Netty ByteBuf integration
- Gradle build system
- Java 17+ compatible
-
- Python implementation for financial protocols
- SSE, SZSE, and risk protocol support
- Easy-to-use parsing and serialization API