From db884a0656a3aabb87da1ae6edf12629507f76a7 Mon Sep 17 00:00:00 2001 From: Mindaugas Vinkelis Date: Tue, 10 Nov 2020 08:28:41 +0200 Subject: [PATCH] release v5.2.1 BufferAdapter statically assert on underlying type size bugfix in StdBitset --- CHANGELOG.md | 8 ++++++++ CMakeLists.txt | 2 +- CONTRIBUTING.md | 4 ++-- include/bitsery/adapter/buffer.h | 2 ++ include/bitsery/bitsery.h | 2 +- include/bitsery/ext/std_bitset.h | 2 +- tests/serialization_ext_std_bitset.cpp | 9 +++++++-- 7 files changed, 22 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a1d79f..2a0e732 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +# [5.2.1](https://github.com/fraillt/bitsery/compare/v5.2.0...v5.2.1) (2020-11-14) + +### Improvements +* `Input/OutputBufferAdapter` now statically asserts that underlying type is 1byte in size. + +### Bug fixes +* fixed serialization in `StdBitset` when it's size is less then `unsigned long long`. + # [5.2.0](https://github.com/fraillt/bitsery/compare/v5.1.0...v5.2.0) (2020-11-09) ### Features diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ea1f96..37e2bf1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.1) project(bitsery LANGUAGES CXX - VERSION 5.2.0) + VERSION 5.2.1) #======== build options =================================== option(BITSERY_BUILD_EXAMPLES "Build examples" OFF) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 01523df..77cc8d3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,7 +6,7 @@ However, to make sure the process of accepting patches goes smoothly, you should you contribute: 1. Fork the repository. -2. Create new branch based on the *master* branch (`git checkout -b your_branch master`). If your contribution is a bug fix, you should name your branch `bugfix/xxx`; for a feature, it should be `feature/xxx`. Otherwise, just use your good judgment. Consistent naming of branches is appreciated since it makes the output of `git branch` easier to understand with a single glance. +2. Create new branch based on the *develop* branch (`git checkout -b your_branch develop`). If your contribution is a bug fix, you should name your branch `bugfix/xxx`; for a feature, it should be `feature/xxx`. Otherwise, just use your good judgment. Consistent naming of branches is appreciated since it makes the output of `git branch` easier to understand with a single glance. 3. Do your modifications on that branch. Except for special cases, your contribution should include proper unit tests and documentation. 4. Make sure your modifications did not break anything by building, running tests: ```shell @@ -23,7 +23,7 @@ you contribute: ./show_coverage.sh build ``` 5. Commit your changes, and push to your fork (`git push origin your_branch`). Commit message should be one line short description. When applicable, please squash adjacent *wip* commits into a single *logical* commit. -6. Open a pull request against Bitsery *master* branch. Currently ongoing development is on *master*. At some point an integration branch will be set-up, and pull-requests should target that, but for now its all against master. You may see feature branches come and go, too. +6. Open a pull request against Bitsery *develop* branch. If you're working with visual studio, there is how to build and run all tests from command line diff --git a/include/bitsery/adapter/buffer.h b/include/bitsery/adapter/buffer.h index ffe428f..4f5e8c6 100644 --- a/include/bitsery/adapter/buffer.h +++ b/include/bitsery/adapter/buffer.h @@ -39,6 +39,7 @@ namespace bitsery { "Please define BufferAdapterTraits or include from "); static_assert(traits::ContainerTraits::type>::isContiguous, "BufferAdapter only works with contiguous containers"); + static_assert(sizeof(TValue) == 1, "BufferAdapter underlying type must be 1byte."); InputBufferAdapter(TIterator beginIt, size_t size) : _beginIt{beginIt}, @@ -196,6 +197,7 @@ namespace bitsery { "Please define BufferAdapterTraits or include from "); static_assert(traits::ContainerTraits::isContiguous, "BufferAdapter only works with contiguous containers"); + static_assert(sizeof(TValue) == 1, "BufferAdapter underlying type must be 1byte."); OutputBufferAdapter(Buffer &buffer) : _buffer{std::addressof(buffer)}, diff --git a/include/bitsery/bitsery.h b/include/bitsery/bitsery.h index b33b0fd..79823ff 100644 --- a/include/bitsery/bitsery.h +++ b/include/bitsery/bitsery.h @@ -26,7 +26,7 @@ #define BITSERY_MAJOR_VERSION 5 #define BITSERY_MINOR_VERSION 2 -#define BITSERY_PATCH_VERSION 0 +#define BITSERY_PATCH_VERSION 1 #define BITSERY_QUOTE_MACRO(name) #name #define BITSERY_BUILD_VERSION_STR(major,minor, patch) \ diff --git a/include/bitsery/ext/std_bitset.h b/include/bitsery/ext/std_bitset.h index 7a5194e..6b83946 100644 --- a/include/bitsery/ext/std_bitset.h +++ b/include/bitsery/ext/std_bitset.h @@ -55,7 +55,7 @@ namespace bitsery { auto data = obj.to_ullong(); for(size_t i = 0u; i < BYTES; ++i) { ser.value1b(static_cast(data & 0xFF)); - data >>= 1; + data >>= 8; } } if (LEFTOVER > 0) { diff --git a/tests/serialization_ext_std_bitset.cpp b/tests/serialization_ext_std_bitset.cpp index d14432a..9d687a1 100644 --- a/tests/serialization_ext_std_bitset.cpp +++ b/tests/serialization_ext_std_bitset.cpp @@ -34,10 +34,13 @@ using testing::Eq; TEST(SerializeExtensionStdBitset, BitsetSmallerThanULongLong) { SerializationContext ctx; - std::bitset<9> data; + std::bitset<31> data; data[2] = true; data[8] = true; - std::bitset<9> res; + data[15] = true; + data[25] = true; + data[30] = true; + std::bitset<31> res; ctx.createSerializer().ext(data, StdBitset{}); ctx.createDeserializer().ext(res, StdBitset{}); @@ -62,6 +65,8 @@ TEST(SerializeExtensionStdBitset, BitsetLargerThanULongLong) { std::bitset<200> data; data[1] = true; + data[31] = true; + data[63] = true; data[100] = true; data[191] = true; std::bitset<200> res;