func formatMessageTarget(w io.Writer, t rpccapnp.MessageTarget) {
	switch t.Which() {
	case rpccapnp.MessageTarget_Which_importedCap:
		fmt.Fprintf(w, "import %d", t.ImportedCap())
	case rpccapnp.MessageTarget_Which_promisedAnswer:
		fmt.Fprint(w, "promise ")
		pa, _ := t.PromisedAnswer()
		formatPromisedAnswer(w, pa)
	default:
		fmt.Fprintf(w, "UNKNOWN TARGET which=%v", t.Which())
	}
}
Exemple #2
0
func (c *Conn) routeCallMessage(result *answer, mt rpccapnp.MessageTarget, cl *capnp.Call) error {
	switch mt.Which() {
	case rpccapnp.MessageTarget_Which_importedCap:
		id := exportID(mt.ImportedCap())
		e := c.exports.get(id)
		if e == nil {
			return errBadTarget
		}
		answer := c.nestedCall(e.client, cl)
		go joinAnswer(result, answer)
	case rpccapnp.MessageTarget_Which_promisedAnswer:
		mpromise, err := mt.PromisedAnswer()
		if err != nil {
			return err
		}
		id := answerID(mpromise.QuestionId())
		if id == result.id {
			// Grandfather paradox.
			return errBadTarget
		}
		pa := c.answers.get(id)
		if pa == nil {
			return errBadTarget
		}
		mtrans, err := mpromise.Transform()
		if err != nil {
			return err
		}
		transform := promisedAnswerOpsToTransform(mtrans)
		if obj, err, done := pa.peek(); done {
			client := clientFromResolution(transform, obj, err)
			answer := c.nestedCall(client, cl)
			go joinAnswer(result, answer)
			return nil
		}
		if err := pa.queueCall(result, transform, cl); err != nil {
			return err
		}
	default:
		panic("unreachable")
	}
	return nil
}