use of org.apache.thrift.TDeserializer in project storm by apache.
the class Utils method thriftDeserialize.
public static <T> T thriftDeserialize(Class<T> c, byte[] b, int offset, int length) {
try {
T ret = c.newInstance();
TDeserializer des = getDes();
des.deserialize((TBase) ret, b, offset, length);
return ret;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.apache.thrift.TDeserializer in project storm by apache.
the class LocalState method deserializeLatestVersion.
private Map<String, TBase> deserializeLatestVersion() throws IOException {
Map<String, TBase> result = new HashMap<>();
TDeserializer td = new TDeserializer();
for (Map.Entry<String, ThriftSerializedObject> ent : partialDeserializeLatestVersion(td).entrySet()) {
result.put(ent.getKey(), deserialize(ent.getValue(), td));
}
return result;
}
use of org.apache.thrift.TDeserializer in project hive by apache.
the class JSONMessageFactory method getTableObj.
public static Table getTableObj(ObjectNode jsonTree) throws Exception {
TDeserializer deSerializer = new TDeserializer(new TJSONProtocol.Factory());
Table tableObj = new Table();
String tableJson = jsonTree.get("tableObjJson").asText();
deSerializer.deserialize(tableObj, tableJson, "UTF-8");
return tableObj;
}
use of org.apache.thrift.TDeserializer in project hive by apache.
the class MetadataJSONSerializer method deserializePartitionSpec.
@Override
public HCatPartitionSpec deserializePartitionSpec(List<String> hcatPartitionSpecStrings) throws HCatException {
try {
List<PartitionSpec> partitionSpecList = new ArrayList<PartitionSpec>();
TDeserializer deserializer = new TDeserializer(new TJSONProtocol.Factory());
for (String stringRep : hcatPartitionSpecStrings) {
PartitionSpec partSpec = new PartitionSpec();
deserializer.deserialize(partSpec, stringRep, "UTF-8");
partitionSpecList.add(partSpec);
}
return new HCatPartitionSpec(null, PartitionSpecProxy.Factory.get(partitionSpecList));
} catch (TException deserializationException) {
throw new HCatException("Failed to deserialize!", deserializationException);
}
}
use of org.apache.thrift.TDeserializer in project grpc-java by grpc.
the class ThriftUtils method metadataMarshaller.
/** Produce a metadata marshaller. */
public static <T extends TBase<T, ?>> Metadata.BinaryMarshaller<T> metadataMarshaller(final MessageFactory<T> factory) {
return new Metadata.BinaryMarshaller<T>() {
@Override
public byte[] toBytes(T value) {
try {
TSerializer serializer = new TSerializer();
return serializer.serialize(value);
} catch (TException e) {
throw Status.INTERNAL.withDescription("Error in serializing Thrift Message").withCause(e).asRuntimeException();
}
}
@Override
public T parseBytes(byte[] serialized) {
try {
TDeserializer deserializer = new TDeserializer();
T message = factory.newInstance();
deserializer.deserialize(message, serialized);
return message;
} catch (TException e) {
throw Status.INTERNAL.withDescription("Invalid thrift Byte Sequence").withCause(e).asRuntimeException();
}
}
};
}
Aggregations