Java 类org.apache.thrift.TDeserializer 实例源码

项目:java-benchmark    文件:DeserThrift.java   
@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);
}
项目:java-benchmark    文件:DeserThrift.java   
@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);
}
项目:java-benchmark    文件:DeserThrift.java   
@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);
}
项目:java-benchmark    文件:DeserThrift.java   
@Setup(Level.Trial)
public void benchSetup(BenchmarkParams params) throws TException {
    testObject = new ThriftTestObject();
    testObject.setField1("1");
    testObject.setField2("2");
    testObject.setField3("3");
    testObject.setField4("4");
    testObject.setField5("5");
    testObject.setField6("6");
    testObject.setField7("7");
    testObject.setField8("8");
    testObject.setField9("9");
    testObject.setField10("10");
    serializer = new TSerializer(new TCompactProtocol.Factory());
    deserializer = new TDeserializer(new TCompactProtocol.Factory());
    testData = serializer.serialize(testObject);
}
项目:java-benchmark    文件:DeserThrift.java   
@Setup(Level.Trial)
public void benchSetup(BenchmarkParams params) throws TException {
    testObject = new ThriftTestObject();
    testObject.setField1(31.415926);
    testObject.setField2(61.415923);
    testObject.setField3(31.415269);
    testObject.setField4(53.141926);
    testObject.setField5(13.145926);
    testObject.setField6(43.115926);
    testObject.setField7(31.419265);
    testObject.setField8(23.141596);
    testObject.setField9(43.161592);
    testObject.setField10(0.112);
    serializer = new TSerializer(new TCompactProtocol.Factory());
    deserializer = new TDeserializer(new TCompactProtocol.Factory());
    testData = serializer.serialize(testObject);
}
项目:java-benchmark    文件:DeserThrift.java   
@Setup(Level.Trial)
public void benchSetup(BenchmarkParams params) throws TException {
    testObject = new ThriftTestObject();
    testObject.addToField1(321);
    testObject.addToField1(123);
    testObject.addToField1(132);
    testObject.addToField1(312);
    testObject.addToField1(321);
    testObject.addToField1(123);
    testObject.addToField1(132);
    testObject.addToField1(312);
    testObject.addToField1(321);
    testObject.addToField1(123);
    testObject.addToField1(132);
    testObject.addToField1(312);
    testObject.addToField1(321);
    testObject.addToField1(123);
    testObject.addToField1(132);
    testObject.addToField1(312);
    serializer = new TSerializer(new TCompactProtocol.Factory());
    deserializer = new TDeserializer(new TCompactProtocol.Factory());
    testData = serializer.serialize(testObject);
}
项目:java-benchmark    文件:DeserThrift.java   
@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);
}
项目:yarpc-java    文件:UnaryThriftTransportHandlerTest.java   
@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());
}
项目:cassandra-kmean    文件:FBUtilities.java   
@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);
    }
}
项目:ACaZoo    文件:FBUtilities.java   
@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);
    }
}
项目:tchannel-java    文件:ThriftSerializer.java   
@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;

}
项目:GraphTrek    文件:FBUtilities.java   
@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);
    }
}
项目:Cassandra-Wasef    文件:FBUtilities.java   
@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);
    }
}
项目:stratio-cassandra    文件:FBUtilities.java   
@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);
    }
}
项目:cassandra-cqlMod    文件:FBUtilities.java   
@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);
    }
}
项目:wso2-cassandra    文件:FBUtilities.java   
@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);
    }
}
项目:cassandra-trunk    文件:FBUtilities.java   
@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);
    }
}
项目:secor    文件:ThriftMessageParser.java   
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();
}
项目:cassandra-1.2.16    文件:FBUtilities.java   
@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);
    }
}
项目:hive-cassandra    文件:CqlPushdownPredicate.java   
/**
 * 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;
}
项目:hive-cassandra    文件:CassandraPushdownPredicate.java   
/**
 * 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;
}
项目:incubator-sentry    文件:TestHMSPathsFullDump.java   
@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));
}
项目:Cassandra-KVPM    文件:FBUtilities.java   
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);
    }
}
项目:Cassandra-KVPM    文件:RangeSliceCommand.java   
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);
}
项目:buck    文件:ThriftRuleKeyDeserializer.java   
/**
 * 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;
  }
}
项目:CadalWorkspace    文件:ProtocolTestBase.java   
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");
  }
}
项目:CadalWorkspace    文件:ProtocolTestBase.java   
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");
  }
}
项目:URingPaxos    文件:Message.java   
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);
}
项目:java-benchmark    文件:DeserThrift.java   
@Setup(Level.Trial)
public void benchSetup(BenchmarkParams params) throws TException {
    testObject = new ThriftTestObject();
    testObject.setField1(24.646182098202726);
    serializer = new TSerializer(new TCompactProtocol.Factory());
    deserializer = new TDeserializer(new TCompactProtocol.Factory());
    testData = serializer.serialize(testObject);
}
项目:java-benchmark    文件:DeserThrift.java   
@Setup(Level.Trial)
public void benchSetup(BenchmarkParams params) throws TException {
    testObject = new ThriftTestObject();
    testObject.setField1("1");
    serializer = new TSerializer(new TCompactProtocol.Factory());
    deserializer = new TDeserializer(new TCompactProtocol.Factory());
    testData = serializer.serialize(testObject);
}
项目:java-benchmark    文件:DeserThrift.java   
@Setup(Level.Trial)
public void benchSetup(BenchmarkParams params) throws TException {
    testObject = new ThriftTestObject();
    testObject.setField1("1");
    testObject.setField2("2");
    testObject.setField3("3");
    testObject.setField4("4");
    testObject.setField5("5");
    serializer = new TSerializer(new TCompactProtocol.Factory());
    deserializer = new TDeserializer(new TCompactProtocol.Factory());
    testData = serializer.serialize(testObject);
}
项目:java-benchmark    文件:DeserThrift.java   
@Setup(Level.Trial)
public void benchSetup(BenchmarkParams params) throws TException {
    testObject = new ThriftTestObject();
    testObject.setField1(31415926);
    serializer = new TSerializer(new TCompactProtocol.Factory());
    deserializer = new TDeserializer(new TCompactProtocol.Factory());
    testData = serializer.serialize(testObject);
}
项目:java-benchmark    文件:DeserThrift.java   
@Setup(Level.Trial)
public void benchSetup(BenchmarkParams params) throws TException {
    testObject = new ThriftTestObject();
    testObject.setField1("0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789");
    serializer = new TSerializer(new TCompactProtocol.Factory());
    deserializer = new TDeserializer(new TCompactProtocol.Factory());
    testData = serializer.serialize(testObject);
}
项目:Mastering-Mesos    文件:ThriftBinaryCodec.java   
/**
 * Decodes a binary-encoded byte array into a target type.
 *
 * @param clazz Class to instantiate and deserialize to.
 * @param buffer Buffer to decode.
 * @param <T> Target type.
 * @return A populated message.
 * @throws CodingException If the message could not be decoded.
 */
