9#include "net/wire/bit_stream.h"
11namespace Vkm::Engine {
14constexpr size_t NET_MESSAGE_MAX_BYTES = 255;
21constexpr size_t NET_MESSAGE_WINDOW = 64;
37 NetOutbox() =
default;
38 ~NetOutbox() =
default;
40 NetOutbox(
const NetOutbox& other) =
default;
41 NetOutbox& operator=(
const NetOutbox& other) =
default;
43 NetOutbox(NetOutbox && other) =
default;
44 NetOutbox& operator=(NetOutbox && other) =
default;
54 bool push(
const uint8_t* bytes,
size_t size);
75 size_t pending()
const {
return m_pending.size(); }
82 uint16_t sequence = 0;
83 std::vector<uint8_t> bytes;
87 std::deque<Message> m_pending;
96 using Deliver = std::function<void(
const uint8_t* bytes,
size_t size)>;
100 ~NetInbox() =
default;
102 NetInbox(
const NetInbox& other) =
default;
103 NetInbox& operator=(
const NetInbox& other) =
default;
105 NetInbox(NetInbox && other) =
default;
106 NetInbox& operator=(NetInbox && other) =
default;
125 uint16_t
newest()
const {
return m_newest; }
129 m_room = NET_MESSAGE_WINDOW;
134 uint16_t m_newest = 0;
135 size_t m_room = NET_MESSAGE_WINDOW;
Reads back what a BitWriter wrote, in the same order.
Definition bit_stream.h:145
Packs values to the bit into a byte buffer.
Definition bit_stream.h:19
uint16_t acknowledge()
newest(), as an acknowledgement sent: the sender may now be handed on as many again.
Definition messages.h:128
bool read(BitReader &in, const Deliver &deliver)
Read a packet's messages, handing on those not seen before.
uint16_t newest() const
The latest sequence handed on, for the acknowledgement; zero before any.
Definition messages.h:125
static constexpr uint32_t NONE_BITS
What write() writes when no message fits: the bit saying none follow.
Definition messages.h:34
void clear()
Forget every message, and number the next one from the start.
size_t pending() const
Messages waiting to be acknowledged.
Definition messages.h:75
bool push(const uint8_t *bytes, size_t size)
Keep size bytes to send.
size_t write(BitWriter &out, size_t budgetBits) const
Write the oldest messages kept that fit in budgetBits.
void acknowledge(uint16_t newest)
The other end has every message up to newest: stop sending them.