FastEngine 0.9.4
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_packetLZ4.hpp
1/*
2 * Copyright 2025 Guillaume Guillet
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _FGE_C_PACKETLZ4_HPP_INCLUDED
18#define _FGE_C_PACKETLZ4_HPP_INCLUDED
19
20#include "FastEngine/fge_extern.hpp"
21#include "C_packet.hpp"
22#include "FastEngine/C_compressorLZ4.hpp"
23#include <atomic>
24
25#define FGE_NET_LZ4HC_DEFAULT_PACKET_MAX_SIZE FGE_COMPRESSOR_LZ4HC_DEFAULT_MAX_SIZE
26#define FGE_NET_LZ4_DEFAULT_PACKET_MAX_SIZE FGE_COMPRESSOR_LZ4_DEFAULT_MAX_SIZE
27
28namespace fge::net
29{
30
31class FGE_API PacketLZ4 : public Packet
32{
33public:
34 PacketLZ4() = default;
35 PacketLZ4(PacketLZ4&& pck) noexcept;
36 PacketLZ4(Packet&& pck) noexcept;
37 PacketLZ4(PacketLZ4 const& pck);
38 PacketLZ4(Packet const& pck);
39 ~PacketLZ4() override = default;
40
41 [[nodiscard]] CompressorLZ4 const& getCompressor() const;
42
43 static std::atomic_uint32_t gMaxUncompressedSize;
44
45protected:
46 bool onSend(std::size_t offset) override;
47 void onReceive(std::span<uint8_t const> const& data) override;
48
49private:
50 CompressorLZ4 g_compressor;
51};
52
53class FGE_API PacketLZ4HC : public Packet
54{
55public:
56 PacketLZ4HC() = default;
57 PacketLZ4HC(PacketLZ4HC&& pck) noexcept;
58 PacketLZ4HC(Packet&& pck) noexcept;
59 PacketLZ4HC(PacketLZ4HC const& pck);
60 PacketLZ4HC(Packet const& pck);
61 ~PacketLZ4HC() override = default;
62
63 [[nodiscard]] CompressorLZ4HC const& getCompressor() const;
64
65 static std::atomic_uint32_t gMaxUncompressedSize;
66 static std::atomic_int gCompressionLevel;
67
68protected:
69 bool onSend(std::size_t offset) override;
70 void onReceive(std::span<uint8_t const> const& data) override;
71
72private:
73 CompressorLZ4HC g_compressor;
74};
75
76} // namespace fge::net
77
78#endif // _FGE_C_PACKETLZ4_HPP_INCLUDED
Definition C_compressorLZ4.hpp:56
Definition C_compressorLZ4.hpp:41