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


Java TDeserializer.deserialize方法代码示例

本文整理汇总了Java中org.apache.thrift.TDeserializer.deserialize方法的典型用法代码示例。如果您正苦于以下问题:Java TDeserializer.deserialize方法的具体用法?Java TDeserializer.deserialize怎么用?Java TDeserializer.deserialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.thrift.TDeserializer的用法示例。


在下文中一共展示了TDeserializer.deserialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: apply

import org.apache.thrift.TDeserializer; //导入方法依赖的package包/类
@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;
}
 
开发者ID:cityzendata,项目名称:warp10-platform,代码行数:31,代码来源:UNWRAPENCODER.java

示例8: unwrapLog

import org.apache.thrift.TDeserializer; //导入方法依赖的package包/类
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;
  }
}
 
开发者ID:cityzendata,项目名称:warp10-platform,代码行数:28,代码来源:LogUtil.java

示例9: readThrift

import org.apache.thrift.TDeserializer; //导入方法依赖的package包/类
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);
  }
}
 
开发者ID:yarpc,项目名称:yarpc-java,代码行数:11,代码来源:UnaryThriftTransportHandler.java

示例10: deserializeObject

import org.apache.thrift.TDeserializer; //导入方法依赖的package包/类
/**
 * Deserialize a Thrift object from JSON.
 *
 * @param serializedObject the JSON string representation of the object
 * @param obj the Thrift object to populate fields
 *
 * @throws MetadataException if there is an error deserializing
 */
public static <T extends TBase> void deserializeObject(String serializedObject, T obj)
    throws MetadataException {
  TDeserializer deserializer = new TDeserializer(new TJSONProtocol.Factory());

  try {
    deserializer.deserialize(obj, serializedObject, "UTF-8");
  } catch (TException e) {
    throw new MetadataException(e);
  }
}
 
开发者ID:airbnb,项目名称:reair,代码行数:19,代码来源:ReplicationUtils.java

示例11: decode

import org.apache.thrift.TDeserializer; //导入方法依赖的package包/类
public Transaction decode(byte[] encoded) throws IOException {
  TTransaction thriftTx = new TTransaction();
  TDeserializer deserializer = new TDeserializer();
  try {
    deserializer.deserialize(thriftTx, encoded);
    return TransactionConverterUtils.unwrap(thriftTx);
  } catch (TException te) {
    throw new IOException(te);
  }
}
 
开发者ID:apache,项目名称:incubator-tephra,代码行数:11,代码来源:TransactionCodec.java

示例12: deserialize

import org.apache.thrift.TDeserializer; //导入方法依赖的package包/类
/**
 * Deserialize a thrift object
 *
 * @param type The type of object
 * @param bytes The bytes of the object
 * @param <T> The type of object
 * @return The object
 */
public static <T extends TBase<?, ?>> T deserialize(Class<T> type, byte[] bytes) throws TException {
    final TDeserializer deserializer = new TDeserializer();
    try {
        final T object = type.newInstance();
        deserializer.deserialize(object, bytes);
        return object;
    } catch (final Exception ex) {
        throw new TException(ex);
    }
}
 
开发者ID:ezbake,项目名称:ezbake-common-java,代码行数:19,代码来源:ThriftUtils.java

示例13: getJobSpec

import org.apache.thrift.TDeserializer; //导入方法依赖的package包/类
@Override
public JobSpecT getJobSpec(UUID jobId) {

    final String json = jdbc.queryForObject("SELECT str_thrift_spec FROM job_history WHERE pk_job=?",
            String.class, jobId);

    final TDeserializer deserializer = new TDeserializer(new TJSONProtocol.Factory());
    final JobSpecT spec = new JobSpecT();
    try {
        deserializer.deserialize(spec, json.getBytes());
        return spec;
    } catch (TException e) {
        throw new JobSpecException("Failed to parse job spec " + e, e);
    }
}
 
开发者ID:chadmv,项目名称:plow,代码行数:16,代码来源:ThriftJobDaoImpl.java

示例14: decodeMessage

import org.apache.thrift.TDeserializer; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
public TBase decodeMessage(String topic, byte[] payload)
        throws InstantiationException, IllegalAccessException, TException {
    TDeserializer serializer = new TDeserializer(messageProtocolFactory);
    TBase result = this.getMessageClass(topic).newInstance();
    serializer.deserialize(result, payload);
    return result;
}
 
开发者ID:pinterest,项目名称:secor,代码行数:9,代码来源:ThriftUtil.java

示例15: deserialize

import org.apache.thrift.TDeserializer; //导入方法依赖的package包/类
public static TRowLock deserialize(byte[] rowLockBytes) throws IOException {
    if (rowLockBytes == null) {
        return new TRowLock(ROW_LOCK_VERSION, TRowLockState.STABLE, Long.MIN_VALUE);
    }
    TRowLock rowLock = new TRowLock();
    TDeserializer deserializer = createDeserializer();
    try {
        deserializer.deserialize(rowLock, rowLockBytes);
        return rowLock;
    } catch (TException e) {
        throw new IOException(e.getMessage(), e);
    }
}
 
开发者ID:VCNC,项目名称:haeinsa,代码行数:14,代码来源:TRowLocks.java


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