/*
* Copyright 2015 Cloudius Systems
*/
/*
* 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 .
*/
#include "serializer.hh"
#include "database.hh"
#include "types.hh"
#include "utils/serialization.hh"
typedef uint32_t count_type; // Me thinks 32-bits are enough for "normal" count purposes.
template<>
db::serializer::serializer(const utils::UUID& uuid)
: _item(uuid), _size(2 * sizeof(uint64_t)) {
}
template<>
void db::serializer::write(output& out,
const type& t) {
out.write(t.get_most_significant_bits());
out.write(t.get_least_significant_bits());
}
template<>
void db::serializer::read(utils::UUID& uuid, input& in) {
uuid = read(in);
}
template<>
void db::serializer::skip(input& in) {
in.skip(2 * sizeof(uint64_t));
}
template<> utils::UUID db::serializer::read(input& in) {
auto msb = in.read();
auto lsb = in.read();
return utils::UUID(msb, lsb);
}
template<>
db::serializer::serializer(const bytes& b)
: _item(b), _size(output::serialized_size(b)) {
}
template<>
void db::serializer::write(output& out, const type& t) {
out.write(t);
}
template<>
void db::serializer::read(bytes& b, input& in) {
b = in.read();
}
template<>
void db::serializer::skip(input& in) {
in.read(); // FIXME: Avoid reading
}
template<>
db::serializer::serializer(const bytes_view& v)
: _item(v), _size(output::serialized_size(v)) {
}
template<>
void db::serializer::write(output& out, const type& t) {
out.write(t);
}
template<>
void db::serializer::read(bytes_view& v, input& in) {
v = in.read();
}
template<>
bytes_view db::serializer::read(input& in) {
return in.read();
}
template<>
db::serializer::serializer(const sstring& s)
: _item(s), _size(output::serialized_size(s)) {
}
template<>
void db::serializer::write(output& out, const type& t) {
out.write(t);
}
template<>
void db::serializer::read(sstring& s, input& in) {
s = in.read();
}
template<>
void db::serializer::skip(input& in) {
in.read(); // FIXME: avoid reading
}
template<>
db::serializer::serializer(const tombstone& t)
: _item(t), _size(sizeof(t.timestamp) + sizeof(decltype(t.deletion_time.time_since_epoch().count()))) {
}
template<>
void db::serializer::write(output& out, const type& t) {
out.write(t.timestamp);
out.write(t.deletion_time.time_since_epoch().count());
}
template<>
void db::serializer::read(tombstone& t, input& in) {
t.timestamp = in.read();
auto deletion_time = in.read();
t.deletion_time = gc_clock::time_point(gc_clock::duration(deletion_time));
}
template<>
db::serializer::serializer(const atomic_cell_view& c)
: _item(c), _size(bytes_view_serializer(c.serialize()).size()) {
}
template<>
void db::serializer::write(output& out, const atomic_cell_view& t) {
bytes_view_serializer::write(out, t.serialize());
}
template<>
void db::serializer::read(atomic_cell_view& c, input& in) {
c = atomic_cell_view::from_bytes(bytes_view_serializer::read(in));
}
template<>
atomic_cell_view db::serializer::read(input& in) {
return atomic_cell_view::from_bytes(bytes_view_serializer::read(in));
}
template<>
db::serializer::serializer(const collection_mutation_view& c)
: _item(c), _size(bytes_view_serializer(c.serialize()).size()) {
}
template<>
void db::serializer::write(output& out, const collection_mutation_view& t) {
bytes_view_serializer::write(out, t.serialize());
}
template<>
void db::serializer::read(collection_mutation_view& c, input& in) {
c = collection_mutation_view::from_bytes(bytes_view_serializer::read(in));
}
// Modified to match sstable/origin serialization. And the actual data type.
// Note however, that afaict, noone uses this serializer now
// (see comment in system_keyspace::save_truncation_record)
// I.e. consider dropping this alltogether.
template<>
db::serializer::serializer(const db::replay_position& rp)
: _item(rp), _size(sizeof(uint64_t) + sizeof(uint32_t)) {
}
template<>
void db::serializer::write(output& out, const db::replay_position& rp) {
out.write(rp.id);
out.write(rp.pos);
}
template<>
void db::serializer::read(db::replay_position& rp, input& in) {
rp.id = in.read();
rp.pos = in.read();
}
template class db::serializer ;
template class db::serializer ;
template class db::serializer ;
template class db::serializer ;
template class db::serializer ;
template class db::serializer ;
template class db::serializer ;
template class db::serializer ;