Learn R Programming

RProtoBuf (version 0.4.22)

read-methods: Read a protocol buffer message from a connection

Description

Read a Message from a connection using its associated Descriptor

Arguments

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

Run this code
# 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