public static void testSerialization(TProtocolFactory factory, TBase object) throws Exception {
    TTransport trans =
        new TTransport() {
          public void write(byte[] bin, int x, int y) throws TTransportException {}

          public int read(byte[] bin, int x, int y) throws TTransportException {
            return 0;
          }

          public void close() {}

          public void open() {}

          public boolean isOpen() {
            return true;
          }
        };

    TProtocol proto = factory.getProtocol(trans);

    long startTime = System.currentTimeMillis();
    for (int i = 0; i < HOW_MANY; i++) {
      object.write(proto);
    }
    long endTime = System.currentTimeMillis();

    System.out.println("Serialization test time: " + (endTime - startTime) + " ms");
  }
コード例 #2
0
ファイル: TBaseStream.java プロジェクト: chenjintao/pinpoint
  public void write(final TBase<?, ?> base) throws TException {
    final TBaseStreamNode node = new TBaseStreamNode(transport);
    node.setClassName(base.getClass().getName());
    node.setBeginPosition(transport.getBufferPosition());

    final TProtocol protocol = protocolFactory.getProtocol(transport);
    base.write(protocol);

    node.setEndPosition(transport.getBufferPosition());
    nodes.add(node);
  }
コード例 #3
0
 @Override
 public void serialize(TBase value, JsonGenerator gen, SerializerProvider provider)
     throws IOException {
   gen.writeRawValue(
       writeThriftObjectAsTText(
           protocol -> {
             try {
               value.write(protocol);
             } catch (TException ex) {
               throw new IllegalArgumentException(ex);
             }
           }));
 }