Search in sources :

Example 6 with PServiceCallType

use of net.morimekta.providence.PServiceCallType in project providence by morimekta.

the class TTupleProtocolSerializer method deserialize.

@Nonnull
@Override
@SuppressWarnings("unchecked")
public <Message extends PMessage<Message, Field>, Field extends PField> PServiceCall<Message, Field> deserialize(@Nonnull InputStream input, @Nonnull PService service) throws SerializerException {
    TMessage tm = null;
    PServiceCallType type = null;
    try {
        TTransport transport = new TIOStreamTransport(input);
        TTupleProtocol protocol = (TTupleProtocol) protocolFactory.getProtocol(transport);
        tm = protocol.readMessageBegin();
        type = PServiceCallType.findById(tm.type);
        if (type == null) {
            throw new SerializerException("Unknown call type for id " + tm.type);
        } else if (type == PServiceCallType.EXCEPTION) {
            PApplicationException exception = readMessage(protocol, PApplicationException.kDescriptor);
            return new PServiceCall(tm.name, type, tm.seqid, exception);
        }
        PServiceMethod method = service.getMethod(tm.name);
        if (method == null) {
            throw new SerializerException("No such method " + tm.name + " on " + service.getQualifiedName());
        }
        PMessageDescriptor<Message, Field> descriptor = isRequestCallType(type) ? method.getRequestType() : method.getResponseType();
        Message message = readMessage(protocol, descriptor);
        protocol.readMessageEnd();
        return new PServiceCall<>(tm.name, type, tm.seqid, message);
    } catch (TTransportException e) {
        throw new SerializerException(e, "Unable to serialize into transport protocol").setExceptionType(PApplicationExceptionType.findById(e.getType())).setCallType(type).setMethodName(tm != null ? tm.name : "").setSequenceNo(tm != null ? tm.seqid : 0);
    } catch (TException e) {
        throw new SerializerException(e, "Transport exception in protocol").setExceptionType(PApplicationExceptionType.PROTOCOL_ERROR).setCallType(type).setMethodName(tm != null ? tm.name : "").setSequenceNo(tm != null ? tm.seqid : 0);
    }
}
Also used : TException(org.apache.thrift.TException) PMessage(net.morimekta.providence.PMessage) TMessage(org.apache.thrift.protocol.TMessage) PServiceCallType(net.morimekta.providence.PServiceCallType) TTransportException(org.apache.thrift.transport.TTransportException) TIOStreamTransport(org.apache.thrift.transport.TIOStreamTransport) SerializerException(net.morimekta.providence.serializer.SerializerException) TTupleProtocol(org.apache.thrift.protocol.TTupleProtocol) PField(net.morimekta.providence.descriptor.PField) TMessage(org.apache.thrift.protocol.TMessage) PApplicationException(net.morimekta.providence.PApplicationException) PServiceCall(net.morimekta.providence.PServiceCall) TTransport(org.apache.thrift.transport.TTransport) PServiceMethod(net.morimekta.providence.descriptor.PServiceMethod) Nonnull(javax.annotation.Nonnull)

Aggregations

PServiceCall (net.morimekta.providence.PServiceCall)6 PServiceCallType (net.morimekta.providence.PServiceCallType)6 PServiceMethod (net.morimekta.providence.descriptor.PServiceMethod)6 Nonnull (javax.annotation.Nonnull)5 PApplicationException (net.morimekta.providence.PApplicationException)5 PMessage (net.morimekta.providence.PMessage)5 PField (net.morimekta.providence.descriptor.PField)4 IOException (java.io.IOException)3 SerializerException (net.morimekta.providence.serializer.SerializerException)2 TException (org.apache.thrift.TException)2 TMessage (org.apache.thrift.protocol.TMessage)2 TIOStreamTransport (org.apache.thrift.transport.TIOStreamTransport)2 TTransport (org.apache.thrift.transport.TTransport)2 TTransportException (org.apache.thrift.transport.TTransportException)2 BinaryFormatUtils.readMessage (net.morimekta.providence.serializer.binary.BinaryFormatUtils.readMessage)1 BinaryFormatUtils.writeMessage (net.morimekta.providence.serializer.binary.BinaryFormatUtils.writeMessage)1 Token (net.morimekta.providence.serializer.pretty.Token)1 Tokenizer (net.morimekta.providence.serializer.pretty.Tokenizer)1 TokenizerException (net.morimekta.providence.serializer.pretty.TokenizerException)1 BigEndianBinaryReader (net.morimekta.util.io.BigEndianBinaryReader)1