mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 10:25:47 +02:00
fix(rdb): Fix loading of small integers and remove code duplication (#1571)
* fix(rdb): Fix loading of small integers and remove code duplication * Add a test
This commit is contained in:
parent
e44cc68b73
commit
3b6b0f5436
2 changed files with 14 additions and 12 deletions
|
@ -1165,20 +1165,14 @@ auto RdbLoaderBase::FetchLzfStringObject() -> io::Result<string> {
|
|||
}
|
||||
|
||||
auto RdbLoaderBase::FetchIntegerObject(int enctype) -> io::Result<string> {
|
||||
long long val;
|
||||
io::Result<long long> val = ReadIntObj(enctype);
|
||||
|
||||
if (enctype == RDB_ENC_INT8) {
|
||||
SET_OR_UNEXPECT(FetchInt<int8_t>(), val);
|
||||
} else if (enctype == RDB_ENC_INT16) {
|
||||
SET_OR_UNEXPECT(FetchInt<uint16_t>(), val);
|
||||
} else if (enctype == RDB_ENC_INT32) {
|
||||
SET_OR_UNEXPECT(FetchInt<uint32_t>(), val);
|
||||
} else {
|
||||
return Unexpected(errc::invalid_encoding);
|
||||
if (!val.has_value()) {
|
||||
return val.get_unexpected();
|
||||
}
|
||||
|
||||
char buf[32];
|
||||
absl::numbers_internal::FastIntToBuffer(val, buf);
|
||||
absl::numbers_internal::FastIntToBuffer(*val, buf);
|
||||
|
||||
return string(buf);
|
||||
}
|
||||
|
@ -1323,9 +1317,9 @@ io::Result<long long> RdbLoaderBase::ReadIntObj(int enctype) {
|
|||
if (enctype == RDB_ENC_INT8) {
|
||||
SET_OR_UNEXPECT(FetchInt<int8_t>(), val);
|
||||
} else if (enctype == RDB_ENC_INT16) {
|
||||
SET_OR_UNEXPECT(FetchInt<uint16_t>(), val);
|
||||
SET_OR_UNEXPECT(FetchInt<int16_t>(), val);
|
||||
} else if (enctype == RDB_ENC_INT32) {
|
||||
SET_OR_UNEXPECT(FetchInt<uint32_t>(), val);
|
||||
SET_OR_UNEXPECT(FetchInt<int32_t>(), val);
|
||||
} else {
|
||||
return Unexpected(errc::invalid_encoding);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue