當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。