com.twitter.common.io
Class ThriftCodec<T extends org.apache.thrift.TBase>

java.lang.Object
  extended by com.twitter.common.io.ThriftCodec<T>
All Implemented Interfaces:
Codec<T>

public class ThriftCodec<T extends org.apache.thrift.TBase>
extends Object
implements Codec<T>

A Codec that can encode and decode thrift structs.


Field Summary
static Function<org.apache.thrift.transport.TTransport,org.apache.thrift.protocol.TProtocol> BINARY_PROTOCOL
           
static Function<org.apache.thrift.transport.TTransport,org.apache.thrift.protocol.TProtocol> COMPACT_PROTOCOL
           
static Function<org.apache.thrift.transport.TTransport,org.apache.thrift.protocol.TProtocol> JSON_PROTOCOL
           
 
Constructor Summary
ThriftCodec(Class<T> thriftStructType, Function<org.apache.thrift.transport.TTransport,org.apache.thrift.protocol.TProtocol> protocolFactory)
          Deprecated. use {@link ThriftCodec#create(thriftStructType, protocolFactory) instead.
ThriftCodec(Supplier<T> templateSupplier, Function<org.apache.thrift.transport.TTransport,org.apache.thrift.protocol.TProtocol> protocolFactory)
           
 
Method Summary
static
<T extends org.apache.thrift.TBase>
ThriftCodec<T>
create(Class<T> thriftStructType, Function<org.apache.thrift.transport.TTransport,org.apache.thrift.protocol.TProtocol> protocolFactory)
           
 T deserialize(InputStream source)
          Reads an item from the source stream that was written by Codec.serialize(Object, java.io.OutputStream).
 void serialize(T item, OutputStream sink)
          Writes a representation of item to the sink that can be read back by Codec.deserialize(java.io.InputStream).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JSON_PROTOCOL

public static final Function<org.apache.thrift.transport.TTransport,org.apache.thrift.protocol.TProtocol> JSON_PROTOCOL

BINARY_PROTOCOL

public static final Function<org.apache.thrift.transport.TTransport,org.apache.thrift.protocol.TProtocol> BINARY_PROTOCOL

COMPACT_PROTOCOL

public static final Function<org.apache.thrift.transport.TTransport,org.apache.thrift.protocol.TProtocol> COMPACT_PROTOCOL
Constructor Detail

ThriftCodec

@Deprecated
public ThriftCodec(Class<T> thriftStructType,
                              Function<org.apache.thrift.transport.TTransport,org.apache.thrift.protocol.TProtocol> protocolFactory)
Deprecated. use {@link ThriftCodec#create(thriftStructType, protocolFactory) instead.


ThriftCodec

public ThriftCodec(Supplier<T> templateSupplier,
                   Function<org.apache.thrift.transport.TTransport,org.apache.thrift.protocol.TProtocol> protocolFactory)
Method Detail

create

public static <T extends org.apache.thrift.TBase> ThriftCodec<T> create(Class<T> thriftStructType,
                                                                        Function<org.apache.thrift.transport.TTransport,org.apache.thrift.protocol.TProtocol> protocolFactory)

serialize

public void serialize(T item,
                      OutputStream sink)
               throws IOException
Description copied from interface: Codec
Writes a representation of item to the sink that can be read back by Codec.deserialize(java.io.InputStream).

Specified by:
serialize in interface Codec<T extends org.apache.thrift.TBase>
Parameters:
item - the item to serialize
sink - the stream to write the item out to
Throws:
IOException - if there is a problem serializing the item

deserialize

public T deserialize(InputStream source)
                                              throws IOException
Description copied from interface: Codec
Reads an item from the source stream that was written by Codec.serialize(Object, java.io.OutputStream).

Specified by:
deserialize in interface Codec<T extends org.apache.thrift.TBase>
Parameters:
source - the stream to read an item from
Returns:
the deserialized item
Throws:
IOException - if there is a problem reading an item