Hi Ortal,
On Wed, Nov 28, 2018 at 10:23 AM ortal levi <[email protected]> wrote:
> I am using cap'n proto to serialize messages in C.
>
I haven't used the C implementation. You might have more success e-mailing
the authors directly or posting a Github issue on the specific project, as
I don't know if they monitor this list.
I can answer for the C++ implementation, though, which might have similar
answers.
> - I would like to validate the request before parsing:
> rv3io_request.which > MAX_UNION_VALUE
> is that possible? If so how can I get the union max value?
>
The C++ implementation does not currently generate any such constant.
I would argue, though, that it might not be what you want anyway. What you
really care about is not what is defined in the schema, but what is
supported by your code. I recommend writing code in such a way that if
someone adds a new field to the schema without updating your code, then
your code continues to operate exactly as it did before the new field was
added. Otherwise, it gets really confusing when simply rebuilding your
program against an updated schema causes it to change behavior.
Usually, when handling enums, I write code like this:
switch (message.which()) {
case Message::FOO:
return handleFoo(message.getFoo());
case Message::BAR:
return handleBar(message.getBar());
// don't include a `default`, because we want a compiler warning if a
new field is added.
}
// which() returned an unrecognized value!
fail("Unknown union member.");
> - I would like to simulate invalid request using CC test:
> rv3io_request->which = MAX_UNION_VALUE
> Is that possible?
>
Hmm, I don't think this is easily possible, at least with the C++
implementation. Maybe you could define a test schema which is identical to
the original except that it has one extra field. Serialize a message using
the test schema, then parse with the real one. Kind of cumbersome, though.
-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.