Example usage for org.apache.thrift TDeserializer deserialize

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

Introduction

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

Prototype

public void deserialize(TBase base, byte[] bytes) throws TException 

Source Link

Document

Deserialize the Thrift object from a byte array.

Usage

From source file:org.kie.server.thrift.Converter.java

License:Apache License

private static Object deserializeToJava(byte[] bytes, String classCanonicalName, ClassLoader classLoader)
        throws ClassNotFoundException, IllegalAccessException, InstantiationException, TException {
    TDeserializer tDeserializer = ThriftMessageReader.pollTDeserializer();
    try {//from   ww  w  .j  av  a 2s .  c  o m
        TBase tBase = (TBase) classLoader.loadClass(classCanonicalName).newInstance();
        tDeserializer.deserialize(tBase, bytes);
        return thriftDispatch.get(tBase.getClass()).convertToJava(tBase);
    } finally {
        if (tDeserializer != null) {
            ThriftMessageReader.addDeserializer(tDeserializer);
        }
    }
}

From source file:org.kie.server.thrift.Converter.java

License:Apache License

private static Object deserializeToTBase(byte[] bytes, String classCanonicalName, ClassLoader classLoader)
        throws ClassNotFoundException, IllegalAccessException, InstantiationException, TException {
    TDeserializer tDeserializer = ThriftMessageReader.pollTDeserializer();
    try {/*from  w  w  w .j ava 2s  .  co m*/
        TBase tBase = (TBase) classLoader.loadClass(classCanonicalName).newInstance();
        tDeserializer.deserialize(tBase, bytes);
        return tBase;
    } finally {
        if (tDeserializer != null) {
            ThriftMessageReader.addDeserializer(tDeserializer);
        }
    }
}

From source file:storm.trident.util.TridentUtils.java

License:Apache License

public static <T> T thriftDeserialize(Class c, byte[] b) {
    try {//from   www  .  j av  a 2 s  . c  o m
        T ret = (T) c.newInstance();
        TDeserializer des = threadDes.get();
        if (des == null) {
            des = new TDeserializer();
            threadDes.set(des);
        }
        des.deserialize((TBase) ret, b);
        return ret;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

}

From source file:tech.sirwellington.alchemy.thrift.ThriftObjects.java

License:Apache License

public static <T extends TBase> T fromBinary(@NonNull T prototype, @NonEmpty byte[] binary) throws TException {
    checkThat(prototype).usingMessage("missing prototype").is(notNull());

    if (binary == null || binary.length == 0) {
        LOG.warn("missing binary: {}", binary);
        return prototype;
    }//w w  w  . java2 s . com

    TProtocolFactory protocol = new TBinaryProtocol.Factory(true, true);
    TDeserializer deserializer = new TDeserializer(protocol);
    deserializer.deserialize(prototype, binary);
    LOG.debug("Binary with length {} deserialized into TObject {}", binary.length, protocol);
    return prototype;
}