Fix serialization bug for TagSet

This commit is contained in:
A.J. Beamon 2020-05-02 15:58:45 -07:00
parent ca1d457c6c
commit b33871a16b
1 changed files with 9 additions and 6 deletions

View File

@ -66,15 +66,15 @@ struct dynamic_size_traits<TagSet> : std::true_type {
// May be called multiple times during one serialization
template <class Context>
static size_t size(const TagSet& t, Context&) {
return t.tags.size() + t.bytes;
return 1 + t.tags.size() + t.bytes;
}
// Guaranteed to be called only once during serialization
template <class Context>
static void save(uint8_t* out, const TagSet& t, Context&) {
*(out++) = (uint8_t)t.size();
for (const auto& tag : t.tags) {
*out = (uint8_t)tag.size();
++out;
*(out++) = (uint8_t)tag.size();
std::copy(tag.begin(), tag.end(), out);
out += tag.size();
@ -85,10 +85,11 @@ struct dynamic_size_traits<TagSet> : std::true_type {
// load call tree.
template <class Context>
static void load(const uint8_t* data, size_t size, TagSet& t, Context& context) {
const uint8_t *start = data;
const uint8_t *end = data + size;
while(data < end) {
uint8_t len = *data;
++data;
uint8_t count = *(data++);
for(uint8_t i = 0; i < count; ++i) {
uint8_t len = *(data++);
TransactionTagRef tag(context.tryReadZeroCopy(data, len), len);
data += len;
@ -96,6 +97,8 @@ struct dynamic_size_traits<TagSet> : std::true_type {
t.bytes += tag.size();
}
ASSERT(data <= end);
// Deserialized tag sets share the arena with the request that contained them
// For this reason, persisting a TagSet that shares memory with other request
// members should be done with caution.