Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed size SEQUENCE OF types should use [T; N] #57

Open
XAMPPRocky opened this issue Oct 19, 2024 · 1 comment
Open

Fixed size SEQUENCE OF types should use [T; N] #57

XAMPPRocky opened this issue Oct 19, 2024 · 1 comment

Comments

@XAMPPRocky
Copy link
Contributor

Currently the compiler always uses the SequenceOf type, but it should use different types if its sizes are restricted. Starting with if it has a fixed size it should use an array.

@6d7a
Copy link
Member

6d7a commented Nov 12, 2024

Thank you for your issue. I was testing this with the following asn1:


IntegerAlias ::= INTEGER (10..14)
FixedSizeAliasSequence ::= SEQUENCE (SIZE (2)) OF IntegerAlias

Which generates the following bindings:

#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, Eq, Hash)]
#[rasn(delegate, size("4"))]
pub struct FixedSizeIntegerSequence(pub [AnonymousFixedSizeIntegerSequence; 4usize]);

#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, Eq, Hash)]
#[rasn(delegate, value("10..=14"))]
pub struct IntegerAlias(pub u8);

However, rasn::Decode requires for [T; 4] that T: Default, so IntegerAlias would need to implement Default. I'm reluctant to derive Default for every type that is used in a fixed size SEQUENCE OF, because of possible conflicts between the derived rust default value and a hypothetical asn1 DEFAULT value for the type in a SEQUENCE or SET.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants