-
Notifications
You must be signed in to change notification settings - Fork 18
Description
This is just a abstract idea I had because I'm currently writing a serializer using this crate:
The pattern I hit right now is that to be able to calculate the final encoded length for write_der_header
I have to wrap all tagged fields and resolve things like their lengths, recursively.
But I have to throw away that state directly afterwards, only to reconstruct it again in the directly following call to write_der_content
.
It's not a big overhead by any means, but I was wondering if I could remove it regardless.
Is that something that'd you be interested in as well and/or would want to work on together?
An idea I had is to make ToDer
have an associated type that stores what is in essence a weak normalized form. The basic idea is that the WNF can be encoded into bytes directly without conditionals and without having to allocate/wrap any fields.
That solution would however make ToDer not object-safe until GATs for trait objects land. Not sure if that is a significant usability problem though.
(Fun fact: The last time I had this issue in asnom I actually inverted encoding, writing out the bodies of fields first and the headers afterwards, making heavy use of scatter/gather-IO. But that approach was absurdly complex, hard to use, and not all that efficient in most cases anyway.)