default values completed, added bool support and applied license

This commit is contained in:
fraillt
2017-02-21 14:54:16 +02:00
parent 7964679ec2
commit bfaf5909ef
25 changed files with 802 additions and 115 deletions

21
LICENSE Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 Mindaugas Vinkelis
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -7,8 +7,9 @@ All cross-platform requirements are enforced at compile time, so serialized data
## Status
**bitsery** is in pre-release state and is looking for your feedback.
It has basic features, serialize arithmetic types, enums, containers and text, but is missing any advanced compression functions like delta changes serialization, entropy encoding, floating point compression, geometry compression, etc...
It has basic features, serialize arithmetic types, enums, containers and text, and few advanced features like value ranges and default values (substitution), but is still missing functions for delta changes and geometry compression.
> Current version do not handle Big/Little Endianness.
> Error handling on deserialization is not tested.
## Example
```cpp
@@ -34,7 +35,7 @@ SERIALIZE(MyStruct) {
return s.
value(o.i).
value(o.e).
container(o.fs);
container(o.fs, 100);
}
void print(const char* msg, const MyStruct& v) {
@@ -94,5 +95,5 @@ int main() {
This library was tested on
* Windows: Visual Studio 2015
* Linux: GCC 5.4, GCC 6.2
* Linux: GCC 5.4, GCC 6.2, Clang 3.9

View File

@@ -1,3 +1,26 @@
#MIT License
#
#Copyright (c) 2017 Mindaugas Vinkelis
#
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in all
#copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
#SOFTWARE.
cmake_minimum_required(VERSION 3.2)
include_directories(${CMAKE_SOURCE_DIR}/include)

View File

@@ -1,6 +1,26 @@
//MIT License
//
// Created by fraillt on 17.2.9.
//Copyright (c) 2017 Mindaugas Vinkelis
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
#include <iostream>
#include <vector>
#include "BufferReader.h"

View File

@@ -1,3 +1,25 @@
#MIT License
#
#Copyright (c) 2017 Mindaugas Vinkelis
#
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in all
#copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
#SOFTWARE.
cmake_minimum_required(VERSION 3.2)
project(gtest_builder C CXX)
include(ExternalProject)

View File

@@ -1,9 +1,29 @@
//MIT License
//
// Created by Mindaugas Vinkelis on 2016-11-11.
//Copyright (c) 2017 Mindaugas Vinkelis
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
#ifndef PROJECT_TEMPLATE_BUFFER_READER_H
#define PROJECT_TEMPLATE_BUFFER_READER_H
#ifndef BITSERY_BUFFER_READER_H
#define BITSERY_BUFFER_READER_H
#include "Common.h"
@@ -126,4 +146,4 @@ namespace bitsery {
}
#endif //PROJECT_TEMPLATE_BUFFER_READER_H
#endif //BITSERY_BUFFER_READER_H

View File

@@ -1,9 +1,29 @@
//MIT License
//
// Created by Mindaugas Vinkelis on 2016-11-11.
//Copyright (c) 2017 Mindaugas Vinkelis
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
#ifndef PROJECT_TEMPLATE_BUFFER_WRITER_H
#define PROJECT_TEMPLATE_BUFFER_WRITER_H
#ifndef BITSERY_BUFFER_WRITER_H
#define BITSERY_BUFFER_WRITER_H
#include "Common.h"
#include <cassert>
@@ -133,6 +153,19 @@ namespace bitsery {
bitsLeft -= bits;
}
}
void writeBitsInternal(const value_type &v, size_t size) {
if (size > 0) {
m_scratch |= static_cast<SCRATCH_TYPE>( v ) << m_scratchBits;
m_scratchBits += size;
if (m_scratchBits >= BITS_SIZE<value_type>) {
auto tmp = static_cast<value_type>(m_scratch & bufTypeMask);
directWrite(&tmp, 1);
m_scratch >>= BITS_SIZE<value_type>;
m_scratchBits -= BITS_SIZE<value_type>;
}
}
}
const value_type bufTypeMask = 0xFF;
using SCRATCH_TYPE = typename BIGGER_TYPE<value_type>::type;
@@ -147,4 +180,4 @@ namespace bitsery {
};
}
#endif //PROJECT_TEMPLATE_BUFFER_WRITER_H
#endif //BITSERY_BUFFER_WRITER_H

View File

@@ -1,9 +1,29 @@
//MIT License
//
// Created by fraillt on 17.1.5.
//Copyright (c) 2017 Mindaugas Vinkelis
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
#ifndef TMP_COMMON_H
#define TMP_COMMON_H
#ifndef BITSERY_COMMON_H
#define BITSERY_COMMON_H
#include <stdint.h>
@@ -95,6 +115,10 @@ namespace bitsery {
template <typename S, typename T, typename std::enable_if<std::is_same<T, ObjectType>::value || std::is_same<T, const ObjectType>::value>::type* = nullptr> \
S& serialize(S& s, T& o)
/*
* range functions
*/
template<typename T>
constexpr size_t calcRequiredBits(T min, T max) {
size_t res{};
@@ -163,6 +187,21 @@ S& serialize(S& s, T& o)
const size_t bitsRequired;
};
template<typename T, typename std::enable_if<std::is_arithmetic<T>::value>::type * = nullptr>
bool isRangeValid(const T &v, const RangeSpec<T> &r) {
return !(r.min > v || v > r.max);
}
template<typename T, typename std::enable_if<std::is_enum<T>::value>::type * = nullptr>
bool isRangeValid(const T &v, const RangeSpec<T> &r) {
using VT = std::underlying_type_t<T>;
return !(static_cast<VT>(r.min) > static_cast<VT>(v)
|| static_cast<VT>(v) > static_cast<VT>(r.max));
}
/*
* delta functions
*/
class ObjectMemoryPosition {
public:
@@ -196,4 +235,4 @@ S& serialize(S& s, T& o)
};
}
#endif //TMP_COMMON_H
#endif //BITSERY_COMMON_H

View File

@@ -1,9 +1,29 @@
//MIT License
//
// Created by fraillt on 17.1.10.
//Copyright (c) 2017 Mindaugas Vinkelis
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
#ifndef TMP_DELTADESERIALIZER_H
#define TMP_DELTADESERIALIZER_H
#ifndef BITSERY_DELTADESERIALIZER_H
#define BITSERY_DELTADESERIALIZER_H
#include <array>
#include <stack>
@@ -43,15 +63,15 @@ namespace bitsery {
template<size_t VSIZE = 1, typename T>
DeltaDeserializer &text(std::basic_string<T> &str, size_t maxSize) {
if (getChangedState(str)) {
_deserializer.text<VSIZE>(str, maxSize);
_deserializer.template text<VSIZE>(str, maxSize);
}
return *this;
}
template<size_t VSIZE = 1, typename T, size_t N>
DeltaDeserializer &text(T (&str)[N], size_t maxSize) {
DeltaDeserializer &text(T (&str)[N]) {
if (getChangedState(str)) {
_deserializer.text<VSIZE>(str, maxSize);
_deserializer.template text<VSIZE>(str);
}
return *this;
}
@@ -197,4 +217,4 @@ namespace bitsery {
};
}
#endif //TMP_DELTADESERIALIZER_H
#endif //BITSERY_DELTADESERIALIZER_H

View File

@@ -1,9 +1,29 @@
//MIT License
//
// Created by fraillt on 17.1.10.
//Copyright (c) 2017 Mindaugas Vinkelis
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
#ifndef TMP_DELTASERIALIZER_H
#define TMP_DELTASERIALIZER_H
#ifndef BITSERY_DELTASERIALIZER_H
#define BITSERY_DELTASERIALIZER_H
#include <array>
#include <stack>
@@ -45,7 +65,7 @@ namespace bitsery {
template<size_t VSIZE = 1, typename T>
DeltaSerializer &text(const std::basic_string<T> &str, size_t maxSize) {
if (setChangedState(str)) {
_serializer.text<VSIZE>(str, maxSize);
_serializer.template text<VSIZE>(str, maxSize);
}
return *this;
@@ -54,7 +74,7 @@ namespace bitsery {
template<size_t VSIZE = 1, typename T, size_t N>
DeltaSerializer &text(const T (&str)[N]) {
if (setChangedState(str)) {
_serializer.text<VSIZE>(str);
_serializer.template text<VSIZE>(str);
}
return *this;
@@ -197,4 +217,4 @@ namespace bitsery {
};
}
#endif //TMP_DELTASERIALIZER_H
#endif //BITSERY_DELTASERIALIZER_H

View File

@@ -1,12 +1,32 @@
//MIT License
//
// Created by Mindaugas Vinkelis on 17.1.9.
//Copyright (c) 2017 Mindaugas Vinkelis
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
#ifndef TMP_DESERIALIZER_H
#define TMP_DESERIALIZER_H
#ifndef BITSERY_DESERIALIZER_H
#define BITSERY_DESERIALIZER_H
#include "Common.h"
#include <array>
#include <utility>
namespace bitsery {
@@ -36,7 +56,7 @@ namespace bitsery {
template<typename Reader>
class Deserializer {
public:
Deserializer(Reader& r):_reader{r} {};
Deserializer(Reader& r):_reader{r}, _isValid{true} {};
template <typename T>
Deserializer& object(T&& obj) {
@@ -51,9 +71,10 @@ namespace bitsery {
Deserializer& value(T& v) {
static_assert(std::numeric_limits<float>::is_iec559, "");
static_assert(std::numeric_limits<double>::is_iec559, "");
constexpr size_t ValueSize = VSIZE == 0 ? sizeof(T) : VSIZE;
_reader.template readBytes<ValueSize>(reinterpret_cast<SAME_SIZE_UNSIGNED<T>&>(v));
if (_isValid) {
constexpr size_t ValueSize = VSIZE == 0 ? sizeof(T) : VSIZE;
_isValid = _reader.template readBytes<ValueSize>(reinterpret_cast<SAME_SIZE_UNSIGNED<T>&>(v));
}
return *this;
}
@@ -61,14 +82,42 @@ namespace bitsery {
Deserializer& value(T& v) {
constexpr size_t ValueSize = VSIZE == 0 ? sizeof(T) : VSIZE;
using UT = std::underlying_type_t<T>;
_reader.template readBytes<ValueSize>(reinterpret_cast<UT&>(v));
if (_isValid) {
_isValid = _reader.template readBytes<ValueSize>(reinterpret_cast<UT&>(v));
}
return *this;
}
template<size_t VSIZE = 0, typename T, typename std::enable_if<std::is_integral<T>::value>::type* = nullptr>
Deserializer& value(T& v) {
constexpr size_t ValueSize = VSIZE == 0 ? sizeof(T) : VSIZE;
_reader.template readBytes<ValueSize>(v);
if (_isValid) {
_isValid = _reader.template readBytes<ValueSize>(v);
}
return *this;
}
/*
* bool
*/
Deserializer& boolBit(bool& v) {
if (_isValid) {
unsigned char tmp;
_isValid = _reader.readBits(tmp, 1);
v = tmp == 1;
}
return *this;
}
Deserializer& boolByte(bool& v) {
if (_isValid) {
unsigned char tmp;
_isValid = _reader.template readBytes<1>(tmp);
if (_isValid)
_isValid = tmp < 2;
v = tmp == 1;
}
return *this;
}
@@ -78,8 +127,12 @@ namespace bitsery {
template <typename T>
Deserializer& range(T& v, const RangeSpec<T>& range) {
_reader.template readBits(reinterpret_cast<SAME_SIZE_UNSIGNED<T>&>(v), range.bitsRequired);
setRangeValue(v, range);
if (_isValid) {
_isValid = _reader.template readBits(reinterpret_cast<SAME_SIZE_UNSIGNED<T>&>(v), range.bitsRequired);
setRangeValue(v, range);
if (_isValid)
_isValid = isRangeValid(v, range);
}
return *this;
}
@@ -90,10 +143,12 @@ namespace bitsery {
Deserializer& substitution(T& v, const std::array<T,N>& expectedValues, Fnc&& fnc) {
size_t index;
range(index, {{}, N + 1});
if (index)
v = expectedValues[index-1];
else
fnc(v);
if (_isValid) {
if (index)
v = expectedValues[index-1];
else
fnc(v);
}
return *this;
};
@@ -101,10 +156,12 @@ namespace bitsery {
Deserializer& substitution(T& v, const std::array<T,N>& expectedValues) {
size_t index;
range(index, {{}, N + 1});
if (index)
v = expectedValues[index-1];
else
ProcessAnyType<VSIZE>::serialize(*this, v);
if (_isValid) {
if (index)
v = expectedValues[index-1];
else
ProcessAnyType<VSIZE>::serialize(*this, v);
}
return *this;
};
@@ -112,10 +169,12 @@ namespace bitsery {
Deserializer& substitution(T& v, const std::array<T,N>& expectedValues) {
size_t index;
range(index, {{}, N + 1});
if (index)
v = expectedValues[index-1];
else
ProcessAnyType<ARITHMETIC_OR_ENUM_SIZE<T>>::serialize(*this, v);
if (_isValid) {
if (index)
v = expectedValues[index-1];
else
ProcessAnyType<ARITHMETIC_OR_ENUM_SIZE<T>>::serialize(*this, v);
}
return *this;
};
@@ -126,22 +185,30 @@ namespace bitsery {
template <size_t VSIZE = 1, typename T>
Deserializer& text(std::basic_string<T>& str, size_t maxSize) {
size_t size;
readLength(size);
std::vector<T> buf(size);
_reader.template readBuffer<VSIZE>(buf.data(), size);
str.assign(buf.data(), size);
// str.resize(size);
// if (size)
// _reader.template readBuffer<VSIZE>(str.data(), size);
readSize(size, maxSize);
if (_isValid) {
str.resize(size);
if (size) {
//if (std::is_const<decltype(std::declval<std::basic_string<T>>().data())>::value) {
std::vector<T> buf(size);
_isValid = _reader.template readBuffer<VSIZE>(buf.data(), size);
str.assign(buf.data(), size);
//} else {
//_isValid = _reader.template readBuffer<VSIZE>(str.data(), size);
//}
}
}
return *this;
}
template<size_t VSIZE=1, typename T, size_t N>
Deserializer& text(T (&str)[N]) {
size_t size;
readLength(size);
_reader.template readBuffer<VSIZE>(str, size);
str[size] = {};
readSize(size, N-1);
if (_isValid) {
_isValid = _reader.template readBuffer<VSIZE>(str, size);
str[size] = {};
}
return *this;
}
@@ -152,28 +219,37 @@ namespace bitsery {
template <typename T, typename Fnc>
Deserializer& container(T&& obj, Fnc&& fnc, size_t maxSize) {
decltype(obj.size()) size{};
readLength(size);
obj.resize(size);
for (auto& v:obj)
fnc(v);
readSize(size, maxSize);
if (_isValid) {
obj.resize(size);
for (auto& v:obj) {
if (_isValid)
fnc(v);
}
}
return *this;
}
template <size_t VSIZE, typename T>
Deserializer& container(T& obj, size_t maxSize) {
decltype(obj.size()) size{};
readLength(size);
obj.resize(size);
procContainer<VSIZE>(obj);
readSize(size, maxSize);
if (_isValid) {
obj.resize(size);
procContainer<VSIZE>(obj);
}
return *this;
}
template <typename T>
Deserializer& container(T& obj, size_t maxSize) {
decltype(obj.size()) size{};
readLength(size);
obj.resize(size);
procContainer<ARITHMETIC_OR_ENUM_SIZE<typename T::value_type>>(obj);
readSize(size, maxSize);
if (_isValid) {
obj.resize(size);
procContainer<ARITHMETIC_OR_ENUM_SIZE<typename T::value_type>>(obj);
}
return *this;
}
@@ -186,7 +262,8 @@ namespace bitsery {
template<typename T, size_t N, typename Fnc>
Deserializer& array(std::array<T,N> &arr, Fnc && fnc) {
for (auto& v: arr)
fnc(v);
if (_isValid)
fnc(v);
return *this;
}
@@ -208,7 +285,8 @@ namespace bitsery {
Deserializer& array(T (&arr)[N], Fnc&& fnc) {
T* tmp = arr;
for (auto i = 0u; i < N; ++i, ++tmp)
fnc(*tmp);
if (_isValid)
fnc(*tmp);
return *this;
}
@@ -223,18 +301,43 @@ namespace bitsery {
procCArray<ARITHMETIC_OR_ENUM_SIZE<T>>(arr);
return *this;
}
bool isValid() const {
return _isValid;
}
private:
Reader& _reader;
void readLength(size_t& size) {
bool _isValid;
void readSize(size_t &size, size_t maxSize) {
size = {};
_reader.readBits(size, 32);
if (_isValid) {
unsigned char firstBit;
_isValid = _reader.readBits(firstBit, 1);
if (_isValid) {
if (firstBit) {
_isValid = _reader.readBits(size, 7);
} else {
unsigned char secondBit;
_isValid = _reader.readBits(secondBit, 1);
if (_isValid) {
if (secondBit) {
_isValid = _reader.readBits(size,14);
} else {
_isValid = _reader.readBits(size,30);
}
}
}
}
if (_isValid)
_isValid = size <= maxSize;
}
}
template <size_t VSIZE, typename T>
void procContainer(T&& obj) {
//todo could be improved for arithmetic types in contiguous containers (std::vector, std::array) (keep in mind std::vector<bool> specialization)
for (auto& v: obj)
ProcessAnyType<VSIZE>::serialize(*this, v);
if (_isValid)
ProcessAnyType<VSIZE>::serialize(*this, v);
};
template <size_t VSIZE, typename T, size_t N>
@@ -242,7 +345,8 @@ namespace bitsery {
//todo could be improved for arithmetic types
T* end = arr + N;
for (T* it = arr; it != end; ++it)
ProcessAnyType<VSIZE>::serialize(*this, *it);
if (_isValid)
ProcessAnyType<VSIZE>::serialize(*this, *it);
};
};
@@ -250,4 +354,4 @@ namespace bitsery {
}
#endif //TMP_DESERIALIZER_H
#endif //BITSERY_DESERIALIZER_H

View File

@@ -1,9 +1,29 @@
//MIT License
//
// Created by Mindaugas Vinkelis on 17.1.3.
//Copyright (c) 2017 Mindaugas Vinkelis
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
#ifndef TMP_SERIALIZER_H
#define TMP_SERIALIZER_H
#ifndef BITSERY_SERIALIZER_H
#define BITSERY_SERIALIZER_H
#include "Common.h"
#include <array>
@@ -14,19 +34,6 @@ namespace bitsery {
* functions for range
*/
template<typename T, typename std::enable_if<std::is_arithmetic<T>::value>::type * = nullptr>
bool isRangeValid(const T &v, const RangeSpec<T> &r) {
return !(r.min > v || v > r.max);
}
template<typename T, typename std::enable_if<std::is_enum<T>::value>::type * = nullptr>
bool isRangeValid(const T &v, const RangeSpec<T> &r) {
using VT = std::underlying_type_t<T>;
return !(static_cast<VT>(r.min) > static_cast<VT>(v)
|| static_cast<VT>(v) > static_cast<VT>(r.max));
}
template<typename T, typename std::enable_if<std::is_integral<T>::value>::type * = nullptr>
auto getRangeValue(const T &v, const RangeSpec<T> &r) {
return static_cast<SAME_SIZE_UNSIGNED<T>>(v - r.min);
@@ -101,6 +108,20 @@ namespace bitsery {
return *this;
}
/*
* bool
*/
Serializer& boolBit(bool v) {
_writter.template writeBits(static_cast<unsigned char>(v ? 1 : 0), 1);
return *this;
}
Serializer& boolByte(bool v) {
_writter.template writeBytes<1>(static_cast<unsigned char>(v ? 1 : 0));
return *this;
}
/*
* range
*/
@@ -166,7 +187,7 @@ namespace bitsery {
template<typename T, typename Fnc>
Serializer& container(const T &obj, Fnc &&fnc, size_t maxSize) {
assert(obj.size() <= maxSize);
writeLength(obj.size());
writeSize(obj.size());
for (auto &v: obj)
fnc(v);
return *this;
@@ -175,7 +196,7 @@ namespace bitsery {
template<size_t VSIZE, typename T>
Serializer& container(const T &obj, size_t maxSize) {
assert(obj.size() <= maxSize);
writeLength(obj.size());
writeSize(obj.size());
procContainer<VSIZE>(obj);
return *this;
}
@@ -183,7 +204,7 @@ namespace bitsery {
template<typename T>
Serializer& container(const T &obj, size_t maxSize) {
assert(obj.size() <= maxSize);
writeLength(obj.size());
writeSize(obj.size());
procContainer<ARITHMETIC_OR_ENUM_SIZE<typename T::value_type>>(obj);
return *this;
}
@@ -235,12 +256,21 @@ namespace bitsery {
return *this;
}
private:
Writter &_writter;
void writeLength(const size_t size) {
_writter.writeBits(size, 32);
void writeSize(const size_t size) {
if (size < 0x80u) {
_writter.writeBits(1u, 1);
_writter.writeBits(size, 7);
} else if (size < 0x4000u) {
_writter.writeBits(2u,2);
_writter.writeBits(size, 14);
} else {
assert(size < 0x40000000u);
_writter.writeBits(0u,2);
_writter.writeBits(size, 30);
}
}
template<size_t VSIZE, typename T>
@@ -260,11 +290,11 @@ namespace bitsery {
template<size_t VSIZE, typename T>
void procText(const T *str, size_t size) {
writeLength(size);
writeSize(size);
if (size)
_writter.template writeBuffer<VSIZE>(str, size);
}
};
}
#endif //TMP_SERIALIZER_H
#endif //BITSERY_SERIALIZER_H

View File

@@ -1,6 +1,26 @@
//MIT License
//
// Created by Mindaugas Vinkelis on 2017-01-10.
//Copyright (c) 2017 Mindaugas Vinkelis
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
#include <gmock/gmock.h>
#include "BufferWriter.h"
#include "BufferReader.h"

View File

@@ -1,6 +1,26 @@
//MIT License
//
// Created by Mindaugas Vinkelis on 2016-11-11.
//Copyright (c) 2017 Mindaugas Vinkelis
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
#include <gmock/gmock.h>
#include "BufferWriter.h"
#include "BufferReader.h"

View File

@@ -1,3 +1,25 @@
#MIT License
#
#Copyright (c) 2017 Mindaugas Vinkelis
#
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in all
#copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
#SOFTWARE.
cmake_minimum_required(VERSION 3.2)
project(${TEST_PROJECT_NAME} C CXX)
@@ -19,7 +41,7 @@ file(GLOB TEST_SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
FOREACH(TEST_PROJECT_FILE ${TEST_SRC_FILES})
get_filename_component(TEST_PROJECT_NAME ${TEST_PROJECT_FILE} NAME_WE)
add_executable(${TEST_PROJECT_NAME} ${TEST_SRC_FILES})
add_executable(${TEST_PROJECT_NAME} ${TEST_PROJECT_FILE})
add_dependencies(${TEST_PROJECT_NAME} googletest)
set_property(TARGET ${TEST_PROJECT_NAME} PROPERTY CXX_STANDARD 14)

View File

@@ -0,0 +1,56 @@
//MIT License
//
//Copyright (c) 2017 Mindaugas Vinkelis
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
#include <gmock/gmock.h>
#include "SerializationTestUtils.h"
using testing::Eq;
TEST(SerializeBooleans, BoolAsBit) {
SerializationContext ctx;
bool t1{true};
bool t2{false};
bool res1;
bool res2;
ctx.createSerializer().boolBit(t1).boolBit(t2);
ctx.createDeserializer().boolBit(res1).boolBit(res2);
EXPECT_THAT(res1, Eq(t1));
EXPECT_THAT(res2, Eq(t2));
EXPECT_THAT(ctx.getBufferSize(), Eq(1));
}
TEST(SerializeBooleans, BoolAsByte) {
SerializationContext ctx;
bool t1{true};
bool t2{false};
bool res1;
bool res2;
ctx.createSerializer().boolByte(t1).boolByte(t2);
ctx.createDeserializer().boolByte(res1).boolByte(res2);
EXPECT_THAT(res1, Eq(t1));
EXPECT_THAT(res2, Eq(t2));
EXPECT_THAT(ctx.getBufferSize(), Eq(2));
}

View File

@@ -1,6 +1,25 @@
//MIT License
//
// Created by fraillt on 17.2.7.
//Copyright (c) 2017 Mindaugas Vinkelis
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
#include <gmock/gmock.h>

View File

@@ -1,6 +1,25 @@
//MIT License
//
// Created by fraillt on 17.2.9.
//Copyright (c) 2017 Mindaugas Vinkelis
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
#include <gmock/gmock.h>
#include "SerializationTestUtils.h"

View File

@@ -1,6 +1,25 @@
//MIT License
//
// Created by fraillt on 17.2.15.
//Copyright (c) 2017 Mindaugas Vinkelis
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
#include <gmock/gmock.h>
#include "SerializationTestUtils.h"

View File

@@ -0,0 +1,62 @@
//MIT License
//
//Copyright (c) 2017 Mindaugas Vinkelis
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
#include <gmock/gmock.h>
#include "SerializationTestUtils.h"
using testing::Eq;
bool SerializeDeserializeContainerSize(SerializationContext& ctx, const size_t size) {
std::vector<char> t1(size);
ctx.createSerializer().container(t1, [](auto ){}, size+1);
t1.clear();
ctx.createDeserializer().container(t1, [](auto ){}, size+1);
return t1.size() == size;
}
TEST(SerializeSize, WhenLengthLessThan128Then1Byte) {
SerializationContext ctx1;
EXPECT_TRUE(SerializeDeserializeContainerSize(ctx1, 127));
EXPECT_THAT(ctx1.getBufferSize(), Eq(1));
SerializationContext ctx2;
EXPECT_TRUE(SerializeDeserializeContainerSize(ctx2, 128));
EXPECT_THAT(ctx2.getBufferSize(), testing::Gt(1));
}
TEST(SerializeSize, WhenLengthLessThan16384Then2Bytes) {
SerializationContext ctx1;
EXPECT_TRUE(SerializeDeserializeContainerSize(ctx1, 16383));
EXPECT_THAT(ctx1.getBufferSize(), Eq(2));
SerializationContext ctx2;
EXPECT_TRUE(SerializeDeserializeContainerSize(ctx2, 16384));
EXPECT_THAT(ctx2.getBufferSize(), testing::Gt(2));
}
TEST(SerializeSize, WhenGreaterThan16383Then4Bytes) {
SerializationContext ctx1;
EXPECT_TRUE(SerializeDeserializeContainerSize(ctx1, 16384));
EXPECT_THAT(ctx1.getBufferSize(), Eq(4));
SerializationContext ctx2;
EXPECT_TRUE(SerializeDeserializeContainerSize(ctx2, 66384));
EXPECT_THAT(ctx2.getBufferSize(), Eq(4));
}

View File

@@ -1,6 +1,25 @@
//MIT License
//
// Created by fraillt on 17.2.20.
//Copyright (c) 2017 Mindaugas Vinkelis
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
#include <gmock/gmock.h>
#include "SerializationTestUtils.h"

View File

@@ -1,6 +1,25 @@
//MIT License
//
// Created by fraillt on 17.2.8.
//Copyright (c) 2017 Mindaugas Vinkelis
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
#ifndef BITSERY_SERIALIZERTESTS_H
#define BITSERY_SERIALIZERTESTS_H
@@ -70,6 +89,10 @@ public:
//since all containers .size() method returns size_t, it cannot be dirrectly serialized, because size_t is platform dependant
//this function returns number of bytes writen to buffer, when reading/writing size of container
static size_t containerSizeSerializedBytesCount(size_t elemsCount) {
if (elemsCount < 0x80u)
return 1;
if (elemsCount < 0x4000u)
return 2;
return 4;
}

View File

@@ -1,6 +1,25 @@
//MIT License
//
// Created by fraillt on 17.2.7.
//Copyright (c) 2017 Mindaugas Vinkelis
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
#include <gmock/gmock.h>
#include "SerializationTestUtils.h"

View File

@@ -1,6 +1,25 @@
//MIT License
//
// Created by fraillt on 17.1.31.
//Copyright (c) 2017 Mindaugas Vinkelis
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
#include <gmock/gmock.h>
#include "SerializationTestUtils.h"

View File

@@ -1,6 +1,24 @@
//MIT License
//
// Created by fraillt on 17.1.5.
//Copyright (c) 2017 Mindaugas Vinkelis
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
#include <gmock/gmock.h>
#include "SerializationTestUtils.h"
@@ -53,4 +71,3 @@ TEST(SerializeValues, ExplicitTypeSize) {
EXPECT_THAT(res, Eq(v));
EXPECT_THAT(TSIZE, Eq(ctx.getBufferSize()));
}