ð Introduction
<span>fin-proto-cpp</span> is an open-source C++ protocol parsing library specifically designed for the financial sector, implementing a low-latency streaming binary protocol codec for the Shanghai Stock Exchange (SSE) and Shenzhen Stock Exchange (SZSE). The project features the following characteristics:
- ⥠High-performance encoding and decoding: Processes exchange binary data streams in milliseconds, utilizing a zero-copy design
- ð Protocol support: Supports the latest Binary protocol versions for both Shanghai and Shenzhen markets
- ðŠķ Lightweight design: Core codec with zero external dependencies
- ð Testability: Built-in CI/CD and unit testing
GitHub address: https://github.com/xinchentechnote/fin-proto-cpp
âïļ Build Process
1. Environment Dependencies
This project depends on the fin-protoc protocol compiler (implemented in Go and ANTLR4). In a Linux environment, you can directly download the precompiled binary and configure it to your <span>PATH</span>:
wget https://github.com/xinchentechnote/fin-protoc/releases/download/v0.1.6/fin-protoc-v0.1.6-linux-amd64.tar.gz
tar -xvf fin-protoc-v0.1.6-linux-amd64.tar.gz
export PATH=$PWD:$PATH
2. One-click Compilation
git clone https://github.com/xinchentechnote/fin-proto-cpp
cd fin-proto-cpp
./build.sh # Automatically triggers CMake build
ð Directory Structure
âââ build.sh
âââ include
â âââ bytebuf.hpp # ByteBuf wrapper, similar to Netty ByteBuf
â âââ checksum.hpp # Checksum interface definition
â âââ codec.hpp # Binary protocol codec interface definition
â âââ sse_binary.hpp # SSE Binary codec
â âââ szse_binary.hpp # SZSE Binary codec
âââ test
âââ bytebuf_test.cpp
âââ checksum_test.cpp
âââ codec_test.cpp
âââ sse_binary_test.cpp
âââ szse_binary_test.cpp
ð Core Interface Design
BinaryCodec Interface
struct BinaryCodec {
virtual ~BinaryCodec() = default;
virtual void encode(ByteBuf & buf) const = 0;
virtual void decode(ByteBuf & buf) = 0;
virtual std::string toString() const = 0;
virtual bool equals(const BinaryCodec & other) const = 0;
bool operator==(const BinaryCodec & other) const { return equals(other); }
bool operator!=(const BinaryCodec & other) const { return !(*this == other); }
};
Checksum Interface
class IChecksumService {
public:
virtual ~IChecksumService() = default;
virtual std::string algorithm() const = 0;
};
template <typename Input, typename Output>
class ChecksumService : public IChecksumService {
public:
using input_type = Input;
using output_type = Output;
virtual Output calc(const Input & data) const = 0;
};
ð UML Design Diagrams
1. Protocol Parsing Architecture

2. Encoding Process

ð SSE and SZSE Protocol Definitions
SSE Binary Protocol
root packet SseBinary {
uint32 MsgType `Message Type`,
uint64 MsgSeqNum `Message Sequence Number`,
uint32 MsgBodyLen @lengthOf(Body) `Message Body Length`,
match MsgType as Body {
33 : Heartbeat,
40 : Logon,
41 : Logout,
58 : NewOrderSingle
},
uint32 Checksum @calculatedFrom("SSE_BIN") `Checksum`,
}
Details of SSE protocol definition https://github.com/xinchentechnote/fin-proto/blob/main/sse/binary/sse_bin_v0.57.pdsl
SZSE Binary Protocol
root packet SzseBinary {
MsgType,
BodyLength @lengthOf(Body),
match MsgType as Body {
1 : Logon,
2 : Logout,
3 : Heartbeat,
10 : TradingSessionStatus,
[100101] : NewOrder
},
int32 Checksum @calculatedFrom("SZSE_BIN"),
}
Details of SZSE protocol definition https://github.com/xinchentechnote/fin-proto/blob/main/szse/binary/szse_bin_v1.29.pdsl
ðĄ Application Scenarios
- Matching Engine: Rapid parsing of exchange binary data
- Trading/Risk Control Systems: Low-latency order processing
- Protocol Parsing Education: Includes complete test cases, can serve as a learning sample
ðŊ Target Audience
Quantitative trading developers | High-frequency trading system engineers | Fintech enthusiasts
ð Related Tags
<span>#c++</span> <span>#fintech</span> <span>#open-source</span> <span>#quantitative-trading</span> <span>#high-frequency-trading</span>