[Rprotobuf-yada] grab the descriptor from the Descriptor pool
Romain François
francoisromain at free.fr
Thu Oct 29 16:40:10 CET 2009
Hi,
Now grabbing the Descriptor [1] pointer for a given message type and
bring it into the R side as an external pointer.
# person.proto is in the current working directory
> RProtoBuf:::readProtoFiles()
<readProtoFiles>
[1] "/tmp/person.proto"
importer.Import( '/tmp/person.proto' )
name = /tmp/person.proto
package = tutorial
number of top level message types = 2
0 : tutorial.Person
1 : tutorial.AddressBook
number of top level enum types = 0
Retrieve the 'tutorial.Person' descriptor from the pool
4 fields
[0] : name (tag number=1, type=9)
[1] : id (tag number=2, type=5)
[2] : email (tag number=3, type=9)
[3] : phone (tag number=4, type=11)
</readProtoFiles>
# all the messages above will disappear, it is just debug info/learning
stuff
# now that the descriptor pool knows about the Person message type,
# we can grab the descriptor
> RProtoBuf:::getProtobufDescriptor( "tutorial.Person" )
<getProtobufDescriptor>
type = [1] "tutorial.Person"
</getProtobufDescriptor>
<pointer: 0x8771140>
# we don't know this message type, so we get NULL
> RProtoBuf:::getProtobufDescriptor( "bla.bla.Yada" )
<getProtobufDescriptor>
type = [1] "bla.bla.Yada"
NULL
Romain
[1]
http://code.google.com/apis/protocolbuffers/docs/reference/cpp/google.protobuf.descriptor.html#Descriptor
--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/BcPw : celebrating R commit #50000
|- http://tr.im/ztCu : RGG #158:161: examples of package IDPmisc
`- http://tr.im/yw8E : New R package : sos
More information about the Rprotobuf-yada
mailing list