opwvhk commented on code in PR #2652:
URL: https://github.com/apache/avro/pull/2652#discussion_r1450508420
##########
lang/java/avro/src/main/java/org/apache/avro/Conversions.java:
##########
@@ -68,6 +79,40 @@ public UUID fromCharSequence(CharSequence value, Schema
schema, LogicalType type
public CharSequence toCharSequence(UUID value, Schema schema, LogicalType
type) {
return value.toString();
}
+
+ @Override
+ public UUID fromFixed(final GenericFixed value, final Schema schema, final
LogicalType type) {
+ long mostSigBits = 0;
+ long leastSigBits = 0;
+ byte[] bytes = value.bytes();
+ for (int i = 0; i < Long.BYTES; i++) {
+ mostSigBits |= ((long) (bytes[i] & 255)) << (Byte.SIZE * i);
+ leastSigBits |= ((long) (bytes[i + Long.BYTES] & 255)) << (Byte.SIZE *
i);
+ }
+
+ return new UUID(this.convert(mostSigBits), this.convert(leastSigBits));
Review Comment:
This certainly works but given the time it takes to read data over a network
/ from disk), I'd prefer a more readable version:
```
ByteBuffer buffer = ByteBuffer.wrap(value.bytes());
long mostSigBits = bugger.getLong();
long leastSigBits = bugger.getLong();
return new UUID(this.convert(mostSigBits), this.convert(leastSigBits));
```
The additional benefit is that we can easily adjust the byte order without
the byte order bug in the original (for LittleEndian order, the meaning of
MostSigBits and LeastSigBits is reversed as well as the bit order).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]