[Rprotobuf-yada] make prototypes of message , field extraction

Romain Francois romain.francois at dbmail.com
Fri Oct 30 21:57:33 CET 2009


On 10/30/2009 08:30 PM, Romain François wrote:
>
> Hi,
>
> Did the first part of this now. so we can now extract non repeated
> fields from a message (primitives and messages). Some precision might
> get lost in the way because R does not have long, etc ... but I don't
> think there is anything that can be done about that (apart from
> implementing them in R).
>
> I've also added basic completion, so that :
>
>   >  Person<- P( "tutorial.Person", file = "/tmp/person.proto" )
>   >  p<- new( Person )
>   >  p$<TAB>
> p$email  p$id     p$name   p$phone
>   >  Person$
> Person$email        Person$name         Person$PhoneNumber
> Person$id           Person$phone        Person$PhoneType
>
> Now need to start thinking about repeated fields (arrays basically)

Done now.

For the moment, repeated Message come back as a simple list of 
protobufMessage object, but maybe the list should be further wrapped in 
an S4 class, so that we can grab for example the type of the elements 
contained in the list, which might be handy for empty such lists:

 > Person<- P( "tutorial.Person", file = "/tmp/person.proto" )
 > p <- new( Person )
 > p$phone
list()


I have also started to think about error handling, but not much, you'll 
find my "thoughts" gathered as raw code in the exceptions.R file. 
Basically the idea is that the internal code should not just call 
Rf_error, but generate a custom condition class, so that we can use 
tryCatch with targetted handlers, for example when we do

p$blabla

and p does not have a "blabla" field, at the moment we get :

 > p$blabla
Error in p$blabla : could not get FieldDescriptor for field 'blabla'

but it would be nicer to be able to catch this as a, say 
"NoSuchFieldException" or something:

tryCatch( p$blabla, NoSuchFieldException = function(e){
	# do something
} )

This, again, is inspired from the new features of rJava 0.8-0. It might 
be more natural in java because there all we do is mimic java exception 
handling, but I think it makes sense for us as well.

Romain

-- 
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