Clarify and correct EndianUtils and SwappedDataInputStream API doc#566
Conversation
| /** | ||
| * Reads a "float" value from a byte array at a given offset. The value is | ||
| * converted to the opposed endian system while reading. | ||
| * Reads a little endian "float" value from a byte array at a given offset. |
There was a problem hiding this comment.
I think that using {@code _type_} would be better here.
There was a problem hiding this comment.
Maybe. What's really confusing here is we need to distinguish two different "floats":
- The Java float primitive in memory in the VM.
- A 4 byte chunk read from an input stream or an array.
I'm not sure I've got this distinction clear enough yet. Let me play with it a bit more.
|
PTAL |
|
|
||
| /** | ||
| * Converts an "int" value between endian systems. | ||
| * Converts an {@code int} value between endian systems. |
There was a problem hiding this comment.
We should be clear that the toggle is between big and little-endian. We'll then avoid the shadow of even thinking about middle-endian madness.
There was a problem hiding this comment.
Good point. Curious, has any system ever actually used middle-endianess or is it just a theoretical possibility? Anyway, let me update this.
|
According to Wikipedia, PDP has something close also referred to PDP-endian! |
elharo
left a comment
There was a problem hiding this comment.
Also corrected Javadoc for SwappedDataInputStream, which had all these problems and some more copy paste errors besides.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #566 +/- ##
=========================================
Coverage 85.98% 85.99%
- Complexity 3496 3497 +1
=========================================
Files 231 231
Lines 8251 8253 +2
Branches 964 964
=========================================
+ Hits 7095 7097 +2
- Misses 865 866 +1
+ Partials 291 290 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| * Reads an unsigned integer (32-bit) value from a byte array at a given | ||
| * offset. The value is converted to the opposed endian system while | ||
| * reading. | ||
| * Reads a little endian unsigned integer (32-bit) value from a byte array at a given |
There was a problem hiding this comment.
Hi @elharo
This is slightly confusing to me: The method returns a long (64-bit) but we are reading an 32-bit integer? Should we clarify this point? Something like "Reads a foo as a bar".
There was a problem hiding this comment.
Since Java's ints are signed you can't fit the unsigned int values from ~2.2 billion to ~4 billion into an int, so you have to return a long. The long will always be <= 2^32, but might be greater than Integer.MAX_INT. Not sure how much of that to say here.
There was a problem hiding this comment.
Makes sense, the comment already mentions "unsigned". TY for the clarification.
Most of the methods in this class are badly named. Except for the swap methods, they all just read and write in little endian order. E.g. consider readSwappedInteger
This always reads four bytes from an input stream and always considers the first byte read to be the least significant. It would have been better named readLittleEndianInteger.
I'm tempted to deprecate the whole thing and replace it with something better named, but for now at least let's correct the Java doc.
@garydgregory