[jira] [Commented] (CODEC-158) Add Codec, StringCodec, and BinaryCodec interfaces that extend both encoder and decoder

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[jira] [Commented] (CODEC-158) Add Codec, StringCodec, and BinaryCodec interfaces that extend both encoder and decoder

Gary D. Gregory (Jira)

    [ https://issues.apache.org/jira/browse/CODEC-158?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13566162#comment-13566162 ]

Gary Gregory commented on CODEC-158:

I'd like to see any new interface work involve generics. So instead of adding more typeless interfaces that would make 2.0 more difficult as a target for porting or compatibility.

For example an Encoder interface would have two types input and output: Encoder<I, O>, same for a Decoder interface. Encoder<I,O> would implement "O encode(<I input>)".

We could then have a "symmetric" Encoder and Decoder interface, ones where the I and O are the same: SymetricEncoder<T> extends Encoder<T,T>.

Then a Codec<I,O> interface would extend both Encoder and Decoder.

The problem today is that because of type erasure and if we had generics, we cannot end up with more than more encode() method. See the generics branch I created for a generics implementation of [codec].

So I'd like to talk about how to solve the generics issue and then backtrack to how this could be back-ported to 1.x in a forward compatible manner if at all possible, I am guessing not though.

> Add Codec, StringCodec, and BinaryCodec interfaces that extend both encoder and decoder
> ---------------------------------------------------------------------------------------
>                 Key: CODEC-158
>                 URL: https://issues.apache.org/jira/browse/CODEC-158
>             Project: Commons Codec
>          Issue Type: Improvement
>    Affects Versions: 1.7
>            Reporter: Mirko Raner
>            Priority: Minor
>         Attachments: CODEC-158.patch, CODEC-158.patch
>   Original Estimate: 1h
>  Remaining Estimate: 1h
> Currently, there are no common interfaces that extend both the encoder and the decoder interfaces. This makes it hard to deal with a codec as a single entity and requires separate treatment of encoder and decoder parts.
> For example, let's say you want to develop a storage abstraction that uses an encoding. Right now, you would need to write
> class Storage
> {
>     @Inject Encoder encoder;
>     @Inject Decoder decoder;
>     //...
> }
> In practice, encoder and decoder need to match, and most likely both encoder and decoder would be bound to the same implementation, like Base64 or URLCodec. Because of the lack of a common superinterface they need to be specified separately. There are some classes like BaseNCodec that can be used to unify some of the encoders and decoders, but they are too specific and restrictive.
> Ideally, I would like to write:
> class Storage
> {
>     @Inject Codec codec;
>     //...
> }
> Assuming that combined encoder/decoder classes like Base64 would implement that Codec interface, this could be directly bound to a combined encoder/decoder implementation.
> It would be nice if these interfaces were added and the existing codec classes (BaseNCodec, Hex, QCodec, QuotedPrintableCodec, URLCodec) could be modified to implement these new interfaces.
> I'm happy to contribute a patch if there is interest in this feature.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira