Package com.facebook.thrift.protocol

Examples of com.facebook.thrift.protocol.TProtocol


    try {
      obj.write(binproto);
      // System.out.println("Size in binary protocol: " + buf.length());

      buf = new TMemoryBuffer(0);
      TProtocol proto = factory.getProtocol(buf);

      obj.write(proto);
      System.out.println("Size in compact protocol: " + buf.length());
      // System.out.println(buf.inspect());
View Full Code Here


      new TMessage("Janky", TMessageType.CALL, 0),
    });

    for (TMessage msg : msgs) {
      TMemoryBuffer buf = new TMemoryBuffer(0);
      TProtocol proto = factory.getProtocol(buf);
      TMessage output = null;

      proto.writeMessageBegin(msg);
      proto.writeMessageEnd();

      output = proto.readMessageBegin();

      if (!msg.equals(output)) {
        throw new RuntimeException("Message was supposed to be " + msg + " but was " + output);
      }
    }
View Full Code Here

    };

    Srv.Processor testProcessor = new Srv.Processor(handler);

    TMemoryBuffer clientOutTrans = new TMemoryBuffer(0);
    TProtocol clientOutProto = factory.getProtocol(clientOutTrans);
    TMemoryBuffer clientInTrans = new TMemoryBuffer(0);
    TProtocol clientInProto = factory.getProtocol(clientInTrans);

    Srv.Client testClient = new Srv.Client(clientInProto, clientOutProto);

    testClient.send_Janky(1);
    // System.out.println(clientOutTrans.inspect());
View Full Code Here

    return s;
  }

  private static void testStructField(StructFieldTestCase testCase) throws Exception {
    TMemoryBuffer buf = new TMemoryBuffer(0);
    TProtocol proto = factory.getProtocol(buf);

    TField field = new TField("test_field", testCase.type_, testCase.id_);
    proto.writeStructBegin(new TStruct("test_struct"));
    proto.writeFieldBegin(field);
    testCase.writeMethod(proto);
    proto.writeFieldEnd();
    proto.writeStructEnd();

    // System.out.println(buf.inspect());

    proto.readStructBegin();
    TField readField = proto.readFieldBegin();
    // TODO: verify the field is as expected
    if (!field.equals(readField)) {
      throw new RuntimeException("Expected " + field + " but got " + readField);
    }
    testCase.readMethod(proto);
    proto.readStructEnd();
  }
View Full Code Here

    TTransport trans = new TIOStreamTransport(new BufferedOutputStream(new FileOutputStream(args[0])));

    TProtocolFactory factory = (TProtocolFactory)Class.forName(args[1]).newInstance();

    TProtocol proto = factory.getProtocol(trans);

    Fixtures.compactProtoTestStruct.write(proto);
    trans.flush();
  }
View Full Code Here

  @Test
  public static void testSerialization() throws Exception {
    TestUnion union = new TestUnion(TestUnion.I32_FIELD, 25);

    TMemoryBuffer buf = new TMemoryBuffer(0);
    TProtocol proto = new TBinaryProtocol(buf);

    union.write(proto);

    TestUnion u2 = new TestUnion();
View Full Code Here

                            boolean framed, boolean header) throws TException{
    TTransport transport;
    TSocket socket = new TSocket("localhost", TEST_PORT);
    socket.setTimeout(1000);
    transport = socket;
    TProtocol prot = new TBinaryProtocol(transport);
    if (unframed) {
      testClient(transport, prot); // Unframed
    }
    List<THeaderTransport.ClientTypes> clientTypes =
      new ArrayList<THeaderTransport.ClientTypes>();
View Full Code Here

   * Write struct to JSON, using given protocol.
   */
  private static String write(TProtocolFactory protocolFactory, TBase s) throws Exception {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    TIOStreamTransport transport = new TIOStreamTransport(null, outputStream);
    TProtocol protocol = protocolFactory.getProtocol(transport);
    s.write(protocol);
    String utf8Encoding = outputStream.toString("UTF-8");
    return utf8Encoding;
  }
View Full Code Here

  private static void read(TProtocolFactory protocolFactory, String string, TBase s)
    throws Exception {
    byte[] byteEncoding = string.getBytes("UTF-8");
    ByteArrayInputStream inputStream = new ByteArrayInputStream(byteEncoding);
    TIOStreamTransport transport = new TIOStreamTransport(inputStream, null);
    TProtocol protocol = protocolFactory.getProtocol(transport);
    s.read(protocol);
  }
View Full Code Here

                            boolean framed, boolean header) throws TException{
    TTransport transport;
    TSocket socket = new TSocket("localhost", TEST_PORT);
    socket.setTimeout(1000);
    transport = socket;
    TProtocol prot = new TBinaryProtocol(transport);
    if (unframed) {
      testClient(transport, prot); // Unframed
    }
    List<THeaderTransport.ClientTypes> clientTypes =
      new ArrayList<THeaderTransport.ClientTypes>();
View Full Code Here

TOP

Related Classes of com.facebook.thrift.protocol.TProtocol

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.