Closed bachrc closed 6 years ago
What do you mean by "byte array output". Output out of where?
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.
You mean byte[] UNumber.getBytes()
? What's the use-case for that?
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.
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.
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.
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.
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!
Yes sure, an example implementation might certainly help. Please also show some links to those questions...
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
And what do those have to do with byte arrays?
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 !
The main advantage, for me, to have unsigned primitives, is to permit a byte array output of the unsigned number.