MehulBatra commented on code in PR #1409:
URL: https://github.com/apache/fluss/pull/1409#discussion_r2258119047
##########
fluss-common/src/main/java/com/alibaba/fluss/row/encode/iceberg/IcebergBinaryRowWriter.java:
##########
@@ -127,26 +119,42 @@ public void writeDouble(double value) {
}
public void writeString(BinaryString value) {
+ writeString(value, false);
+ }
+
+ public void writeString(BinaryString value, boolean skipEncodeLength) {
// Convert to UTF-8 byte array
byte[] bytes = BinaryString.encodeUTF8(value.toString());
- // Write length prefix followed by UTF-8 bytes
- writeInt(bytes.length); // 4-byte length prefix
+ if (!skipEncodeLength) {
Review Comment:
Seems like we are repeating the same logic in both places how byte arrays
are written, I suggest we combine the common part into a single private helper
method so that the logic is only written once and can be reused.
```
private void writeByteArray(byte[] bytes, boolean skipEncodeLength) {
if (!skipEncodeLength) {
writeInt(bytes.length);
}
ensureCapacity(bytes.length);
segment.put(cursor, bytes, 0, bytes.length);
cursor += bytes.length;
}
```
##########
fluss-common/src/main/java/com/alibaba/fluss/row/encode/iceberg/IcebergBinaryRowWriter.java:
##########
@@ -127,26 +119,42 @@ public void writeDouble(double value) {
}
public void writeString(BinaryString value) {
+ writeString(value, false);
+ }
+
+ public void writeString(BinaryString value, boolean skipEncodeLength) {
// Convert to UTF-8 byte array
byte[] bytes = BinaryString.encodeUTF8(value.toString());
- // Write length prefix followed by UTF-8 bytes
- writeInt(bytes.length); // 4-byte length prefix
+ if (!skipEncodeLength) {
+ // Write length prefix followed by UTF-8 bytes
+ writeInt(bytes.length); // 4-byte length prefix
+ }
ensureCapacity(bytes.length); // Ensure space for actual string bytes
segment.put(cursor, bytes, 0, bytes.length);
cursor += bytes.length;
}
public void writeBytes(byte[] bytes) {
- // Write length prefix followed by binary data
- writeInt(bytes.length); // 4-byte length prefix
+ writeBytes(bytes, false);
+ }
+
+ public void writeBytes(byte[] bytes, boolean skipEncodeLength) {
Review Comment:
With helper method it will be
```
public void writeBytes(byte[] bytes, boolean skipEncodeLength) {
writeByteArray(bytes, skipEncodeLength);
}
```
--
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]