diff --git a/src/mfast/coder/encoder/fast_encoder.cpp b/src/mfast/coder/encoder/fast_encoder.cpp index 27257ac5..7515d18e 100644 --- a/src/mfast/coder/encoder/fast_encoder.cpp +++ b/src/mfast/coder/encoder/fast_encoder.cpp @@ -174,7 +174,8 @@ void fast_encoder_impl::visit(message_cref cref, bool force_reset) { template_instruction *instruction = *this->find(template_id); if (instruction != nullptr) { - current_pmap().init(&this->strm_, std::max(instruction->segment_pmap_size(), 1)); + constexpr std::size_t template_id_bit = 1; + current_pmap().init(&this->strm_, std::max(instruction->segment_pmap_size() + template_id_bit, 1)); } else { using namespace coder; BOOST_THROW_EXCEPTION(fast_dynamic_error("D9") diff --git a/src/mfast/coder/encoder_v2/fast_encoder_core.cpp b/src/mfast/coder/encoder_v2/fast_encoder_core.cpp index ffefc0b7..71be2ccd 100644 --- a/src/mfast/coder/encoder_v2/fast_encoder_core.cpp +++ b/src/mfast/coder/encoder_v2/fast_encoder_core.cpp @@ -23,7 +23,8 @@ void fast_encoder_core::encode_segment(const message_cref cref, encoder_presence_map pmap; this->current_ = &pmap; - pmap.init(&this->strm_, std::max(instruction->segment_pmap_size(), 1)); + constexpr std::size_t template_id_bit = 1; + pmap.init(&this->strm_, std::max(instruction->segment_pmap_size() + template_id_bit, 1)); pmap.set_next_bit(need_encode_template_id); if (need_encode_template_id) { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index fb9d29bc..8e70caf8 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -23,6 +23,7 @@ FASTTYPEGEN_TARGET(simple_types11 simple11.xml) FASTTYPEGEN_TARGET(simple_types12 simple12.xml) FASTTYPEGEN_TARGET(simple_types13 simple13.xml) FASTTYPEGEN_TARGET(simple_types14 simple14.xml) +FASTTYPEGEN_TARGET(simple_types15 simple15.xml) FASTTYPEGEN_TARGET(test_types1 test1.xml test2.xml) @@ -42,6 +43,8 @@ add_executable (mfast_test encoder_test.cpp encoder_decoder_test.cpp encoder_decoder_test_v2.cpp + encoder_decoder_pmap.cpp + encoder_decoder_pmap_v2.cpp field_comparator_test.cpp group_encoder_decoder_v2.cpp group_encoder_decoder.cpp @@ -66,6 +69,7 @@ add_executable (mfast_test ${FASTTYPEGEN_simple_types12_OUTPUTS} ${FASTTYPEGEN_simple_types13_OUTPUTS} ${FASTTYPEGEN_simple_types14_OUTPUTS} + ${FASTTYPEGEN_simple_types15_OUTPUTS} fast_type_gen_test.cpp dictionary_builder_test.cpp json_test.cpp diff --git a/tests/encoder_decoder_pmap.cpp b/tests/encoder_decoder_pmap.cpp new file mode 100644 index 00000000..4dfc0ed1 --- /dev/null +++ b/tests/encoder_decoder_pmap.cpp @@ -0,0 +1,28 @@ +#include "catch.hpp" +#include + +#include "fast_test_coding_case.hpp" + +#include "simple15.h" + +using namespace test::coding; + +TEST_CASE("full pmap occupied encoder/decoder","[full_pmap_occupied_encoder_decoder]") +{ + fast_test_coding_case test_case; + + SECTION("encode fields") + { + simple15::Test_1 test_1; + simple15::Test_1_mref test_1_mref = test_1.mref(); + test_1_mref.set_field_1_1().as(1); + test_1_mref.set_field_1_2().as(2); + test_1_mref.set_field_1_3().as(3); + test_1_mref.set_field_1_4().as(4); + test_1_mref.set_field_1_5().as(5); + test_1_mref.set_field_1_6().as(6); + test_1_mref.set_field_1_7().as(7); + REQUIRE(test_case.encoding(test_1.cref(),"\x3F\xC0\x82\x83\x84\x85\x86\x87\x88",true)); + REQUIRE(test_case.decoding("\x3F\xC0\x82\x83\x84\x85\x86\x87\x88",test_1.cref(),true)); + } +} diff --git a/tests/encoder_decoder_pmap_v2.cpp b/tests/encoder_decoder_pmap_v2.cpp new file mode 100644 index 00000000..28075160 --- /dev/null +++ b/tests/encoder_decoder_pmap_v2.cpp @@ -0,0 +1,28 @@ +#include "catch.hpp" +#include + +#include "fast_test_coding_case_v2.hpp" + +#include "simple15.h" + +using namespace test::coding; + +TEST_CASE("full pmap occupied encoder_v2/decoder_v2","[full_pmap_occupied_encoder_v2_decoder_v2]") +{ + fast_test_coding_case_v2 test_case; + + SECTION("encode fields") + { + simple15::Test_1 test_1; + simple15::Test_1_mref test_1_mref = test_1.mref(); + test_1_mref.set_field_1_1().as(1); + test_1_mref.set_field_1_2().as(2); + test_1_mref.set_field_1_3().as(3); + test_1_mref.set_field_1_4().as(4); + test_1_mref.set_field_1_5().as(5); + test_1_mref.set_field_1_6().as(6); + test_1_mref.set_field_1_7().as(7); + REQUIRE(test_case.encoding(test_1.cref(),"\x3F\xC0\x82\x83\x84\x85\x86\x87\x88",true)); + REQUIRE(test_case.decoding("\x3F\xC0\x82\x83\x84\x85\x86\x87\x88",test_1.cref(),true)); + } +} diff --git a/tests/simple15.xml b/tests/simple15.xml new file mode 100644 index 00000000..ce387869 --- /dev/null +++ b/tests/simple15.xml @@ -0,0 +1,12 @@ + + + +