71#include "utilities/serialization/record.hpp"
72#include "wire_format.hpp"
74#include <nonstd/expected.hpp>
86using nonstd::expected;
87using nonstd::make_unexpected;
104using ::ngen::serialization::parse_timestamp;
122#ifndef NGEN_BMI_MAX_RECORD_PAYLOAD_BYTES
123#define NGEN_BMI_MAX_RECORD_PAYLOAD_BYTES (1ULL << 30)
137 -> expected<Status, std::string> {
143 return make_unexpected(
144 "serialization_record: bad magic 0x" + std::to_string(prefix.magic)
145 +
" — file is not a v0.2 record stream or is corrupted "
146 "at the record boundary"
150 return make_unexpected(
151 "serialization_record: unsupported wire_version " + std::to_string(prefix.wire_version)
152 +
" (this reader supports v"
157 return make_unexpected(
158 "serialization_record: payload_length " + std::to_string(prefix.payload_length)
159 +
" exceeds MAX_RECORD_PAYLOAD_BYTES sanity cap"
186 -> expected<void, std::string> {
191 prefix.
id_length =
static_cast<uint16_t
>(rec.id.size());
192 prefix.
payload_length =
static_cast<uint64_t
>(rec.payload.size());
196 if (!rec.id.empty()) {
197 out.write(rec.id.data(),
static_cast<std::streamsize
>(rec.id.size()));
199 if (!rec.payload.empty()) {
200 out.write(rec.payload.data(),
static_cast<std::streamsize
>(rec.payload.size()));
203 return make_unexpected(
204 std::string(
"serialization_record: stream failed during record write")
222 -> expected<void, std::string> {
227 prefix.
id_length =
static_cast<uint16_t
>(rec.id.size());
228 prefix.
payload_length =
static_cast<uint64_t
>(rec.payload.size());
231 if (!rec.id.empty()) {
232 out.write(rec.id.data(),
static_cast<std::streamsize
>(rec.id.size()));
234 if (!rec.payload.empty()) {
235 out.write(rec.payload.data(),
static_cast<std::streamsize
>(rec.payload.size()));
238 return make_unexpected(
239 std::string(
"serialization_record: stream failed during record write")
257 -> expected<Status, std::string> {
267 in.read(&
id[0],
static_cast<std::streamsize
>(prefix.
id_length));
268 if (
static_cast<uint64_t
>(in.gcount()) != prefix.
id_length) {
274 std::vector<char> payload;
277 in.read(payload.data(),
static_cast<std::streamsize
>(prefix.
payload_length));
278 if (
static_cast<uint64_t
>(in.gcount()) != prefix.
payload_length) {
283 rec.id = std::move(
id);
287 rec.payload = std::move(payload);
309 -> expected<Status, std::string> {
337) -> expected<Status, std::string> {
342 id_out.resize(prefix_out.id_length);
343 if (prefix_out.id_length > 0) {
344 in.read(&id_out[0],
static_cast<std::streamsize
>(prefix_out.id_length));
345 if (
static_cast<uint64_t
>(in.gcount()) != prefix_out.id_length) {
350 if (prefix_out.payload_length > 0) {
351 in.seekg(
static_cast<std::streamoff
>(prefix_out.payload_length), std::ios::cur);
Definition deserialization.hpp:40
constexpr uint64_t MAX_RECORD_PAYLOAD_BYTES
Definition serialization_record.hpp:125
nsel_NODISCARD auto read_record_length(std::istream &in, uint64_t &body_out) -> expected< Status, std::string >
Read the prefix at the current stream position and report the record's body length (id bytes + payloa...
Definition serialization_record.hpp:308
nsel_NODISCARD auto read_record_metadata(std::istream &in, serialization::wire_format::RecordPrefix &prefix_out, std::string &id_out) -> expected< Status, std::string >
Read the prefix and id at the current stream position and skip past the payload, leaving in positione...
Definition serialization_record.hpp:333
nsel_NODISCARD auto write_record(std::ostream &out, const SerializationRecordView &rec) -> expected< void, std::string >
Append a record to out using the v0.2 wire format (fixed-size prefix + id bytes + payload bytes).
Definition serialization_record.hpp:185
nsel_NODISCARD auto read_next_record(std::istream &in, SerializationRecord &rec) -> expected< Status, std::string >
Read the next record from in.
Definition serialization_record.hpp:256
auto read_validated_prefix(std::istream &in, serialization::wire_format::RecordPrefix &prefix) -> expected< Status, std::string >
Definition serialization_record.hpp:136
Definition AbstractCLibBmiAdapter.hpp:6
detail::RecordT< std::vector< char > > Record
A checkpoint record that owns its payload.
Definition record.hpp:182
detail::RecordT< boost::span< const char > > RecordView
A checkpoint record that views its payload (non-owning).
Definition record.hpp:192
Definition record.hpp:151