Skip to content

Commit

Permalink
types: switch deserialize from bytes_view to FragmentedView
Browse files Browse the repository at this point in the history
The final part of the transition of deserialize from bytes_view to
FragmentedView.
Adds a FragmentedView overload to abstract_type::deserialize and
switches deserialize_visitor from bytes_view to FragmentedView, allowing
deserialization of all types with no intermediate linearization.
  • Loading branch information
michoecho committed Nov 24, 2020
1 parent 63ef1f6 commit 3d07611
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
19 changes: 13 additions & 6 deletions types.cc
Expand Up @@ -1987,11 +1987,12 @@ decltype(auto) deserialize_value(const T& t, bytes_view v) {
}

namespace {
template <FragmentedView View>
struct deserialize_visitor {
bytes_view v;
View v;
data_value operator()(const reversed_type_impl& t) { return t.underlying_type()->deserialize(v); }
template <typename T> data_value operator()(const T& t) {
if (v.empty()) {
if (!v.size_bytes()) {
return t.make_empty();
}
return t.make_value(deserialize_value(t, v));
Expand All @@ -2003,7 +2004,7 @@ struct deserialize_visitor {
return t.make_value(deserialize_value(t, v));
}
data_value operator()(const bytes_type_impl& t) {
return t.make_value(std::make_unique<bytes_type_impl::native_type>(v.begin(), v.end()));
return t.make_value(std::make_unique<bytes_type_impl::native_type>(linearized(v)));
}
data_value operator()(const counter_type_impl& t) {
return static_cast<const long_type_impl&>(*long_type).make_value(read_simple_exactly<int64_t>(v));
Expand All @@ -2023,9 +2024,15 @@ struct deserialize_visitor {
};
}

data_value abstract_type::deserialize(bytes_view v) const {
return visit(*this, deserialize_visitor{v});
}
template <FragmentedView View>
data_value abstract_type::deserialize(View v) const {
return visit(*this, deserialize_visitor<View>{v});
}
// Explicit instantiation.
// This should be repeated for every type passed to deserialize().
template data_value abstract_type::deserialize<>(fragmented_temporary_buffer::view) const;
template data_value abstract_type::deserialize<>(single_fragmented_view) const;
template data_value abstract_type::deserialize<>(ser::buffer_view<bytes_ostream::fragment_iterator>) const;

int32_t compare_aux(const tuple_type_impl& t, bytes_view v1, bytes_view v2) {
// This is a slight modification of lexicographical_tri_compare:
Expand Down
11 changes: 9 additions & 2 deletions types.hh
Expand Up @@ -504,9 +504,16 @@ public:
size_t hash(bytes_view v) const;
bool equal(bytes_view v1, bytes_view v2) const;
int32_t compare(bytes_view v1, bytes_view v2) const;
data_value deserialize(bytes_view v) const;
data_value deserialize_value(bytes_view v) const {
// Explicitly instantiated in .cc
template <FragmentedView View> data_value deserialize(View v) const;
data_value deserialize(bytes_view v) const {
return deserialize(single_fragmented_view(v));
}
template <FragmentedView View> data_value deserialize_value(View v) const {
return deserialize(v);
}
data_value deserialize_value(bytes_view v) const {
return deserialize(single_fragmented_view(v));
};
void validate(const fragmented_temporary_buffer::view& view, cql_serialization_format sf) const;
void validate(bytes_view view, cql_serialization_format sf) const;
Expand Down

0 comments on commit 3d07611

Please sign in to comment.