Пример #1
0
  public static void main(String[] args) throws TException {
    TMemoryBuffer trans = new TMemoryBuffer(4096);
    TProtocol proto = new TBinaryProtocol(trans);

    proto.writeString("Hello Thrift Serialization");
    System.out.println("Wrote " + trans.length() + " bytes to the TMemoryBuffer");

    String strMsg = proto.readString();
    System.out.println("Recovered string: " + strMsg);
  }
Пример #2
0
 public String toJSON() {
   TMemoryBuffer trans = new TMemoryBuffer(1024);
   TJSONProtocol protocol = new TJSONProtocol(trans);
   try {
     _analyzerDefinition.write(protocol);
   } catch (TException e) {
     throw new RuntimeException(e);
   }
   trans.close();
   byte[] array = trans.getArray();
   return new String(array, 0, trans.length());
 }
Пример #3
0
 private static String writeThriftObjectAsTText(Consumer<TProtocol> writer) {
   TMemoryBuffer buffer = new TMemoryBuffer(1024);
   TProtocol protocol = new TTextProtocol.Factory().getProtocol(buffer);
   writer.accept(protocol);
   return new String(buffer.getArray(), 0, buffer.length());
 }