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); }
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()); }
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()); }