-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodec.h
More file actions
32 lines (26 loc) · 751 Bytes
/
codec.h
File metadata and controls
32 lines (26 loc) · 751 Bytes
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
#pragma once
#include <cstdint>
#include <cstddef>
struct Order
{
uint64_t order_id;
uint32_t price;
uint32_t quantity;
uint8_t side; // SIDE_BUY or SIDE_SELL
};
enum class CodecResult
{
OK,
BUFFER_TOO_SMALL,
INVALID_MSG_TYPE,
INVALID_MSG_LEN,
CHECKSUM_MISMATCH
};
// Returns number of bytes written, or 0 on failure
size_t encode_order(uint8_t *buf, size_t buf_len, const Order &order);
// Decodes order from buffer, returns result code
CodecResult decode_order(const uint8_t *buf, size_t buf_len, Order &out);
// Utility: compute simple XOR checksum over buffer
uint16_t compute_checksum(const uint8_t *data, size_t len);
// Get human-readable error string
const char *codec_result_str(CodecResult result);