Skip to content

Commit

Permalink
feat!: Integer as enum type and optimized constrained and variable-…
Browse files Browse the repository at this point in the history
…sized integer encoding (#289)

* Initial working version for optimized integer encoding

* Add int bench

* OER: Reduce integer-related allocations

* Add some docs, typo fixes

* Fix jer integer encoding

* Fix integer encoding of unsigned as signed bytes, cleanup

* PER: reduce unwraps on integer encoding

* Initial adjusted version

* Fix jer integer encoding

* OER: remove unnecessary use of custom to_vec method on BitVec

* Integer types cleanup

* Impl Encode for BigInt, clippy fixes, custom PartialEq

* Bug fixes, clippy, associated UnsignedPair and SignedPair types

* Docs

* Unnecessary full type in Decode for ConstrainedInteger

* Add extra integer tests

* All int bench tests

* PER: explicit usize decoding for choice

* Remove unnecessary parentheses

* Inline some core functions of IntegerType trait

* PER: parse integer small optimization

* Make constraint minimum copy explicit

* One clone less in constraints

* More integer tests
  • Loading branch information
Nicceboy authored Sep 5, 2024
1 parent 7ff1d46 commit 0417ff5
Show file tree
Hide file tree
Showing 21 changed files with 1,515 additions and 503 deletions.
92 changes: 51 additions & 41 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ name = "iai"
path = "benches/iai.rs"
harness = false

[[bench]]
name = "criterion_integer"
path = "benches/integer.rs"
harness = false
test = true

[dependencies]
nom = { version = "7.1.3", default-features = false, features = ["alloc"] }
num-bigint = { version = "0.4.3", default-features = false }
Expand All @@ -59,11 +65,11 @@ nom-bitvec = { package = "bitvec-nom2", version = "0.2.0" }
arrayvec = { version = "0.7.4", default-features = false }
either = { version = "1.9.0", default-features = false }
once_cell = { version = "1.18.0", default-features = false, features = [
"race",
"alloc",
"race",
"alloc",
] }
num-integer = { version = "0.1.45", default-features = false, features = [
"i128",
"i128",
] }
jzon = { version = "0.12.5", optional = true }

Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ type TestTypeB = bool;
type TestTypeA = TestTypeB;
```
```rust
// or
// or
use rasn::prelude::*;

#[derive(AsnType, Decode, Encode)]
Expand Down Expand Up @@ -621,11 +621,11 @@ Test-type-a ::= CHOICE {
raisin OCTET STRING
}
Test-type-b ::= CHOICE {
juice INTEGER (0..3,...),
Test-type-b ::= CHOICE {
juice INTEGER (0..3,...),
wine OCTET STRING,
...,
grappa INTEGER
grappa INTEGER
}
```

Expand Down Expand Up @@ -663,8 +663,8 @@ enum TestTypeB {
<td>

```asn
Test-type-a ::= SEQUENCE {
juice INTEGER (0..3,...),
Test-type-a ::= SEQUENCE {
juice INTEGER (0..3,...),
wine OCTET STRING,
...,
grappa INTEGER OPTIONAL,
Expand Down Expand Up @@ -699,7 +699,7 @@ struct TestTypeA {
<td>

```asn
Test-type-a ::= SET {
Test-type-a ::= SET {
seed NULL,
grape BOOLEAN,
raisin INTEGER
Expand All @@ -711,7 +711,7 @@ Test-type-a ::= SET {

```rust
use rasn::prelude::*;
/// the SET declaration is basically identical to a SEQUENCE declaration,
/// the SET declaration is basically identical to a SEQUENCE declaration,
/// except for the `set` annotation
#[derive(AsnType, Decode, Encode)]
#[rasn(set, automatic_tags)]
Expand All @@ -730,7 +730,7 @@ struct TestTypeA {
<td>

```asn
Test-type-a ::= SEQUENCE {
Test-type-a ::= SEQUENCE {
notQuiteRustCase INTEGER
}
```
Expand All @@ -757,7 +757,7 @@ struct TestTypeA {
<td>

```asn
Test-type-a ::= SEQUENCE {
Test-type-a ::= SEQUENCE {
seed BOOLEAN DEFAULT TRUE,
grape INTEGER OPTIONAL,
raisin INTEGER DEFAULT 1
Expand All @@ -773,7 +773,7 @@ use rasn::prelude::*;
#[derive(AsnType, Decode, Encode)]
#[rasn(automatic_tags)]
struct TestTypeA {
#[rasn(default = "default_seed")]
#[rasn(default = "default_seed")]
seed: bool,
grape: Option<Integer>,
#[rasn(default = "default_raisin")]
Expand Down
Loading

0 comments on commit 0417ff5

Please sign in to comment.