Hi Jeroen,

It's been my experience that creating your own generator classes that hook 
directly into libprotoc has solved this exact issue. I've implemented a 
ruby generator for the protobuf ruby gem[1]. By hooking in and registering 
your generator you let protoc do all the work of parsing the .proto files 
and validating their structure. If everything checks out you're handed nice 
descriptor objects that you can use to generate your own language-specific 
definitions. The gem used to have a custom racc parser but I moved away 
from it because it had inconsistent parsing behavior from that of protoc. 
Now that we're hooking into libprotoc we get all the parse validation you 
normally get.

If it's any help you can check out my generator[2][3] class. I've also 
linked to a sample file that was created by the generator[4]. Let me know 
if that helps answer your question, or if it raises more. :)

Good luck,
BJ Neilsen

  [1] https://github.com/localshred/protobuf
  [2] 
https://github.com/localshred/protobuf/blob/master/ext/ruby_generator/RubyGenerator.h
  [3] 
https://github.com/localshred/protobuf/blob/master/ext/ruby_generator/RubyGenerator.cpp
  
[4] 
https://github.com/localshred/protobuf/blob/master/spec/support/test/resource.pb.rb

On Friday, November 16, 2012 5:08:16 PM UTC-7, Jeroen Ooms wrote:
>
> I am using the RProtoBuf package, which interfaces to the c++ protobuf 
> library. I was wondering if there is any way of 'validating' a pb 
> message, in the sense that you can check if it actually is a valid 
> message for a given pb description. Currently, RProtoBuf is very 
> permissive and will basically accept anything. E.g the code below will 
> not throw an error, even though the file obviously is not a valid 
> tutorial.Person message:
>
> library(RProtoBuf)
> read(tutorial.Person, "/etc/passwd")
>
> In practice, it is quite easy to introduce errors by accidentally reading 
> a message using the wrong description. It would be very helpful if there 
> was a way of preventing this kind of problems by some sort of validation.
>
> Is there support for this in the c++ library, or does protobuf basically 
> assume that the user/application has some other way of validating a message?
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/protobuf/-/yuXaa6Oa4QMJ.
To post to this group, send email to protobuf@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.

Reply via email to