mirror of
https://github.com/scylladb/scylladb.git
synced 2026-05-12 19:02:12 +00:00
serializer: Define serializer<> specializations for integral types
This commit is contained in:
107
serializer.hh
107
serializer.hh
@@ -49,87 +49,38 @@ inline void serialize_integral(Output& output, T data) {
|
||||
output.write(reinterpret_cast<const char*>(&data), sizeof(T));
|
||||
}
|
||||
|
||||
// For integer type
|
||||
template<typename Input>
|
||||
int8_t deserialize(Input& input, boost::type<int8_t>) {
|
||||
return deserialize_integral<int8_t>(input);
|
||||
}
|
||||
template<typename Input>
|
||||
uint8_t deserialize(Input& input, boost::type<uint8_t>) {
|
||||
return deserialize_integral<uint8_t>(input);
|
||||
}
|
||||
template<typename Input>
|
||||
bool deserialize(Input& input, boost::type<bool>) {
|
||||
return deserialize(input, boost::type<uint8_t>());
|
||||
}
|
||||
template<typename Input>
|
||||
int16_t deserialize(Input& input, boost::type<int16_t>) {
|
||||
return deserialize_integral<int16_t>(input);
|
||||
}
|
||||
template<typename Input>
|
||||
uint16_t deserialize(Input& input, boost::type<uint16_t>) {
|
||||
return deserialize_integral<uint16_t>(input);
|
||||
}
|
||||
template<typename Input>
|
||||
int32_t deserialize(Input& input, boost::type<int32_t>) {
|
||||
return deserialize_integral<int32_t>(input);
|
||||
}
|
||||
template<typename Input>
|
||||
uint32_t deserialize(Input& input, boost::type<uint32_t>) {
|
||||
return deserialize_integral<uint32_t>(input);
|
||||
}
|
||||
template<typename Input>
|
||||
int64_t deserialize(Input& input, boost::type<int64_t>) {
|
||||
return deserialize_integral<int64_t>(input);
|
||||
}
|
||||
template<typename Input>
|
||||
uint64_t deserialize(Input& input, boost::type<uint64_t>) {
|
||||
return deserialize_integral<uint64_t>(input);
|
||||
}
|
||||
|
||||
template<typename Output>
|
||||
void serialize(Output& output, int8_t data) {
|
||||
serialize_integral(output, data);
|
||||
}
|
||||
template<typename Output>
|
||||
void serialize(Output& output, uint8_t data) {
|
||||
serialize_integral(output, data);
|
||||
}
|
||||
template<typename Output>
|
||||
void serialize(Output& output, bool data) {
|
||||
serialize(output, uint8_t(data));
|
||||
}
|
||||
template<typename Output>
|
||||
void serialize(Output& output, int16_t data) {
|
||||
serialize_integral(output, data);
|
||||
}
|
||||
template<typename Output>
|
||||
void serialize(Output& output, uint16_t data) {
|
||||
serialize_integral(output, data);
|
||||
}
|
||||
template<typename Output>
|
||||
void serialize(Output& output, int32_t data) {
|
||||
serialize_integral(output, data);
|
||||
}
|
||||
template<typename Output>
|
||||
void serialize(Output& output, uint32_t data) {
|
||||
serialize_integral(output, data);
|
||||
}
|
||||
template<typename Output>
|
||||
void serialize(Output& output, int64_t data) {
|
||||
serialize_integral(output, data);
|
||||
}
|
||||
template<typename Output>
|
||||
void serialize(Output& output, uint64_t data) {
|
||||
serialize_integral(output, data);
|
||||
}
|
||||
template<typename Output>
|
||||
void safe_serialize_as_uint32(Output& output, uint64_t data);
|
||||
|
||||
|
||||
template<typename T>
|
||||
struct serializer;
|
||||
|
||||
template<typename T>
|
||||
struct integral_serializer {
|
||||
template<typename Input>
|
||||
static T read(Input& v) {
|
||||
return deserialize_integral<T>(v);
|
||||
}
|
||||
template<typename Output>
|
||||
static void write(Output& out, T v) {
|
||||
serialize_integral(out, v);
|
||||
}
|
||||
template<typename Input>
|
||||
static void skip(Input& v) {
|
||||
read(v);
|
||||
}
|
||||
};
|
||||
|
||||
template<> struct serializer<bool> : public integral_serializer<int8_t> {};
|
||||
template<> struct serializer<int8_t> : public integral_serializer<int8_t> {};
|
||||
template<> struct serializer<uint8_t> : public integral_serializer<uint8_t> {};
|
||||
template<> struct serializer<int16_t> : public integral_serializer<int16_t> {};
|
||||
template<> struct serializer<uint16_t> : public integral_serializer<uint16_t> {};
|
||||
template<> struct serializer<int32_t> : public integral_serializer<int32_t> {};
|
||||
template<> struct serializer<uint32_t> : public integral_serializer<uint32_t> {};
|
||||
template<> struct serializer<int64_t> : public integral_serializer<int64_t> {};
|
||||
template<> struct serializer<uint64_t> : public integral_serializer<uint64_t> {};
|
||||
|
||||
template<typename Output>
|
||||
void safe_serialize_as_uint32(Output& output, uint64_t data);
|
||||
|
||||
template<typename T, typename Output>
|
||||
inline void serialize(Output& out, const T& v) {
|
||||
serializer<T>::write(out, v);
|
||||
|
||||
Reference in New Issue
Block a user