-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprotocol.h
More file actions
39 lines (31 loc) · 1.11 KB
/
protocol.h
File metadata and controls
39 lines (31 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#pragma once
#include <cstdint>
#include <cstddef>
namespace protocol
{
// Message type identifiers
constexpr uint16_t MSG_ORDER = 0x0001;
constexpr uint16_t MSG_CANCEL = 0x0002;
constexpr uint16_t MSG_ACK = 0x0003;
// Header layout: [msg_type: 2][msg_len: 2][checksum: 2] = 6 bytes
constexpr size_t HEADER_SIZE = 6;
// Order payload: [order_id: 8][price: 4][quantity: 4][side: 1][padding: 1] = 18 bytes
constexpr size_t ORDER_PAYLOAD_SIZE = 18;
constexpr size_t ORDER_MSG_SIZE = HEADER_SIZE + ORDER_PAYLOAD_SIZE; // 24 bytes total
// Field offsets within message buffer
namespace offset
{
constexpr size_t MSG_TYPE = 0;
constexpr size_t MSG_LEN = 2;
constexpr size_t CHECKSUM = 4;
constexpr size_t PAYLOAD = 6;
// Order payload offsets (relative to PAYLOAD)
constexpr size_t ORDER_ID = 0;
constexpr size_t PRICE = 8;
constexpr size_t QUANTITY = 12;
constexpr size_t SIDE = 16;
}
// Order sides
constexpr uint8_t SIDE_BUY = 0x01;
constexpr uint8_t SIDE_SELL = 0x02;
} // namespace protocol