jOOQ / jOOU

jOOU - Unsigned Integers jOOU provides unsigned integer versions for the four Java integer types byte, short, int and long.
http://www.jooq.org/products
Apache License 2.0
228 stars 32 forks source link

Add a byte array output #15

Closed bachrc closed 6 years ago

bachrc commented 6 years ago

The main advantage, for me, to have unsigned primitives, is to permit a byte array output of the unsigned number.

lukaseder commented 6 years ago

What do you mean by "byte array output". Output out of where?

bachrc commented 6 years ago

You know, when you have an unsigned short for example, you have 2 bytes for your number. It would be really interesting to have a 2-bytes output for a UShort, a 4-bytes for an UInt, etc.

lukaseder commented 6 years ago

You mean byte[] UNumber.getBytes()? What's the use-case for that?

bachrc commented 6 years ago

I have a very strict specification for sending data, where values must be unsigned numbers on 8 bits, 16 bits, etc. And yeah, a byte[] UNumber.getBytes() would be perfect ! And conversely, a UInt, UShort, etc. constructor from bytes ! It would be really helpful.

lukaseder commented 6 years ago

I'm sorry, this is not a viable description of a use-case that justifies adding a rather esoteric feature to a core library of jOOQ. Can you please take some time to explain in detail for what kind of usage this is useful? Also, please include how this would translate to general-purpose usage of such API in other cases than your own. I sincerely doubt it should be a part of jOOU, but maybe I'm missing a really really obvious use-case. "helpful (for you)" is not good enough.

Prior to seeing such a use-case, I'm closing this (for now) as won't fix.

bachrc commented 6 years ago

Maybe my english is bad, sorry. But I need to send a 36 bytes trame, which contains multiple values, and all of them are unsigned. First is an unsigned number of 8 bits, so the value is between 0 and 255. The current signed model in Java reserves a bit for the sign. So I can't have a byte valued 198 for example. The second one is a 2-bytes unsigned short, etc.

And in the end, I need to join all those unsigned byte[] to make one with a 36 bytes size, which I send via MQTT.

lukaseder commented 6 years ago

Thanks for the explanation. As I expected, this sounds super specific to your particular environment and thus is unsuitable for inclusion in the library. You can simply write a small utility (static method) that does this kind of conversion on your side.

bachrc commented 6 years ago

I found that this improvement would suit this library for byte manipulation. Many people I found on stack overflow are struggling with the conversion of unsigned numbers to byte arrays. I can try to implement this functionnality if I have time if you want, and you'll judge if it's worth a pull request!

lukaseder commented 6 years ago

Yes sure, an example implementation might certainly help. Please also show some links to those questions...

bachrc commented 6 years ago

A simple search on google and you have tons of it. For example : https://stackoverflow.com/questions/7401550/how-to-convert-int-to-unsigned-byte-and-back https://stackoverflow.com/questions/4266756/can-we-make-unsigned-byte-in-java

lukaseder commented 6 years ago

And what do those have to do with byte arrays?

bachrc commented 6 years ago

It isn't plural, but if we're talking about bigger variables like int or shorts, the need is here. It's how I see it after some days of researches, my point of view isn't absolute. I'll give it a shot, I think this could really be an improvement !