mirror of
https://github.com/scylladb/scylladb.git
synced 2026-05-12 19:02:12 +00:00
types: collection: add versions of pack for fragmented buffers
We will need them to port the representation of collection types in cql3/ from bytes to managed_bytes. The version which takes an iterator of `bytes` as an argument will be removed after that transition is complete.
This commit is contained in:
@@ -52,8 +52,18 @@ public:
|
||||
lw_shared_ptr<cql3::column_specification> make_collection_receiver(const cql3::column_specification& collection, bool is_key) const;
|
||||
virtual bool is_compatible_with_frozen(const collection_type_impl& previous) const = 0;
|
||||
virtual bool is_value_compatible_with_frozen(const collection_type_impl& previous) const = 0;
|
||||
template <typename BytesViewIterator>
|
||||
static bytes pack(BytesViewIterator start, BytesViewIterator finish, int elements, cql_serialization_format sf);
|
||||
|
||||
template <typename Iterator>
|
||||
requires requires (Iterator it) { {*it} -> std::convertible_to<bytes_view>; }
|
||||
static bytes pack(Iterator start, Iterator finish, int elements, cql_serialization_format sf);
|
||||
|
||||
template <typename Iterator>
|
||||
requires requires (Iterator it) { {*it} -> std::convertible_to<bytes_view>; }
|
||||
static managed_bytes pack_fragmented(Iterator start, Iterator finish, int elements, cql_serialization_format sf);
|
||||
|
||||
template <typename Iterator>
|
||||
requires requires (Iterator it) { {*it} -> std::convertible_to<managed_bytes_view>; }
|
||||
static managed_bytes pack_fragmented(Iterator start, Iterator finish, int elements, cql_serialization_format sf);
|
||||
|
||||
private:
|
||||
// Explicitly instantiated in types.cc
|
||||
@@ -104,9 +114,10 @@ public:
|
||||
bytes serialize_map(const map_type_impl& map_type, const data_value& value) const;
|
||||
};
|
||||
|
||||
template <typename BytesViewIterator>
|
||||
template <typename Iterator>
|
||||
requires requires (Iterator it) { {*it} -> std::convertible_to<bytes_view>; }
|
||||
bytes
|
||||
collection_type_impl::pack(BytesViewIterator start, BytesViewIterator finish, int elements, cql_serialization_format sf) {
|
||||
collection_type_impl::pack(Iterator start, Iterator finish, int elements, cql_serialization_format sf) {
|
||||
size_t len = collection_size_len(sf);
|
||||
size_t psz = collection_value_len(sf);
|
||||
for (auto j = start; j != finish; j++) {
|
||||
@@ -120,3 +131,40 @@ collection_type_impl::pack(BytesViewIterator start, BytesViewIterator finish, in
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// TODO: remove after all collections types in cql3/ are converted to managed_bytes
|
||||
template <typename Iterator>
|
||||
requires requires (Iterator it) { {*it} -> std::convertible_to<bytes_view>; }
|
||||
managed_bytes
|
||||
collection_type_impl::pack_fragmented(Iterator start, Iterator finish, int elements, cql_serialization_format sf) {
|
||||
size_t len = collection_size_len(sf);
|
||||
size_t psz = collection_value_len(sf);
|
||||
for (auto j = start; j != finish; j++) {
|
||||
len += j->size() + psz;
|
||||
}
|
||||
managed_bytes out(managed_bytes::initialized_later(), len);
|
||||
managed_bytes_mutable_view v(out);
|
||||
write_collection_size(v, elements, sf);
|
||||
while (start != finish) {
|
||||
write_collection_value(v, sf, *start++);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
template <typename Iterator>
|
||||
requires requires (Iterator it) { {*it} -> std::convertible_to<managed_bytes_view>; }
|
||||
managed_bytes
|
||||
collection_type_impl::pack_fragmented(Iterator start, Iterator finish, int elements, cql_serialization_format sf) {
|
||||
size_t len = collection_size_len(sf);
|
||||
size_t psz = collection_value_len(sf);
|
||||
for (auto j = start; j != finish; j++) {
|
||||
len += j->size() + psz;
|
||||
}
|
||||
managed_bytes out(managed_bytes::initialized_later(), len);
|
||||
managed_bytes_mutable_view v(out);
|
||||
write_collection_size(v, elements, sf);
|
||||
while (start != finish) {
|
||||
write_collection_value(v, sf, *start++);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user