diff --git a/src/limestone/log_entry.h b/src/limestone/log_entry.h index e8cc7f6e..1a40fcd0 100644 --- a/src/limestone/log_entry.h +++ b/src/limestone/log_entry.h @@ -47,17 +47,17 @@ class log_entry { static void begin_session(FILE* strm, epoch_id_type epoch) { entry_type type = entry_type::marker_begin; write_uint8(strm, static_cast(type)); - write_uint64(strm, static_cast(epoch)); + write_uint64le(strm, static_cast(epoch)); } static void end_session(FILE* strm, epoch_id_type epoch) { entry_type type = entry_type::marker_end; write_uint8(strm, static_cast(type)); - write_uint64(strm, static_cast(epoch)); + write_uint64le(strm, static_cast(epoch)); } static void durable_epoch(FILE* strm, epoch_id_type epoch) { entry_type type = entry_type::marker_durable; write_uint8(strm, static_cast(type)); - write_uint64(strm, static_cast(epoch)); + write_uint64le(strm, static_cast(epoch)); } // for writer (entry) @@ -89,17 +89,17 @@ class log_entry { std::size_t key_len = key.length(); assert(key_len <= UINT32_MAX); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay) - write_uint32(strm, static_cast(key_len)); + write_uint32le(strm, static_cast(key_len)); std::size_t value_len = value.length(); assert(value_len <= UINT32_MAX); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay) - write_uint32(strm, static_cast(value_len)); + write_uint32le(strm, static_cast(value_len)); - write_uint64(strm, static_cast(storage_id)); + write_uint64le(strm, static_cast(storage_id)); fwrite(key.data(), static_cast(key_len), 1, strm); // NOLINT TODO: check error - write_uint64(strm, static_cast(write_version.epoch_number_)); - write_uint64(strm, static_cast(write_version.minor_write_version_)); + write_uint64le(strm, static_cast(write_version.epoch_number_)); + write_uint64le(strm, static_cast(write_version.minor_write_version_)); fwrite(value.data(), static_cast(value_len), 1, strm); // NOLINT TODO: check error } @@ -109,11 +109,11 @@ class log_entry { std::size_t key_len = key_sid.length() - sizeof(storage_id_type); assert(key_len <= UINT32_MAX); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay) - write_uint32(strm, static_cast(key_len)); + write_uint32le(strm, static_cast(key_len)); std::size_t value_len = value_etc.length() - (sizeof(epoch_id_type) + sizeof(std::uint64_t)); assert(value_len <= UINT32_MAX); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay) - write_uint32(strm, static_cast(value_len)); + write_uint32le(strm, static_cast(value_len)); fwrite(key_sid.data(), static_cast(key_sid.length()), 1, strm); // NOLINT TODO: check error fwrite(value_etc.data(), static_cast(value_etc.length()), 1, strm); // NOLINT TODO: check error @@ -125,13 +125,13 @@ class log_entry { std::size_t key_len = key.length(); assert(key_len <= UINT32_MAX); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay) - write_uint32(strm, static_cast(key_len)); + write_uint32le(strm, static_cast(key_len)); - write_uint64(strm, static_cast(storage_id)); + write_uint64le(strm, static_cast(storage_id)); fwrite(key.data(), static_cast(key_len), 1, strm); // NOLINT TODO: check error - write_uint64(strm, static_cast(write_version.epoch_number_)); - write_uint64(strm, static_cast(write_version.minor_write_version_)); + write_uint64le(strm, static_cast(write_version.epoch_number_)); + write_uint64le(strm, static_cast(write_version.minor_write_version_)); } static void write_remove(FILE* strm, std::string_view key_sid, std::string_view value_etc) { @@ -140,7 +140,7 @@ class log_entry { std::size_t key_len = key_sid.length() - sizeof(storage_id_type); assert(key_len <= UINT32_MAX); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay) - write_uint32(strm, static_cast(key_len)); + write_uint32le(strm, static_cast(key_len)); fwrite(key_sid.data(), static_cast(key_sid.length()), 1, strm); // NOLINT TODO: check error fwrite(value_etc.data(), static_cast(value_etc.length()), 1, strm); // NOLINT TODO: check error @@ -157,8 +157,8 @@ class log_entry { switch(entry_type_) { case entry_type::normal_entry: { - std::size_t key_len = read_uint32(strm); - std::size_t value_len = read_uint32(strm); + std::size_t key_len = read_uint32le(strm); + std::size_t value_len = read_uint32le(strm); key_sid_.resize(key_len + sizeof(storage_id_type)); strm.read(key_sid_.data(), static_cast(key_sid_.length())); @@ -168,7 +168,7 @@ class log_entry { } case entry_type::remove_entry: { - std::size_t key_len = read_uint32(strm); + std::size_t key_len = read_uint32le(strm); key_sid_.resize(key_len + sizeof(storage_id_type)); strm.read(key_sid_.data(), static_cast(key_sid_.length())); @@ -179,7 +179,7 @@ class log_entry { case entry_type::marker_begin: case entry_type::marker_end: case entry_type::marker_durable: - epoch_id_ = static_cast(read_uint64(strm)); + epoch_id_ = static_cast(read_uint64le(strm)); break; case entry_type::this_id_is_not_used: @@ -238,20 +238,20 @@ class log_entry { static void write_uint8(FILE* out, const std::uint8_t value) { fputc(value, out); // NOLINT TODO: check error } - static void write_uint32(FILE* out, const std::uint32_t value) { + static void write_uint32le(FILE* out, const std::uint32_t value) { fputc(static_cast((value>>0U)&0xFFU), out); // NOLINT TODO: check error fputc(static_cast((value>>8U)&0xFFU), out); // NOLINT TODO: check error fputc(static_cast((value>>16U)&0xFFU), out); // NOLINT TODO: check error fputc(static_cast((value>>24U)&0xFFU), out); // NOLINT TODO: check error } - static std::uint32_t read_uint32(std::istream& in) { + static std::uint32_t read_uint32le(std::istream& in) { std::uint32_t value = (static_cast(in.get())&0xFFU); value |= (static_cast(in.get())&0xFFU)<<8U; value |= (static_cast(in.get())&0xFFU)<<16U; value |= (static_cast(in.get())&0xFFU)<<24U; return value; } - static void write_uint64(FILE* out, const std::uint64_t value) { + static void write_uint64le(FILE* out, const std::uint64_t value) { fputc(static_cast((value>>0U)&0xFFU), out); // NOLINT TODO: check error fputc(static_cast((value>>8U)&0xFFU), out); // NOLINT TODO: check error fputc(static_cast((value>>16U)&0xFFU), out); // NOLINT TODO: check error @@ -261,7 +261,7 @@ class log_entry { fputc(static_cast((value>>48U)&0xFFU), out); // NOLINT TODO: check error fputc(static_cast((value>>56U)&0xFFU), out); // NOLINT TODO: check error } - static std::uint64_t read_uint64(std::istream& in) { + static std::uint64_t read_uint64le(std::istream& in) { std::uint64_t value_l = (static_cast(in.get())&0xFFU); value_l |= (static_cast(in.get())&0xFFU)<<8U; value_l |= (static_cast(in.get())&0xFFU)<<16U;