mmodzelewski commented on code in PR #2516:
URL: https://github.com/apache/iggy/pull/2516#discussion_r2650535368
##########
foreign/java/java-sdk/src/main/java/org/apache/iggy/serde/BytesDeserializer.java:
##########
@@ -194,8 +196,26 @@ public static Message readPolledMessage(ByteBuf response) {
new MessageHeader(checksum, id, offset, timestamp,
originTimestamp, userHeadersLength, payloadLength);
var payload = newByteArray(payloadLength);
response.readBytes(payload);
- // TODO: Add support for user headers.
- return new Message(header, payload, Optional.empty());
+ Optional<Map<String, HeaderValue>> userHeaders = Optional.empty();
+ if (userHeadersLength > 0) {
+ ByteBuf userHeadersBuffer =
response.readSlice(Math.toIntExact(userHeadersLength));
+ Map<String, HeaderValue> headers = new HashMap<>();
+ while (userHeadersBuffer.isReadable()) {
+ long userHeaderKeyLength =
userHeadersBuffer.readUnsignedIntLE();
+ byte[] userHeaderKeyBytes = new
byte[Math.toIntExact(userHeaderKeyLength)];
+ userHeadersBuffer.readBytes(userHeaderKeyBytes);
+ int userHeaderKindCode = userHeadersBuffer.readUnsignedByte();
+ long userHeaderValueLength =
userHeadersBuffer.readUnsignedIntLE();
+ byte[] userHeaderValueBytes = new
byte[Math.toIntExact(userHeaderValueLength)];
+ userHeadersBuffer.readBytes(userHeaderValueBytes);
+ String userHeaderKey = new String(userHeaderKeyBytes,
StandardCharsets.UTF_8);
Review Comment:
for reading `String`, please use an existing convention, e.g.
```
var hostname = response.readCharSequence(toInt(hostnameLength),
StandardCharsets.UTF_8)
.toString();
```
##########
foreign/java/java-sdk/src/main/java/org/apache/iggy/message/Message.java:
##########
@@ -20,26 +20,74 @@
package org.apache.iggy.message;
import java.math.BigInteger;
+import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
public record Message(MessageHeader header, byte[] payload,
Optional<Map<String, HeaderValue>> userHeaders) {
Review Comment:
Let's remove the optional mapping from the type declaration and the methods.
We don't benefit from it here, we can always pass an empty Map instead.
##########
foreign/java/java-sdk/src/main/java/org/apache/iggy/serde/BytesDeserializer.java:
##########
@@ -194,8 +196,26 @@ public static Message readPolledMessage(ByteBuf response) {
new MessageHeader(checksum, id, offset, timestamp,
originTimestamp, userHeadersLength, payloadLength);
var payload = newByteArray(payloadLength);
response.readBytes(payload);
- // TODO: Add support for user headers.
- return new Message(header, payload, Optional.empty());
+ Optional<Map<String, HeaderValue>> userHeaders = Optional.empty();
+ if (userHeadersLength > 0) {
+ ByteBuf userHeadersBuffer =
response.readSlice(Math.toIntExact(userHeadersLength));
+ Map<String, HeaderValue> headers = new HashMap<>();
+ while (userHeadersBuffer.isReadable()) {
+ long userHeaderKeyLength =
userHeadersBuffer.readUnsignedIntLE();
+ byte[] userHeaderKeyBytes = new
byte[Math.toIntExact(userHeaderKeyLength)];
Review Comment:
Convert to int with the helper method `toInt`. You can update its
implementation to use the `toIntExact`
--
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]