/* vim:set ts=2 sw=2 sts=2 et: */
/**
* \author Marcus Holland-Moritz (github@mhxnet.de)
* \copyright Copyright (c) Marcus Holland-Moritz
*
* This file is part of dwarfs.
*
* dwarfs is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* dwarfs 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 dwarfs. If not, see .
*/
#include
#include
#include
#include
#include
#include
namespace dwarfs::writer::internal {
namespace {
template
std::pair, std::vector>
freeze_to_buffer(const T& x) {
using namespace ::apache::thrift::frozen;
Layout layout;
size_t content_size = LayoutRoot::layout(x, layout);
std::string schema;
serializeRootLayout(layout, schema);
size_t schema_size = schema.size();
auto schema_begin = reinterpret_cast(schema.data());
std::vector schema_buffer(schema_begin, schema_begin + schema_size);
std::vector data_buffer;
data_buffer.resize(content_size, 0);
folly::MutableByteRange content_range(data_buffer.data(), data_buffer.size());
ByteRangeFreezer::freeze(layout, x, content_range);
data_buffer.resize(data_buffer.size() - content_range.size());
return {schema_buffer, data_buffer};
}
} // namespace
std::pair, std::vector>
metadata_freezer::freeze(const thrift::metadata::metadata& data) {
return freeze_to_buffer(data);
}
} // namespace dwarfs::writer::internal