-
-
Notifications
You must be signed in to change notification settings - Fork 51
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
Change trait method signature of octet string decoding to use generic #374
Conversation
Thank you for your PR! However I think in regards to the trait method, I think it would be better to move the octet_string to having a generic for its return type. The motivation for that being, that it would reduce API surface, and allow us to support multiple different container types (e.g. smallvec). |
src/ber/de.rs
Outdated
// BER is not aware of the constraints | ||
let data = self.decode_octet_string(tag, constraints)?; | ||
let mut array = [0u8; N]; | ||
array.copy_from_slice(data.as_slice()); | ||
Ok(array) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BER is not constraint aware, meaning that it doesn't make any format optimisations, but we can still optimise and check this case. If we're parsing a fixed length octet we can still both check that the length matches the fixed length constraint, and copy directly from the input into the array, skipping the vec here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point!
The branching overhead was quite measurable in this case. Having own special function optimizes into single memcpy. I can try the generic version again if it can be avoided. |
7da7194
to
1b09605
Compare
75aab27
to
bf35b2f
Compare
bf35b2f
to
f4a8389
Compare
Main branch might need a manual fix. Something related to partial release of the packages? |
Yeah I'm not sure what the final API looks like, but I think we can combine the constraint validation with the path we should take for the container. E.g. If we have a fixed size constraint, we can try to directly copy into the container. If we don't have a fixed size constraint, but a fixed size container we return an error. trait SequenceOf<T> {
const SIZE: Option<Size> = None;
}
enum Size {
Fixed(usize),
Minimum(usize),
Maximum(usize),
Range(usize, usize),
} |
For UPER, performance boosts is around 20x
For OER, around 2,5x
BER and JER do not use constraints for this case.