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();
}
}
};
}
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;
}
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);
}
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;
}
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);
}
}
Aggregations