public static <T extends TBase<T, ?>> T decodeNonNull(Class<T> clazz, byte[] buffer)
    throws CodingException {

  requireNonNull(clazz);
  requireNonNull(buffer);

  try {
    T t = newInstance(clazz);
    new TDeserializer(PROTOCOL_FACTORY).deserialize(t, buffer);
    return t;
  } catch (TException e) {
    throw new CodingException("Failed to deserialize thrift object.", e);
  }
}
项目:zipkin    文件:CodecBenchmarks.java   
private static com.twitter.zipkin.thriftjava.Span deserialize(byte[] serialized) {
  com.twitter.zipkin.thriftjava.Span result = new com.twitter.zipkin.thriftjava.Span();
  try {
    // TDeserializer isn't thread-safe
    new TDeserializer(TBINARY_PROTOCOL_FACTORY).deserialize(result, serialized);
  } catch (TException e) {
    throw new AssertionError(e);
  }
  return result;
}
项目:warp10-platform    文件:UNWRAPENCODER.java   
@Override
public Object apply(WarpScriptStack stack) throws WarpScriptException {
  Object top = stack.pop();

  if (!(top instanceof String) && !(top instanceof byte[])) {
    throw new WarpScriptException(getName() + " operates on a string or byte array.");
  }

  byte[] bytes = top instanceof String ? OrderPreservingBase64.decode(top.toString().getBytes(Charsets.US_ASCII)) : (byte[]) top;

  TDeserializer deser = new TDeserializer(new TCompactProtocol.Factory());

  try {
    GTSWrapper wrapper = new GTSWrapper();

    deser.deserialize(wrapper, bytes);

    GTSDecoder decoder = GTSWrapperHelper.fromGTSWrapperToGTSDecoder(wrapper);

    decoder.next();

    stack.push(decoder.getEncoder(true));
  } catch (TException te) {
    throw new WarpScriptException(getName() + " failed to unwrap encoder.", te);
  } catch (IOException ioe) {
    throw new WarpScriptException(getName() + " failed to unwrap encoder.", ioe);
  }      

  return stack;
}
项目:warp10-platform    文件:LogUtil.java   
public static final LoggingEvent unwrapLog(byte[] key, String logmsg) {    
  try {
    byte[] data = OrderPreservingBase64.decode(logmsg.getBytes(Charsets.US_ASCII));

    if (null == data) {
      return null;      
    }

    data = CryptoUtils.unwrap(key, data);

    if (null == data) {
      return null;
    }

    TDeserializer deserializer = new TDeserializer(new TCompactProtocol.Factory());
    LoggingEvent event = new LoggingEvent();
    try {
      deserializer.deserialize(event, data);
    } catch (TException te) {
      return null;
    }

    return event;      
  } catch (Exception e) {
    return null;
  }
}
项目:yarpc-java    文件:UnaryThriftTransportHandler.java   
private I readThrift(TransportRequest req, byte[] input) {
  try {
    I data = klass.newInstance();
    TDeserializer deserializer = new TDeserializer(protocolFactory);
    deserializer.deserialize(data, input);
    return data;
  } catch (TException | InstantiationException | IllegalAccessException e) {
    throw RequestDecodingException.fromTransportRequest(req, e);
  }
}
项目:yarpc-java    文件:OnewayThriftTransportHandler.java   
@Override
public Completable handleOneway(TransportRequest req) {
  Context ctx = Context.fromRequest(req);
  return req.getBody()
      .accumulate()
      .flatMapCompletable(
          reqBody -> {
            T reqData = klass.newInstance();
            TDeserializer deserializer = new TDeserializer(protocolFactory);
            deserializer.deserialize(reqData, reqBody);
            return CompletionStages.toCompletable(handler.handleOneway(ctx, reqData));
          });
}
项目:yarpc-java    文件:ThriftClient.java   
private <R extends TBase> Single<Reply<R>> buildReply(TransportResponse res, Class<R> resClass) {
  return res.getBody()
      .accumulate()
      .map(
          resBody -> {
            R resData = resClass.newInstance();
            TDeserializer deserializer = new TDeserializer(protocolFactory);
            deserializer.deserialize(resData, resBody);
            return DefaultReply.<R>builder().headers(res.getHeaders()).body(resData).build();
          });
}