Skip to content

Commit

Permalink
Fix decoding for u128 as well
Browse files Browse the repository at this point in the history
  • Loading branch information
filmor committed Mar 13, 2024
1 parent aba8ba4 commit e4d9885
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion rustler/src/types/i128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl<'a> Decoder<'a> for u128 {
}

let mut res = [0u8; 16];
res[16 - n..].copy_from_slice(&input[4..4 + n]);
res[..n].copy_from_slice(&input[4..4 + n]);
Ok(u128::from_le_bytes(res))
}
}
6 changes: 5 additions & 1 deletion rustler_tests/test/primitives_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ defmodule RustlerTest.PrimitivesTest do
i = 1 <<< 63
assert i == RustlerTest.echo_u128(i)

i = 1 <<< 80
assert i == RustlerTest.echo_u128(i)

i = 1 <<< 127
assert i == RustlerTest.echo_u128(i)

Expand All @@ -79,6 +82,7 @@ defmodule RustlerTest.PrimitivesTest do

assert_raise ArgumentError, fn -> RustlerTest.echo_u128(:non_int) end
assert_raise ArgumentError, fn -> RustlerTest.echo_u128(123.45) end
assert_raise ArgumentError, fn -> RustlerTest.echo_i128(1 <<< 129) end
assert_raise ArgumentError, fn -> RustlerTest.echo_u128(i + 1) end
assert_raise ArgumentError, fn -> RustlerTest.echo_u128(1 <<< 129) end
end
end

0 comments on commit e4d9885

Please sign in to comment.