public virtual int ReadVInt()
{
// .NET Port: Going back to original code instead of Java code below due to sbyte/byte diff
/*byte b = ReadByte();
int i = b & 0x7F;
for (int shift = 7; (b & 0x80) != 0; shift += 7)
{
b = ReadByte();
i |= (b & 0x7F) << shift;
}
return i;*/
byte b = ReadByte();
if ((sbyte)b >= 0)
{
return b;
}
int i = b & 0x7F;
b = ReadByte();
i |= (b & 0x7F) << 7;
if ((sbyte)b >= 0)
{
return i;
}
b = ReadByte();
i |= (b & 0x7F) << 14;
if ((sbyte)b >= 0)
{
return i;
}
b = ReadByte();
i |= (b & 0x7F) << 21;
if ((sbyte)b >= 0)
{
return i;
}
b = ReadByte();
// Warning: the next ands use 0x0F / 0xF0 - beware copy/paste errors:
i |= (b & 0x0F) << 28;
if (((sbyte)b & 0xF0) == 0)
{
return i;
}
throw new System.IO.IOException("Invalid vInt detected (too many bits)");
}
/// <summary> /// Restore a <seealso cref="ForUtil"/> from a <seealso cref="DataInput"/>. /// </summary> public ForUtil(DataInput @in) { int packedIntsVersion = @in.ReadVInt(); PackedInts.CheckVersion(packedIntsVersion); EncodedSizes = new int[33]; Encoders = new PackedInts.Encoder[33]; Decoders = new PackedInts.Decoder[33]; Iterations = new int[33]; for (int bpv = 1; bpv <= 32; ++bpv) { int code = @in.ReadVInt(); int formatId = (int)((uint)code >> 5); int bitsPerValue = (code & 31) + 1; PackedInts.Format format = PackedInts.Format.ById(formatId); Debug.Assert(format.IsSupported(bitsPerValue)); EncodedSizes[bpv] = EncodedSize(format, packedIntsVersion, bitsPerValue); Encoders[bpv] = PackedInts.GetEncoder(format, packedIntsVersion, bitsPerValue); Decoders[bpv] = PackedInts.GetDecoder(format, packedIntsVersion, bitsPerValue); Iterations[bpv] = ComputeIterations(Decoders[bpv]); } }