--
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+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/capnproto.
To unsubscribe from this group and stop receiving emails from it, send an email to capnproto+...@googlegroups.com.
HI - I got your email on the lack of text parser. Makes sense. So what is the proper way to parse a _binary_ object from a char * to a MyMessage::Reader, given a precompiled schema for MyMessage?
For those who didn't see it, this is how I responded to Derrick's question about text parsing when he e-mailed it directly to me:Hi Derrick,Right now, the capnp library includes the ability to convert *to* text format, but only the capnp command-line tool has the ability to *parse* it.Partially this limitation exists because the parsing code actually uses the schema parser, since the text format is actually the format used to specify constants and default values in the schema language, so reusing that parser was easy. The schema parser is pretty heavy and not written in a way that would make it convenient to parse text format based on a binary schema. So, creating a proper runtime text format parser library would take some work.At the same time, I'm not sure if it's the right thing to do philosophically. With Protobufs, I noticed a lot of people tended to abuse runtime text-format parsing in cases where the right thing to do would have been to convert the text format message to binary ahead-of-time (as you can do with the capnp too) and then load the binary message at runtime. Or, worse, people would send machine-to-machine messages in text format, even when no human was involved (text format makes no sense if neither the producer nor the consumer is human). These people would then tend to demand that the text format parser do things like ignore unknown fields, which is just not a good idea when interacting with humans that can easily make typos.So, I'm debating whether or not to ever support this.On the other hand, at some point there will be a JSON transcoder, and since JSON is (unfortunately, IMO) commonly used machine-to-machine, it will definitely support runtime parsing and ignore unknown fields.All that said, I'd like to hear your opinion on this, even if (actually, especially if) you disagree. What do you think?
I once spent a couple months cleaning up an inappropriate use of text-format protos (after it brought down my service while I was on call), so I certainly sympathize with the motivation. However, in my experience the text format is invaluable for unit testing, since it lets you specify the test inputs concisely, in-line in the test code. You can accomplish the same thing by setting individual fields one by one via the message API, but that's tedious and annoying, and the result is harder to read. I'm in favor of just about anything that decreases the friction of writing tests, so I think it's worth providing a text format parser for that purpose.
One qualification: it's arguably possible that a sufficiently clean fluent-style builder API could allow you to populate a message via that API in a way that's just as concise and readable as the text format. I don't have any hands-on experience with Cap'n Proto, so I'm not sure if its Builders would fit the bill (the example code at the top of http://kentonv.github.io/capnproto/cxx.html is not encouraging).
I wish C++ supported C99's named aggregate initializer syntax, since this would be a perfect use case for those. You could write:
EXPECT_CAPNP_EQ({ .foo = 123, .bar = "abc", .baz = { .qux = {456, 789} } }, myMessage);
On Mon, Sep 16, 2013 at 7:59 AM, Geoffrey Romer <gro...@google.com> wrote:
I once spent a couple months cleaning up an inappropriate use of text-format protos (after it brought down my service while I was on call), so I certainly sympathize with the motivation. However, in my experience the text format is invaluable for unit testing, since it lets you specify the test inputs concisely, in-line in the test code. You can accomplish the same thing by setting individual fields one by one via the message API, but that's tedious and annoying, and the result is harder to read. I'm in favor of just about anything that decreases the friction of writing tests, so I think it's worth providing a text format parser for that purpose.
That's a really good point. Or rather, I'd say that this was by far the least-bad way of testing protobufs -- I always hated the fact that errors in my test string weren't detected until runtime, but the alternatives were far, far worse.
One qualification: it's arguably possible that a sufficiently clean fluent-style builder API could allow you to populate a message via that API in a way that's just as concise and readable as the text format. I don't have any hands-on experience with Cap'n Proto, so I'm not sure if its Builders would fit the bill (the example code at the top of http://kentonv.github.io/capnproto/cxx.html is not encouraging).
You may be on to something here. The builder interfaces cannot be very literate because of the allocation constraints (you can't just allocate a Cap'n Proto object from thin air; you have to specify what message to put it in). Perhaps, though, this is an important enough use case to generate code specifically for it. To avoid bloating builds too much, the code could live in a separate file included only by tests.
I wish C++ supported C99's named aggregate initializer syntax, since this would be a perfect use case for those.
You could write:EXPECT_CAPNP_EQ({ .foo = 123, .bar = "abc", .baz = { .qux = {456, 789} } }, myMessage);Alas, it is not to be.The best syntax I can come up with requires specifying the type name, which would have to have a suffix like "Init" to distinguish from the main types:EXPECT_CAPNP_EQ(MyTypeInit().foo(123).bar("abc").baz(BazTypeInit().qux({456, 789})), myMessage);Thoughts?