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

项目: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);
}
项目:GlobalFS    文件:CommunicationService.java   
/**
 * Atomically multicast command.
 * 
 * @param command
 * @return A FutureDecision that can be waited on
 */
public void amcast(Command command) throws FSError {
    // right now, it either sends to the given partition or to the global
    // ring
    byte ringid = GLOBAL_RING;
    if (command.getInvolvedPartitions().size() == 1) {
        ringid = command.getInvolvedPartitions().iterator().next().byteValue();
    }
    // TODO: right now its not possible to submit to rings the replica is
    // not part of. Make the replica act as a proxy to one of the responsible replicas?
    log.debug(new StrBuilder().append("Submitting command to ring ").append(ringid).toString());
    Proposer p = this.proposers.get(Byte.valueOf(ringid));
    // TSerializer is not threadsafe, create a new one for each amcast. Is
    // this too expensive?
    final TSerializer serializer = new TSerializer();
    try {
        p.propose(serializer.serialize(command));
    } catch (TException e) {
        e.printStackTrace();
        throw new FSError(Errno.EREMOTEIO, "Error serializing message");
    }
}
项目:warp10-platform    文件:WRAPRAW.java   
@Override
protected Object gtsOp(Map<String, Object> params, GeoTimeSerie gts) throws WarpScriptException {

  GTSWrapper wrapper;

  if (opt) {
    wrapper = GTSWrapperHelper.fromGTSToGTSWrapper(gts, true, 1.0, true);
  } else {
    wrapper = GTSWrapperHelper.fromGTSToGTSWrapper(gts, true);
  }

  TSerializer serializer = new TSerializer(new TCompactProtocol.Factory());

  try {
    byte[] bytes = serializer.serialize(wrapper);

    return bytes;
  } catch (TException te) {
    throw new WarpScriptException(getName() + " failed to wrap GTS.");
  }        
}
项目:warp10-platform    文件:WRAP.java   
@Override
protected Object gtsOp(Map<String, Object> params, GeoTimeSerie gts) throws WarpScriptException {

  GTSWrapper wrapper;

  if (opt) {
    wrapper = GTSWrapperHelper.fromGTSToGTSWrapper(gts, this.compress, 1.0, true);
  } else {
    wrapper = GTSWrapperHelper.fromGTSToGTSWrapper(gts, this.compress);
  }

  TSerializer serializer = new TSerializer(new TCompactProtocol.Factory());

  try {
    byte[] bytes = serializer.serialize(wrapper);

    return new String(OrderPreservingBase64.encode(bytes), Charsets.US_ASCII);
  } catch (TException te) {
    throw new WarpScriptException(getName() + " failed to wrap GTS.");
  }        
}
项目:warp10-platform    文件:GEOPACK.java   
public static String pack(GeoXPShape shape) throws WarpScriptException {
  long[] cells = GeoXPLib.getCells(shape);

  GTSEncoder encoder = new GTSEncoder();

  try {
    for (long cell: cells) {
      encoder.addValue(cell, GeoTimeSerie.NO_LOCATION, GeoTimeSerie.NO_ELEVATION, true);
    }      
  } catch (IOException ioe) {
    throw new WarpScriptException(ioe);
  }

  GTSWrapper wrapper = GTSWrapperHelper.fromGTSEncoderToGTSWrapper(encoder, true);

  TSerializer serializer = new TSerializer(new TCompactProtocol.Factory());

  try {
    byte[] serialized = serializer.serialize(wrapper);

    return new String(OrderPreservingBase64.encode(serialized, 0, serialized.length), Charsets.US_ASCII);      
  } catch (TException te) {
    throw new WarpScriptException(te);
  }
}
项目:warp10-platform    文件:Ingress.java   
void pushMetadataMessage(Metadata metadata) throws IOException {

  if (null == metadata) {
    pushMetadataMessage(null, null);
    return;
  }

  //
  // Compute class/labels Id
  //

  metadata.setClassId(GTSHelper.classId(this.classKey, metadata.getName()));
  metadata.setLabelsId(GTSHelper.labelsId(this.labelsKey, metadata.getLabels()));

  TSerializer serializer = new TSerializer(new TCompactProtocol.Factory());
  try {
    byte[] bytes = new byte[16];
    GTSHelper.fillGTSIds(bytes, 0, metadata.getClassId(), metadata.getLabelsId());
    pushMetadataMessage(bytes, serializer.serialize(metadata));
  } catch (TException te) {
    throw new IOException("Unable to push metadata.");
  }
}
项目:warp10-platform    文件:LogUtil.java   
public static final String serializeLoggingEvent(KeyStore keystore, LoggingEvent event) {
  if (null == event) {
    return null;
  }

  TSerializer serializer = new TSerializer(new TCompactProtocol.Factory());

  byte[] serialized = null;

  try {
    serialized = serializer.serialize(event);
  } catch (TException te) {
    return null;
  }

  if (!checkedAESKey) {
    checkedAESKey = true;
    loggingAESKey = keystore.getKey(KeyStore.AES_LOGGING);      
  }
  if (null != loggingAESKey) {
    serialized = CryptoUtils.wrap(loggingAESKey, serialized);
  }

  return new String(OrderPreservingBase64.encode(serialized), Charsets.US_ASCII); 
}
项目:yarpc-java    文件:ThriftClient.java   
private TransportRequest buildTransportRequest(
    DefaultCall<?> call, Context ctx, String procedure, TBase reqBody)
    throws ThriftEncodingException {
  TSerializer serializer = new TSerializer(protocolFactory);
  try {
    return DefaultTransportRequest.builder()
        .caller(clientConfig.getCaller())
        .service(clientConfig.getService())
        .procedure(procedure)
        .encoding(ThriftEncoding.ENCODING)
        .headers(call.getHeaders())
        .deadline(ctx.getDeadline())
        .span(ctx.getSpan())
        .body(TransportBody.fromByteArray(serializer.serialize(reqBody)))
        .build();
  } catch (TException e) {
    throw new ThriftEncodingException(e);
  }
}
项目: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 serialize(TSerializer serializer, TBase struct, DataOutput out)
throws IOException
{
    assert serializer != null;
    assert struct != null;
    assert out != null;
    byte[] bytes;
    try
    {
        bytes = serializer.serialize(struct);
    }
    catch (TException e)
    {
        throw new RuntimeException(e);
    }
    out.writeInt(bytes.length);
    out.write(bytes);
}
项目:ACaZoo    文件:FBUtilities.java   
@Deprecated
public static void serialize(TSerializer serializer, TBase struct, DataOutput out)
throws IOException
{
    assert serializer != null;
    assert struct != null;
    assert out != null;
    byte[] bytes;
    try
    {
        bytes = serializer.serialize(struct);
    }
    catch (TException e)
    {
        throw new RuntimeException(e);
    }
    out.writeInt(bytes.length);
    out.write(bytes);
}
项目:ezbake-common-java    文件:PostgresConfigurationHelper.java   
public Connection getEzPostgresConnection(EzSecurityToken token) throws SQLException, TException {
    String appName = ezProperties.getProperty(EzBakePropertyConstants.EZBAKE_APPLICATION_NAME);
    Properties dbProperties = new Properties();
    dbProperties.putAll(ezProperties);
    dbProperties.put("user", ezProperties.getProperty(EzBakePropertyConstants.POSTGRES_USERNAME, appName));
    dbProperties.put("password", ezProperties.getProperty(EzBakePropertyConstants.POSTGRES_PASSWORD, appName));
    if (useSSL()) {
        dbProperties.put("ssl", "true");
        dbProperties.put("sslfactory", "org.postgresql.ssl.NonValidatingFactory");
    }

    if (token != null) {
        dbProperties.put("ezbakeTokenProvider", "ezbake.data.postgres.ExplicitTokenProvider");
        dbProperties.put("ezbakeToken", new String(Base64.encodeBase64(new TSerializer().serialize(token)),
                Charsets.US_ASCII));
    }

    return DriverManager.getConnection(String.format("jdbc:ezbake:postgresql://%s:%s/%s",
                    ezProperties.getProperty(EzBakePropertyConstants.POSTGRES_HOST, "localhost"),
                    ezProperties.getProperty(EzBakePropertyConstants.POSTGRES_PORT, "5432"),
                    ezProperties.getProperty(EzBakePropertyConstants.POSTGRES_DB, appName)),
            dbProperties);
}
项目:ezbake-training    文件:SSRConverter.java   
@Override
public SSRJSON convert(TweetWithRaw tweetAndRaw) throws TException {
    Tweet tweet = tweetAndRaw.getTweet();
    SSRJSON ssrJson = new SSRJSON();
    SSR ssr = new SSR();
    ssr.setUri(uriPrefix + tweet.getId());
    ssr.setTitle(String.valueOf(tweet.getId()));
    ssr.setVisibility(new Visibility().setFormalVisibility("U"));
    ssr.setSnippet(tweet.getText());
    if (tweet.getGeoLocation() != null) {
        Coordinate coordinate = new Coordinate();
        coordinate.setLatitude(tweet.getGeoLocation().getLatitude());
        coordinate.setLongitude(tweet.getGeoLocation().getLongitude());
    }
    ssr.setResultDate(TimeUtil.convertToThriftDateTime(tweet.getTimestamp()));
    ssrJson.setSsr(ssr);
    ssrJson.setJsonString(new TSerializer(new TSimpleJSONProtocol.Factory()).toString(tweet));
    return ssrJson;
}
项目:diqube    文件:DiqubeFileWriter.java   
/**
 * Writes the files footer.
 */
