Uploaded image for project: 'Commons Codec'
  1. Commons Codec
  2. CODEC-158

Add Codec, StringCodec, and BinaryCodec interfaces that extend both encoder and decoder

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.7
    • Fix Version/s: None
    • Labels:
      None

      Description

      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.

        Attachments

        1. CODEC-158.patch
          11 kB
          Mirko Raner
        2. CODEC-158.patch
          11 kB
          Mirko Raner

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              mirko@raner.ws Mirko Raner
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:

                Time Tracking

                Estimated:
                Original Estimate - 1h
                1h
                Remaining:
                Remaining Estimate - 1h
                1h
                Logged:
                Time Spent - Not Specified
                Not Specified