//#include "../SerializeValuesByName.h" #include "Marshal.h" #include "MarshalValuesByName.h" void marshal(std::string &destination, Parse::ValuesByName const &source) { std::vector< std::string const & > names; names.reserve(destination.size()); FieldId i = 0; RecordBuilder rb for (auto const &kvp : source) { names.emplace_back(kvp.first); kvp.second.appendTo(rb, i); i++; } marshal(destination, names); const bool hasData = !rb.empty(); // There are some issues trying to read a record with 0 non-null fields. // Better to just avoid it. marshal(hasData); if (hasData) { const size_t sizeGoesHere = destination.size(); destination.resize(sizeGoesHere + 3); rb.exportAndAppend(destination); size_t sizeOfRecord = destination - sizeGoesHere - 3; assert(sizeOfRecord < 0x1000000); // Fits in the 3 bytes we've allocated. // static_assert(little endian) memcpy(&destination[sizeGoesHere], &sizeOfRecord, 3); } /* RecordBuilder rb; SerializeRecords serializer; serializer.loadNames(rb, source); serializer.go(rb, source); marshal(destination, rb.exportAsString()); */ }