Skip to content

Commit 41b8deb

Browse files
Merge pull request #137 from martinfantini/pmap_calculation
Correct Pmap calculation for the template id and group types
2 parents 3e00da0 + a8c91cc commit 41b8deb

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

src/mfast/instructions/field_instruction.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ class MFAST_EXPORT field_instruction {
165165
virtual void update_invariant() {
166166
nullable_flag_ = optional_flag_ && (operator_id_ != operator_constant);
167167
has_pmap_bit_ = operator_id_ > operator_delta ||
168-
((operator_id_ == operator_constant) && optional_flag_);
168+
((operator_id_ == operator_constant) && optional_flag_)||
169+
(field_type_ == field_type_group && optional_flag_);
169170
}
170171

171172
// uint16_t field_index_;
@@ -208,7 +209,8 @@ inline field_instruction::field_instruction(operator_enum_t operator_id,
208209
optional_flag_(optional),
209210
nullable_flag_(optional && (operator_id != operator_constant)),
210211
has_pmap_bit_(operator_id > operator_delta ||
211-
((operator_id == operator_constant) && optional)),
212+
((operator_id == operator_constant) && optional) ||
213+
(field_type == field_type_group && optional)),
212214
has_initial_value_(false), field_type_(field_type),
213215
previous_value_shared_(false), id_(id), name_(name), ns_(ns),
214216
tag_(std::move(tag)) {}

src/mfast/instructions/template_instruction.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class MFAST_EXPORT template_instruction : public group_field_instruction {
2222
cpp_ns, tag),
2323
template_ns_(template_ns), reset_(reset) {
2424
field_type_ = field_type_template;
25+
segment_pmap_size_++; // Add one to the template id bit
2526
}
2627

2728
const char *template_ns() const { return template_ns_; }

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ add_executable (mfast_test
6464
aggregate_view_test.cpp
6565
simple_coder_test.cpp
6666
scp_reset_test.cpp
67+
message_pmap_test.cpp
6768
)
6869

6970
target_link_libraries (mfast_test

tests/message_pmap_test.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "catch.hpp"
2+
#include <mfast.h>
3+
4+
#include "simple1.h"
5+
#include "simple2.h"
6+
7+
TEST_CASE("test message pmap message number of bits of a field message content","[message_pmap_number_bits_field]")
8+
{
9+
simple1::Test msg;
10+
simple1::Test_mref msg_ref = msg.mref();
11+
12+
msg_ref.set_field1().as(1);
13+
msg_ref.set_field2().as(2);
14+
msg_ref.set_field3().as(3);
15+
16+
CHECK(msg.instruction()->segment_pmap_size() == 4);
17+
}
18+
19+
TEST_CASE("test message pmap message number of bits of a field and group message content","[message_pmap_number_bits_group]")
20+
{
21+
simple2::Test msg;
22+
simple2::Test_mref msg_ref = msg.mref();
23+
24+
msg_ref.set_field1().as(1);
25+
msg_ref.set_group1().set_field2().as(2);
26+
msg_ref.set_group1().set_field3().as(3);
27+
28+
CHECK(msg.instruction()->segment_pmap_size() == 3);
29+
}

0 commit comments

Comments
 (0)