FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_packetBZ2.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_PACKETBZ2_HPP_INCLUDED
18#define _FGE_C_PACKETBZ2_HPP_INCLUDED
19
20#include "FastEngine/fge_extern.hpp"
21#include "C_packet.hpp"
22
23/*
24 * This file is using the library :
25 * libbzip2
26 * copyright (C) 1996-2019 Julian R Seward.
27 */
28
29#define FGE_PACKETBZ2_DEFAULT_WORKFACTOR 0
30#define FGE_PACKETBZ2_DEFAULT_BLOCKSIZE 4
31
32#define FGE_PACKETBZ2_DEFAULT_MAXUNCOMPRESSEDRECEIVEDSIZE 65536
33#define FGE_PACKETBZ2_VERSION "1.0.8"
34
35namespace fge::net
36{
37
38class FGE_API PacketBZ2 : public fge::net::Packet
39{
40public:
41 PacketBZ2();
42 PacketBZ2(PacketBZ2&& pck) noexcept;
43 PacketBZ2(Packet&& pck) noexcept;
44 PacketBZ2(PacketBZ2 const& pck);
45 PacketBZ2(Packet const& pck);
46 ~PacketBZ2() override = default;
47
48 static uint32_t _maxUncompressedReceivedSize;
49
50 void setBlockSize(int blockSize);
51 [[nodiscard]] int getBlockSize() const;
52 void setWorkFactor(int factor);
53 [[nodiscard]] int getWorkFactor() const;
54
55 [[nodiscard]] std::size_t getLastCompressionSize() const;
56
57protected:
58 void onSend(std::vector<uint8_t>& buffer, std::size_t offset) override;
59 void onReceive(void* data, std::size_t dsize) override;
60
61private:
62 int g_blockSize;
63 int g_workfactor;
64
65 std::vector<char> g_buffer;
66 std::size_t g_lastCompressionSize;
67};
68
69} // namespace fge::net
70
71#endif // _FGE_C_PACKETBZ2_HPP_INCLUDED
Definition C_packetBZ2.hpp:39
Definition C_packet.hpp:70