Search in sources :

Example 6 with CountingOutputStream

use of net.morimekta.util.io.CountingOutputStream in project providence by morimekta.

the class TProtocolSerializer method serialize.

@Override
public <Message extends PMessage<Message, Field>, Field extends PField> int serialize(@Nonnull OutputStream output, @Nonnull PServiceCall<Message, Field> call) throws IOException {
    CountingOutputStream wrapper = new CountingOutputStream(output);
    TTransport transport = new TIOStreamTransport(wrapper);
    try {
        TProtocol protocol = protocolFactory.getProtocol(transport);
        TMessage tm = new TMessage(call.getMethod(), (byte) call.getType().asInteger(), call.getSequence());
        protocol.writeMessageBegin(tm);
        writeMessage(call.getMessage(), protocol);
        protocol.writeMessageEnd();
        transport.flush();
        wrapper.flush();
        return wrapper.getByteCount();
    } catch (TException e) {
        throw new SerializerException(e, e.getMessage());
    }
}
Also used : TException(org.apache.thrift.TException) CountingOutputStream(net.morimekta.util.io.CountingOutputStream) TProtocol(org.apache.thrift.protocol.TProtocol) TMessage(org.apache.thrift.protocol.TMessage) TIOStreamTransport(org.apache.thrift.transport.TIOStreamTransport) TTransport(org.apache.thrift.transport.TTransport) SerializerException(net.morimekta.providence.serializer.SerializerException)

Example 7 with CountingOutputStream

use of net.morimekta.util.io.CountingOutputStream in project providence by morimekta.

the class TProtocolSerializer method serialize.

@Override
public <Message extends PMessage<Message, Field>, Field extends PField> int serialize(@Nonnull OutputStream output, @Nonnull Message message) throws IOException {
    CountingOutputStream wrapper = new CountingOutputStream(output);
    TTransport transport = new TIOStreamTransport(wrapper);
    try {
        TProtocol protocol = protocolFactory.getProtocol(transport);
        writeMessage(message, protocol);
        transport.flush();
        wrapper.flush();
        return wrapper.getByteCount();
    } catch (TException e) {
        throw new SerializerException(e, e.getMessage());
    }
}
Also used : TException(org.apache.thrift.TException) CountingOutputStream(net.morimekta.util.io.CountingOutputStream) TProtocol(org.apache.thrift.protocol.TProtocol) TIOStreamTransport(org.apache.thrift.transport.TIOStreamTransport) TTransport(org.apache.thrift.transport.TTransport) SerializerException(net.morimekta.providence.serializer.SerializerException)

Example 8 with CountingOutputStream

use of net.morimekta.util.io.CountingOutputStream in project providence by morimekta.

the class TTupleProtocolSerializer method serialize.

@Override
public <Message extends PMessage<Message, Field>, Field extends PField> int serialize(@Nonnull OutputStream output, @Nonnull Message message) throws IOException {
    CountingOutputStream wrapper = new CountingOutputStream(output);
    TTransport transport = new TIOStreamTransport(wrapper);
    try {
        TTupleProtocol protocol = (TTupleProtocol) protocolFactory.getProtocol(transport);
        writeMessage(message, protocol);
        transport.flush();
        wrapper.flush();
        return wrapper.getByteCount();
    } catch (TException e) {
        throw new SerializerException(e, e.getMessage());
    }
}
Also used : TException(org.apache.thrift.TException) CountingOutputStream(net.morimekta.util.io.CountingOutputStream) TIOStreamTransport(org.apache.thrift.transport.TIOStreamTransport) TTransport(org.apache.thrift.transport.TTransport) SerializerException(net.morimekta.providence.serializer.SerializerException) TTupleProtocol(org.apache.thrift.protocol.TTupleProtocol)

Aggregations

CountingOutputStream (net.morimekta.util.io.CountingOutputStream)8 SerializerException (net.morimekta.providence.serializer.SerializerException)4 TException (org.apache.thrift.TException)4 TIOStreamTransport (org.apache.thrift.transport.TIOStreamTransport)4 TTransport (org.apache.thrift.transport.TTransport)4 IndentedPrintWriter (net.morimekta.util.io.IndentedPrintWriter)2 JsonWriter (net.morimekta.util.json.JsonWriter)2 PrettyJsonWriter (net.morimekta.util.json.PrettyJsonWriter)2 TMessage (org.apache.thrift.protocol.TMessage)2 TProtocol (org.apache.thrift.protocol.TProtocol)2 TTupleProtocol (org.apache.thrift.protocol.TTupleProtocol)2