/* * Copyright 2016 ScyllaDB */ /* * This file is part of Scylla. * * Scylla is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Scylla is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Scylla. If not, see . */ #pragma once #include #include #include "core/sstring.hh" #include #include #include "enum_set.hh" #include "utils/managed_bytes.hh" #include "bytes_ostream.hh" #include "core/simple-stream.hh" #include "boost/variant/variant.hpp" #include "bytes_ostream.hh" #include "utils/input_stream.hh" namespace ser { using size_type = uint32_t; template inline T deserialize_integral(Input& input) { static_assert(std::is_integral::value, "T should be integral"); T data; input.read(reinterpret_cast(&data), sizeof(T)); return le_to_cpu(data); } template inline void serialize_integral(Output& output, T data) { static_assert(std::is_integral::value, "T should be integral"); data = cpu_to_le(data); output.write(reinterpret_cast(&data), sizeof(T)); } template struct serializer; template struct integral_serializer { template static T read(Input& v) { return deserialize_integral(v); } template static void write(Output& out, T v) { serialize_integral(out, v); } template static void skip(Input& v) { read(v); } }; template<> struct serializer : public integral_serializer {}; template<> struct serializer : public integral_serializer {}; template<> struct serializer : public integral_serializer {}; template<> struct serializer : public integral_serializer {}; template<> struct serializer : public integral_serializer {}; template<> struct serializer : public integral_serializer {}; template<> struct serializer : public integral_serializer {}; template<> struct serializer : public integral_serializer {}; template<> struct serializer : public integral_serializer {}; template void safe_serialize_as_uint32(Output& output, uint64_t data); template inline void serialize(Output& out, const T& v) { serializer::write(out, v); }; template inline auto deserialize(Input& in, boost::type t) { return serializer::read(in); }; template inline void skip(Input& v, boost::type) { return serializer::skip(v); } template size_type get_sizeof(const T& obj); template void set_size(seastar::measuring_output_stream& os, const T& obj); template void set_size(Stream& os, const T& obj); template Buffer serialize_to_buffer(const T& v, size_t head_space = 0); template T deserialize_from_buffer(const Buffer&, boost::type, size_t head_space = 0); template void serialize(Output& out, const boost::variant& v); template boost::variant deserialize(Input& in, boost::type>); struct unknown_variant_type { size_type index; sstring data; }; template void serialize(Output& out, const unknown_variant_type& v); template unknown_variant_type deserialize(Input& in, boost::type); template struct normalize { using type = T; }; template <> struct normalize { using type = bytes; }; template <> struct normalize { using type = bytes; }; template <> struct normalize { using type = bytes; }; template struct is_equivalent : std::is_same>>::type, typename normalize>>::type> { }; } /* * Import the auto generated forward decleration code */