Ok, thanks for clearing that up for me.

On Monday, July 19, 2021 at 4:56:51 PM UTC-5 ken...@cloudflare.com wrote:

> Sorry, I'm not sure what you mean. `myns::Person` isn't a real type, it's 
> just an empty class that acts as a namespace containing the `Reader` and 
> `Builder` types. `Reader` is your "handle to the data", and its getters are 
> the only way to read the underlying data (the getters read directly from 
> the raw underlying byte buffer).
>
> -Kenton
>
> On Mon, Jul 19, 2021 at 3:45 PM SR D <software.resea...@gmail.com> wrote:
>
>> Ok, so after some thinking, I can put something together to communicate 
>> the type. Let's say I now know the type upon receiving the data, I make 
>> this call ...
>>
>>     auto m = reader.getRoot<Person>();
>>     
>> Here, m is of type myns::Person::Reader. So although I know the type, I 
>> looked at the person.capnp.h file and found no way to get a handle to the 
>> actual data I care about, the myns::Person object, rather just the getters.
>>
>> I understand I can rebuild the object by calling the individual fields 
>> like m.getXXX()'s, but I'm trying to do this in a generic way and not have 
>> to call the individual fields to get a myns::Person and pass the object to 
>> another thread for processing. So, my goal is to not have to call any proto 
>> object methods (getters or setters) and hope to call something from the 
>> Reader to get some sort of reference to the object since I know it's type.
>>
>> Is that possible?
>>
>>
>> On Saturday, July 17, 2021 at 12:22:10 PM UTC-5 ken...@cloudflare.com 
>> wrote:
>>
>>> 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.resea...@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+...@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+...@googlegroups.com.
>>
> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/capnproto/9545bbfc-38a3-44d4-bf5d-2f059e32dfa3n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/capnproto/9545bbfc-38a3-44d4-bf5d-2f059e32dfa3n%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/50987430-84fd-4c12-9c7e-fed0e673bba9n%40googlegroups.com.

Reply via email to