TrinityCore
UpdateField.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "UpdateField.h"
19#include "ByteBuffer.h"
20
21void UF::WriteDynamicFieldUpdateMask(std::size_t size, std::vector<uint32> const& updateMask, ByteBuffer& data, int32 bitsForSize /*= 32*/)
22{
23 data.WriteBits(size, bitsForSize);
24 if (size > 32)
25 {
26 if (data.HasUnfinishedBitPack())
27 for (std::size_t block = 0; block < size / 32; ++block)
28 data.WriteBits(updateMask[block], 32);
29 else
30 for (std::size_t block = 0; block < size / 32; ++block)
31 data << uint32(updateMask[block]);
32 }
33 else if (size == 32)
34 {
35 data.WriteBits(updateMask.back(), 32);
36 return;
37 }
38
39 if (size % 32)
40 data.WriteBits(updateMask.back(), size % 32);
41}
42
43void UF::WriteCompleteDynamicFieldUpdateMask(std::size_t size, ByteBuffer& data, int32 bitsForSize /*= 32*/)
44{
45 data.WriteBits(size, bitsForSize);
46 if (size > 32)
47 {
48 if (data.HasUnfinishedBitPack())
49 for (std::size_t block = 0; block < size / 32; ++block)
50 data.WriteBits(0xFFFFFFFFu, 32);
51 else
52 for (std::size_t block = 0; block < size / 32; ++block)
53 data << uint32(0xFFFFFFFFu);
54 }
55 else if (size == 32)
56 {
57 data.WriteBits(0xFFFFFFFFu, 32);
58 return;
59 }
60
61 if (size % 32)
62 data.WriteBits(0xFFFFFFFFu, size % 32);
63}
int32_t int32
Definition: Define.h:138
uint32_t uint32
Definition: Define.h:142
void WriteBits(std::size_t value, int32 bits)
Definition: ByteBuffer.h:203
bool HasUnfinishedBitPack() const
Definition: ByteBuffer.h:150
constexpr std::size_t size()
Definition: UpdateField.h:796
void WriteCompleteDynamicFieldUpdateMask(std::size_t size, ByteBuffer &data, int32 bitsForSize=32)
Definition: UpdateField.cpp:43
void WriteDynamicFieldUpdateMask(std::size_t size, std::vector< uint32 > const &updateMask, ByteBuffer &data, int32 bitsForSize=32)
Definition: UpdateField.cpp:21