Skip to content

Commit 3e00da0

Browse files
Merge pull request #136 from martinfantini/00_by_encodeing
00 by encoding
2 parents bb197b2 + c881d17 commit 3e00da0

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

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);

tests/CMakeLists.txt

Lines changed: 3 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

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/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)