MINA
  1. MINA
  2. DIRMINA-823

Add IoBuffer.putUnsigned* methods to balance the getUnsigned* methods for completeness

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Trivial Trivial
    • Resolution: Fixed
    • Affects Version/s: 2.0.2
    • Fix Version/s: 2.0.3
    • Component/s: Core
    • Labels:
      None
    • Environment:
      WXP SP3, Sun SDK 1.5

      Description

      While unsigned integers types are quite meaningful in networking protocols, Java does not provide unsigned integer primitive types. The IoBuffer.getUnsigned* methods are filling the gap between the need of unsigned integers and the real Java programs.

      But IoBuffer does not provide the correlative IoBuffer.putUnsigned* methods. Thus for completeness, this issue proposes to add those IoBuffer.putUnsigned* methods.

      Rgds

        Activity

        Hide
        Emmanuel Lecharny added a comment -

        putUnsigned(xxx) methods don't make a lot of sense. There is no specific treatment applied when doing a put(byte), putInt(int) or putLong(long).

        So why should we implement the symetric operation when the simple existing operations are already doing the job ?

        I mean, yes, it would be candy to the eye, but what kind of added value does it bring ?

        Show
        Emmanuel Lecharny added a comment - putUnsigned(xxx) methods don't make a lot of sense. There is no specific treatment applied when doing a put(byte), putInt(int) or putLong(long). So why should we implement the symetric operation when the simple existing operations are already doing the job ? I mean, yes, it would be candy to the eye, but what kind of added value does it bring ?
        Hide
        Francis ANDRE added a comment -

        For the same reason that Mina provides the getUnsignedShort(), getUnsignedMiddleInt() and getUnsignedInt(): lisibility and share of the code...

        Otherwise, why Mina provides putInt(), putMiddleInt(), putShort() if not for a better lisibility and clean code??? All thoses methods can be expressed by a combination of one or more put(byte b) but the resulting code is quite a bit clumsy. So, the same reasons should apply: lisibility, evidence of the semantic, share of the code, and clean resulting code.

        Show
        Francis ANDRE added a comment - For the same reason that Mina provides the getUnsignedShort(), getUnsignedMiddleInt() and getUnsignedInt(): lisibility and share of the code... Otherwise, why Mina provides putInt(), putMiddleInt(), putShort() if not for a better lisibility and clean code??? All thoses methods can be expressed by a combination of one or more put(byte b) but the resulting code is quite a bit clumsy. So, the same reasons should apply: lisibility, evidence of the semantic, share of the code, and clean resulting code.
        Hide
        Emmanuel Lecharny added a comment -

        I read you. Howerver, again, there is no difference between putInt() and putUnsignedInt().
        In fact, the message I wanted to convey is that the getUnsignedXXX methods have a very specific semantic : to guarantee that we cast a value into a bigger container (getUnsignedInt stores the value into a long), and the semantic of such a method is really wrong, IMHO.

        Should we continue to walk this path, just because the initial API has (again, IMHO) decided to provide some semantically wrong methods ?

        (note that I didn't rejected the issue, I just try to get a clear opinion about this one. Adding the requested methods would be a matter of minutes)

        Show
        Emmanuel Lecharny added a comment - I read you. Howerver, again, there is no difference between putInt() and putUnsignedInt(). In fact, the message I wanted to convey is that the getUnsignedXXX methods have a very specific semantic : to guarantee that we cast a value into a bigger container (getUnsignedInt stores the value into a long), and the semantic of such a method is really wrong, IMHO. Should we continue to walk this path, just because the initial API has (again, IMHO) decided to provide some semantically wrong methods ? (note that I didn't rejected the issue, I just try to get a clear opinion about this one. Adding the requested methods would be a matter of minutes)
        Hide
        Francis ANDRE added a comment -

        IMHO, what is really wrong is the lack of unsigned primitive integral types in Java (but this is another story, blame to Gossling).

        Thus, those methods are doing exactly what it is needed. For example, some communications protocols are using non negative values whith a domain from 0 to 65535 and stored as a 2 bytes bigendian unsigned short.

        As a matter of fact, there is no other choice in Java than to compute and use those formal unsigned short quantities with an int as the container for getting positive computations. So, those IoBuffer methods have the proper signature for getting the job done. (because in any case, the result will end in a bigger container as: short & 0xFFFF)

        So yes, one should continue the same walk for the putUnsignedXXX counter parts for the same reasons.

        Show
        Francis ANDRE added a comment - IMHO, what is really wrong is the lack of unsigned primitive integral types in Java (but this is another story, blame to Gossling). Thus, those methods are doing exactly what it is needed. For example, some communications protocols are using non negative values whith a domain from 0 to 65535 and stored as a 2 bytes bigendian unsigned short. As a matter of fact, there is no other choice in Java than to compute and use those formal unsigned short quantities with an int as the container for getting positive computations. So, those IoBuffer methods have the proper signature for getting the job done. (because in any case, the result will end in a bigger container as: short & 0xFFFF) So yes, one should continue the same walk for the putUnsignedXXX counter parts for the same reasons.
        Hide
        Emmanuel Lecharny added a comment -

        Added the putUnsigned() and putUnsigned(index) method.

        Will add the other ones soon.

        Show
        Emmanuel Lecharny added a comment - Added the putUnsigned() and putUnsigned(index) method. Will add the other ones soon.
        Hide
        Emmanuel Lecharny added a comment -

        putUnsigned() and putUnsigned(int) methods :
        http://svn.apache.org/viewvc?rev=1090567&view=rev

        putUnsignedInt() methods :
        http://svn.apache.org/viewvc?rev=1090572&view=rev

        Show
        Emmanuel Lecharny added a comment - putUnsigned() and putUnsigned(int) methods : http://svn.apache.org/viewvc?rev=1090567&view=rev putUnsignedInt() methods : http://svn.apache.org/viewvc?rev=1090572&view=rev
        Hide
        Emmanuel Lecharny added a comment -
        Show
        Emmanuel Lecharny added a comment - putUnsignedShort() methods : http://svn.apache.org/viewvc?rev=1090588&view=rev
        Hide
        Emmanuel Lecharny added a comment -

        Methods added.

        Show
        Emmanuel Lecharny added a comment - Methods added.

          People

          • Assignee:
            Emmanuel Lecharny
            Reporter:
            Francis ANDRE
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development