Example usage for org.apache.thrift.protocol TTupleProtocol writeMessageBegin

List of usage examples for org.apache.thrift.protocol TTupleProtocol writeMessageBegin

Introduction

In this page you can find the example usage for org.apache.thrift.protocol TTupleProtocol writeMessageBegin.

Prototype

@Override
public void writeMessageBegin(TMessage message) throws TException 

Source Link

Document

Write a message header to the wire.

Usage

From source file:net.morimekta.providence.thrift.TTupleProtocolSerializer.java

License:Apache License

@Override
public <Message extends PMessage<Message, Field>, Field extends PField> int serialize(OutputStream output,
        PServiceCall<Message, Field> call) throws IOException {
    CountingOutputStream wrapper = new CountingOutputStream(output);
    TTransport transport = new TIOStreamTransport(wrapper);
    try {//from   www . ja  v  a  2s .  co m
        TTupleProtocol protocol = (TTupleProtocol) protocolFactory.getProtocol(transport);
        TMessage tm = new TMessage(call.getMethod(), (byte) call.getType().getValue(), 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());
    }
}