Thrift 中以GBK传输中文字符和分词服务搭建(五)
8) break;
shift += 7;
off++;
}
this.trans_.consumeBuffer(off + 1);
} else {
while (true) {
byte b = readByte();
result |= (b & 0x7F) << shift;
if ((b & 0x80) != 128) break;
shift += 7;
}
}
return result;
}
private long readVarint64()
throws TException {
int shift = 0;
long result = 0L;
if (this.trans_.getBytesRemainingInBuffer() >= 10) {
byte[] buf = this.trans_.getBuffer();
int pos = this.trans_.getBufferPosition();
int off = 0;
while (true) {
byte b = buf[(pos + off)];
result |= b & 0x7F << shift;
if ((b & 0x80) != 128) break;
shift += 7;
off++;
}
this.trans_.consumeBuffer(off + 1);
} else {
while (true) {
byte b = readByte();
result |= b & 0x7F << shift;
if ((b & 0x80) != 128) break;
shift += 7;
}
}
return result;
}
private int zigzagToInt(int n) {
return n >>> 1 ^ -(n & 0x1);
}
private long zigzagToLong(long n) {
return n >>> 1 ^ -(n & 1L);
}
private long bytesToLong(byte[] bytes) {
return (bytes[7] & 0xFF) << 56 | (bytes[6] & 0xFF) << 48 | (bytes[5] & 0xFF) << 40 | (bytes[4] & 0xFF) << 32 | (bytes[3] & 0xFF) << 24 | (bytes[2] & 0xFF) << 16 | (bytes[1] & 0xFF) << 8 | bytes[0] & 0xFF;
}
private boolean isBoolType(byte b) {
int lowerNibble = b & 0xF;
return (lowerNibble == 1) || (lowerNibble == 2);
}
private byte getTType(byte type)
throws TProtocolException {
switch ((byte) (type & 0xF)) {
case 0:
return 0;
case 1:
case 2:
return 2;
case 3:
return 3;
case 4:
return 6;
case 5:
return 8;
case 6:
return 10;
case 7:
return 4;
case 8:
return 11;
case 9:
return 15;
case 10:
return 14;
case 11:
return 13;
case 12:
return 12;
}
throw new TProtocolException("don't know what type: " + (byte) (type & 0xF));
}
private byte getCompactType(byte ttype) {
return ttypeToCompactType[ttype];
}
static {
ttypeToCompactType[0] = 0;
ttypeToCompactType[2] = 1;
ttypeToCompactType[3] = 3;
ttypeToCompactType[6] = 4;
ttypeToCompactType[8] = 5;
ttypeToCompactType[10] = 6;
ttypeToCompactType[4] = 7;
ttypeToCompactType[11] = 8;
ttypeToCompactType[15] = 9;
ttypeToCompactType[14] = 10;
ttypeToCompactType[13] = 11;
ttypeToCompactType[12] = 12;
}
private static class Types {
public static final byte BOOLEAN_TRUE = 1;
public static final byte BOOLEAN_FALSE = 2;
public static final byte BYTE = 3;
public static final byte I16 = 4;
public static final byte I32 = 5;
public static final byte I64 = 6;
public static final byte DOUBLE = 7;
public static final byte BINARY = 8;
public static final byte LIST = 9;
public static final byte SET = 10;
public static final byte MAP = 11;
public static final byte STRUCT = 12;
}