/* * Copyright 2015 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 . */ #include "frozen_schema.hh" #include "db/schema_tables.hh" #include "schema_mutations.hh" template class db::serializer; frozen_schema::frozen_schema(const schema_ptr& s) : _data([&s] { bytes_ostream out; db::serializer(s->version()).write(out); schema_mutations sm = db::schema_tables::make_table_mutations(s, api::new_timestamp()); db::serializer(sm).write(out); return to_bytes(out.linearize()); }()) { } schema_ptr frozen_schema::unfreeze() const { data_input in(_data); auto version = db::serializer::read(in); auto mutations = db::serializer::read(in); return db::schema_tables::create_table_from_mutations(mutations, version); } frozen_schema::frozen_schema(bytes b) : _data(std::move(b)) { } template<> db::serializer::serializer(const frozen_schema& v) : _item(v) , _size(db::serializer(v._data).size()) { } template<> void db::serializer::write(output& out, const frozen_schema& v) { db::serializer(v._data).write(out); } template<> frozen_schema db::serializer::read(input& in) { return frozen_schema(db::serializer::read(in)); }