# example file that contains a "tutorial.AddressBook" message
book <- system.file( "examples", "addressbook.pb", package = "RProtoBuf" )
# read the message
message <- read( tutorial.AddressBook, book )
# or using the pseudo method
message <- tutorial.AddressBook$read( book )
# write its debug string
writeLines( as.character( message ) )
# grab the name of each person
sapply( message$person, function(p) p$name )
# read from a binary file connection
f <- file( book, open = "rb" )
message2 <- read( tutorial.AddressBook, f )
close( f )
# read from a message payload (raw vector)
payload <- readBin( book, raw(0), 5000 )
message3 <- tutorial.AddressBook$read( payload )
# \dontshow{
stopifnot( identical( message, message2) )
stopifnot( identical( message, message3) )
# }
Run the code above in your browser using DataLab