@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); } })); } }
public byte[] toBytes(T object) { MemoryBuffer buffer = new MemoryBuffer(); TProtocol protocol = createThriftProtocol(buffer); try { object.write(protocol); } catch(TException e) { throw new SerializationException(e); } return buffer.toByteArray(); }
break; case TMessageType.REPLY: resultObj.write(protocol); break; default:
break; case TMessageType.REPLY: resultObj.write(protocol); break; default:
private static HttpData encodeSuccess(ServiceRequestContext ctx, RpcResponse reply, SerializationFormat serializationFormat, String methodName, int seqId, TBase<?, ?> result) { final ByteBuf buf = ctx.alloc().buffer(128); boolean success = false; try { final TTransport transport = new TByteBufTransport(buf); final TProtocol outProto = ThriftProtocolFactories.get(serializationFormat).getProtocol(transport); final TMessage header = new TMessage(methodName, TMessageType.REPLY, seqId); outProto.writeMessageBegin(header); result.write(outProto); outProto.writeMessageEnd(); ctx.logBuilder().responseContent(reply, new ThriftReply(header, result)); final HttpData encoded = new ByteBufHttpData(buf, false); success = true; return encoded; } catch (TException e) { throw new Error(e); // Should never reach here. } finally { if (!success) { buf.release(); } } }
args.write(protocol); protocol.writeMessageEnd(); protocol.getTransport().flush();
args.write(protocol); protocol.writeMessageEnd(); protocol.getTransport().flush();
/** * Serialize the Thrift object into a byte array. The process is simple, * just clear the byte array output, write the object into it, and grab the * raw bytes. * * @param base The object to serialize * @return Serialized object in byte[] format */ public byte[] serialize(TBase base) throws TException { baos_.reset(); base.write(protocol_); return baos_.toByteArray(); }
@SuppressWarnings("rawtypes") final TBase tArgs = func.newArgs(args); tArgs.write(tProtocol); tProtocol.writeMessageEnd();
/** * Convert the {@code msg} to a byte array representation * * @param msg * The message to serialize * @return The serialized message * @throws IOException * When serialization fails */ public ByteBuffer serialize(TBase<?,?> msg) throws IOException { requireNonNull(msg); transport.reset(); try { msg.write(protocol); // We should flush(), but we know its a noop } catch (TException e) { throw new IOException(e); } return ByteBuffer.wrap(transport.getBuf().array(), 0, transport.getPos()); }
private void sendBase(String methodName, TBase<?,?> args, byte type) throws TException { oprot_.writeMessageBegin(new TMessage(methodName, type, ++seqid_)); args.write(oprot_); oprot_.writeMessageEnd(); oprot_.getTransport().flush(); }
public void serialize(TBase t) throws IOException { try { t.write(protocol); } catch (TException e) { throw new IOException(e); } }
/** * Write the object to disk. */ public void write(TBase t) throws IOException { try { t.write(binaryOut); dataOutputStream.flush(); } catch (TException e) { throw new IOException(e); } }
@Override public void write(T record) { try { record.write(parquetWriteProtocol); } catch (TException e) { throw new ParquetEncodingException(e); } } }
@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); } })); } }
@Override public void write(T record) { try { record.write(parquetWriteProtocol); } catch (TException e) { throw new ParquetEncodingException(e); } } }
@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); } })); } }
public static <A extends TBase> InputStream toStream(A base){ try { ByteArrayOutputStream out = new ByteArrayOutputStream(); TIOStreamTransport sport = new TIOStreamTransport(out); TProtocol protocol = createTProtocol(sport); base.write(protocol); sport.close(); return new ByteArrayInputStream(out.toByteArray()); } catch (Exception e) { throw new RuntimeException(e); } }
public void write(final DataOutput out) throws IOException { // cast to OutputStream - ugly, but should work transport.setOutputStream((OutputStream) out); try { tbase.write(protocol); } catch (TException e) { throw new IOException(e.toString()); } }
public int getSize(TBase<?,?> thriftBase) throws Exception { memoryTransport.reset(); thriftBase.write(protocolFactory.getProtocol(memoryTransport)); return memoryTransport.getPos(); }