本文整理匯總了Java中org.apache.thrift.TDeserializer類的典型用法代碼示例。如果您正苦於以下問題:Java TDeserializer類的具體用法?Java TDeserializer怎麽用?Java TDeserializer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
TDeserializer類屬於org.apache.thrift包,在下文中一共展示了TDeserializer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: benchSetup
import org.apache.thrift.TDeserializer; //導入依賴的package包/類
@Setup(Level.Trial)
public void benchSetup(BenchmarkParams params) throws TException {
testObject = new ThriftTestObject();
testObject.addToField1(createElement("1"));
testObject.addToField1(createElement("2"));
testObject.addToField1(createElement("3"));
testObject.addToField1(createElement("4"));
testObject.addToField1(createElement("1"));
testObject.addToField1(createElement("2"));
testObject.addToField1(createElement("3"));
testObject.addToField1(createElement("4"));
testObject.addToField1(createElement("1"));
testObject.addToField1(createElement("2"));
testObject.addToField1(createElement("3"));
testObject.addToField1(createElement("4"));
testObject.addToField1(createElement("1"));
testObject.addToField1(createElement("2"));
testObject.addToField1(createElement("3"));
testObject.addToField1(createElement("4"));
serializer = new TSerializer(new TCompactProtocol.Factory());
deserializer = new TDeserializer(new TCompactProtocol.Factory());
testData = serializer.serialize(testObject);
}
示例2: benchSetup
import org.apache.thrift.TDeserializer; //導入依賴的package包/類
@Setup(Level.Trial)
public void benchSetup(BenchmarkParams params) throws TException {
ThriftTestWriteObject testObject = new ThriftTestWriteObject();
testObject.setField1(Arrays.asList("1", "2", "3", "4", "5",
"1", "2", "3", "4", "5",
"1", "2", "3", "4", "5"));
HashMap<String, List<String>> field2 = new HashMap<>();
field2.put("1", Arrays.asList("1", "2", "3", "4", "5"));
field2.put("2", Arrays.asList("1", "2", "3", "4", "5"));
field2.put("3", Arrays.asList("1", "2", "3", "4", "5"));
testObject.setField2(field2);
testObject.setField3("x-3");
serializer = new TSerializer(new TCompactProtocol.Factory());
deserializer = new TDeserializer(new TCompactProtocol.Factory());
testData = serializer.serialize(testObject);
}
示例3: benchSetup
import org.apache.thrift.TDeserializer; //導入依賴的package包/類
@Setup(Level.Trial)
public void benchSetup(BenchmarkParams params) throws TException {
testObject = new ThriftTestObject();
testObject.addToField1(31.415926);
testObject.addToField1(61.415923);
testObject.addToField1(31.415269);
testObject.addToField1(53.141926);
testObject.addToField1(13.145926);
testObject.addToField1(43.115926);
testObject.addToField1(31.419265);
testObject.addToField1(23.141596);
testObject.addToField1(43.161592);
testObject.addToField1(0.112);
serializer = new TSerializer(new TCompactProtocol.Factory());
deserializer = new TDeserializer(new TCompactProtocol.Factory());
testData = serializer.serialize(testObject);
}
示例4: benchSetup
import org.apache.thrift.TDeserializer; //導入依賴的package包/類
@Setup(Level.Trial)
public void benchSetup(BenchmarkParams params) throws TException {
testObject = new ThriftTestObject();
testObject.setField1(31415926);
testObject.setField2(61415923);
testObject.setField3(31415269);
testObject.setField4(53141926);
testObject.setField5(13145926);
testObject.setField6(43115926);
testObject.setField7(31419265);
testObject.setField8(23141596);
testObject.setField9(43161592);
testObject.setField10(112);
serializer = new TSerializer(new TCompactProtocol.Factory());
deserializer = new TDeserializer(new TCompactProtocol.Factory());
testData = serializer.serialize(testObject);
}
示例5: testHandleUnary
import org.apache.thrift.TDeserializer; //導入依賴的package包/類
@Test
public void testHandleUnary() throws Exception {
KeyValue.getValue_args reqData = new KeyValue.getValue_args("foo");
TSerializer serializer = new TSerializer(ThriftEncoding.defaultProtocolFactory());
when(req.getBody()).thenReturn(TransportBody.fromByteArray(serializer.serialize(reqData)));
when(dataHandler.handleUnary(any(), argThat(data -> "foo".equals(data.getKey()))))
.thenReturn(
CompletableFuture.completedFuture(
DefaultReply.<KeyValue.getValue_result>builder()
.body(new KeyValue.getValue_result("result", null))
.build()));
UnaryThriftTransportHandler<KeyValue.getValue_args, KeyValue.getValue_result> transportHandler =
new UnaryThriftTransportHandler<>(dataHandler, KeyValue.getValue_args.class);
TransportResponse res = transportHandler.handleUnary(req).blockingGet();
TDeserializer deserializer = new TDeserializer(ThriftEncoding.defaultProtocolFactory());
KeyValue.getValue_result resData = KeyValue.getValue_result.class.newInstance();
deserializer.deserialize(resData, res.getBody().blockingSingle().array());
assertEquals("result", resData.getSuccess());
assertNull(resData.getNotFound());
}
示例6: deserialize
import org.apache.thrift.TDeserializer; //導入依賴的package包/類
@Deprecated
public static void deserialize(TDeserializer deserializer, TBase struct, DataInput in)
throws IOException
{
assert deserializer != null;
assert struct != null;
assert in != null;
byte[] bytes = new byte[in.readInt()];
in.readFully(bytes);
try
{
deserializer.deserialize(struct, bytes);
}
catch (TException ex)
{
throw new IOException(ex);
}
}
示例7: decodeBody
import org.apache.thrift.TDeserializer; //導入依賴的package包/類
@Override
public @Nullable <T> T decodeBody(@NotNull ByteBuf arg3, @NotNull Class<T> bodyType) {
try {
// Create a new instance of type 'T'
T base = bodyType.newInstance();
// Get byte[] from ByteBuf
byte[] payloadBytes = new byte[arg3.readableBytes()];
arg3.readBytes(payloadBytes);
// Actually deserialize the payload
TDeserializer deserializer = new TDeserializer(new TBinaryProtocol.Factory());
deserializer.deserialize((TBase<?, ?>) base, payloadBytes);
return base;
} catch (InstantiationException | IllegalAccessException | TException e) {
logger.error("Failed to decode body to {}", bodyType.getName(), e);
}
return null;
}
示例8: ThriftMessageParser
import org.apache.thrift.TDeserializer; //導入依賴的package包/類
public ThriftMessageParser(SecorConfig config)
throws InstantiationException, IllegalAccessException,
ClassNotFoundException {
super(config);
TProtocolFactory protocolFactory = null;
String protocolName = mConfig.getThriftProtocolClass();
if (StringUtils.isNotEmpty(protocolName)) {
String factoryClassName = protocolName.concat("$Factory");
protocolFactory = ((Class<? extends TProtocolFactory>) Class.forName(factoryClassName)).newInstance();
} else
protocolFactory = new TBinaryProtocol.Factory();
mDeserializer = new TDeserializer(protocolFactory);
mThriftPath = new ThriftPath(mConfig.getMessageTimestampName(),(short) mConfig.getMessageTimestampId());
mTimestampType = mConfig.getMessageTimestampType();
}
示例9: deserializeIndexedColumns
import org.apache.thrift.TDeserializer; //導入依賴的package包/類
/**
* Serialize a set of ColumnDefs for indexed columns, read from Job
* configuration
*
* @param serialized column metadata
* @return list of column metadata objects which may be empty, but not null
*/
public static Set<ColumnDef> deserializeIndexedColumns(String serialized) {
Set<ColumnDef> columns = new HashSet<ColumnDef>();
if (null == serialized) {
return columns;
}
Iterable<String> strings = Splitter.on(AbstractCassandraSerDe.DELIMITER).omitEmptyStrings().trimResults().split(serialized);
TDeserializer deserializer = new TDeserializer(new TBinaryProtocol.Factory());
for (String encoded : strings) {
ColumnDef column = new ColumnDef();
try {
logger.info("Encoded column def: " + encoded);
deserializer.deserialize(column, Hex.hexToBytes(encoded));
} catch (TException e) {
logger.warn("Error deserializing indexed column definition", e);
}
if (null == column.getName() || null == column.validation_class) {
continue;
}
columns.add(column);
}
return columns;
}
示例10: testThrftSerialization
import org.apache.thrift.TDeserializer; //導入依賴的package包/類
@Test
public void testThrftSerialization() throws TException {
HMSPathsDumper serDe = genHMSPathsDumper();
long t1 = System.currentTimeMillis();
TPathsDump pathsDump = serDe.createPathsDump();
TProtocolFactory protoFactory = useCompact ? new TCompactProtocol.Factory(
ServiceConstants.ClientConfig.SENTRY_HDFS_THRIFT_MAX_MESSAGE_SIZE_DEFAULT,
ServiceConstants.ClientConfig.SENTRY_HDFS_THRIFT_MAX_MESSAGE_SIZE_DEFAULT)
: new TBinaryProtocol.Factory(true, true,
ServiceConstants.ClientConfig.SENTRY_HDFS_THRIFT_MAX_MESSAGE_SIZE_DEFAULT,
ServiceConstants.ClientConfig.SENTRY_HDFS_THRIFT_MAX_MESSAGE_SIZE_DEFAULT);
byte[] ser = new TSerializer(protoFactory).serialize(pathsDump);
long serTime = System.currentTimeMillis() - t1;
System.out.println("Serialization Time: " + serTime + ", " + ser.length);
t1 = System.currentTimeMillis();
TPathsDump tPathsDump = new TPathsDump();
new TDeserializer(protoFactory).deserialize(tPathsDump, ser);
HMSPaths fromDump = serDe.initializeFromDump(tPathsDump);
System.out.println("Deserialization Time: " + (System.currentTimeMillis() - t1));
Assert.assertEquals(new HashSet<String>(Arrays.asList("db9.tbl999")), fromDump.findAuthzObject(new String[]{"user", "hive", "warehouse", "db9", "tbl999"}, false));
Assert.assertEquals(new HashSet<String>(Arrays.asList("db9.tbl999")), fromDump.findAuthzObject(new String[]{"user", "hive", "warehouse", "db9", "tbl999", "part99"}, false));
}
示例11: deserialize
import org.apache.thrift.TDeserializer; //導入依賴的package包/類
public static void deserialize(TDeserializer deserializer, TBase struct, DataInput in)
throws IOException
{
assert deserializer != null;
assert struct != null;
assert in != null;
byte[] bytes = new byte[in.readInt()];
in.readFully(bytes);
try
{
deserializer.deserialize(struct, bytes);
}
catch (TException ex)
{
throw new IOException(ex);
}
}
示例12: deserialize
import org.apache.thrift.TDeserializer; //導入依賴的package包/類
public RangeSliceCommand deserialize(DataInputStream dis, int version) throws IOException
{
String keyspace = dis.readUTF();
String column_family = dis.readUTF();
int scLength = dis.readInt();
ByteBuffer super_column = null;
if (scLength > 0)
super_column = ByteBuffer.wrap(readBuf(scLength, dis));
TDeserializer dser = new TDeserializer(new TBinaryProtocol.Factory());
SlicePredicate pred = new SlicePredicate();
FBUtilities.deserialize(dser, pred, dis);
AbstractBounds range = AbstractBounds.serializer().deserialize(dis);
int max_keys = dis.readInt();
return new RangeSliceCommand(keyspace, column_family, super_column, pred, range, max_keys);
}
示例13: readRuleKeys
import org.apache.thrift.TDeserializer; //導入依賴的package包/類
/**
* Reads in a list of rule keys from a file
*
* @param logPath The path to the file
* @return A list of FullRuleKey objects from the file
* @throws IOException Could not read the file
* @throws TException Could not deserialize an entry from the file
*/
public static List<FullRuleKey> readRuleKeys(Path logPath) throws IOException, TException {
ByteBuffer lengthBuf = ByteBuffer.allocate(4);
List<FullRuleKey> ret = new ArrayList<>();
try (FileInputStream logFileStream = new FileInputStream(logPath.toAbsolutePath().toString())) {
while (logFileStream.available() > 0) {
logFileStream.read(lengthBuf.array());
int length = lengthBuf.getInt();
lengthBuf.rewind();
byte[] serialized = new byte[length];
logFileStream.read(serialized);
TDeserializer serializer = new TDeserializer(new TCompactProtocol.Factory());
FullRuleKey ruleKey = new FullRuleKey();
serializer.deserialize(ruleKey, serialized);
ret.add(ruleKey);
}
return ret;
}
}
示例14: benchmark
import org.apache.thrift.TDeserializer; //導入依賴的package包/類
protected void benchmark() throws Exception {
for (int trial = 0; trial < NUM_TRIALS; trial++) {
TSerializer ser = new TSerializer(getFactory());
byte[] serialized = null;
long serStart = System.currentTimeMillis();
for (int rep = 0; rep < NUM_REPS; rep++) {
serialized = ser.serialize(Fixtures.holyMoley);
}
long serEnd = System.currentTimeMillis();
long serElapsed = serEnd - serStart;
System.out.println("Ser:\t" + serElapsed + "ms\t"
+ ((double)serElapsed / NUM_REPS) + "ms per serialization");
HolyMoley cpts = new HolyMoley();
TDeserializer deser = new TDeserializer(getFactory());
long deserStart = System.currentTimeMillis();
for (int rep = 0; rep < NUM_REPS; rep++) {
deser.deserialize(cpts, serialized);
}
long deserEnd = System.currentTimeMillis();
long deserElapsed = deserEnd - deserStart;
System.out.println("Des:\t" + deserElapsed + "ms\t"
+ ((double)deserElapsed / NUM_REPS) + "ms per deserialization");
}
}
示例15: fromByteArray
import org.apache.thrift.TDeserializer; //導入依賴的package包/類
public static Message fromByteArray(byte[] b){
TDeserializer deserializer = new TDeserializer(new TBinaryProtocol.Factory());
ch.usi.da.dlog.thrift.gen.Message m = new ch.usi.da.dlog.thrift.gen.Message();
try {
deserializer.deserialize(m, b);
if(m.to == null){
return null;
}
} catch (TException e) {
return null;
}
List<Command> cmds = new ArrayList<Command>();
for(Cmd c : m.getCommands()){
cmds.add(Command.toCommand(c));
}
return new Message(m.getId(),m.getFrom(),m.getTo(),cmds);
}