Example #1
0
// ReadReply reads enveloped responses from the given reader.
func ReadReply(p protocol.Protocol, r io.ReaderAt) (_ wire.Value, seqID int32, _ error) {
	envelope, err := p.DecodeEnveloped(r)
	if err != nil {
		return wire.Value{}, 0, err
	}

	switch {
	case envelope.Type == wire.Reply:
		return envelope.Value, envelope.SeqID, nil
	case envelope.Type != wire.Exception:
		return envelope.Value, envelope.SeqID, fmt.Errorf("unknown envelope type for reply, got %v", envelope.Type)
	}

	// Decode the exception payload.
	ex := &exception.TApplicationException{}
	if err := ex.FromWire(envelope.Value); err != nil {
		return envelope.Value, envelope.SeqID, fmt.Errorf("failed to decode exception: %v", err)
	}

	return envelope.Value, envelope.SeqID, ex
}