Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public void appendTimestamp(long microsSinceEpoch) {
public void appendFloat(float f) {
checkCapacity(1 + 4);
writeBuffer[writePos++] = primitiveHeader(FLOAT);
writeLong(writeBuffer, writePos, Float.floatToIntBits(f), 8);
writeLong(writeBuffer, writePos, Float.floatToIntBits(f), 4);
Copy link
Contributor

@davidradl davidradl Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I missing something? Long is 8 bytes and it is a writeLong. Could it be that checkCapacity(1 + 4); is incorrect and it should be checkCapacity(1 + 8); Line 286 is a write long with 8 bytes

Copy link
Contributor Author

@JinkunLiu JinkunLiu Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of writeLong function might be misleading. The writeLong function does not always write 8 bytes. Its actual functionality is to write Float.floatToIntBits(f) into writeBuffer[writePos, writePos + numBytes). Similarly, you can refer to Line 198

Copy link
Contributor

@davidradl davidradl Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JinkunLiu ok thanks for the clarification. It agree it is strange/misleading that the method is called writeLong, I would have expected the method to be called writeInt as it seems to have nothing to do with Longs and is writing an Int. Or writeBytes to be more generic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hello @Sxnan, What do you think about the name of writeLong function.

writePos += 4;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@

import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

class BinaryVariantInternalBuilderTest {
Expand Down Expand Up @@ -116,4 +119,12 @@ void testParseJsonObject() throws IOException {
assertThat(variant.getField("k1").getByte()).isEqualTo((byte) 2);
assertThat(variant.getField("k2").getDecimal()).isEqualTo(BigDecimal.valueOf(1.5));
}

@Test
void testAppendFloat() {
BinaryVariantInternalBuilder builder = new BinaryVariantInternalBuilder(false);
ArrayList<Float> floatList = new ArrayList<>(Collections.nCopies(25, 4.2f));

assertThatCode(() -> floatList.forEach(builder::appendFloat)).doesNotThrowAnyException();
}
}