Background: I'm doing development of Order Management System referring NSE document. Snapshot of requirement is below: 2 bytes Structure detail is as follows
2nd screenshot - remaining 8 BITs
Above structure is further used in another structure. As seen below above structure needs to be 2 BYTES or 16 BITS only
Question:
What is the best way to code this structure in C++? I have used std::bitset<16> but when I see the sizeof(std::bitset<16>), it is coming as 8 bytes instead of expected 2 bytes. Whole purpose of bitset is to save memory. I know that compiler is doing padding internally so it is adding 6 bytes. This is causing problem when I send data packets via socket (send(iSockFd, chSignInBuffer, 276, 0)) as NSE expects only 2 bytes for above structure and remaining 274 bytes for other data. Because of bitset<16>, structure size became 282 bytes instead of expected 276 bytes (additional 6 bytes).
There are many structures which are referring to BIT. What is the best way to code this in C++ such that I can easily send and receive bits?
Any good library or optimization tips is highly appreciated as this system is being developed for High Frequency Trading (HFT). I'm using Linux operating system - Ubuntu 22 and Visual Studio code for development. Compiler G++ 11 (supporting C++20 as well).