List of usage examples for org.apache.thrift.protocol TProtocolFactory getProtocol
public TProtocol getProtocol(TTransport trans);
From source file:com.ambiata.poacher.mr.TDeserializerCopy.java
License:Apache License
/** * Create a new TDeserializer. It will use the TProtocol specified by the * factory that is passed in./*from w w w . j ava 2 s .co m*/ * * @param protocolFactory Factory to create a protocol */ public TDeserializerCopy(TProtocolFactory protocolFactory) { trans_ = new TMemoryInputTransport(); protocol_ = protocolFactory.getProtocol(trans_); }
From source file:com.baidu.oped.apm.thrift.io.ChunkHeaderTBaseDeserializer.java
License:Apache License
ChunkHeaderTBaseDeserializer(TProtocolFactory protocolFactory, TBaseLocator locator) { this.trans = new TMemoryInputTransport(); this.protocol = protocolFactory.getProtocol(trans); this.locator = locator; }
From source file:com.baidu.oped.apm.thrift.io.HeaderTBaseDeserializer.java
License:Apache License
/** * Create a new TDeserializer. It will use the TProtocol specified by the * factory that is passed in.// ww w .j a v a 2 s .c o m * * @param protocolFactory Factory to create a protocol */ HeaderTBaseDeserializer(TProtocolFactory protocolFactory, TBaseLocator locator) { this.trans = new TMemoryInputTransport(); this.protocol = protocolFactory.getProtocol(trans); this.locator = locator; }
From source file:com.baidu.oped.apm.thrift.io.HeaderTBaseSerializer.java
License:Apache License
/** * Create a new HeaderTBaseSerializer. // ww w.ja va 2s. co m */ HeaderTBaseSerializer(ResettableByteArrayOutputStream bos, TProtocolFactory protocolFactory, TBaseLocator locator) { this.baos = bos; TIOStreamTransport transport = new TIOStreamTransport(bos); this.protocol = protocolFactory.getProtocol(transport); this.locator = locator; }
From source file:com.ebay.nest.io.sede.thrift.ThriftByteStreamTypedSerDe.java
License:Apache License
private void init(TProtocolFactory inFactory, TProtocolFactory outFactory) throws Exception { outTransport = new TIOStreamTransport(bos); inTransport = new TIOStreamTransport(bis); outProtocol = outFactory.getProtocol(outTransport); inProtocol = inFactory.getProtocol(inTransport); }
From source file:com.facebook.nifty.codec.DefaultThriftFrameDecoder.java
License:Apache License
protected ChannelBuffer tryDecodeUnframedMessage(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer, TProtocolFactory inputProtocolFactory) throws TException { // Perform a trial decode, skipping through // the fields, to see whether we have an entire message available. int messageLength = 0; int messageStartReaderIndex = buffer.readerIndex(); try {/*from w w w . ja v a 2 s .c o m*/ TNiftyTransport decodeAttemptTransport = new TNiftyTransport(channel, buffer, ThriftTransportType.UNFRAMED); int initialReadBytes = decodeAttemptTransport.getReadByteCount(); TProtocol inputProtocol = inputProtocolFactory.getProtocol(decodeAttemptTransport); // Skip through the message inputProtocol.readMessageBegin(); TProtocolUtil.skip(inputProtocol, TType.STRUCT); inputProtocol.readMessageEnd(); messageLength = decodeAttemptTransport.getReadByteCount() - initialReadBytes; } catch (TTransportException | IndexOutOfBoundsException e) { // No complete message was decoded: ran out of bytes return null; } finally { if (buffer.readerIndex() - messageStartReaderIndex > maxFrameSize) { Channels.fireExceptionCaught(ctx, new TooLongFrameException("Maximum frame size of " + maxFrameSize + " exceeded")); } buffer.readerIndex(messageStartReaderIndex); } if (messageLength <= 0) { return null; } // We have a full message in the read buffer, slice it off ChannelBuffer messageBuffer = extractFrame(buffer, messageStartReaderIndex, messageLength); buffer.readerIndex(messageStartReaderIndex + messageLength); return messageBuffer; }
From source file:com.facebook.nifty.duplex.TDuplexProtocolFactory.java
License:Apache License
public static TDuplexProtocolFactory fromSingleFactory(final TProtocolFactory protocolFactory) { return new TDuplexProtocolFactory() { @Override/*ww w. j a va 2 s .c o m*/ public TProtocolPair getProtocolPair(TTransportPair transportPair) { return TProtocolPair.fromSeparateProtocols( protocolFactory.getProtocol(transportPair.getInputTransport()), protocolFactory.getProtocol(transportPair.getOutputTransport())); } }; }
From source file:com.facebook.nifty.duplex.TDuplexProtocolFactory.java
License:Apache License
public static TDuplexProtocolFactory fromSeparateFactories(final TProtocolFactory inputProtocolFactory, final TProtocolFactory outputProtocolFactory) { return new TDuplexProtocolFactory() { @Override//from www .j av a 2 s .co m public TProtocolPair getProtocolPair(TTransportPair transportPair) { return TProtocolPair.fromSeparateProtocols( inputProtocolFactory.getProtocol(transportPair.getInputTransport()), outputProtocolFactory.getProtocol(transportPair.getOutputTransport())); } }; }
From source file:com.facebook.swift.codec.AbstractThriftCodecManagerTest.java
License:Apache License
private <T> T testRoundTripSerialize(ThriftCodec<T> readCodec, ThriftCodec<T> writeCodec, Type structType, T structInstance, TProtocolFactory protocolFactory) throws Exception { ThriftCatalog readCatalog = readCodecManager.getCatalog(); ThriftStructMetadata readMetadata = readCatalog.getThriftStructMetadata(structType); assertNotNull(readMetadata);//from w ww . j a va 2 s.c o m ThriftCatalog writeCatalog = writeCodecManager.getCatalog(); ThriftStructMetadata writeMetadata = writeCatalog.getThriftStructMetadata(structType); assertNotNull(writeMetadata); TMemoryBuffer transport = new TMemoryBuffer(10 * 1024); TProtocol protocol = protocolFactory.getProtocol(transport); writeCodec.write(structInstance, protocol); T copy = readCodec.read(protocol); assertNotNull(copy); assertEquals(copy, structInstance); return copy; }
From source file:com.facebook.swift.codec.TestThriftCodecManager.java
License:Apache License
private <T> void testRoundTripSerialize(ThriftType type, T value, TProtocolFactory protocolFactory) throws Exception { // write value TMemoryBuffer transport = new TMemoryBuffer(10 * 1024); TProtocol protocol = protocolFactory.getProtocol(transport); codecManager.write(type, value, protocol); // read value back T copy = (T) codecManager.read(type, protocol); assertNotNull(copy);/* w w w. ja v a 2 s. co m*/ // verify they are the same assertEquals(copy, value); }