/* * Copyright 2015 Cloudius Systems */ #ifndef DB_SERIALIZER_HH_ #define DB_SERIALIZER_HH_ #include "utils/data_input.hh" #include "utils/data_output.hh" #include "bytes.hh" #include "database.hh" namespace db { /** * Serialization objects for various types and using "internal" format. (Not CQL, origin whatnot). * The design rationale is that a "serializer" can be instansiated for an object, and will contain * the obj + size, and is useable as a functor. * * Serialization can also be done "explicitly" through the static method "write" * (Not using "serialize", because writing "serializer::serialize" all the time is tiring and redundant) * though care should be takes than data will fit of course. */ template class serializer { public: typedef T type; typedef data_output output; typedef data_input input; typedef serializer _MyType; typedef database context; serializer(const context&, const type&); // apply to memory, must be at least size() large. const _MyType& operator()(output& out) const { write(_ctxt, out, _item); return *this; } static void write(const context&, output&, const T&); static void read(const context&, T&, input&); static T read(const context&, input&); size_t size() const { return _size; } private: const context& _ctxt; const T& _item; size_t _size; }; template<> serializer::serializer(const context&, const utils::UUID &); template<> void serializer::write(const context&, output&, const type&); template<> void serializer::read(const context&, utils::UUID&, input&); template<> utils::UUID serializer::read(const context&, input&); template<> serializer::serializer(const context&, const bytes &); template<> void serializer::write(const context&, output&, const type&); template<> void serializer::read(const context&, bytes&, input&); template<> serializer::serializer(const context&, const bytes_view&); template<> void serializer::write(const context&, output&, const type&); template<> void serializer::read(const context&, bytes_view&, input&) = delete; template<> bytes_view serializer::read(const context&, input&) = delete; template<> serializer::serializer(const context&, const sstring&); template<> void serializer::write(const context&, output&, const type&); template<> void serializer::read(const context&, sstring&, input&); template<> serializer::serializer(const context&, const tombstone &); template<> void serializer::write(const context&, output&, const type&); template<> void serializer::read(const context&, tombstone&, input&); template<> serializer::serializer(const context&, const atomic_cell_or_collection &); template<> void serializer::write(const context&, output&, const type&); template<> void serializer::read(const context&, atomic_cell_or_collection&, input&); template<> serializer::serializer(const context&, const row &); template<> void serializer::write(const context&, output&, const type&); template<> void serializer::read(const context&, row&, input&); template<> serializer::serializer(const context&, const mutation_partition &); template<> void serializer::write(const context&, output&, const type&); template<> void serializer::read(const context&, mutation_partition&, input&); template<> mutation_partition serializer::read(const context&, input&) = delete; template<> serializer::serializer(const context&, const mutation &); template<> void serializer::write(const context&, output&, const type&); template<> void serializer::read(const context&, mutation&, input&) = delete; template<> mutation serializer::read(const context&, input&); template T serializer::read(const context& ctxt, input& in) { type t; read(ctxt, t, in); return std::move(t); } extern template class serializer; extern template class serializer; extern template class serializer; extern template class serializer; extern template class serializer; extern template class serializer; extern template class serializer; extern template class serializer; extern template class serializer; typedef serializer mutation_serializer; typedef serializer mutation_partition_serializer; typedef serializer tombstone_serializer; typedef serializer row_serializer; typedef serializer bytes_serializer; typedef serializer bytes_view_serializer; typedef serializer sstring_serializer; typedef serializer atomic_cell_or_collection_serializer; typedef serializer uuid_serializer; } #endif /* DB_SERIALIZER_HH_ */