Skip to content

Commit 4528bd6

Browse files
Merge branch 'master' into double_free
2 parents 84f85be + 41b8deb commit 4528bd6

7 files changed

Lines changed: 83 additions & 3 deletions

File tree

src/mfast/coder/encoder/fast_encoder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ void fast_encoder_impl::visit(message_cref cref, bool force_reset) {
189189

190190
if (need_encode_template_id) {
191191
active_message_id_ = template_id;
192-
strm_.encode(active_message_id_, false, false);
192+
strm_.encode(template_id, false, false);
193193
}
194194

195195
aggregate_cref message(cref.field_storage(0), instruction);

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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ FASTTYPEGEN_TARGET(simple_types7 simple7.xml)
1919
FASTTYPEGEN_TARGET(simple_types8 simple8.xml)
2020
FASTTYPEGEN_TARGET(simple_types9 simple9.xml)
2121
FASTTYPEGEN_TARGET(simple_types10 simple10.xml)
22+
FASTTYPEGEN_TARGET(simple_types11 simple11.xml)
2223

2324

2425
FASTTYPEGEN_TARGET(test_types1 test1.xml test2.xml)
@@ -35,6 +36,7 @@ add_executable (mfast_test
3536
fast_ostream_test.cpp
3637
decoder_operator_test.cpp
3738
encoder_operator_test.cpp
39+
encoder_test.cpp
3840
field_comparator_test.cpp
3941
coder_test.cpp
4042
value_storage_test.cpp
@@ -53,6 +55,7 @@ add_executable (mfast_test
5355
${FASTTYPEGEN_simple_types8_OUTPUTS}
5456
${FASTTYPEGEN_simple_types9_OUTPUTS}
5557
${FASTTYPEGEN_simple_types10_OUTPUTS}
58+
${FASTTYPEGEN_simple_types11_OUTPUTS}
5659
fast_type_gen_test.cpp
5760
dictionary_builder_test.cpp
5861
json_test.cpp
@@ -62,6 +65,7 @@ add_executable (mfast_test
6265
simple_coder_test.cpp
6366
scp_reset_test.cpp
6467
template_repo_base.cpp
68+
message_pmap_test.cpp
6569
)
6670

6771
target_link_libraries (mfast_test

tests/encoder_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+
#include <mfast/coder/fast_encoder.h>
4+
#include <cstring>
5+
#include <stdexcept>
6+
7+
#include "simple11.h"
8+
#include "byte_stream.h"
9+
10+
TEST_CASE("test simple encoder","[test_encoder]")
11+
{
12+
mfast::fast_encoder encoder_;
13+
encoder_.include({simple11::description()});
14+
15+
const int buffer_size = 128;
16+
char buffer[buffer_size];
17+
18+
simple11::Test_1 msg;
19+
simple11::Test_1_mref msg_ref = msg.mref();
20+
21+
msg_ref.set_field1().as(1);
22+
msg_ref.set_field2().as(2);
23+
msg_ref.set_field3().as(3);
24+
25+
std::size_t encoded_size = encoder_.encode(msg_ref, buffer, buffer_size);
26+
27+
byte_stream result("\xF8\x81\x81\x82\x83");
28+
CHECK(result == byte_stream(buffer, encoded_size));
29+
}

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+
}

tests/simple11.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" ?>
2+
<templates xmlns="http://www.fixprotocol.org/ns/template-definition"
3+
templateNs="http://www.fixprotocol.org/ns/templates/sample"
4+
ns="http://www.fixprotocol.org/ns/fix">
5+
<template name="Test_1" id="1">
6+
<uInt32 name="field1" id="11"><copy/></uInt32>
7+
<uInt32 name="field2" id="12"><copy/></uInt32>
8+
<uInt32 name="field3" id="13"><copy/></uInt32>
9+
</template>
10+
<template name="Test_2" id="2">
11+
<uInt32 name="field4" id="21"><copy/></uInt32>
12+
<uInt32 name="field5" id="22"><copy/></uInt32>
13+
<uInt32 name="field6" id="23"><copy/></uInt32>
14+
</template>
15+
</templates>

0 commit comments

Comments
 (0)