コード例 #1
0
func (c *Conn) descriptorForClient(desc rpccapnp.CapDescriptor, client capnp.Client) error {
	client = extractRPCClient(client)
	if ic, ok := client.(*importClient); ok && isImportFromConn(ic, c) {
		desc.SetReceiverHosted(uint32(ic.id))
		return nil
	}
	if pc, ok := client.(*capnp.PipelineClient); ok {
		p := (*capnp.Pipeline)(pc)
		if q, ok := p.Answer().(*question); ok && isQuestionFromConn(q, c) {
			a, err := desc.NewReceiverAnswer()
			if err != nil {
				return err
			}
			a.SetQuestionId(uint32(q.id))
			err = transformToPromisedAnswer(desc.Segment(), a, p.Transform())
			if err != nil {
				return err
			}
			return nil
		}
	}
	id := c.exports.add(client)
	desc.SetSenderHosted(uint32(id))
	return nil
}
コード例 #2
0
func formatCapDescriptor(w io.Writer, c rpccapnp.CapDescriptor) {
	switch c.Which() {
	case rpccapnp.CapDescriptor_Which_none:
		fmt.Fprint(w, "none")
	case rpccapnp.CapDescriptor_Which_senderHosted:
		fmt.Fprintf(w, "sender-hosted %d", c.SenderHosted())
	case rpccapnp.CapDescriptor_Which_senderPromise:
		fmt.Fprintf(w, "sender promise %d", c.SenderPromise())
	case rpccapnp.CapDescriptor_Which_receiverHosted:
		fmt.Fprintf(w, "receiver-hosted %d", c.ReceiverHosted())
	case rpccapnp.CapDescriptor_Which_receiverAnswer:
		ans, _ := c.ReceiverAnswer()
		fmt.Fprint(w, "receiver answer ")
		formatPromisedAnswer(w, ans)
	case rpccapnp.CapDescriptor_Which_thirdPartyHosted:
		fmt.Fprint(w, "third-party hosted")
	default:
		fmt.Fprintf(w, "UNKNOWN CAPABILITY which=%v", c.Which())
	}
}