当前位置: 首页>>代码示例>>Java>>正文


Java TDeserializer类代码示例

本文整理汇总了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);
}
 
开发者ID:json-iterator,项目名称:java-benchmark,代码行数:27,代码来源:DeserThrift.java

示例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);
}
 
开发者ID:json-iterator,项目名称:java-benchmark,代码行数:17,代码来源:DeserThrift.java

示例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);
}
 
开发者ID:json-iterator,项目名称:java-benchmark,代码行数:18,代码来源:DeserThrift.java

示例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);
}
 
开发者ID:json-iterator,项目名称:java-benchmark,代码行数:18,代码来源:DeserThrift.java

示例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());
}
 
开发者ID:yarpc,项目名称:yarpc-java,代码行数:23,代码来源:UnaryThriftTransportHandlerTest.java

示例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);
    }
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:19,代码来源:FBUtilities.java

示例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;

}
 
开发者ID:uber,项目名称:tchannel-java,代码行数:24,代码来源:ThriftSerializer.java

示例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();
}
 
开发者ID:pinterest,项目名称:secor,代码行数:18,代码来源:ThriftMessageParser.java

示例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;
}
 
开发者ID:2013Commons,项目名称:hive-cassandra,代码行数:31,代码来源:CqlPushdownPredicate.java

示例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));
}
 
开发者ID:apache,项目名称:incubator-sentry,代码行数:25,代码来源:TestHMSPathsFullDump.java

示例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);
    }
}
 
开发者ID:devdattakulkarni,项目名称:Cassandra-KVPM,代码行数:18,代码来源:FBUtilities.java

示例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);
}
 
开发者ID:devdattakulkarni,项目名称:Cassandra-KVPM,代码行数:19,代码来源:RangeSliceCommand.java

示例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;
  }
}
 
开发者ID:facebook,项目名称:buck,代码行数:28,代码来源:ThriftRuleKeyDeserializer.java

示例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");
  }
}
 
开发者ID:YinYanfei,项目名称:CadalWorkspace,代码行数:26,代码来源:ProtocolTestBase.java

示例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);
}
 
开发者ID:sambenz,项目名称:URingPaxos,代码行数:18,代码来源:Message.java


注:本文中的org.apache.thrift.TDeserializer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。