@Override
public void close() throws IOException {
  SDiqubeFileFooter footer = new SDiqubeFileFooter();
  footer.setComment((comment != null) ? comment : "");
  footer.setNumberOfRows(numberOfRows);
  footer.setNumberOfTableShards(numberOfTableShards);

  try {
    byte[] footerBytes = compactSerializer.serialize(footer);
    outputStream.write(footerBytes);

    SDiqubeFileFooterInfo fileFooterInfo = new SDiqubeFileFooterInfo();
    fileFooterInfo.setFooterLengthBytes(footerBytes.length);
    byte[] fileFooterInfoBytes = new TSerializer(new TBinaryProtocol.Factory()).serialize(fileFooterInfo);
    outputStream.write(fileFooterInfoBytes);

    outputStream.flush();
  } catch (TException | IOException e) {
    throw new IOException("Could not serialize/write footer", e);
  }
}
项目:GraphTrek    文件:FBUtilities.java   
@Deprecated
public static void serialize(TSerializer serializer, TBase struct, DataOutput out)
throws IOException
{
    assert serializer != null;
    assert struct != null;
    assert out != null;
    byte[] bytes;
    try
    {
        bytes = serializer.serialize(struct);
    }
    catch (TException e)
    {
        throw new RuntimeException(e);
    }
    out.writeInt(bytes.length);
    out.write(bytes);
}
项目:Cassandra-Wasef    文件:FBUtilities.java   
@Deprecated
public static void serialize(TSerializer serializer, TBase struct, DataOutput out)
throws IOException
{
    assert serializer != null;
    assert struct != null;
    assert out != null;
    byte[] bytes;
    try
    {
        bytes = serializer.serialize(struct);
    }
    catch (TException e)
    {
        throw new RuntimeException(e);
    }
    out.writeInt(bytes.length);
    out.write(bytes);
}
项目:stratio-cassandra    文件:FBUtilities.java   
@Deprecated
public static void serialize(TSerializer serializer, TBase struct, DataOutput out)
throws IOException
{
    assert serializer != null;
    assert struct != null;
    assert out != null;
    byte[] bytes;
    try
    {
        bytes = serializer.serialize(struct);
    }
    catch (TException e)
    {
        throw new RuntimeException(e);
    }
    out.writeInt(bytes.length);
    out.write(bytes);
}
项目:cassandra-cqlMod    文件:FBUtilities.java   
@Deprecated
public static void serialize(TSerializer serializer, TBase struct, DataOutput out)
throws IOException
{
    assert serializer != null;
    assert struct != null;
    assert out != null;
    byte[] bytes;
    try
    {
        bytes = serializer.serialize(struct);
    }
    catch (TException e)
    {
        throw new RuntimeException(e);
    }
    out.writeInt(bytes.length);
    out.write(bytes);
}
项目:wso2-cassandra    文件:FBUtilities.java   
@Deprecated
public static void serialize(TSerializer serializer, TBase struct, DataOutput out)
throws IOException
{
    assert serializer != null;
    assert struct != null;
    assert out != null;
    byte[] bytes;
    try
    {
        bytes = serializer.serialize(struct);
    }
    catch (TException e)
    {
        throw new RuntimeException(e);
    }
    out.writeInt(bytes.length);
    out.write(bytes);
}
项目:cassandra-trunk    文件:FBUtilities.java   
@Deprecated
public static void serialize(TSerializer serializer, TBase struct, DataOutput out)
throws IOException
{
    assert serializer != null;
    assert struct != null;
    assert out != null;
    byte[] bytes;
    try
    {
        bytes = serializer.serialize(struct);
    }
    catch (TException e)
    {
        throw new RuntimeException(e);
    }
    out.writeInt(bytes.length);
    out.write(bytes);
}
项目:cassandra-1.2.16    文件:FBUtilities.java   
@Deprecated
public static void serialize(TSerializer serializer, TBase struct, DataOutput out)
throws IOException
{
    assert serializer != null;
    assert struct != null;
    assert out != null;
    byte[] bytes;
    try
    {
        bytes = serializer.serialize(struct);
    }
    catch (TException e)
    {
        throw new RuntimeException(e);
    }
    out.writeInt(bytes.length);
    out.write(bytes);
}
项目: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 serialize(TSerializer serializer, TBase struct, DataOutput out)
throws IOException
{
    assert serializer != null;
    assert struct != null;
    assert out != null;
    byte[] bytes;
    try
    {
        bytes = serializer.serialize(struct);
    }
    catch (TException e)
    {
        throw new RuntimeException(e);
    }
    out.writeInt(bytes.length);
    out.write(bytes);
}
项目: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 byte[] toByteArray(Message m){
    TSerializer serializer = new TSerializer(new TBinaryProtocol.Factory());
    ch.usi.da.dlog.thrift.gen.Message msg = new ch.usi.da.dlog.thrift.gen.Message();
    msg.setId(m.getID());
    msg.setFrom(m.getFrom());
    msg.setTo(m.getTo());
    List<Cmd> cmds = new ArrayList<Cmd>();
    for(Command c : m.getCommands()){
        cmds.add(Command.toCmd(c));
    }
    msg.setCommands(cmds);
    try {
        return serializer.serialize(msg);
    } catch (TException e) {
        return new byte[0];
    }
}
项目: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);
}
项目:grift    文件:ThriftUtilsTest.java   
@Test
public void testAvailable() throws Exception {
  Message m = new Message();
  m.i = 10;
  InputStream is = marshaller.stream(m);
  assertEquals(is.available(), new TSerializer().serialize(m).length);
  is.read();
  assertEquals(is.available(), new TSerializer().serialize(m).length - 1);
  while (is.read() != -1) {}
  assertEquals(-1, is.read());
  assertEquals(0, is.available());
}
项目:Mastering-Mesos    文件:ThriftBinaryCodec.java   
/**
 * Encodes a thrift object into a binary array.
 *
 * @param tBase Object to encode.
 * @return Encoded object.
 * @throws CodingException If the object could not be encoded.
 */
public static byte[] encodeNonNull(TBase<?, ?> tBase) throws CodingException {
  requireNonNull(tBase);

  try {
    return new TSerializer(PROTOCOL_FACTORY).serialize(tBase);
  } catch (TException e) {
    throw new CodingException("Failed to serialize: " + tBase, e);
  }
}
项目:linden    文件:LindenController.java   
public static <T extends TBase> String ThriftToJSON(T thrift) {
  TSerializer serializer = new TSerializer(new TSimpleJSONProtocol.Factory());
  try {
    return serializer.toString(thrift);
  } catch (TException e) {
  }
  throw new IllegalStateException("Convert to json failed : " + thrift);
}