File size: 469 Bytes
f86fb3b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include "../../include/protocol/binary_protocol.hpp"

namespace quant::protocol {

std::optional<FrameHeader> BinaryProtocol::parse_header(std::span<const uint8_t> buffer) noexcept {
    if (buffer.size() < sizeof(FrameHeader)) {
        return std::nullopt;
    }

    const auto* hdr = reinterpret_cast<const FrameHeader*>(buffer.data());
    if (hdr->magic != PROTOCOL_MAGIC) {
        return std::nullopt;
    }

    return *hdr;
}

} // namespace quant::protocol