Thrift 中以GBK传输中文字符和分词服务搭建(三)

2014-11-24 09:07:07 · 作者: · 浏览: 11
t64out[(idx++)] = (byte) (int) (n & 0x7F | 0x80);
n >>>= 7;
}
this.trans_.write(this.varint64out, 0, idx);
}
private long longToZigzag(long l) {
return l << 1 ^ l >> 63;
}
private int intToZigZag(int n) {
return n << 1 ^ n >> 31;
}
private void fixedLongToBytes(long n, byte[] buf, int off) {
buf[(off + 0)] = (byte) (int) (n & 0xFF);
buf[(off + 1)] = (byte) (int) (n >> 8 & 0xFF);
buf[(off + 2)] = (byte) (int) (n >> 16 & 0xFF);
buf[(off + 3)] = (byte) (int) (n >> 24 & 0xFF);
buf[(off + 4)] = (byte) (int) (n >> 32 & 0xFF);
buf[(off + 5)] = (byte) (int) (n >> 40 & 0xFF);
buf[(off + 6)] = (byte) (int) (n >> 48 & 0xFF);
buf[(off + 7)] = (byte) (int) (n >> 56 & 0xFF);
}
private void writeByteDirect(byte b)
throws TException {
this.byteDirectBuffer[0] = b;
this.trans_.write(this.byteDirectBuffer);
}
private void writeByteDirect(int n)
throws TException {
writeByteDirect((byte) n);
}
public TMessage readMessageBegin()
throws TException {
byte protocolId = readByte();
if (protocolId != -126) {
throw new TProtocolException("Expected protocol id " + Integer.toHexString(-126) + " but got " + Integer.toHexString(protocolId));
}
byte versionAndType = readByte();
byte version = (byte) (versionAndType & 0x1F);
if (version != 1) {
throw new TProtocolException("Expected version 1 but got " + version);
}
byte type = (byte) (versionAndType >> 5 & 0x3);
int seqid = readVarint32();
String messageName = readString();
return new TMessage(messageName, type, seqid);
}
public TStruct readStructBegin()
throws TException {
this.lastField_.push(this.lastFieldId_);
this.lastFieldId_ = 0;
return ANONYMOUS_STRUCT;
}
public void readStructEnd()
throws TException {
this.lastFieldId_ = this.lastField_.pop();
}
public TField readFieldBegin()
throws TException {
byte type = readByte();
if (type == 0) {
return TSTOP;
}
short modifier = (short) ((type & 0xF0) >> 4);
short fieldId;
if (modifier == 0) {
fieldId = readI16();
} else {
fieldId = (short) (this.lastFieldId_ + modifier);
}
TField field = new TField("", getTType((byte) (type & 0xF)), fieldId);
if (isBoolType(type)) {
this.boolValue_ = ((byte) (type & 0xF) == 1 Boolean.TRUE : Boolean.FALSE);
}
this.lastFieldId_ = field.id;
return field;
}
public TMap readMapBegin()
throws TException {
int size = readVarint32();
byte keyAndValueType = size == 0 0 : readByte();
return new TMap(getTType((byte) (keyAndValueType >> 4)), getTType((byte) (keyAndValueType & 0xF)), size);
}
public TList readListBegin()
throws TException {
byte size_and_type = readByte();
int size = size_and_type >> 4 & 0xF;
if (size == 15) {
size = readVarint32();
}
byte type = getTType(size_and_type);