API
For each message class there is a constructor and the deserialize
method which accepts a pointer to raw data buffer and its size. This buffer should contain all message data including message type and body length (i.e. header).
Under the hood, the constructor calls deserialize
method so you can use the same object to deserialize from different data samples.
- Note
- It is important to pass a buffer with the message header because
deserialize
method uses absolute offsets, i.e. first field should be located after three bytes of the message header.
Example
1 std::ifstream ifs("FuturesProductDefinition.bin");
4 ifs.read(&msgType, sizeof(msgType));
6 unsigned short bodyLen = 0;
7 ifs.read((char*)&bodyLen, sizeof(bodyLen));
8 bodyLen = rotate(bodyLen);
10 const size_t offset = sizeof(msgType) + sizeof(bodyLen);
11 const size_t msgSize = offset + bodyLen;
12 std::vector<char> data(msgSize);
13 ifs.read(&data[offset], bodyLen);
15 FuturesProductDefinition msg(&data[0], data.size());