fix(codec): Fix flat encoding and decoding of arbitrarily size integers (#378)
This commits fixes the flat encoding and decoding (and consequently,
the zigzag) for large integers in the following ways:
- It removes support for encoding and decoding i128 values.
- It optionally (feature = "num-bigint") introduces encoding and
decoding of large sized integers through the num-bigint::BigInt
type.
Without the feature enabled, it is still possible to encode and decode
isize values; but the use of i128 is now prohibited (as it would
overflow on boundaries) in favor of arbitrarily sized integers.
The commit also introduces a missing property roundtrip for encoding
and decoding large integers, which was missing and thus, failed to
identify the overflow problem.
See related issue: https://github.com/aiken-lang/aiken/issues/796
This commit is contained in:
parent
0c026ef4c9
commit
0b1e5f0231
8 changed files with 133 additions and 54 deletions
|
|
@ -3,6 +3,9 @@ mod error;
|
|||
|
||||
use crate::flat::filler::Filler;
|
||||
|
||||
#[cfg(feature = "num-bigint")]
|
||||
use num_bigint::BigInt;
|
||||
|
||||
pub use decoder::Decoder;
|
||||
pub use error::Error;
|
||||
|
||||
|
|
@ -36,9 +39,10 @@ impl Decode<'_> for isize {
|
|||
}
|
||||
}
|
||||
|
||||
impl Decode<'_> for i128 {
|
||||
#[cfg(feature = "num-bigint")]
|
||||
impl Decode<'_> for BigInt {
|
||||
fn decode(d: &mut Decoder) -> Result<Self, Error> {
|
||||
d.big_integer()
|
||||
Ok(d.big_integer()?.into())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue