Skip to content

Commit 02cad40

Browse files
Merge pull request #150 from martinfantini/pmap_full
Pmap full
2 parents 98bebac + 056dedb commit 02cad40

File tree

6 files changed

+76
-2
lines changed

6 files changed

+76
-2
lines changed

src/mfast/coder/encoder/fast_encoder.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ void fast_encoder_impl::visit(message_cref cref, bool force_reset) {
184184
template_instruction *instruction = *this->find(template_id);
185185

186186
if (instruction != nullptr) {
187-
current_pmap().init(&this->strm_, std::max<std::size_t>(instruction->segment_pmap_size(), 1));
187+
constexpr std::size_t template_id_bit = 1;
188+
current_pmap().init(&this->strm_, std::max<std::size_t>(instruction->segment_pmap_size() + template_id_bit, 1));
188189
} else {
189190
using namespace coder;
190191
BOOST_THROW_EXCEPTION(fast_dynamic_error("D9")

src/mfast/coder/encoder_v2/fast_encoder_core.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ void fast_encoder_core::encode_segment(const message_cref cref,
2323

2424
encoder_presence_map pmap;
2525
this->current_ = &pmap;
26-
pmap.init(&this->strm_, std::max<std::size_t>(instruction->segment_pmap_size(), 1));
26+
constexpr std::size_t template_id_bit = 1;
27+
pmap.init(&this->strm_, std::max<std::size_t>(instruction->segment_pmap_size() + template_id_bit, 1));
2728
pmap.set_next_bit(need_encode_template_id);
2829

2930
if (need_encode_template_id) {

tests/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ FASTTYPEGEN_TARGET(simple_types11 simple11.xml)
2323
FASTTYPEGEN_TARGET(simple_types12 simple12.xml)
2424
FASTTYPEGEN_TARGET(simple_types13 simple13.xml)
2525
FASTTYPEGEN_TARGET(simple_types14 simple14.xml)
26+
FASTTYPEGEN_TARGET(simple_types15 simple15.xml)
2627

2728

2829
FASTTYPEGEN_TARGET(test_types1 test1.xml test2.xml)
@@ -42,6 +43,8 @@ add_executable (mfast_test
4243
encoder_test.cpp
4344
encoder_decoder_test.cpp
4445
encoder_decoder_test_v2.cpp
46+
encoder_decoder_pmap.cpp
47+
encoder_decoder_pmap_v2.cpp
4548
field_comparator_test.cpp
4649
group_encoder_decoder_v2.cpp
4750
group_encoder_decoder.cpp
@@ -66,6 +69,7 @@ add_executable (mfast_test
6669
${FASTTYPEGEN_simple_types12_OUTPUTS}
6770
${FASTTYPEGEN_simple_types13_OUTPUTS}
6871
${FASTTYPEGEN_simple_types14_OUTPUTS}
72+
${FASTTYPEGEN_simple_types15_OUTPUTS}
6973
fast_type_gen_test.cpp
7074
dictionary_builder_test.cpp
7175
json_test.cpp

tests/encoder_decoder_pmap.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "catch.hpp"
2+
#include <mfast.h>
3+
4+
#include "fast_test_coding_case.hpp"
5+
6+
#include "simple15.h"
7+
8+
using namespace test::coding;
9+
10+
TEST_CASE("full pmap occupied encoder/decoder","[full_pmap_occupied_encoder_decoder]")
11+
{
12+
fast_test_coding_case<simple15::templates_description> test_case;
13+
14+
SECTION("encode fields")
15+
{
16+
simple15::Test_1 test_1;
17+
simple15::Test_1_mref test_1_mref = test_1.mref();
18+
test_1_mref.set_field_1_1().as(1);
19+
test_1_mref.set_field_1_2().as(2);
20+
test_1_mref.set_field_1_3().as(3);
21+
test_1_mref.set_field_1_4().as(4);
22+
test_1_mref.set_field_1_5().as(5);
23+
test_1_mref.set_field_1_6().as(6);
24+
test_1_mref.set_field_1_7().as(7);
25+
REQUIRE(test_case.encoding(test_1.cref(),"\x3F\xC0\x82\x83\x84\x85\x86\x87\x88",true));
26+
REQUIRE(test_case.decoding("\x3F\xC0\x82\x83\x84\x85\x86\x87\x88",test_1.cref(),true));
27+
}
28+
}

tests/encoder_decoder_pmap_v2.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "catch.hpp"
2+
#include <mfast.h>
3+
4+
#include "fast_test_coding_case_v2.hpp"
5+
6+
#include "simple15.h"
7+
8+
using namespace test::coding;
9+
10+
TEST_CASE("full pmap occupied encoder_v2/decoder_v2","[full_pmap_occupied_encoder_v2_decoder_v2]")
11+
{
12+
fast_test_coding_case_v2<simple15::templates_description> test_case;
13+
14+
SECTION("encode fields")
15+
{
16+
simple15::Test_1 test_1;
17+
simple15::Test_1_mref test_1_mref = test_1.mref();
18+
test_1_mref.set_field_1_1().as(1);
19+
test_1_mref.set_field_1_2().as(2);
20+
test_1_mref.set_field_1_3().as(3);
21+
test_1_mref.set_field_1_4().as(4);
22+
test_1_mref.set_field_1_5().as(5);
23+
test_1_mref.set_field_1_6().as(6);
24+
test_1_mref.set_field_1_7().as(7);
25+
REQUIRE(test_case.encoding(test_1.cref(),"\x3F\xC0\x82\x83\x84\x85\x86\x87\x88",true));
26+
REQUIRE(test_case.decoding("\x3F\xC0\x82\x83\x84\x85\x86\x87\x88",test_1.cref(),true));
27+
}
28+
}

tests/simple15.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version=\" 1.0 \"?>
2+
<templates xmlns="http://www.fixprotocol.org/ns/fast/td/1.1">
3+
<template name="Test_1" id="1">
4+
<uInt32 name="field_1_1" id="11" presence="optional"><copy/></uInt32>
5+
<uInt32 name="field_1_2" id="12" presence="optional"><copy/></uInt32>
6+
<uInt32 name="field_1_3" id="13" presence="optional"><copy/></uInt32>
7+
<uInt32 name="field_1_4" id="14" presence="optional"><copy/></uInt32>
8+
<uInt32 name="field_1_5" id="15" presence="optional"><copy/></uInt32>
9+
<uInt32 name="field_1_6" id="16" presence="optional"><copy/></uInt32>
10+
<uInt32 name="field_1_7" id="17" presence="optional"><copy/></uInt32>
11+
</template>
12+
</templates>

0 commit comments

Comments
 (0)