Skip to content

Commit

Permalink
Merge pull request #4 from Keniis0712/master
Browse files Browse the repository at this point in the history
Better version of parse_int with clearer intention also cleanup the debugging log left over
  • Loading branch information
Codetector1374 authored Aug 6, 2024
2 parents 60f3b90 + cb485f0 commit 834313b
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/innodb/table/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,15 @@ impl Field {
num = (num << 8) | (byte as u64);
}
if signed {
let numeric_value = num & ((1u64 << (len * 8 - 1)) - 1);
let is_positive = (num & (1u64 << (len * 8 - 1))) != 0;
let mask = if is_positive {
0u64
num ^= 1u64 << (len * 8 - 1); // Filp the sign bit -- I don`t know why but it works

let signed_value;
if (num & (1u64 << (len * 8 - 1))) != 0 {
num = !(num - 1);
num &= (1u64 << (len * 8)) - 1; // Clear other bits
signed_value = -(num as i64);
} else {
u64::MAX << (len * 8 - 1)
};
let signed_value = (numeric_value | mask) as i64;
if signed_value == -127 && len == 1 {
info!(
"DBG: numeric_value: {:#x}, pos: {}",
numeric_value, is_positive
);
signed_value = num as i64;
}
FieldValue::SignedInt(signed_value)
} else {
Expand Down

0 comments on commit 834313b

Please sign in to comment.