protobuf
This commit is contained in:
@@ -114,81 +114,54 @@ public class ProtobufByteBufferReader extends ProtobufReader {
|
|||||||
return nextBytes(size);
|
return nextBytes(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected final int readRawVarint32() { // readUInt32
|
protected final int readRawVarint32() { // readUInt32
|
||||||
fastpath:
|
byte b = nextByte();
|
||||||
{
|
if (b >= 0) {
|
||||||
if (!hasNext()) {
|
return b;
|
||||||
break fastpath;
|
|
||||||
}
|
}
|
||||||
int x;
|
int result = b & 0x7f;
|
||||||
if ((x = nextByte()) >= 0) {
|
if ((b = nextByte()) >= 0) {
|
||||||
return x;
|
result |= b << 7;
|
||||||
} else if (remaining() < 9) {
|
|
||||||
break fastpath;
|
|
||||||
} else if ((x ^= (nextByte() << 7)) < 0) {
|
|
||||||
x ^= (~0 << 7);
|
|
||||||
} else if ((x ^= (nextByte() << 14)) >= 0) {
|
|
||||||
x ^= (~0 << 7) ^ (~0 << 14);
|
|
||||||
} else if ((x ^= (nextByte() << 21)) < 0) {
|
|
||||||
x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21);
|
|
||||||
} else {
|
} else {
|
||||||
int y = nextByte();
|
result |= (b & 0x7f) << 7;
|
||||||
x ^= y << 28;
|
if ((b = nextByte()) >= 0) {
|
||||||
x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21) ^ (~0 << 28);
|
result |= b << 14;
|
||||||
if (y < 0 && nextByte() < 0 && nextByte() < 0 && nextByte() < 0 && nextByte() < 0 && nextByte() < 0) {
|
} else {
|
||||||
break fastpath; // Will throw malformedVarint()
|
result |= (b & 0x7f) << 14;
|
||||||
|
if ((b = nextByte()) >= 0) {
|
||||||
|
result |= b << 21;
|
||||||
|
} else {
|
||||||
|
result |= (b & 0x7f) << 21;
|
||||||
|
result |= (b = nextByte()) << 28;
|
||||||
|
if (b < 0) {
|
||||||
|
// Discard upper 32 bits.
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
if (nextByte() >= 0) {
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return x;
|
throw new ConvertException("readRawVarint32 error");
|
||||||
}
|
}
|
||||||
return (int) readRawVarint64SlowPath();
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected final long readRawVarint64() {
|
protected final long readRawVarint64() {
|
||||||
fastpath:
|
int shift = 0;
|
||||||
{
|
long result = 0;
|
||||||
if (!hasNext()) {
|
while (shift < 64) {
|
||||||
break fastpath;
|
final byte b = nextByte();
|
||||||
|
result |= (long) (b & 0x7F) << shift;
|
||||||
|
if ((b & 0x80) == 0) {
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
long x;
|
shift += 7;
|
||||||
int y;
|
|
||||||
if ((y = nextByte()) >= 0) {
|
|
||||||
return y;
|
|
||||||
} else if (remaining() < 9) {
|
|
||||||
break fastpath;
|
|
||||||
} else if ((y ^= (nextByte() << 7)) < 0) {
|
|
||||||
x = y ^ (~0 << 7);
|
|
||||||
} else if ((y ^= (nextByte() << 14)) >= 0) {
|
|
||||||
x = y ^ ((~0 << 7) ^ (~0 << 14));
|
|
||||||
} else if ((y ^= (nextByte() << 21)) < 0) {
|
|
||||||
x = y ^ ((~0 << 7) ^ (~0 << 14) ^ (~0 << 21));
|
|
||||||
} else if ((x = y ^ ((long) nextByte() << 28)) >= 0L) {
|
|
||||||
x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28);
|
|
||||||
} else if ((x ^= ((long) nextByte() << 35)) < 0L) {
|
|
||||||
x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35);
|
|
||||||
} else if ((x ^= ((long) nextByte() << 42)) >= 0L) {
|
|
||||||
x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35) ^ (~0L << 42);
|
|
||||||
} else if ((x ^= ((long) nextByte() << 49)) < 0L) {
|
|
||||||
x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35) ^ (~0L << 42) ^ (~0L << 49);
|
|
||||||
} else {
|
|
||||||
x ^= ((long) nextByte() << 56);
|
|
||||||
x ^= (~0L << 7)
|
|
||||||
^ (~0L << 14)
|
|
||||||
^ (~0L << 21)
|
|
||||||
^ (~0L << 28)
|
|
||||||
^ (~0L << 35)
|
|
||||||
^ (~0L << 42)
|
|
||||||
^ (~0L << 49)
|
|
||||||
^ (~0L << 56);
|
|
||||||
if (x < 0L) {
|
|
||||||
if (nextByte() < 0L) {
|
|
||||||
break fastpath; // Will throw malformedVarint()
|
|
||||||
}
|
}
|
||||||
}
|
throw new ConvertException("readRawVarint64 error");
|
||||||
}
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
return readRawVarint64SlowPath();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final long readRawVarint64SlowPath() {
|
protected final long readRawVarint64SlowPath() {
|
||||||
|
|||||||
@@ -367,6 +367,30 @@ public class ProtobufFactory extends ConvertFactory<ProtobufReader, ProtobufWrit
|
|||||||
|| componentType == String.class;
|
|| componentType == String.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// see io.protostuff.ProtobufOutput
|
||||||
|
protected static int computeRawVarint32Size(final int value) {
|
||||||
|
if (value == 0) return 1;
|
||||||
|
if ((value & (0xffffffff << 7)) == 0) return 1;
|
||||||
|
if ((value & (0xffffffff << 14)) == 0) return 2;
|
||||||
|
if ((value & (0xffffffff << 21)) == 0) return 3;
|
||||||
|
if ((value & (0xffffffff << 28)) == 0) return 4;
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static int computeRawVarint64Size(final long value) {
|
||||||
|
if (value == 0) return 1;
|
||||||
|
if ((value & (0xffffffffffffffffL << 7)) == 0) return 1;
|
||||||
|
if ((value & (0xffffffffffffffffL << 14)) == 0) return 2;
|
||||||
|
if ((value & (0xffffffffffffffffL << 21)) == 0) return 3;
|
||||||
|
if ((value & (0xffffffffffffffffL << 28)) == 0) return 4;
|
||||||
|
if ((value & (0xffffffffffffffffL << 35)) == 0) return 5;
|
||||||
|
if ((value & (0xffffffffffffffffL << 42)) == 0) return 6;
|
||||||
|
if ((value & (0xffffffffffffffffL << 49)) == 0) return 7;
|
||||||
|
if ((value & (0xffffffffffffffffL << 56)) == 0) return 8;
|
||||||
|
if ((value & (0xffffffffffffffffL << 63)) == 0) return 9;
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
|
||||||
// see com.google.protobuf.CodedOutputStream
|
// see com.google.protobuf.CodedOutputStream
|
||||||
protected static int computeInt32SizeNoTag(final int value) {
|
protected static int computeInt32SizeNoTag(final int value) {
|
||||||
if (value == 0) {
|
if (value == 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user