Search in sources :

Example 11 with TDeserializer

use of org.apache.thrift.TDeserializer in project grpc-java by grpc.

the class ThriftUtils method marshaller.

/** Create a {@code Marshaller} for thrift messages. */
public static <T extends TBase<T, ?>> Marshaller<T> marshaller(final MessageFactory<T> factory) {
    return new Marshaller<T>() {

        @Override
        public InputStream stream(T value) {
            return new ThriftInputStream(value);
        }

        @Override
        public T parse(InputStream stream) {
            try {
                byte[] bytes = IoUtils.toByteArray(stream);
                TDeserializer deserializer = new TDeserializer();
                T message = factory.newInstance();
                deserializer.deserialize(message, bytes);
                return message;
            } catch (TException e) {
                throw Status.INTERNAL.withDescription("Invalid Stream").withCause(e).asRuntimeException();
            } catch (IOException e) {
                throw Status.INTERNAL.withDescription("failed to read stream").withCause(e).asRuntimeException();
            }
        }
    };
}
Also used : TException(org.apache.thrift.TException) Marshaller(io.grpc.MethodDescriptor.Marshaller) TDeserializer(org.apache.thrift.TDeserializer) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 12 with TDeserializer

use of org.apache.thrift.TDeserializer in project eiger by wlloyd.

the class CassandraStorage method cfdefFromString.

private static CfDef cfdefFromString(String st) {
    assert st != null;
    TDeserializer deserializer = new TDeserializer(new TBinaryProtocol.Factory());
    CfDef cfDef = new CfDef();
    try {
        deserializer.deserialize(cfDef, Hex.hexToBytes(st));
    } catch (TException e) {
        throw new RuntimeException(e);
    }
    return cfDef;
}
Also used : TException(org.apache.thrift.TException) TDeserializer(org.apache.thrift.TDeserializer)

Example 13 with TDeserializer

use of org.apache.thrift.TDeserializer in project eiger by wlloyd.

the class RangeSliceCommandSerializer method deserialize.

public RangeSliceCommand deserialize(DataInput dis, int version) throws IOException {
    String keyspace = dis.readUTF();
    String columnFamily = dis.readUTF();
    int scLength = dis.readInt();
    ByteBuffer superColumn = null;
    if (scLength > 0) {
        byte[] buf = new byte[scLength];
        dis.readFully(buf);
        superColumn = ByteBuffer.wrap(buf);
    }
    TDeserializer dser = new TDeserializer(new TBinaryProtocol.Factory());
    SlicePredicate pred = new SlicePredicate();
    FBUtilities.deserialize(dser, pred, dis);
    List<IndexExpression> rowFilter = null;
    if (version >= MessagingService.VERSION_11) {
        int filterCount = dis.readInt();
        rowFilter = new ArrayList<IndexExpression>(filterCount);
        for (int i = 0; i < filterCount; i++) {
            IndexExpression expr = new IndexExpression();
            FBUtilities.deserialize(dser, expr, dis);
            rowFilter.add(expr);
        }
    }
    AbstractBounds<RowPosition> range = AbstractBounds.serializer().deserialize(dis, version).toRowBounds();
    int maxResults = dis.readInt();
    boolean maxIsColumns = false;
    if (version >= MessagingService.VERSION_11) {
        maxIsColumns = dis.readBoolean();
    }
    return new RangeSliceCommand(keyspace, columnFamily, superColumn, pred, range, rowFilter, maxResults, maxIsColumns);
}
Also used : TDeserializer(org.apache.thrift.TDeserializer) IndexExpression(org.apache.cassandra.thrift.IndexExpression) SlicePredicate(org.apache.cassandra.thrift.SlicePredicate) ByteBuffer(java.nio.ByteBuffer) TBinaryProtocol(org.apache.cassandra.thrift.TBinaryProtocol)

Example 14 with TDeserializer

use of org.apache.thrift.TDeserializer in project eiger by wlloyd.

the class ConfigHelper method keyRangeFromString.

private static KeyRange keyRangeFromString(String st) {
    assert st != null;
    TDeserializer deserializer = new TDeserializer(new TBinaryProtocol.Factory());
    KeyRange keyRange = new KeyRange();
    try {
        deserializer.deserialize(keyRange, Hex.hexToBytes(st));
    } catch (TException e) {
        throw new RuntimeException(e);
    }
    return keyRange;
}
Also used : TException(org.apache.thrift.TException) TDeserializer(org.apache.thrift.TDeserializer) TBinaryProtocol(org.apache.cassandra.thrift.TBinaryProtocol) KeyRange(org.apache.cassandra.thrift.KeyRange)

Example 15 with TDeserializer

use of org.apache.thrift.TDeserializer in project storm by apache.

the class GzipThriftSerializationDelegate method deserialize.

@Override
public <T> T deserialize(byte[] bytes, Class<T> clazz) {
    try {
        TBase instance = (TBase) clazz.newInstance();
        new TDeserializer().deserialize(instance, Utils.gunzip(bytes));
        return (T) instance;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : TDeserializer(org.apache.thrift.TDeserializer) TBase(org.apache.thrift.TBase) TException(org.apache.thrift.TException)

Aggregations

TDeserializer (org.apache.thrift.TDeserializer)30 TException (org.apache.thrift.TException)19 IOException (java.io.IOException)8 TBase (org.apache.thrift.TBase)6 Table (org.apache.hadoop.hive.metastore.api.Table)4 TBinaryProtocol (org.apache.cassandra.thrift.TBinaryProtocol)3 HCatException (org.apache.hive.hcatalog.common.HCatException)3 ThriftSerializedObject (org.apache.storm.generated.ThriftSerializedObject)3 TJSONProtocol (org.apache.thrift.protocol.TJSONProtocol)3 LoggerFactory (org.slf4j.LoggerFactory)3 RT (clojure.lang.RT)2 FileNotFoundException (java.io.FileNotFoundException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 SlicePredicate (org.apache.cassandra.thrift.SlicePredicate)2 ExecuteException (org.apache.commons.exec.ExecuteException)2 Partition (org.apache.hadoop.hive.metastore.api.Partition)2 ParseException (org.json.simple.parser.ParseException)2 Example (com.airbnb.aerosolve.core.Example)1 AgentStatMemoryGcBo (com.navercorp.pinpoint.common.server.bo.AgentStatMemoryGcBo)1