Skip to content

Commit

Permalink
refactor: specify byteorder in function names
Browse files Browse the repository at this point in the history
  • Loading branch information
ban-nobuhiro committed Oct 6, 2023
1 parent 8af53a4 commit 31c7c84
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions src/limestone/log_entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::uint8_t>(type));
write_uint64(strm, static_cast<std::uint64_t>(epoch));
write_uint64le(strm, static_cast<std::uint64_t>(epoch));
}
static void end_session(FILE* strm, epoch_id_type epoch) {
entry_type type = entry_type::marker_end;
write_uint8(strm, static_cast<std::uint8_t>(type));
write_uint64(strm, static_cast<std::uint64_t>(epoch));
write_uint64le(strm, static_cast<std::uint64_t>(epoch));
}
static void durable_epoch(FILE* strm, epoch_id_type epoch) {
entry_type type = entry_type::marker_durable;
write_uint8(strm, static_cast<std::uint8_t>(type));
write_uint64(strm, static_cast<std::uint64_t>(epoch));
write_uint64le(strm, static_cast<std::uint64_t>(epoch));
}

// for writer (entry)
Expand Down Expand Up @@ -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<std::uint32_t>(key_len));
write_uint32le(strm, static_cast<std::uint32_t>(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<std::uint32_t>(value_len));
write_uint32le(strm, static_cast<std::uint32_t>(value_len));

write_uint64(strm, static_cast<std::uint64_t>(storage_id));
write_uint64le(strm, static_cast<std::uint64_t>(storage_id));
fwrite(key.data(), static_cast<std::streamsize>(key_len), 1, strm); // NOLINT TODO: check error

write_uint64(strm, static_cast<std::uint64_t>(write_version.epoch_number_));
write_uint64(strm, static_cast<std::uint64_t>(write_version.minor_write_version_));
write_uint64le(strm, static_cast<std::uint64_t>(write_version.epoch_number_));
write_uint64le(strm, static_cast<std::uint64_t>(write_version.minor_write_version_));
fwrite(value.data(), static_cast<std::streamsize>(value_len), 1, strm); // NOLINT TODO: check error
}

Expand All @@ -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<std::uint32_t>(key_len));
write_uint32le(strm, static_cast<std::uint32_t>(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<std::uint32_t>(value_len));
write_uint32le(strm, static_cast<std::uint32_t>(value_len));

fwrite(key_sid.data(), static_cast<std::streamsize>(key_sid.length()), 1, strm); // NOLINT TODO: check error
fwrite(value_etc.data(), static_cast<std::streamsize>(value_etc.length()), 1, strm); // NOLINT TODO: check error
Expand All @@ -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<std::uint32_t>(key_len));
write_uint32le(strm, static_cast<std::uint32_t>(key_len));

write_uint64(strm, static_cast<std::uint64_t>(storage_id));
write_uint64le(strm, static_cast<std::uint64_t>(storage_id));
fwrite(key.data(), static_cast<std::streamsize>(key_len), 1, strm); // NOLINT TODO: check error

write_uint64(strm, static_cast<std::uint64_t>(write_version.epoch_number_));
write_uint64(strm, static_cast<std::uint64_t>(write_version.minor_write_version_));
write_uint64le(strm, static_cast<std::uint64_t>(write_version.epoch_number_));
write_uint64le(strm, static_cast<std::uint64_t>(write_version.minor_write_version_));
}

static void write_remove(FILE* strm, std::string_view key_sid, std::string_view value_etc) {
Expand All @@ -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<std::uint32_t>(key_len));
write_uint32le(strm, static_cast<std::uint32_t>(key_len));

fwrite(key_sid.data(), static_cast<std::streamsize>(key_sid.length()), 1, strm); // NOLINT TODO: check error
fwrite(value_etc.data(), static_cast<std::streamsize>(value_etc.length()), 1, strm); // NOLINT TODO: check error
Expand All @@ -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<std::streamsize>(key_sid_.length()));
Expand All @@ -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<std::streamsize>(key_sid_.length()));
Expand All @@ -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<epoch_id_type>(read_uint64(strm));
epoch_id_ = static_cast<epoch_id_type>(read_uint64le(strm));
break;

case entry_type::this_id_is_not_used:
Expand Down Expand Up @@ -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<int>((value>>0U)&0xFFU), out); // NOLINT TODO: check error
fputc(static_cast<int>((value>>8U)&0xFFU), out); // NOLINT TODO: check error
fputc(static_cast<int>((value>>16U)&0xFFU), out); // NOLINT TODO: check error
fputc(static_cast<int>((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<std::uint8_t>(in.get())&0xFFU);
value |= (static_cast<std::uint8_t>(in.get())&0xFFU)<<8U;
value |= (static_cast<std::uint8_t>(in.get())&0xFFU)<<16U;
value |= (static_cast<std::uint8_t>(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<int>((value>>0U)&0xFFU), out); // NOLINT TODO: check error
fputc(static_cast<int>((value>>8U)&0xFFU), out); // NOLINT TODO: check error
fputc(static_cast<int>((value>>16U)&0xFFU), out); // NOLINT TODO: check error
Expand All @@ -261,7 +261,7 @@ class log_entry {
fputc(static_cast<int>((value>>48U)&0xFFU), out); // NOLINT TODO: check error
fputc(static_cast<int>((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<std::uint8_t>(in.get())&0xFFU);
value_l |= (static_cast<std::uint8_t>(in.get())&0xFFU)<<8U;
value_l |= (static_cast<std::uint8_t>(in.get())&0xFFU)<<16U;
Expand Down

0 comments on commit 31c7c84

Please sign in to comment.