| 70 | size_t LevinProtocol::HEADER_SIZE() { return sizeof(bucket_head2); } |
| 71 | |
| 72 | size_t LevinProtocol::read_command_header(const BinaryArray &raw_header, CommandType *rrn, uint32_t *command) { |
| 73 | bucket_head2 head = {}; |
| 74 | if (raw_header.size() != sizeof(head)) |
| 75 | throw std::runtime_error("Levin wrong header size " + common::to_string(raw_header.size())); |
| 76 | memmove(&head, raw_header.data(), sizeof(head)); // TODO - endian |
| 77 | |
| 78 | if (head.m_magic != LEVIN_MAGIC) |
| 79 | throw std::runtime_error("Levin magic mismatch raw_header=" + common::to_hex(raw_header)); |
| 80 | |
| 81 | *command = head.m_command; |
| 82 | *rrn = (head.m_flags & LEVIN_PACKET_RESPONSE) == LEVIN_PACKET_RESPONSE ? RESPONSE |
| 83 | : head.m_command_type ? REQUEST : NOTIFY; |
| 84 | return common::integer_cast<size_t>(head.m_cb); |
| 85 | } |