This is an automated email from the ASF dual-hosted git repository.
rpuch pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/main by this push:
new 87217d4897 IGNITE-23461 Remove NaiveVarInts (#4576)
87217d4897 is described below
commit 87217d4897c2aebecb83198372d4c6d28883200f
Author: Roman Puchkovskiy <[email protected]>
AuthorDate: Thu Oct 17 10:56:17 2024 +0400
IGNITE-23461 Remove NaiveVarInts (#4576)
---
.../ClusterStatePersistentSerializerTest.java | 18 ++--
.../cluster/management/LocalStateStorageTest.java | 4 +-
.../topology/api/LogicalNodeSerializerTest.java | 6 +-
.../api/LogicalTopologySnapshotSerializerTest.java | 6 +-
.../internal/util/io/IgniteUnsafeDataInput.java | 2 +-
.../internal/util/io/IgniteUnsafeDataOutput.java | 2 +-
.../ignite/internal/util/io/NaiveVarInts.java | 92 ------------------
.../ignite/internal/util/io/NaiveVarIntsTest.java | 105 ---------------------
.../network/ClusterNodeSerializerTest.java | 6 +-
.../serialization/marshal/ProtocolMarshalling.java | 32 +++++--
10 files changed, 49 insertions(+), 224 deletions(-)
diff --git
a/modules/cluster-management/src/test/java/org/apache/ignite/internal/cluster/management/ClusterStatePersistentSerializerTest.java
b/modules/cluster-management/src/test/java/org/apache/ignite/internal/cluster/management/ClusterStatePersistentSerializerTest.java
index eb8191bb5c..dc57d08024 100644
---
a/modules/cluster-management/src/test/java/org/apache/ignite/internal/cluster/management/ClusterStatePersistentSerializerTest.java
+++
b/modules/cluster-management/src/test/java/org/apache/ignite/internal/cluster/management/ClusterStatePersistentSerializerTest.java
@@ -17,7 +17,6 @@
package org.apache.ignite.internal.cluster.management;
-import static java.util.UUID.randomUUID;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
@@ -43,9 +42,12 @@ class ClusterStatePersistentSerializerTest {
.cmgNodes(Set.of("a", "b"))
.metaStorageNodes(Set.of("c", "d"))
.version("3.0.0")
- .clusterTag(ClusterTag.randomClusterTag(CMG_MESSAGES_FACTORY,
"cluster"))
+ .clusterTag(ClusterTag.clusterTag(CMG_MESSAGES_FACTORY,
"cluster", new UUID(0x1234567890ABCDEFL, 0xFEDCBA0987654321L)))
.initialClusterConfiguration("config")
- .formerClusterIds(List.of(randomUUID(), randomUUID()))
+ .formerClusterIds(List.of(
+ new UUID(0x1234567890ABCDEFL, 0xFEDCBA0987654321L),
+ new UUID(0xFEDCBA0987654321L, 0x1234567890ABCDEFL)
+ ))
.build();
byte[] bytes = VersionedSerialization.toBytes(originalState,
serializer);
@@ -60,7 +62,7 @@ class ClusterStatePersistentSerializerTest {
.cmgNodes(Set.of("a", "b"))
.metaStorageNodes(Set.of("c", "d"))
.version("3.0.0")
- .clusterTag(ClusterTag.randomClusterTag(CMG_MESSAGES_FACTORY,
"cluster"))
+ .clusterTag(ClusterTag.clusterTag(CMG_MESSAGES_FACTORY,
"cluster", new UUID(0x1234567890ABCDEFL, 0xFEDCBA0987654321L)))
.initialClusterConfiguration(null)
.formerClusterIds(null)
.build();
@@ -73,17 +75,19 @@ class ClusterStatePersistentSerializerTest {
@Test
void v1CanBeDeserialized() {
- byte[] bytes =
Base64.getDecoder().decode("Ae++QwMBYQFiAwFjAWQFMy4wLjAHY2x1c3Rlcp1Ct7dR35ELuoeboFbabrgHY29uZmlnAztFBahaoEfJtxGam"
- + "Q6WXJNFRfruL76Bv254dP54iF6V");
+ byte[] bytes =
Base64.getDecoder().decode("Ae++QwMCYgJhAwJkAmMGMy4wLjAIY2x1c3Rlcu/Nq5B4VjQSIUNlhwm63P4HY29uZmlnA+/Nq5B4VhI0IUN"
+ + "lhwm63P4hQ2WHCbrc/u/Nq5B4VjQS");
ClusterState restoredState = VersionedSerialization.fromBytes(bytes,
serializer);
assertThat(restoredState.cmgNodes(), containsInAnyOrder("a", "b"));
assertThat(restoredState.metaStorageNodes(), containsInAnyOrder("c",
"d"));
assertThat(restoredState.version(), is("3.0.0"));
+ assertThat(restoredState.clusterTag().clusterName(), is("cluster"));
+ assertThat(restoredState.clusterTag().clusterId(), is(new
UUID(0x1234567890ABCDEFL, 0xFEDCBA0987654321L)));
assertThat(restoredState.initialClusterConfiguration(), is("config"));
assertThat(
restoredState.formerClusterIds(),
-
contains(UUID.fromString("c947a05a-a805-453b-935c-960e999a11b7"),
UUID.fromString("bf81be2f-eefa-4545-955e-8878fe74786e"))
+ contains(new UUID(0x3412567890ABCDEFL, 0xFEDCBA0987654321L),
new UUID(0xFEDCBA0987654321L, 0x1234567890ABCDEFL))
);
}
}
diff --git
a/modules/cluster-management/src/test/java/org/apache/ignite/internal/cluster/management/LocalStateStorageTest.java
b/modules/cluster-management/src/test/java/org/apache/ignite/internal/cluster/management/LocalStateStorageTest.java
index ca97f2b7be..b0796cf2ae 100644
---
a/modules/cluster-management/src/test/java/org/apache/ignite/internal/cluster/management/LocalStateStorageTest.java
+++
b/modules/cluster-management/src/test/java/org/apache/ignite/internal/cluster/management/LocalStateStorageTest.java
@@ -55,7 +55,7 @@ class LocalStateStorageTest {
void serializationAndDeserialization() {
LocalState originalState = new LocalState(
Set.of("a", "b"),
- ClusterTag.clusterTag(CMG_MESSAGES_FACTORY, "cluster", new
UUID(0x12345678L, 0x87654321L))
+ ClusterTag.clusterTag(CMG_MESSAGES_FACTORY, "cluster", new
UUID(0x1234567890ABCDEFL, 0xFEDCBA0987654321L))
);
storage.saveLocalState(originalState);
@@ -69,7 +69,7 @@ class LocalStateStorageTest {
@Test
void v1CanBeDeserialized() {
- vault.put(new ByteArray("cmg_state"),
Base64.getDecoder().decode("Ae++QwMBYQFiB2NsdXN0ZXLvzauQeFY0EiFDZYcJutz+"));
+ vault.put(new ByteArray("cmg_state"),
Base64.getDecoder().decode("Ae++QwMCYQJiCGNsdXN0ZXLvzauQeFY0EiFDZYcJutz+"));
LocalState localState = storage.getLocalState();
diff --git
a/modules/cluster-management/src/test/java/org/apache/ignite/internal/cluster/management/topology/api/LogicalNodeSerializerTest.java
b/modules/cluster-management/src/test/java/org/apache/ignite/internal/cluster/management/topology/api/LogicalNodeSerializerTest.java
index 72d2af3dd6..61ef8b74ff 100644
---
a/modules/cluster-management/src/test/java/org/apache/ignite/internal/cluster/management/topology/api/LogicalNodeSerializerTest.java
+++
b/modules/cluster-management/src/test/java/org/apache/ignite/internal/cluster/management/topology/api/LogicalNodeSerializerTest.java
@@ -36,7 +36,7 @@ class LogicalNodeSerializerTest {
@Test
void serializationAndDeserialization() {
LogicalNode originalNode = new LogicalNode(
- UUID.randomUUID(),
+ new UUID(0x1234567890ABCDEFL, 0xFEDCBA0987654321L),
"test",
new NetworkAddress("host", 3000),
new NodeMetadata("ext-host", 3001, 3002),
@@ -59,8 +59,8 @@ class LogicalNodeSerializerTest {
@Test
void v1CanBeDeserialized() {
- byte[] bytes =
Base64.getDecoder().decode("Ae++QwHvvkPvzauQeFY0EiFDZYcJutz+BHRlc3QEaG9zdLkXAQhleHQtaG9zdLoXuxcCBHVrZXkEdXZhbAI"
- + "Ec2tleQRzdmFsAgdwcm9maWxl");
+ byte[] bytes =
Base64.getDecoder().decode("Ae++QwHvvkPvzauQeFY0EiFDZYcJutz+BXRlc3QFaG9zdLkXAQlleHQtaG9zdLoXuxcCBXVrZXkFdXZhbAI"
+ + "Fc2tleQVzdmFsAghwcm9maWxl");
LogicalNode restoredNode = VersionedSerialization.fromBytes(bytes,
serializer);
diff --git
a/modules/cluster-management/src/test/java/org/apache/ignite/internal/cluster/management/topology/api/LogicalTopologySnapshotSerializerTest.java
b/modules/cluster-management/src/test/java/org/apache/ignite/internal/cluster/management/topology/api/LogicalTopologySnapshotSerializerTest.java
index dcc911a5da..81e88fa402 100644
---
a/modules/cluster-management/src/test/java/org/apache/ignite/internal/cluster/management/topology/api/LogicalTopologySnapshotSerializerTest.java
+++
b/modules/cluster-management/src/test/java/org/apache/ignite/internal/cluster/management/topology/api/LogicalTopologySnapshotSerializerTest.java
@@ -62,9 +62,9 @@ class LogicalTopologySnapshotSerializerTest {
@Test
void v1CanBeDeserialized() {
- byte[] bytes =
Base64.getDecoder().decode("Ae++Q3wDAe++QwHvvkO+uv7K776t3gAAAAAAAAAABW5vZGUwBWhvc3QwuRcBCnJlc3QtaG9zdDBRvAMCBHVrZ"
- +
"XkFdXZhbDACBHNrZXkFc3ZhbDADBXByb2YxBXByb2YyAe++QwHvvkO+uv7K776t3gEAAAAAAAAABW5vZGUxBWhvc3QxuhcBCnJlc3QtaG9zdDFSvQMCBH"
- +
"VrZXkFdXZhbDECBHNrZXkFc3ZhbDEDBXByb2YxBXByb2YyAQAAAAAAAAACAAAAAAAAAA==");
+ byte[] bytes =
Base64.getDecoder().decode("Ae++Q3wDAe++QwHvvkO+uv7K776t3gAAAAAAAAAABm5vZGUwBmhvc3QwuRcBC3Jlc3QtaG9zdDBRvAMCBXV"
+ +
"rZXkGdXZhbDACBXNrZXkGc3ZhbDADBnByb2YxBnByb2YyAe++QwHvvkO+uv7K776t3gEAAAAAAAAABm5vZGUxBmhvc3QxuhcBC3Jlc3QtaG9zdDFSvQ"
+ +
"MCBXVrZXkGdXZhbDECBXNrZXkGc3ZhbDEDBnByb2YxBnByb2YyAQAAAAAAAAACAAAAAAAAAA==");
LogicalTopologySnapshot restoredSnapshot =
VersionedSerialization.fromBytes(bytes, serializer);
assertThat(restoredSnapshot.version(), is(123L));
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/util/io/IgniteUnsafeDataInput.java
b/modules/core/src/main/java/org/apache/ignite/internal/util/io/IgniteUnsafeDataInput.java
index 0f5d3655c0..1a1d1e53f7 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/util/io/IgniteUnsafeDataInput.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/util/io/IgniteUnsafeDataInput.java
@@ -745,7 +745,7 @@ public class IgniteUnsafeDataInput extends InputStream
implements IgniteDataInpu
/** {@inheritDoc} */
@Override
public String readUTF() throws IOException {
- return readUtfBody(NaiveVarInts.readUnsignedInt(this));
+ return readUtfBody(readVarIntAsInt());
}
/**
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/util/io/IgniteUnsafeDataOutput.java
b/modules/core/src/main/java/org/apache/ignite/internal/util/io/IgniteUnsafeDataOutput.java
index 4996262e93..c52d4e1fe8 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/util/io/IgniteUnsafeDataOutput.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/util/io/IgniteUnsafeDataOutput.java
@@ -719,7 +719,7 @@ public class IgniteUnsafeDataOutput extends OutputStream
implements IgniteDataOu
* @throws IOException In case of error.
*/
private void writeUtf(String s, int utfLen) throws IOException {
- NaiveVarInts.writeUnsignedInt(utfLen, this);
+ writeVarInt(utfLen);
if (utfLen == s.length()) {
writeAsciiStringBytes(s);
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/util/io/NaiveVarInts.java
b/modules/core/src/main/java/org/apache/ignite/internal/util/io/NaiveVarInts.java
deleted file mode 100644
index 095fdc298d..0000000000
---
a/modules/core/src/main/java/org/apache/ignite/internal/util/io/NaiveVarInts.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal.util.io;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import org.apache.ignite.internal.util.VarIntUtils;
-
-/**
- * Utils to read/write naive variable length ints.
- *
- * <p>The 'naivety' relates to a simple algorithm. The naive varints produce
more compact results than the 'general purpose' varints
- * (see {@link VarIntUtils}) when the input integer is approximately between
127 and 254, so they seem to be more appropriate
- * for small values (like lengths of short strings and collections).
- */
-// TODO: IGNITE-23461 remove this class, use VarIntUtils instead.
-public class NaiveVarInts {
- private NaiveVarInts() {
- }
-
- /**
- * Writes an unsigned int using variable length format. If it's less than
0xFF, it's written as one byte.
- * If it's more than 0xFE, but less than 0xFFFF, it's written as 3 bytes:
first one byte equal to 0xFF, then 2 bytes
- * as {@link DataOutput#writeShort(int)} writes them. Otherwise, it writes
3 0xFF bytes, then writes
- * {@link DataOutput#writeInt(int)}.
- * This may be beneficial for the cases when we need to write an unsigned
int, but most of the time the values
- * are small (for example, when writing an array/collection/string length).
- *
- * @param value value to write
- * @param output where to write to value to
- * @throws IOException if an I/O error occurs
- */
- public static void writeUnsignedInt(int value, DataOutput output) throws
IOException {
- if (value < 0) {
- throw new IllegalArgumentException(value + " is negative");
- }
-
- if (value < 0xFF) {
- output.writeByte(value);
- } else if (value < 0xFFFF) {
- output.writeByte(0xFF);
- output.writeShort(value);
- } else {
- output.writeByte(0xFF);
- output.writeShort(0xFFFF);
- output.writeInt(value);
- }
- }
-
- /**
- * Reads an unsigned int written using {@link #writeUnsignedInt(int,
DataOutput)}.
- *
- * @param input from where to read
- * @return the unsigned int value
- * @throws IOException if an I/O error occurs
- * @see #writeUnsignedInt(int, DataOutput)
- */
- public static int readUnsignedInt(DataInput input) throws IOException {
- int first = input.readUnsignedByte();
- if (first < 0xFF) {
- return first;
- }
-
- int second = input.readUnsignedShort();
- if (second < 0xFFFF) {
- return second;
- }
-
- int third = input.readInt();
- if (third < 0) {
- throw new IllegalStateException(third + " is negative");
- }
-
- return third;
- }
-}
diff --git
a/modules/core/src/test/java/org/apache/ignite/internal/util/io/NaiveVarIntsTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/util/io/NaiveVarIntsTest.java
deleted file mode 100644
index 7ce70a22ad..0000000000
---
a/modules/core/src/test/java/org/apache/ignite/internal/util/io/NaiveVarIntsTest.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal.util.io;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.lessThan;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.DataInput;
-import java.io.DataInputStream;
-import java.io.DataOutput;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.stream.Stream;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.Arguments;
-import org.junit.jupiter.params.provider.MethodSource;
-
-class NaiveVarIntsTest {
- @ParameterizedTest
- @MethodSource("intRangeBorders")
- void writesIntsWithCorrectLengths(IntWriteSpec spec) throws Exception {
- byte[] bytes = writeToBytes(output ->
NaiveVarInts.writeUnsignedInt(spec.value, output));
-
- assertThat(bytes.length, is(spec.expectedLength));
- }
-
- private static Stream<Arguments> intRangeBorders() {
- return Stream.of(
- new IntWriteSpec(0, 1),
- new IntWriteSpec(0xFE, 1),
- new IntWriteSpec(0xFF, 3),
- new IntWriteSpec(0xFFFE, 3),
- new IntWriteSpec(0xFFFF, 7),
- new IntWriteSpec(Integer.MAX_VALUE, 7)
- ).map(Arguments::of);
- }
-
- private byte[] writeToBytes(StreamWriter streamWriter) throws IOException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- try (var dos = new DataOutputStream(baos)) {
- streamWriter.write(dos);
- }
- return baos.toByteArray();
- }
-
- private int readIntFromBytesConsuming(byte[] bytes, StreamReader
streamReader) throws IOException {
- ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
- try (var dos = new DataInputStream(bais)) {
- int result = streamReader.read(dos);
- assertThat("Stream was not fully consumed", dos.read(),
is(lessThan(0)));
- return result;
- }
- }
-
- @ParameterizedTest
- @MethodSource("intRangeBorders")
- void writesAndReadsInts(IntWriteSpec spec) throws Exception {
- byte[] bytes = writeToBytes(output ->
NaiveVarInts.writeUnsignedInt(spec.value, output));
- int result = readIntFromBytesConsuming(bytes,
NaiveVarInts::readUnsignedInt);
-
- assertThat(result, is(spec.value));
- }
-
- private interface StreamWriter {
- void write(DataOutput output) throws IOException;
- }
-
- private interface StreamReader {
- int read(DataInput input) throws IOException;
- }
-
- private static class IntWriteSpec {
- private final int value;
- private final int expectedLength;
-
- private IntWriteSpec(int value, int expectedLength) {
- this.value = value;
- this.expectedLength = expectedLength;
- }
-
- /** {@inheritDoc} */
- @Override
- public String toString() {
- return Integer.toString(value);
- }
- }
-}
diff --git
a/modules/network-api/src/test/java/org/apache/ignite/internal/network/ClusterNodeSerializerTest.java
b/modules/network-api/src/test/java/org/apache/ignite/internal/network/ClusterNodeSerializerTest.java
index 4dcfc3eeae..844b6c9caf 100644
---
a/modules/network-api/src/test/java/org/apache/ignite/internal/network/ClusterNodeSerializerTest.java
+++
b/modules/network-api/src/test/java/org/apache/ignite/internal/network/ClusterNodeSerializerTest.java
@@ -34,7 +34,7 @@ class ClusterNodeSerializerTest {
@Test
void serializationAndDeserialization() {
ClusterNode originalNode = new ClusterNodeImpl(
- UUID.randomUUID(),
+ new UUID(0x1234567890ABCDEFL, 0xFEDCBA0987654321L),
"test",
new NetworkAddress("host", 3000),
new NodeMetadata("ext-host", 3001, 3002)
@@ -51,11 +51,11 @@ class ClusterNodeSerializerTest {
@Test
void v1CanBeDeserialized() {
- byte[] bytes =
Base64.getDecoder().decode("Ae++Q5FHweYb0PNweo7gWHuyYaUEdGVzdARob3N0uRcBCGV4dC1ob3N0uhe7Fw==");
+ byte[] bytes =
Base64.getDecoder().decode("Ae++Q+/Nq5B4VjQSIUNlhwm63P4FdGVzdAVob3N0uRcBCWV4dC1ob3N0uhe7Fw==");
ClusterNode restoredNode = VersionedSerialization.fromBytes(bytes,
serializer);
- assertThat(restoredNode.id(),
equalTo(UUID.fromString("70f3d01b-e6c1-4791-a561-b27b58e08e7a")));
+ assertThat(restoredNode.id(), equalTo(new UUID(0x1234567890ABCDEFL,
0xFEDCBA0987654321L)));
assertThat(restoredNode.name(), equalTo("test"));
assertThat(restoredNode.address(), equalTo(new NetworkAddress("host",
3000)));
assertThat(restoredNode.nodeMetadata(), equalTo(new
NodeMetadata("ext-host", 3001, 3002)));
diff --git
a/modules/network/src/main/java/org/apache/ignite/internal/network/serialization/marshal/ProtocolMarshalling.java
b/modules/network/src/main/java/org/apache/ignite/internal/network/serialization/marshal/ProtocolMarshalling.java
index 0f775a6d9d..33faecdacb 100644
---
a/modules/network/src/main/java/org/apache/ignite/internal/network/serialization/marshal/ProtocolMarshalling.java
+++
b/modules/network/src/main/java/org/apache/ignite/internal/network/serialization/marshal/ProtocolMarshalling.java
@@ -21,7 +21,7 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.BitSet;
-import org.apache.ignite.internal.util.io.NaiveVarInts;
+import org.apache.ignite.internal.util.VarIntUtils;
/**
* Protocol-wide elements marshalling.
@@ -31,28 +31,46 @@ class ProtocolMarshalling {
static final int MAX_LENGTH_BYTE_COUNT = 4;
static void writeDescriptorOrCommandId(int id, DataOutput output) throws
IOException {
- NaiveVarInts.writeUnsignedInt(id, output);
+ writeUnsignedVarInt(id, output);
+ }
+
+ private static void writeUnsignedVarInt(int val, DataOutput output) throws
IOException {
+ assert val >= 0 : val;
+
+ // We subtract 1 because VarIntUtils#writeVarInt() adds 1. It does so
to effectively pass a frequenly used -1, but we don't need
+ // it here as the values are always unsigned.
+ VarIntUtils.writeVarInt(val - 1, output);
}
static int readDescriptorOrCommandId(DataInput input) throws IOException {
- return NaiveVarInts.readUnsignedInt(input);
+ return readUnsignedVarInt(input);
+ }
+
+ private static int readUnsignedVarInt(DataInput input) throws IOException {
+ long value = VarIntUtils.readVarInt(input);
+
+ //noinspection NumericCastThatLosesPrecision
+ assert value >= -1 && (int) value == value : value;
+
+ // We add 1 because #readUnsignedVarInt() subtracts 1.
+ return (int) value + 1;
}
static void writeObjectId(int id, DataOutput output) throws IOException {
- NaiveVarInts.writeUnsignedInt(id, output);
+ writeUnsignedVarInt(id, output);
}
static int readObjectId(DataInput input) throws IOException {
- return NaiveVarInts.readUnsignedInt(input);
+ return readUnsignedVarInt(input);
}
static void writeLength(int length, DataOutput output) throws IOException {
- NaiveVarInts.writeUnsignedInt(length, output);
+ writeUnsignedVarInt(length, output);
}
static int readLength(DataInput input) throws IOException {
- return NaiveVarInts.readUnsignedInt(input);
+ return readUnsignedVarInt(input);
}
static void writeFixedLengthBitSet(BitSet bitset, int bitSetLength,
DataOutput output) throws IOException {