com.twitter.common.memcached
Class ThriftTranscoder<T extends org.apache.thrift.TBase>

java.lang.Object
  extended by com.twitter.common.memcached.ThriftTranscoder<T>
Type Parameters:
T - the type to transcode
All Implemented Interfaces:
net.spy.memcached.transcoders.Transcoder<T>

public class ThriftTranscoder<T extends org.apache.thrift.TBase>
extends Object
implements net.spy.memcached.transcoders.Transcoder<T>

A memcached value transcoder that can transcode for a given thrift type.


Constructor Summary
ThriftTranscoder(Class<T> thriftStructType, Function<org.apache.thrift.transport.TTransport,org.apache.thrift.protocol.TProtocol> encoder)
           
 
Method Summary
 boolean asyncDecode(net.spy.memcached.CachedData cachedData)
          Should the transcoder be run asyncronously.
 T decode(net.spy.memcached.CachedData cachedData)
          Decode the cached object into the object it represents.
 net.spy.memcached.CachedData encode(T thriftStruct)
          Encode the given object for storage.
 int getMaxSize()
          Get the maximum size of objects handled by this transcoder.
static
<T extends org.apache.thrift.TBase>
net.spy.memcached.transcoders.Transcoder<T>
of(Class<T> thriftStructType)
          A convenience method that creates a new Transcoder for the given thrift type using the thrift compact binary encoding.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThriftTranscoder

public ThriftTranscoder(Class<T> thriftStructType,
                        Function<org.apache.thrift.transport.TTransport,org.apache.thrift.protocol.TProtocol> encoder)
Parameters:
thriftStructType - the type to transcode
encoder - a factory that can produce a transport for a given protocol
Method Detail

of

public static <T extends org.apache.thrift.TBase> net.spy.memcached.transcoders.Transcoder<T> of(Class<T> thriftStructType)
A convenience method that creates a new Transcoder for the given thrift type using the thrift compact binary encoding.

Type Parameters:
T - the type to transcode
Parameters:
thriftStructType - the type to transcode
Returns:
a new Transcoder that can transcode the given thrift type

encode

public net.spy.memcached.CachedData encode(T thriftStruct)
Description copied from interface: net.spy.memcached.transcoders.Transcoder
Encode the given object for storage.

Specified by:
encode in interface net.spy.memcached.transcoders.Transcoder<T extends org.apache.thrift.TBase>
Parameters:
thriftStruct - the object
Returns:
the CachedData representing what should be sent

decode

public T decode(net.spy.memcached.CachedData cachedData)
Description copied from interface: net.spy.memcached.transcoders.Transcoder
Decode the cached object into the object it represents.

Specified by:
decode in interface net.spy.memcached.transcoders.Transcoder<T extends org.apache.thrift.TBase>
Parameters:
cachedData - the data
Returns:
the return value

asyncDecode

public boolean asyncDecode(net.spy.memcached.CachedData cachedData)
Description copied from interface: net.spy.memcached.transcoders.Transcoder
Should the transcoder be run asyncronously.

Specified by:
asyncDecode in interface net.spy.memcached.transcoders.Transcoder<T extends org.apache.thrift.TBase>
Returns:
True if the CachedData should be decoded Asyncronously

getMaxSize

public int getMaxSize()
Description copied from interface: net.spy.memcached.transcoders.Transcoder
Get the maximum size of objects handled by this transcoder.

Specified by:
getMaxSize in interface net.spy.memcached.transcoders.Transcoder<T extends org.apache.thrift.TBase>