public TProtocol getProtocol(TTransport trans) { return new TCompactProtocolDirect(trans, this.useDirectBuffers); } }
/** * {@inheritDoc} */ @Override public void writeBinary(ByteBuffer buffer) throws TException { int length = buffer.remaining(); writeVarInt32(length); // call this in blocking transport case also to correctly deal with // case when ByteBuffer is not a heap one ThriftUtils.writeByteBuffer(buffer, trans_, nonBlockingTransport, length); }
/** * {@inheritDoc} */ @Override public ByteBuffer readDirectBinary() throws TException { if (this.useDirectBuffers && this.nonBlockingTransport != null) { int length = readVarInt32(); if (length < 0) { throw new TProtocolException(TProtocolException.NEGATIVE_SIZE, "Negative length: " + length); } return ThriftUtils.readByteBuffer(this.nonBlockingTransport, length); } else { return super.readBinary(); } }
/** * Copied from private TCompactProtocol.readVarint32 */ private int readVarInt32() throws TException { int result = 0; int shift = 0; if (trans_.getBytesRemainingInBuffer() >= 5) { byte[] buf = trans_.getBuffer(); int pos = trans_.getBufferPosition(); int off = 0; while (true) { byte b = buf[pos + off]; result |= (b & 0x7f) << shift; if ((b & 0x80) != 0x80) break; shift += 7; off++; } trans_.consumeBuffer(off + 1); } else { while (true) { byte b = readByte(); result |= (b & 0x7f) << shift; if ((b & 0x80) != 0x80) break; shift += 7; } } return result; }
this.useDirectBuffers); } else { inProtocol = new TCompactProtocolDirect(inTransport, this.useDirectBuffers); outProtocol = new TCompactProtocolDirect(outTransport, this.useDirectBuffers);