Example usage for org.apache.thrift TDeserializer TDeserializer

List of usage examples for org.apache.thrift TDeserializer TDeserializer

Introduction

In this page you can find the example usage for org.apache.thrift TDeserializer TDeserializer.

Prototype

public TDeserializer() 

Source Link

Document

Create a new TDeserializer that uses the TBinaryProtocol by default.

Usage

From source file:backtype.storm.serialization.GzipThriftSerializationDelegate.java

License:Apache License

@Override
public <T> T deserialize(byte[] bytes, Class<T> clazz) {
    try {//from   w  ww .j a v  a 2s.c  om
        TBase instance = (TBase) clazz.newInstance();
        new TDeserializer().deserialize(instance, Utils.gunzip(bytes));
        return (T) instance;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:backtype.storm.serialization.ThriftSerializationDelegate.java

License:Apache License

@Override
public <T> T deserialize(byte[] bytes, Class<T> clazz) {
    try {//w ww  . j  a  va2 s .  c  om
        TBase instance = (TBase) clazz.newInstance();
        new TDeserializer().deserialize(instance, bytes);
        return (T) instance;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:backtype.storm.utils.LocalState.java

License:Apache License

private Map<String, TBase> deserializeLatestVersion() throws IOException {
    Map<String, TBase> result = new HashMap<String, TBase>();
    TDeserializer td = new TDeserializer();
    for (Map.Entry<String, ThriftSerializedObject> ent : partialDeserializeLatestVersion(td).entrySet()) {
        result.put(ent.getKey(), deserialize(ent.getValue(), td));
    }//w ww.ja  v a  2s .  c  o m
    return result;
}

From source file:backtype.storm.utils.LocalState.java

License:Apache License

private Map<String, ThriftSerializedObject> partialDeserializeLatestVersion(TDeserializer td) {
    try {//from w w w.j a  v a  2  s . c o m
        String latestPath = _vs.mostRecentVersionPath();
        Map<String, ThriftSerializedObject> result = new HashMap<String, ThriftSerializedObject>();
        if (latestPath != null) {
            byte[] serialized = FileUtils.readFileToByteArray(new File(latestPath));
            if (serialized.length == 0) {
                LOG.warn("LocalState file '{}' contained no data, resetting state", latestPath);
            } else {
                if (td == null) {
                    td = new TDeserializer();
                }
                LocalStateData data = new LocalStateData();
                td.deserialize(data, serialized);
                result = data.get_serialized_parts();
            }
        }
        return result;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:backtype.storm.utils.LocalState.java

License:Apache License

public TBase get(String key) {
    TDeserializer td = new TDeserializer();
    Map<String, ThriftSerializedObject> partial = partialSnapshot(td);
    ThriftSerializedObject tso = partial.get(key);
    TBase ret = null;/* ww w  .  j a  v  a2s  . c  o  m*/
    if (tso != null) {
        ret = deserialize(tso, td);
    }
    return ret;
}

From source file:co.cask.tephra.TransactionCodec.java

License:Apache License

public Transaction decode(byte[] encoded) throws IOException {
    TTransaction thriftTx = new TTransaction();
    TDeserializer deserializer = new TDeserializer();
    try {/*  ww  w . j a v  a  2  s.  c  om*/
        deserializer.deserialize(thriftTx, encoded);
        return TransactionConverterUtils.unwrap(thriftTx);
    } catch (TException te) {
        throw new IOException(te);
    }
}

From source file:com.helixleisure.candidates.test.ThriftSerializeDeserializeTest.java

License:Apache License

protected void setUp() throws Exception {
    super.setUp();
    ser = new TSerializer();
    des = new TDeserializer();
}

From source file:com.hopped.runner.rabbitmq.RPCClient.java

License:Open Source License

/**
 * @param request//from w  w  w .j  a v  a 2s.co m
 * @return
 * @throws Exception
 */
public RunList getRunsByUser(RunRequest request) throws Exception {
    RunList response = new RunList();
    String corrId = java.util.UUID.randomUUID().toString();

    BasicProperties props = new BasicProperties.Builder().correlationId(corrId).replyTo(replyQueueName).build();
    TSerializer serializer = new TSerializer();
    channel.basicPublish("", requestQueueName, props, serializer.serialize(request));

    while (true) {
        QueueingConsumer.Delivery delivery = consumer.nextDelivery();
        if (delivery.getProperties().getCorrelationId().equals(corrId)) {
            TDeserializer deserializer = new TDeserializer();
            deserializer.deserialize(response, delivery.getBody());
            break;
        }
    }

    return response;
}

From source file:com.inmobi.messaging.publisher.TestPublisher.java

License:Apache License

@Test
public void testAuditMessage() throws IOException, InterruptedException, TException, EndOfStreamException {
    ClientConfig conf = new ClientConfig();
    conf.set("publisher.classname", "com.inmobi.messaging.publisher.MockInMemoryPublisher");
    conf.set(AuditService.WINDOW_SIZE_KEY, "60");
    conf.set(AuditService.AGGREGATE_WINDOW_KEY, "5");
    conf.set(AbstractMessagePublisher.AUDIT_ENABLED_KEY, "true");

    MessagePublisher publisher = MessagePublisherFactory.create(conf, MockInMemoryPublisher.class.getName());
    publisher.publish("topic", new Message("message".getBytes()));
    publisher.close();//from  w w w .  jav a  2  s  . c  o m
    conf.set("topic.name", AuditUtil.AUDIT_STREAM_TOPIC_NAME);
    conf.set("consumer.name", "c1");
    MessageConsumer consumer = MessageConsumerFactory.create(conf, MockInMemoryConsumer.class.getName());
    ((MockInMemoryConsumer) consumer).setSource(((MockInMemoryPublisher) (publisher)).source);
    Message m = consumer.next();
    TDeserializer deserializer = new TDeserializer();
    AuditMessage audit = new AuditMessage();
    deserializer.deserialize(audit, m.getData().array());
    Collection<Long> values = audit.getReceived().values();
    assert (values.iterator().hasNext());
    assert (values.iterator().next() == 1);

}

From source file:com.mycompany.mavenpails2.ThriftPailStructure.java

private TDeserializer getDeserializer() {
    if (des == null)
        des = new TDeserializer();
    return des;
}