Merge pull request #14087 from jasontedor/vle-integral-arrays
Add methods for variable-length encoding integral arrays
This commit is contained in:
commit
b7e09582ce
|
@ -460,6 +460,15 @@ public abstract class StreamInput extends InputStream {
|
|||
return values;
|
||||
}
|
||||
|
||||
public int[] readVIntArray() throws IOException {
|
||||
int length = readVInt();
|
||||
int[] values = new int[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
values[i] = readVInt();
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
public long[] readLongArray() throws IOException {
|
||||
int length = readVInt();
|
||||
long[] values = new long[length];
|
||||
|
@ -469,6 +478,15 @@ public abstract class StreamInput extends InputStream {
|
|||
return values;
|
||||
}
|
||||
|
||||
public long[] readVLongArray() throws IOException {
|
||||
int length = readVInt();
|
||||
long[] values = new long[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
values[i] = readVLong();
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
public float[] readFloatArray() throws IOException {
|
||||
int length = readVInt();
|
||||
float[] values = new float[length];
|
||||
|
|
|
@ -438,6 +438,13 @@ public abstract class StreamOutput extends OutputStream {
|
|||
}
|
||||
}
|
||||
|
||||
public void writeVIntArray(int[] values) throws IOException {
|
||||
writeVInt(values.length);
|
||||
for (int value : values) {
|
||||
writeVInt(value);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeLongArray(long[] values) throws IOException {
|
||||
writeVInt(values.length);
|
||||
for (long value : values) {
|
||||
|
@ -445,6 +452,13 @@ public abstract class StreamOutput extends OutputStream {
|
|||
}
|
||||
}
|
||||
|
||||
public void writeVLongArray(long[] values) throws IOException {
|
||||
writeVInt(values.length);
|
||||
for (long value : values) {
|
||||
writeVLong(value);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeFloatArray(float[] values) throws IOException {
|
||||
writeVInt(values.length);
|
||||
for (float value : values) {
|
||||
|
|
|
@ -276,8 +276,12 @@ public class BytesStreamsTests extends ESTestCase {
|
|||
out.writeDouble(2.2);
|
||||
int[] intArray = {1, 2, 3};
|
||||
out.writeGenericValue(intArray);
|
||||
int[] vIntArray = {4, 5, 6};
|
||||
out.writeVIntArray(vIntArray);
|
||||
long[] longArray = {1, 2, 3};
|
||||
out.writeGenericValue(longArray);
|
||||
long[] vLongArray = {4, 5, 6};
|
||||
out.writeVLongArray(vLongArray);
|
||||
float[] floatArray = {1.1f, 2.2f, 3.3f};
|
||||
out.writeGenericValue(floatArray);
|
||||
double[] doubleArray = {1.1, 2.2, 3.3};
|
||||
|
@ -296,7 +300,9 @@ public class BytesStreamsTests extends ESTestCase {
|
|||
assertThat((double)in.readFloat(), closeTo(1.1, 0.0001));
|
||||
assertThat(in.readDouble(), closeTo(2.2, 0.0001));
|
||||
assertThat(in.readGenericValue(), equalTo((Object) intArray));
|
||||
assertThat(in.readVIntArray(), equalTo(vIntArray));
|
||||
assertThat(in.readGenericValue(), equalTo((Object)longArray));
|
||||
assertThat(in.readVLongArray(), equalTo(vLongArray));
|
||||
assertThat(in.readGenericValue(), equalTo((Object)floatArray));
|
||||
assertThat(in.readGenericValue(), equalTo((Object)doubleArray));
|
||||
assertThat(in.readString(), equalTo("hello"));
|
||||
|
|
Loading…
Reference in New Issue