From fb24a40eea3914fe1e112776a92d62d1feeb93fb Mon Sep 17 00:00:00 2001 From: Jan Sucan Date: Sun, 26 Jan 2025 16:10:51 +0100 Subject: Reduce diff file version field size --- src/format_v2.h | 14 +++++++------- tests/400-expected_backup_output.bin | Bin 54 -> 53 bytes 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/format_v2.h b/src/format_v2.h index e1c752a..f79df1e 100644 --- a/src/format_v2.h +++ b/src/format_v2.h @@ -36,7 +36,7 @@ namespace FormatV2 { const std::string FileSignature{"diff-dd image"}; -const uint16_t FileVersion{2}; +const uint8_t FileVersion{2}; const size_t RecordHeaderSize{sizeof(uint64_t) + sizeof(uint32_t)}; struct RecordData { @@ -77,7 +77,7 @@ class Writer { m_writer.write(FileSignature.data(), FileSignature.size()); - uint16_t val{htobe16(FileVersion)}; + uint8_t val{FileVersion}; m_writer.write(reinterpret_cast(&val), sizeof(val)); }; @@ -123,13 +123,13 @@ class Reader throw new Error("wrong file header signature"); } - uint16_t rawVersion; - r = {m_reader.read(sizeof(rawVersion), - reinterpret_cast(&rawVersion))}; - if (r < sizeof(rawVersion)) { + uint8_t version; + r = { + m_reader.read(sizeof(version), reinterpret_cast(&version))}; + if (r < sizeof(version)) { throw new Error("cannot read file header version"); } - if (be16toh(rawVersion) != FileVersion) { + if (version != FileVersion) { throw new Error("wrong file header version"); } }; diff --git a/tests/400-expected_backup_output.bin b/tests/400-expected_backup_output.bin index ad5f72b..a4f3755 100644 Binary files a/tests/400-expected_backup_output.bin and b/tests/400-expected_backup_output.bin differ -- cgit v1.2.3