From ed6fa0bd1a11f87043cd984e98db25bacea7e3d4 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Mon, 19 Jul 2021 12:44:29 -0700 Subject: [PATCH] fix encoding of (Sub)Struct w/ valid set --- src/dataencode.cpp | 13 ++++-- test/testxcode.cpp | 100 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 108 insertions(+), 5 deletions(-) diff --git a/src/dataencode.cpp b/src/dataencode.cpp index 4301418..ad85ff4 100644 --- a/src/dataencode.cpp +++ b/src/dataencode.cpp @@ -229,9 +229,10 @@ void to_wire_field(Buffer& buf, const FieldDesc* desc, const std::shared_ptrsize())) { auto cdesc = desc + off; + if(cdesc->code==TypeCode::Struct) // skip sub-struct nodes. Would be redundant + continue; std::shared_ptr cstore(store, store.get()+off); // TODO avoid shared_ptr/aliasing here - if(cdesc->code!=TypeCode::Struct) - to_wire_field(buf, cdesc, cstore); + to_wire_field(buf, cdesc, cstore); } } return; @@ -428,9 +429,13 @@ void to_wire_valid(Buffer& buf, const Value& val, const BitMask* mask) BitMask valid(desc->size()); - for(auto bit : range(desc->size())) { - if((store.get()+bit)->valid && (!mask || (*mask)[bit])) + for(size_t bit=0u, N=desc->size(); bit(), 0x700000f6u); + std::vector actual_payload; + testToBytes(false, [&payload](Buffer& buf) { + to_wire_valid(buf, payload); + testOk1(buf.good()); + }, reencoded_value); +} + // test the common case for a pvRequest of caching an empty Struct void testEmptyRequest() { @@ -983,7 +1080,7 @@ void testEmptyRequest() MAIN(testxcode) { - testPlan(122); + testPlan(129); testSetup(); testDeserializeString(); testSerialize1(); @@ -996,6 +1093,7 @@ MAIN(testxcode) testArrayXCode(); testXCodeNTScalar(); testXCodeNTNDArray(); + testRegressRedundantBitMask(); testEmptyRequest(); return testDone(); }