From 249250f5275c558c3b153deaa79f269dd161b408 Mon Sep 17 00:00:00 2001 From: Roberto Martin Fantini Date: Mon, 24 Feb 2025 15:37:24 +0100 Subject: [PATCH 1/2] Use template_id, bacause it is uint32_t and it will not add 0x00 at the begining --- src/mfast/coder/encoder/fast_encoder.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mfast/coder/encoder/fast_encoder.cpp b/src/mfast/coder/encoder/fast_encoder.cpp index 35b22057..e7f06163 100644 --- a/src/mfast/coder/encoder/fast_encoder.cpp +++ b/src/mfast/coder/encoder/fast_encoder.cpp @@ -189,7 +189,7 @@ void fast_encoder_impl::visit(message_cref cref, bool force_reset) { if (need_encode_template_id) { active_message_id_ = template_id; - strm_.encode(active_message_id_, false, false); + strm_.encode(template_id, false, false); } aggregate_cref message(cref.field_storage(0), instruction); From c881d17917cdce854cb3f5a62a1f41c78946d687 Mon Sep 17 00:00:00 2001 From: Roberto Martin Fantini Date: Mon, 24 Feb 2025 15:55:17 +0100 Subject: [PATCH 2/2] Add unit test for the simple encode --- tests/CMakeLists.txt | 3 +++ tests/encoder_test.cpp | 29 +++++++++++++++++++++++++++++ tests/simple11.xml | 15 +++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 tests/encoder_test.cpp create mode 100644 tests/simple11.xml diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2859a552..1b5b3439 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -19,6 +19,7 @@ FASTTYPEGEN_TARGET(simple_types7 simple7.xml) FASTTYPEGEN_TARGET(simple_types8 simple8.xml) FASTTYPEGEN_TARGET(simple_types9 simple9.xml) FASTTYPEGEN_TARGET(simple_types10 simple10.xml) +FASTTYPEGEN_TARGET(simple_types11 simple11.xml) FASTTYPEGEN_TARGET(test_types1 test1.xml test2.xml) @@ -35,6 +36,7 @@ add_executable (mfast_test fast_ostream_test.cpp decoder_operator_test.cpp encoder_operator_test.cpp + encoder_test.cpp field_comparator_test.cpp coder_test.cpp value_storage_test.cpp @@ -53,6 +55,7 @@ add_executable (mfast_test ${FASTTYPEGEN_simple_types8_OUTPUTS} ${FASTTYPEGEN_simple_types9_OUTPUTS} ${FASTTYPEGEN_simple_types10_OUTPUTS} + ${FASTTYPEGEN_simple_types11_OUTPUTS} fast_type_gen_test.cpp dictionary_builder_test.cpp json_test.cpp diff --git a/tests/encoder_test.cpp b/tests/encoder_test.cpp new file mode 100644 index 00000000..add40124 --- /dev/null +++ b/tests/encoder_test.cpp @@ -0,0 +1,29 @@ +#include "catch.hpp" +#include +#include +#include +#include + +#include "simple11.h" +#include "byte_stream.h" + +TEST_CASE("test simple encoder","[test_encoder]") +{ + mfast::fast_encoder encoder_; + encoder_.include({simple11::description()}); + + const int buffer_size = 128; + char buffer[buffer_size]; + + simple11::Test_1 msg; + simple11::Test_1_mref msg_ref = msg.mref(); + + msg_ref.set_field1().as(1); + msg_ref.set_field2().as(2); + msg_ref.set_field3().as(3); + + std::size_t encoded_size = encoder_.encode(msg_ref, buffer, buffer_size); + + byte_stream result("\xF8\x81\x81\x82\x83"); + CHECK(result == byte_stream(buffer, encoded_size)); +} diff --git a/tests/simple11.xml b/tests/simple11.xml new file mode 100644 index 00000000..430d33a1 --- /dev/null +++ b/tests/simple11.xml @@ -0,0 +1,15 @@ + + + + +