beanit / asn1bean

ASN1bean (formerly known as jASN1) is a Java ASN.1 BER and DER encoding/decoding library
https://www.beanit.com/asn1/
Apache License 2.0
110 stars 45 forks source link

Use Interface on generated classes that includes encode/decode withTag variant #13

Closed maddenj-ie closed 5 years ago

maddenj-ie commented 6 years ago

Hi @sfeuerhahn

I recently updated to the latest version of the JASN.1 library 1.10.0 and I see that a new BerType interface has been added so first of all I would like to thank you for considering it and adding it.

I see the BerType has been added to all types in the type hierarchy and includes the encode/decode methods.

To expand a little on my use case, in order to integrate with a legacy asn.1 message using my RPC framework, I need to be able to use the encode(Inputstream, boolean) variant in order to encode without prepending the tag.

I currently work around this by weaving in my own interface called BerSerializable, into the classes generated by the JASN.1 compiler. I use aspectj to do this at the moment but I would really like to remove it.

Would it be possible to add another interface like BerSerializable that extends BerType but which is only applied to the generated classes produced by the JASN.1 compiler.

Thanks.

sfeuerhahn commented 5 years ago

Hi, sorry for replying so late. I reviewed your code but I'm afraid I cannot merge it since it does not seem generally applicable. I'm sure it serves your specific needs but I don't think many people need this.

maddenj-ie commented 5 years ago

Hi @sfeuerhahn. Thanks for reviewing. The change I'm proposing does not change the behaviour. The methods I'd like to capture in the interface are already public methods on the generated classes. Like the BerType added in a previous PR, the goal is to have the generated classes implement an interface.

In this PR, I've introduced a new interface BerSerializable to achieve this. I only did this as some of the built in Ber types do not have the encode/decode with tag methods so I wanted to isolate the changes.

Would you consider exposing the same methods in an existing interface class like BerType and update the other built in types accordingly.

Thanks for your time.

sfeuerhahn commented 5 years ago

The problem is I cannot add it to BerType because I would not only have to change the built in types but also the encode and decode functions of generated choices and any types. Sorry, I had to decline your pull request.