read-methods {RProtoBuf} | R Documentation |
Read a protocol buffer message from a connection
Description
Read a Message from a connection using its associated Descriptor
Methods
signature(descriptor = "Descriptor", input = "character")
Read the message from a file
signature(descriptor = "Descriptor")
Read from a binary connection.
signature(descriptor = "Descriptor", input = "raw")
Read the message from a raw vector
Examples
# 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 )
[Package RProtoBuf version 0.4.22 Index]