/*
* 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 "core/sstring.hh"
#include
#include
#include "enum_set.hh"
#include "core/simple-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));
}
// For integer type
template
int8_t deserialize(Input& input, boost::type) {
return deserialize_integral(input);
}
template
uint8_t deserialize(Input& input, boost::type) {
return deserialize_integral(input);
}
template
bool deserialize(Input& input, boost::type) {
return deserialize(input, boost::type());
}
template
int16_t deserialize(Input& input, boost::type) {
return deserialize_integral(input);
}
template
uint16_t deserialize(Input& input, boost::type) {
return deserialize_integral(input);
}
template
int32_t deserialize(Input& input, boost::type) {
return deserialize_integral(input);
}
template
uint32_t deserialize(Input& input, boost::type) {
return deserialize_integral(input);
}
template
int64_t deserialize(Input& input, boost::type) {
return deserialize_integral(input);
}
template
uint64_t deserialize(Input& input, boost::type) {
return deserialize_integral(input);
}
template
void serialize(Output& output, int8_t data) {
serialize_integral(output, data);
}
template
void serialize(Output& output, uint8_t data) {
serialize_integral(output, data);
}
template
void serialize(Output& output, bool data) {
serialize(output, uint8_t(data));
}
template
void serialize(Output& output, int16_t data) {
serialize_integral(output, data);
}
template
void serialize(Output& output, uint16_t data) {
serialize_integral(output, data);
}
template
void serialize(Output& output, int32_t data) {
serialize_integral(output, data);
}
template
void serialize(Output& output, uint32_t data) {
serialize_integral(output, data);
}
template
void serialize(Output& output, int64_t data) {
serialize_integral(output, data);
}
template
void serialize(Output& output, uint64_t data) {
serialize_integral(output, data);
}
template
void safe_serialize_as_uint32(Output& output, uint64_t data);
// For vectors
template
inline void serialize(Output& out, const std::vector& v);
template
inline std::vector deserialize(Input& in, boost::type>);
template
inline void serialize(Output& out, const std::map& v);
template
inline std::map deserialize(Input& in, boost::type>);
template
size_type get_sizeof(const T& obj);
// For sstring
template
void serialize(Output& out, const sstring& v);
template
sstring deserialize(Input& in, boost::type);
// For optional
template
inline void serialize(Output& out, const std::experimental::optional& v);
template
inline std::experimental::optional deserialize(Input& in, boost::type>);
template
// For unique_ptr
inline void serialize(Output& out, const std::unique_ptr& v);
template
inline std::unique_ptr deserialize(Input& in, boost::type>);
// For time_point
template
inline void serialize(Output& out, const std::chrono::time_point& v);
template
inline std::chrono::time_point deserialize(Input& in, boost::type>);
// For enum_set
template
inline void serialize(Output& out, const enum_set& v);
template
inline enum_set deserialize(Input& in, boost::type>);
// For bytes/bytes_view
template
void serialize(Output& out, const bytes_view& v);
template
void serialize(Output& out, const bytes& v);
template
bytes deserialize(Input& in, boost::type);
// For bytes_ostream
template
void serialize(Output& out, const bytes_ostream& v);
template
bytes_ostream deserialize(Input& in, boost::type);
template
void set_size(seastar::simple_output_stream& os, const T& obj);
template
void set_size(seastar::measuring_output_stream& os, const T& obj);
template
Buffer serialize_to_buffer(const T& v, size_t head_space = 0);
}
/*
* Import the auto generated forward decleration code
*/