OK, makes sense.

The trickiest part here is that we'll need to introduce a new pipeline
operator that checks the union discriminant and fails if it doesn't match
some expected value. See:

https://github.com/sandstorm-io/capnproto/blob/master/c++/src/capnp/rpc.capnp#L1003-L1024

We can't just use `getPointerField` without some sort of check since the
union could be a union of multiple capability types that may in fact have
compatible interfaces.

Line 1017 actually mentions this use case.

On Wed, May 31, 2017 at 11:57 PM, Johannes Zeppenfeld <[email protected]>
wrote:

> p.s. I just reread the C++ Serialization section on unions and realized
> that calling get for the wrong field returns garbage (i.e., undefined
> behavior) in non-debug mode rather than throwing an exception as I had
> assumed up to now. Is the check really such a hit to performance that this
> change in behavior between debug and release is necessary? If so, it may be
> better to add an assert rather than an exception in debug mode, otherwise
> code may suddenly start failing in mysterious ways in release.
>

The thing is that any correct code is going to call `which()` or `isFoo()`
before calling `getFoo()`. I feel sad forcing the same check to happen
again when it's redundant in any correct code...

-Kenton

-- 
You received this message because you are subscribed to the Google Groups 
"Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at https://groups.google.com/group/capnproto.

Reply via email to