diff --git a/src/mfast/coder/encoder_v2/fast_encoder_core.h b/src/mfast/coder/encoder_v2/fast_encoder_core.h index b90d169d..6a706c3a 100644 --- a/src/mfast/coder/encoder_v2/fast_encoder_core.h +++ b/src/mfast/coder/encoder_v2/fast_encoder_core.h @@ -2,6 +2,7 @@ #include "../mfast_coder_export.h" #include "../../sequence_ref.h" +#include "../../enum_ref.h" #include "../../nested_message_ref.h" #include "../../malloc_allocator.h" #include "../common/template_repo.h" @@ -31,6 +32,11 @@ inline bool equivalent(const decimal_cref &v, const value_storage &prev) { v.exponent() == prev.of_decimal.exponent_; } +inline bool equivalent(const enum_cref &v, const value_storage &prev) { + return v.absent() == prev.is_empty() && + v.value() == prev.of_uint64.content_; +} + template inline bool equivalent(const vector_cref &v, const value_storage &prev) { return v.size() == prev.of_array.len_ - 1 && diff --git a/src/mfast/enum_ref.h b/src/mfast/enum_ref.h index e12f763c..33e7ab15 100644 --- a/src/mfast/enum_ref.h +++ b/src/mfast/enum_ref.h @@ -97,6 +97,11 @@ class enum_mref : public make_field_mref { *this->storage() = this->instruction()->initial_value(); } value_type value() const { return this->storage()->get(); } + +protected: + friend class mfast::detail::codec_helper; + + void copy_from(value_storage v) const { *this->storage() = v; } }; template <> struct mref_of { typedef enum_mref type; }; diff --git a/tests/enum_encoder_decoder.cpp b/tests/enum_encoder_decoder.cpp index 9e89d59f..e8a0ca8f 100644 --- a/tests/enum_encoder_decoder.cpp +++ b/tests/enum_encoder_decoder.cpp @@ -17,3 +17,13 @@ TEST_CASE("enum test encoder/decoder","[enum_encoder_decoder]") REQUIRE(test_case.encoding(test_1.cref(),"\xC0\x81\x83",true)); REQUIRE(test_case.decoding("\xC0\x81\x83",test_1.cref(),true)); } + +TEST_CASE("enum test copy encoder/decoder","[enum_copy_encoder_decoder]") +{ + fast_test_coding_case test_case; + simple16::Test_3 test_3; + simple16::Test_3_mref test_3_mref = test_3.mref(); + test_3_mref.set_discrete().as_Three(); + REQUIRE(test_case.encoding(test_3.cref(),"\xE0\x83\x83",true)); + REQUIRE(test_case.decoding("\xE0\x83\x83",test_3.cref(),true)); +} diff --git a/tests/enum_encoder_decoder_v2.cpp b/tests/enum_encoder_decoder_v2.cpp index 281a041a..0643b6c2 100644 --- a/tests/enum_encoder_decoder_v2.cpp +++ b/tests/enum_encoder_decoder_v2.cpp @@ -17,3 +17,13 @@ TEST_CASE("enum test encoder_V2/decoder_v2","[enum_encoder_v2_decoder_v2]") REQUIRE(test_case.encoding(test_1.cref(),"\xC0\x81\x83",true)); REQUIRE(test_case.decoding("\xC0\x81\x83",test_1.cref(),true)); } + +TEST_CASE("enum test copy encoder_V2/decoder_v2","[enum_copy_encoder_v2_decoder_v2]") +{ + fast_test_coding_case_v2 test_case; + simple16::Test_3 test_3; + simple16::Test_3_mref test_3_mref = test_3.mref(); + test_3_mref.set_discrete().as_Three(); + REQUIRE(test_case.encoding(test_3.cref(),"\xE0\x83\x83",true)); + REQUIRE(test_case.decoding("\xE0\x83\x83",test_3.cref(),true)); +} diff --git a/tests/simple16.xml b/tests/simple16.xml index e32fafc2..cb8207cd 100644 --- a/tests/simple16.xml +++ b/tests/simple16.xml @@ -18,4 +18,8 @@ +