Skip to content

Commit ea4ba5a

Browse files
Merge pull request #67 from RewritableJ/fix_absent_optional_fields
Fix #65. Add test case for the issue.
2 parents 94f42de + f38b350 commit ea4ba5a

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/mfast/coder/encoder/fast_encoder.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ inline void fast_encoder_impl::visit(group_cref cref, int) {
117117
// apply_accessor(*this, field);;
118118

119119
for (auto &&field : aggregate_cref(cref)) {
120-
if (field.present())
121120
apply_accessor(*this, field);
122121
}
123122

@@ -154,7 +153,6 @@ inline void fast_encoder_impl::visit(sequence_element_cref cref, int) {
154153
}
155154

156155
for (auto &&field : cref) {
157-
if (field.present())
158156
apply_accessor(*this, field);
159157
}
160158
commit_pmap(state);

tests/coder_test.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,42 @@ TEST_CASE("test fast coder without code generation for a simple template with se
179179

180180
}
181181

182+
TEST_CASE("test fast coder without code generation for a simple template with absent optiona fields in a sequence","[absent_optional_fields_coder_test]")
183+
{
184+
fast_coding_test_case test_case (
185+
"<?xml version=\" 1.0 \"?>\n"
186+
"<templates xmlns=\"http://www.fixprotocol.org/ns/template-definition\" "
187+
"templateNs=\"http://www.fixprotocol.org/ns/templates/sample\" ns=\"http://www.fixprotocol.org/ns/fix\">\n"
188+
"<template name=\"Test\" id=\"1\">\n"
189+
"<uInt32 name=\"field1\" id=\"11\"><copy/></uInt32>\n"
190+
"<sequence name=\"sequence1\" presence=\"optional\">"
191+
"<uInt32 name=\"field2\" id=\"12\" presence=\"optional\"></uInt32>\n"
192+
"<uInt32 name=\"field3\" id=\"13\" presence=\"optional\"></uInt32>\n"
193+
"</sequence>"
194+
"</template>\n"
195+
"</templates>\n");
196+
197+
debug_allocator alloc;
198+
message_type msg(&alloc, test_case.template_with_id(1));
199+
message_mref msg_ref = msg.mref();
200+
201+
msg_ref[0].as(1);
202+
sequence_mref seq(msg_ref[1]);
203+
seq.resize(2);
204+
205+
seq[0][1].as(3);
206+
207+
seq[1][0].as(1);
208+
209+
REQUIRE(test_case.encoding(msg_ref,
210+
// pmap | f1 | s1 len| f2 | f3 | f2 | f3 |
211+
// A0 81 83 80 84 82 80
212+
"\xA0\x81\x83\x80\x84\x82\x80"
213+
));
214+
REQUIRE(test_case.decoding("\xA0\x81\x83\x80\x84\x82\x80", msg_ref));
215+
216+
}
217+
182218
TEST_CASE("test fast coder without code generation for a simple template with static templateref","[static_templateref_coder_test]")
183219
{
184220
fast_coding_test_case test_case (

0 commit comments

Comments
 (0)