types: switch serialize_for_cql from bytes to bytes_ostream

Now we can serialize collections from collection_mutation_view_description
without linearizations.
This commit is contained in:
Michał Chojnowski
2020-12-04 16:03:47 +01:00
parent 81a55b032d
commit d43fd456cd
5 changed files with 9 additions and 10 deletions

View File

@@ -136,4 +136,4 @@ collection_mutation merge(const abstract_type&, collection_mutation_view, collec
collection_mutation difference(const abstract_type&, collection_mutation_view, collection_mutation_view);
// Serializes the given collection of cells to a sequence of bytes ready to be sent over the CQL protocol.
bytes serialize_for_cql(const abstract_type&, collection_mutation_view, cql_serialization_format);
bytes_ostream serialize_for_cql(const abstract_type&, collection_mutation_view, cql_serialization_format);

View File

@@ -704,7 +704,7 @@ void write_cell(RowWriter& w, const query::partition_slice& slice, data_type typ
w.add().write().skip_timestamp()
.skip_expiry()
.write_value(serialize_for_cql(*type, std::move(v), slice.cql_format()))
.write_fragmented_value(serialize_for_cql(*type, std::move(v), slice.cql_format()))
.skip_ttl()
.end_qr_cell();
}

View File

@@ -543,10 +543,9 @@ struct serializer<bytes> {
requires FragmentRange<FragmentedBuffer>
static void write_fragmented(Output& out, FragmentedBuffer&& fragments) {
safe_serialize_as_uint32(out, uint32_t(fragments.size_bytes()));
using boost::range::for_each;
for_each(fragments, [&out] (bytes_view frag) {
for (bytes_view frag : fragments) {
out.write(reinterpret_cast<const char*>(frag.begin()), frag.size());
});
}
}
template<typename Input>
static void skip(Input& in) {

View File

@@ -296,8 +296,8 @@ public:
assert(c.is_live());
actual = c.value().linearize();
} else {
actual = serialize_for_cql(*col_def->type,
cell->as_collection_mutation(), cql_serialization_format::internal());
actual = linearized(serialize_for_cql(*col_def->type,
cell->as_collection_mutation(), cql_serialization_format::internal()));
}
assert(col_def->type->equal(actual, exp));
});

View File

@@ -3123,10 +3123,10 @@ static bytes_ostream serialize_for_cql_aux(const user_type_impl& type, collectio
return out;
}
bytes serialize_for_cql(const abstract_type& type, collection_mutation_view v, cql_serialization_format sf) {
bytes_ostream serialize_for_cql(const abstract_type& type, collection_mutation_view v, cql_serialization_format sf) {
assert(type.is_multi_cell());
return linearized(v.with_deserialized(type, [&] (collection_mutation_view_description mv) {
return v.with_deserialized(type, [&] (collection_mutation_view_description mv) {
return visit(type, make_visitor(
[&] (const map_type_impl& ctype) { return serialize_for_cql_aux(ctype, std::move(mv), sf); },
[&] (const set_type_impl& ctype) { return serialize_for_cql_aux(ctype, std::move(mv), sf); },
@@ -3136,7 +3136,7 @@ bytes serialize_for_cql(const abstract_type& type, collection_mutation_view v, c
throw std::runtime_error(format("attempted to serialize a collection of cells with type: {}", o.name()));
}
));
}));
});
}
bytes serialize_field_index(size_t idx) {