There is no way to find out a message's type if you don't know it already.
So, you'll need to arrange to communicate the type yourself. The easiest
way is to write an "envelope" message that is a union of all your other
messages.

struct OuterMessage {
  union {
    foo @0 :FooMessage;
    bar @1 :BarMessage;
    baz @2 :BazMessage;
  }
}

Then, always send OuterMessage as the top-level message type.

-Kenton

On Sat, Jul 17, 2021 at 11:55 AM SR D <
software.research.developm...@gmail.com> wrote:

> If the sender is sending any number of different data types that have been
> serialized across the network, how does one know which type is coming in so
> that it can be pulled off using FlatArrayMessageReader's::getRoot<>?
>
> E.g., say this while loop is constantly reading serialized data from the
> network and results in a vector of message buffers.
>
>         for (auto& msg : messages) {
>             auto arr = kj::ArrayPtr<const capnp::word>(
>                 reinterpret_cast<const capnp::word*>(msg),
>                 size / sizeof(capnp::word));
>
>             capnp::FlatArrayMessageReader reader(arr);
>
>             // how would one know what type to use here?
>             auto msg = reader.getRoot<?>();
>         }
>
> --
> 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 capnproto+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/capnproto/c89926fe-3b18-4e0f-9d30-8f8134b78a0an%40googlegroups.com
> <https://groups.google.com/d/msgid/capnproto/c89926fe-3b18-4e0f-9d30-8f8134b78a0an%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 capnproto+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/capnproto/CAJouXQ%3DdJLEYS9fTpa77DqNGVd7pK6jXtTafyjVN%3D22AnuCdGQ%40mail.gmail.com.

Reply via email to