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
4 changes: 2 additions & 2 deletions src/com/esotericsoftware/kryo/io/Output.java
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ public void writeLong (long value) throws KryoException {
* {@link #writeVarLong(long, boolean)} explicitly when writing values that should always use variable length encoding (eg
* values that appear many times).
* @return The number of bytes written.
* @see #longLength(int, boolean) */
* @see #longLength(long, boolean) */
public int writeLong (long value, boolean optimizePositive) throws KryoException {
if (varEncoding) return writeVarLong(value, optimizePositive);
writeLong(value);
Expand Down Expand Up @@ -594,7 +594,7 @@ public int writeVarLong (long value, boolean optimizePositive) throws KryoExcept
}

/** Returns the number of bytes that would be written with {@link #writeLong(long, boolean)}. */
public int longLength (int value, boolean optimizePositive) {
public int longLength (long value, boolean optimizePositive) {
if (varEncoding) return varLongLength(value, optimizePositive);
return 8;
}
Comment on lines 596 to 600
Expand Down
16 changes: 16 additions & 0 deletions test/com/esotericsoftware/kryo/io/InputOutputTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ void testByteBufferInputEnd () {
assertTrue(in.end());
}

@Test
void testLongLength () {
// Values spanning each var-long byte boundary, including values outside int range and negatives.
long[] values = {0L, 127L, 128L, 1L << 28, 1L << 32, 1L << 40, 1L << 48, 1L << 56, Long.MAX_VALUE, -1L,
Long.MIN_VALUE};
Comment on lines +56 to +58
for (boolean optimizePositive : new boolean[] {true, false}) {
for (long value : values) {
Output output = new Output(16);
int written = output.writeVarLong(value, optimizePositive);
assertEquals(written, output.longLength(value, optimizePositive),
"value=" + value + " optimizePositive=" + optimizePositive);
assertEquals(written, Output.varLongLength(value, optimizePositive));
}
}
}

@Test
void testOutputStream () throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
Expand Down
Loading