|
Aegis2D
Modular C++26 2D game engine for networked games
|
Optional LZ4 compression of datagram payloads, flagged in the packet header. More...
#include <aegis2d/net/binary.hpp>#include <aegis2d/net/export.hpp>#include <aegis2d/net/packet.hpp>#include <cstddef>#include <optional>#include <span>#include <vector>Go to the source code of this file.
Namespaces | |
| namespace | aegis2d |
| Root namespace of the engine. | |
| namespace | aegis2d::net |
| Binary serialization, UDP/TCP sockets and the network thread. | |
Functions | |
| std::optional< std::vector< std::byte > > | aegis2d::net::compress_payload (std::span< const std::byte > payload) |
| Compresses a payload with LZ4. | |
| std::optional< std::vector< std::byte > > | aegis2d::net::decompress_payload (std::span< const std::byte > compressed) |
| Decompresses a payload written by compress_payload(). | |
| void | aegis2d::net::write_datagram (BinaryWriter &writer, PacketHeader header, std::span< const std::byte > payload, std::optional< std::size_t > threshold=std::nullopt) |
| Writes a datagram: its header, then its payload, compressed when that pays. | |
| std::optional< std::vector< std::byte > > | aegis2d::net::read_payload (const PacketHeader &header, BinaryReader &reader) |
| Reads the payload of a datagram, decompressed if its header says it is compressed. | |
Variables | |
| constexpr std::size_t | aegis2d::net::default_compression_threshold = 128 |
| Default size from which write_datagram() tries to compress a payload, in bytes. | |
Optional LZ4 compression of datagram payloads, flagged in the packet header.
Implements the compressed payloads of the protocol RFC (docs/rfc/udp-header.md, section 2.6). A compressed payload is the size of the original payload (u16), then that payload as one LZ4 block; the header says so with PacketHeader::compressed. A payload is compressed only when it is long enough and comes out smaller, so a peer that never compresses still reads every datagram of one that does.