FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_packetLZ4.hpp
1/*
2 * Copyright 2024 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
23/*
24 * This file is using the library :
25 * LZ4 - Fast LZ compression algorithm
26 * Copyright (C) 2011-present, Yann Collet.
27 * BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
28 */
29
30#define FGE_PACKETLZ4_DEFAULT_MAXUNCOMPRESSEDRECEIVEDSIZE 65536
31#define FGE_PACKETLZ4HC_DEFAULT_MAXUNCOMPRESSEDRECEIVEDSIZE 65536
32#define FGE_PACKETLZ4_VERSION "1.9.4"
33
34namespace fge::net
35{
36
37class FGE_API PacketLZ4 : public Packet
38{
39public:
40 PacketLZ4();
41 PacketLZ4(PacketLZ4&& pck) noexcept;
42 PacketLZ4(Packet&& pck) noexcept;
43 PacketLZ4(PacketLZ4 const& pck);
44 PacketLZ4(Packet const& pck);
45 ~PacketLZ4() override = default;
46
47 static uint32_t _maxUncompressedReceivedSize;
48
49 [[nodiscard]] std::size_t getLastCompressionSize() const;
50
51protected:
52 void onSend(std::vector<uint8_t>& buffer, std::size_t offset) override;
53 void onReceive(void* data, std::size_t dsize) override;
54
55private:
56 std::vector<char> g_buffer;
57 std::size_t g_lastCompressionSize;
58};
59
60class FGE_API PacketLZ4HC : public Packet
61{
62public:
64 PacketLZ4HC(PacketLZ4HC&& pck) noexcept;
65 PacketLZ4HC(Packet&& pck) noexcept;
66 PacketLZ4HC(PacketLZ4HC const& pck);
67 PacketLZ4HC(Packet const& pck);
68 ~PacketLZ4HC() override = default;
69
70 static uint32_t _maxUncompressedReceivedSize;
71
72 void setCompressionLevel(int value);
73 [[nodiscard]] int getCompressionLevel() const;
74
75 [[nodiscard]] std::size_t getLastCompressionSize() const;
76
77protected:
78 void onSend(std::vector<uint8_t>& buffer, std::size_t offset) override;
79 void onReceive(void* data, std::size_t dsize) override;
80
81private:
82 std::vector<char> g_buffer;
83 int g_compressionLevel;
84 std::size_t g_lastCompressionSize;
85};
86
87} // namespace fge::net
88
89#endif // _FGE_C_PACKETLZ4_HPP_INCLUDED
Definition C_packetLZ4.hpp:61
Definition C_packetLZ4.hpp:38
Definition C_packet.hpp:70