Title: | R Interface to the 'Protocol Buffers' 'API' (Version 2 or 3) |
---|---|
Description: | Protocol Buffers are a way of encoding structured data in an efficient yet extensible format. Google uses Protocol Buffers for almost all of its internal 'RPC' protocols and file formats. Additional documentation is available in two included vignettes one of which corresponds to our 'JSS' paper (2016, <doi:10.18637/jss.v071.i02>. A sufficiently recent version of 'Protocol Buffers' library is required; currently version 3.3.0 from 2017 is the stated minimum. |
Authors: | Romain Francois [aut] , Dirk Eddelbuettel [aut, cre] , Murray Stokely [aut] , Jeroen Ooms [aut] |
Maintainer: | Dirk Eddelbuettel <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.4.22.4 |
Built: | 2024-12-12 06:29:56 UTC |
Source: | https://github.com/eddelbuettel/rprotobuf |
Protocol Buffers are a way of encoding structured data in an efficient yet extensible format. Google uses Protocol Buffers for almost all of its internal RPC protocols and file formats.
This package provides R API to create, manipulate, parse and serialize protocol buffer messages from R
Romain Francois, Dirk Eddelbuettel, Murray Stokely and Jeroen Ooms.
https://github.com/eddelbuettel/rprotobuf
Message for some examples
## Not run: # an example proto file system.file( "proto", "addressbook.proto", package = "RProtoBuf" ) # create a message of type AddressBook, defined in the example proto file demo( "addressbook", package = "RProtoBuf" ) # using R binary connections and files to read and write messages demo( "io", package = "RProtoBuf" ) # more documentation in the vignette vignette( "RProtoBuf", package = "RProtoBuf" ) ## End(Not run)
## Not run: # an example proto file system.file( "proto", "addressbook.proto", package = "RProtoBuf" ) # create a message of type AddressBook, defined in the example proto file demo( "addressbook", package = "RProtoBuf" ) # using R binary connections and files to read and write messages demo( "io", package = "RProtoBuf" ) # more documentation in the vignette vignette( "RProtoBuf", package = "RProtoBuf" ) ## End(Not run)
Add elements to a repeated field of a message.
signature(object = "Message")
add elements to a repeated field of a message
unitest.proto.file <- system.file("tinytest", "data", "unittest.proto", package = "RProtoBuf" ) readProtoFiles(file = unitest.proto.file) test <- new(protobuf_unittest.TestAllTypes) test$add("repeated_int32", 1) test$add("repeated_int32", 2:10) test$repeated_int32
unitest.proto.file <- system.file("tinytest", "data", "unittest.proto", package = "RProtoBuf" ) readProtoFiles(file = unitest.proto.file) test <- new(protobuf_unittest.TestAllTypes) test$add("repeated_int32", 1) test$add("repeated_int32", 2:10) test$repeated_int32
A ZeroCopyInputStream backed by an in-memory array of bytes
Objects can be created by the ArrayInputStream function
pointer
: External pointer to the google::protobuf::io::ArrayInputStream
C++ object
Class "ZeroCopyInputStream"
, directly.
Romain Francois <[email protected]>
The ArrayInputStream
class from the protobuf C++ library.
ZeroCopyInputStream for methods
stream <- ArrayInputStream(as.raw(0:10)) stream$ReadRaw(5) stringsstream <- ArrayInputStream(as.raw(c(0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67))) stringsstream$ReadString(7) intstream <- ArrayInputStream(as.raw(c(0x9e, 0xa7, 0x05))) intstream$ReadVarint32()
stream <- ArrayInputStream(as.raw(0:10)) stream$ReadRaw(5) stringsstream <- ArrayInputStream(as.raw(c(0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67))) stringsstream$ReadString(7) intstream <- ArrayInputStream(as.raw(c(0x9e, 0xa7, 0x05))) intstream$ReadVarint32()
Constructor for ArrayInputStream objects
signature(payload = "raw", block_size = "missing" )
Creates a ArrayInputStream using the raw vector as the payload of the stream
signature(payload = "raw", block_size = "integer" )
Creates a ArrayInputStream ... same with block size.
signature(payload = "raw", block_size = "numeric" )
Creates a ArrayInputStream ... same with block size.
A ZeroCopyOutputStream backed by an in-memory array of bytes
Objects can be created by the ArrayOutputStream function
pointer
: External pointer to the google::protobuf::io::ArrayOutputStream
C++ object
Class "ZeroCopyOutputStream"
, directly.
Romain Francois <[email protected]>
The ArrayOutputStream
class from the protobuf C++ library.
ZeroCopyOutputStream for methods
Constructor for ArrayOutputStream objects
signature(size = "integer", block_size = "missing" )
Creates a ArrayOutputStream using of the given size
signature(size = "integer", block_size = "integer" )
Creates a ArrayOutputStream ... same with block size.
signature(size = "integer", block_size = "numeric" )
Creates a ArrayOutputStream ... same with block size.
signature(size = "numeric", block_size = "missing" )
Creates a ArrayOutputStream using of the given size
signature(size = "numeric", block_size = "integer" )
Creates a ArrayOutputStream ... same with block size.
signature(size = "numeric", block_size = "numeric" )
Creates a ArrayOutputStream ... same with block size.
Utility to grab the protocol buffer message as an R list, with one item per field.
## S3 method for class 'Message' as.list(x, ...) ## S3 method for class 'Descriptor' as.list(x, ...) ## S3 method for class 'EnumDescriptor' as.list(x, ...) ## S3 method for class 'FileDescriptor' as.list(x, ...) ## S3 method for class 'ServiceDescriptor' as.list(x, ...)
## S3 method for class 'Message' as.list(x, ...) ## S3 method for class 'Descriptor' as.list(x, ...) ## S3 method for class 'EnumDescriptor' as.list(x, ...) ## S3 method for class 'FileDescriptor' as.list(x, ...) ## S3 method for class 'ServiceDescriptor' as.list(x, ...)
x |
A protocol buffer message, instance of Message, or a protocol message descriptor, instance of Descriptor |
... |
ignored |
For messages, a list of the content of the fields is returned.
For message type descriptors, a list containing nested type descriptors (Descriptor objects), enum type descriptors (EnumDescriptor objects), then field descriptors (FieldDescriptor objects) in that order.
For enum descriptors, a named list of the enumerated values.
For file descriptors, a named list of descriptors defined in the specified file descriptor.
For service descriptors, ...
Romain Francois <[email protected]>
Person <- P( "tutorial.Person" ) romain <- new( Person, email = "[email protected]", id = 1 ) as.list( romain ) as.list( Person ) as.list( Person$PhoneType)
Person <- P( "tutorial.Person" ) romain <- new( Person, email = "[email protected]", id = 1 ) as.list( romain ) as.list( Person ) as.list( Person$PhoneType)
coerce an object to the Message class.
This is a short-hand to the as method with the
Class
argument set to "Message"
asMessage(x, ...)
asMessage(x, ...)
x |
object to coerce to a protobuf message |
... |
Passed to |
a Message object
Romain Francois <[email protected]>
# coerce a message type descriptor to a message asMessage( tutorial.Person ) # coerce a enum descriptor asMessage( tutorial.Person.PhoneType ) # coerce a field descriptor asMessage( tutorial.Person$email ) # coerce a file descriptor asMessage( fileDescriptor( tutorial.Person ) )
# coerce a message type descriptor to a message asMessage( tutorial.Person ) # coerce a enum descriptor asMessage( tutorial.Person.PhoneType ) # coerce a field descriptor asMessage( tutorial.Person$email ) # coerce a file descriptor asMessage( fileDescriptor( tutorial.Person ) )
Backs up a number of bytes from a stream
ZeroCopyInputStream implements BackUp.
The number of bytes read/written since the object was created
ZeroCopyInputStream implements ByteCount.
The number of bytes taken by a Message
signature(object = "Message")
The number of bytes the message would take when serialized
message <- new( tutorial.Person, name = "dddd", email = "eeeeeee", id = 1 ) bytesize( message )
message <- new( tutorial.Person, name = "dddd", email = "eeeeeee", id = 1 ) bytesize( message )
Clear one field or all fields of the message and set them to their default values
signature(object = "Message", field = "missing")
Clear all fields of the message and set them to their default values
signature(object = "Message", field = "character")
Clear the field identified by its name
signature(object = "Message", field = "integer")
Clear the field identified by its tag number
signature(object = "Message", field = "numeric")
Clear the field identified by its tag number
signature(object = "Message", field = "raw")
Clear the field identified by its tag number
message <- new( tutorial.Person, name = "dddd", email = "eeeeeee", id = 1 ) writeLines( as.character( message ) ) clear( message ) # clear works also as a pseudo method : message$clear() writeLines( as.character( message ) ) # clear single fields message <- new( tutorial.Person, name = "dddd", email = "eeeeeee", id = 1 ) message$clear( "name" ) writeLines( as.character( message ) )
message <- new( tutorial.Person, name = "dddd", email = "eeeeeee", id = 1 ) writeLines( as.character( message ) ) clear( message ) # clear works also as a pseudo method : message$clear() writeLines( as.character( message ) ) # clear single fields message <- new( tutorial.Person, name = "dddd", email = "eeeeeee", id = 1 ) message$clear( "name" ) writeLines( as.character( message ) )
Generic "clone" function and associated method for Message objects
signature(object = "Message")
clone the message
## Not run: # example proto file supplied with this package proto.file <- system.file( "proto", "addressbook.proto", package = "RProtoBuf" ) # reading a proto file and creating the descriptor Person <- P( "tutorial.Person", file = proto.file ) ## End(Not run) # creating a prototype message from the descriptor sheep <- new( Person, email = "[email protected]", id = 2 ) # cloning the sheep newsheep <- clone( sheep ) # clone and update at once newsheep <- clone( sheep, id = 3 ) # this can also be used as a pseudo method sheep$clone() sheep$clone( id = 3 )
## Not run: # example proto file supplied with this package proto.file <- system.file( "proto", "addressbook.proto", package = "RProtoBuf" ) # reading a proto file and creating the descriptor Person <- P( "tutorial.Person", file = proto.file ) ## End(Not run) # creating a prototype message from the descriptor sheep <- new( Person, email = "[email protected]", id = 2 ) # cloning the sheep newsheep <- clone( sheep ) # clone and update at once newsheep <- clone( sheep, id = 3 ) # this can also be used as a pseudo method sheep$clone() sheep$clone( id = 3 )
These functions support completion of protocol buffer messages and descriptors.
## S3 method for class 'Message' .DollarNames(x, pattern = "") ## S3 method for class 'Descriptor' .DollarNames(x, pattern = "") ## S3 method for class 'EnumDescriptor' .DollarNames(x, pattern = "") ## S3 method for class 'FieldDescriptor' .DollarNames(x, pattern = "") ## S3 method for class 'FileDescriptor' .DollarNames(x, pattern = "") ## S3 method for class 'ServiceDescriptor' .DollarNames(x, pattern = "") ## S3 method for class 'MethodDescriptor' .DollarNames(x, pattern = "") ## S3 method for class 'ZeroCopyInputStream' .DollarNames(x, pattern = "") ## S3 method for class 'ZeroCopyOutputStream' .DollarNames(x, pattern = "")
## S3 method for class 'Message' .DollarNames(x, pattern = "") ## S3 method for class 'Descriptor' .DollarNames(x, pattern = "") ## S3 method for class 'EnumDescriptor' .DollarNames(x, pattern = "") ## S3 method for class 'FieldDescriptor' .DollarNames(x, pattern = "") ## S3 method for class 'FileDescriptor' .DollarNames(x, pattern = "") ## S3 method for class 'ServiceDescriptor' .DollarNames(x, pattern = "") ## S3 method for class 'MethodDescriptor' .DollarNames(x, pattern = "") ## S3 method for class 'ZeroCopyInputStream' .DollarNames(x, pattern = "") ## S3 method for class 'ZeroCopyOutputStream' .DollarNames(x, pattern = "")
x |
message (Message) or descriptor (Descriptor) |
pattern |
filter |
Character vector containing potential completions.
For Message objects, completions are the fields of the message and a set of pseudo methods ("has")
For EnumDescriptor objects, completions are the names of the possible constants
For Descriptor objects, completions are the names of the fields, enum types and nested message types defined in the associated message type.
For FileDescriptor objects, completions are the names of the top-level descriptors (message, enum or service) contained in the associated file, or pseudo methods.
Romain Francois <[email protected]>
# creating a prototype message from the descriptor p <- new( tutorial.Person ) .DollarNames( p ) .DollarNames( tutorial.Person ) # but this is usually used with the <TAB> expansion on the command line # <TAB> means "press the TAB key" # p$<TAB> # Person$<TAB>
# creating a prototype message from the descriptor p <- new( tutorial.Person ) .DollarNames( p ) .DollarNames( tutorial.Person ) # but this is usually used with the <TAB> expansion on the command line # <TAB> means "press the TAB key" # p$<TAB> # Person$<TAB>
A ZeroCopyInputStream reading from a binary R connection
Objects can be created by the ConnectionInputStream function
pointer
: External pointer to the rprotobuf::ConnectionInputStream
C++ object
Class "ZeroCopyInputStream"
, directly.
Romain Francois <[email protected]>
The internal C++ class ConnectionInputStream
ZeroCopyInputStream for methods
Constructor for ConnectionInputStream objects
signature(object="connection")
Creates a ConnectionInputStream reading from the given R binary connection.
A ZeroCopyOutputStream writing to a binary R connection
Objects can be created by the ConnectionOutputStream function
pointer
: External pointer to the rprotobuf::ConnectionOutputStream
C++ object
Class "ZeroCopyOutputStream"
, directly.
Romain Francois <[email protected]>
The internal C++ class ConnectionOutputStream
ZeroCopyOutputStream for methods
Constructor for ConnectionOutputStream objects
signature(object="connection")
Creates a ConnectionOutputStream writing to the given R binary connection.
Gets a Descriptor describing the message type that contains the descriptor.
The method is implemented for these classes : Descriptor, EnumDescriptor, FieldDescriptor
# Containing type of a field is the message descriptor tutorial.Person$id$containing_type() # No containing type for the top-level message descriptor. tutorial.Person$containing_type()
# Containing type of a field is the message descriptor tutorial.Person$id$containing_type() # No containing type for the top-level message descriptor. tutorial.Person$containing_type()
full descriptive information about a protocol buffer
message type. This is a thin wrapper around the
C++ class Descriptor
Objects are usually created by calls to the P
function.
pointer
:external pointer holding a Descriptor
object
type
:full name of the corresponding message type
signature(x = "Descriptor")
:
returns the debug string of the descriptor.
This is retrieved by a call to the DebugString
method of the Descriptor object.
signature(x = "Descriptor")
: same as as.character
signature(x = "Descriptor")
: retrieves a
descriptor for a member of the message type. This can
either be another "Descriptor" instance describing
a nested type, or a EnumDescriptor object
describing an enum type, or a FieldDescriptor
object describing a field of the message
signature(Class = "Descriptor")
: creates
a prototype message (Message) of this
descriptor
signature(object = "Descriptor")
:
simple information
signature(object = "Descriptor")
: returns a descriptor of the message type that contains this message descriptor, or NULL
if this is a top-level message type.
signature(object = "Descriptor")
: The number of fields of this message type.
signature(object = "Descriptor")
: The number of nested types of this message type.
signature(object = "Descriptor")
: The number of enum types of this message type.
signature(object = "Descriptor")
: extract a field descriptor from a descriptor.
Exactly one argument of index
, number
or name
has to be used.
If index
is used, the field descriptor is retrieved by
position, using the field
method of the google::protobuf::Descriptor
C++ class.
If number
is used, the field descriptor is retrieved using
the tag number, with the FindFieldByNumber
C++ method.
If name
is used, the field descriptor is retrieved by name
using the FindFieldByName
signature(object = "Descriptor")
:
extracts a message type descriptor that is nested
in this descriptor.
Exactly one argument of index
of name
has to be used.
If index
is used, the nested type will be retrieved
using its position with the nested_type
method
of the google::protobuf::Descriptor
C++ class.
If name
is used, the nested type will be retrieved
using its name, with the FindNestedTypeByName
C++ method
signature(object = "Descriptor")
:
extracts an enum type descriptor that is contained
in this descriptor.
Exactly one argument of index
of name
has to be used.
If index
is used, the enum type will be retrieved
using its position with the enum_type
method
of the google::protobuf::Descriptor
C++ class.
If name
is used, the enum type will be retrieved
using its name, with the FindEnumTypeByName
C++ method
signature(x = "Descriptor")
: extracts a field identified by its name or declared tag number
signature(x = "Descriptor")
: extracts names of this descriptor
signature(x = "Descriptor")
: extracts length of this descriptor
Romain Francois <[email protected]>
the P
function creates "Descriptor" messages.
## Not run: # example proto file supplied with this package proto.file <- system.file( "proto", "addressbook.proto", package = "RProtoBuf" ) # reading a proto file and creating the descriptor Person <- P( "tutorial.Person", file = proto.file ) ## End(Not run) # enum type Person$PhoneType # nested type Person$PhoneNumber # field Person$email # use this descriptor to create a message new( Person )
## Not run: # example proto file supplied with this package proto.file <- system.file( "proto", "addressbook.proto", package = "RProtoBuf" ) # reading a proto file and creating the descriptor Person <- P( "tutorial.Person", file = proto.file ) ## End(Not run) # enum type Person$PhoneType # nested type Person$PhoneNumber # field Person$email # use this descriptor to create a message new( Person )
Get the Descriptor associated with a Message
signature(object = "Message")
Get the descriptor of the message, as a Descriptor instance
The number of enum types
The method is implemented for the Descriptor class
Extract a EnumDescriptor contained in a Descriptor
The method is implemented for the Descriptor class
R representation of an enum descriptor. This
is a thin wrapper around the EnumDescriptor
c++ class.
Objects of this class are typically retrieved as members of Descriptor objects
pointer
:external pointer to the EnumDescriptor
instance
name
:simple name of the enum
full_name
:fully qualified name
type
:fully qualified name of the type that contains this enumeration
signature(object = "EnumDescriptor")
: small information
signature(x = "EnumDescriptor")
:
returns the debug string of the enum descriptor.
This is retrieved by a call to the DebugString
method of the EnumDescriptor object.
signature(x = "EnumDescriptor")
: same as as.character
signature(x = "EnumDescriptor")
: get the
number associated with the name
signature(object = "EnumDescriptor")
: indicate if
the given name is a constant present in this enum.
signature(object = "EnumDescriptor")
: returns a Descriptor of the message type that contains this enum descriptor, or NULL if this is a top level enum descriptor.
signature(x = "EnumDescriptor")
: number of constants in this enum.
signature(object = "EnumDescriptor")
: number of constants in this enum.
signature(object = "EnumDescriptor")
: extracts an EnumValueDescriptor.
Exactly one argument of index
, number
or name
has to be
used.
If index
is used, the enum value descriptor is retrieved
by position, using the value
method of the C++ class.
If number
is used, the enum value descriptor is retrieved
using the value of the constant, using the FindValueByNumber
C++ method.
If name
is used, the enum value descriptor is retrieved
using the name of the constant, using the FindValueByName
C++ method.
signature(x = "EnumDescriptor")
: extracts field identified by its name or declared tag number
signature(x = "EnumDescriptor")
: extracts names of this enum
Romain Francois <[email protected]>
The EnumDescriptor
C++ class
The Descriptor class
## Not run: # example proto file supplied with this package proto.file <- system.file( "proto", "addressbook.proto", package = "RProtoBuf" ) # reading a proto file and creating the descriptor Person <- P( "tutorial.Person", file = proto.file ) ## End(Not run) # enum type Person$PhoneType has(Person$PhoneType, "MOBILE") has(Person$PhoneType, "HOME") has(Person$PhoneType, "WORK") has(Person$PhoneType, "FOOBAR") length(Person$PhoneType)
## Not run: # example proto file supplied with this package proto.file <- system.file( "proto", "addressbook.proto", package = "RProtoBuf" ) # reading a proto file and creating the descriptor Person <- P( "tutorial.Person", file = proto.file ) ## End(Not run) # enum type Person$PhoneType has(Person$PhoneType, "MOBILE") has(Person$PhoneType, "HOME") has(Person$PhoneType, "WORK") has(Person$PhoneType, "FOOBAR") length(Person$PhoneType)
R representation of an enum value descriptor. This
is a thin wrapper around the EnumValueDescriptor
c++ class.
Objects of this class are typically retrieved with the
value
method of the EnumDescriptor class
pointer
:external pointer to the EnumValueDescriptor
instance
name
:simple name of the enum
full_name
:fully qualified name
signature(object = "EnumValueDescriptor")
: small information
signature(x = "EnumValueDescriptor")
:
returns the debug string of the enum descriptor.
This is retrieved by a call to the DebugString
method of the EnumDescriptor object.
signature(x = "EnumValueDescriptor")
: same as as.character
signature(x = "EnumValueDescriptor")
: invoke pseudo
methods
signature(object = "EnumValueDescriptor", full = "logical")
:
return the name of this enum constant.
signature(object = "EnumValueDescriptor")
:
return the numeric value of this enum constant.
signature(object = "EnumDescriptor")
: retrieves the EnumDescriptor related to this value descriptor.
Romain Francois <[email protected]>
## Not run: # example proto file supplied with this package proto.file <- system.file( "proto", "addressbook.proto", package = "RProtoBuf" ) # reading a proto file and creating the descriptor Person <- P( "tutorial.Person", file = proto.file ) ## End(Not run) # enum type Person$PhoneType # enum value type value(Person$PhoneType, 1) name(value(Person$PhoneType, 1)) name(value(Person$PhoneType, 1), TRUE) number(value(Person$PhoneType, number=1)) enum_type(value(Person$PhoneType, number=1))
## Not run: # example proto file supplied with this package proto.file <- system.file( "proto", "addressbook.proto", package = "RProtoBuf" ) # reading a proto file and creating the descriptor Person <- P( "tutorial.Person", file = proto.file ) ## End(Not run) # enum type Person$PhoneType # enum value type value(Person$PhoneType, 1) name(value(Person$PhoneType, 1)) name(value(Person$PhoneType, 1), TRUE) number(value(Person$PhoneType, number=1)) enum_type(value(Person$PhoneType, number=1))
Fetch content of a repeated field of a message
signature(object = "Message")
Fetch content of a message repeated field
The number of fields
The method is implemented for the Descriptor class
Extract a FieldDescriptor from a Descriptor
The method is implemented for the Descriptor class
R representation of message type field descriptor.
This is a thin wrapper around the C++ class FieldDescriptor
Objects typically are retrieved from FieldDescriptor
pointer
:external pointer to the FieldDescriptor
c++ object
name
:name of the field within the message type
full_name
:Fully qualified name of the field
type
:Fully qualified name of the type that contains this field
signature(object = "FieldDescriptor")
: small description
signature(x = "FieldDescriptor")
:
returns the debug string of the field descriptor.
This is retrieved by a call to the DebugString
method of the FieldDescriptor object.
signature(x = "FieldDescriptor")
: same as as.character
signature(x = "FieldDescriptor")
: used to invoke pseudo methods
signature(object = "FieldDescriptor")
: returns a Descriptor of the message type that contains this field descriptor.
signature(object = "FieldDescriptor")
: indicates if this is an extension.
signature(object = "FieldDescriptor")
: gets the declared tag number of this field.
signature(object = "FieldDescriptor")
: type of this field.
signature(object = "FieldDescriptor")
: c++ type of this field.
signature(object = "FieldDescriptor")
: label of this field.
signature(object = "FieldDescriptor")
: is this field required.
signature(object = "FieldDescriptor")
: is this field optional.
signature(object = "FieldDescriptor")
: is this field repeated.
signature(object = "FieldDescriptor")
: indicates if this field has a default value.
signature(object = "FieldDescriptor")
: the default value of this field.
signature(object = "FieldDescriptor")
: the Descriptor for the associated message type. Generates an error if this field is not a message type field.
signature(object = "FieldDescriptor")
: the EnumDescriptor for the associated enum type.Generates an error if this field is not an enum type field
Romain Francois <[email protected]>
The FieldDescriptor
C++ class
## Not run: # example proto file supplied with this package proto.file <- system.file( "proto", "addressbook.proto", package = "RProtoBuf" ) # reading a proto file and creating the descriptor Person <- P( "tutorial.Person", file = proto.file ) ## End(Not run) # field descriptor object Person$email # debug string as.character( Person$email ) # or as a pseudo method Person$email$as.character() Person$email$is_required() Person$email$is_optional() Person$email$is_repeated() Person$email$has_default_value() Person$email$default_value() Person$email$is_extension() # Get the default values has_default_value(Person$id) has_default_value(Person$email) has_default_value(Person$phone) default_value(Person$id) default_value(Person$email) default_value(Person$phone) # Get the types of field descriptors type(Person$id) type(Person$id, as.string=TRUE) cpp_type(Person$email) cpp_type(Person$email, TRUE) # Get the label of a field descriptor label(Person$id) label(Person$email) label(Person$phone) label(Person$id, TRUE) label(Person$email, TRUE) label(Person$phone, TRUE) LABEL_OPTIONAL LABEL_REQUIRED LABEL_REPEATED # Test if a field is optional is_optional(Person$id) is_optional(Person$email) is_optional(Person$phone) # Test if a field is repeated is_repeated(Person$id) is_repeated(Person$email) is_repeated(Person$phone) # Test if a field is required is_required(Person$id) is_required(Person$email) is_required(Person$phone) # Return the class of a message field message_type(Person$phone)
## Not run: # example proto file supplied with this package proto.file <- system.file( "proto", "addressbook.proto", package = "RProtoBuf" ) # reading a proto file and creating the descriptor Person <- P( "tutorial.Person", file = proto.file ) ## End(Not run) # field descriptor object Person$email # debug string as.character( Person$email ) # or as a pseudo method Person$email$as.character() Person$email$is_required() Person$email$is_optional() Person$email$is_repeated() Person$email$has_default_value() Person$email$default_value() Person$email$is_extension() # Get the default values has_default_value(Person$id) has_default_value(Person$email) has_default_value(Person$phone) default_value(Person$id) default_value(Person$email) default_value(Person$phone) # Get the types of field descriptors type(Person$id) type(Person$id, as.string=TRUE) cpp_type(Person$email) cpp_type(Person$email, TRUE) # Get the label of a field descriptor label(Person$id) label(Person$email) label(Person$phone) label(Person$id, TRUE) label(Person$email, TRUE) label(Person$phone, TRUE) LABEL_OPTIONAL LABEL_REQUIRED LABEL_REPEATED # Test if a field is optional is_optional(Person$id) is_optional(Person$email) is_optional(Person$phone) # Test if a field is repeated is_repeated(Person$id) is_repeated(Person$email) is_repeated(Person$phone) # Test if a field is required is_required(Person$id) is_required(Person$email) is_required(Person$phone) # Return the class of a message field message_type(Person$phone)
Class "FileDescriptor"
Objects are usually created using the fileDescriptor
method
pointer
:external pointer to a google::protobuf::FileDescriptor
C++ object
package
:the package name defined in the file, e.g. 'tutorial'.
filename
:the filename of this FileDescriptor
signature(x = "FileDescriptor")
: used to invoke a pseudo method of the
file descriptor or get a top level message, enum or service descriptor
signature(x = "FileDescriptor" )
: gets the debug string
signature(x = "FileDescriptor" )
: gets the debug string
signature(x = "FileDescriptor" )
: prints small text
signature(object = "FileDescriptor" )
: name of the file
Romain Francois <[email protected]>
# example proto file supplied with this package desc <- P("tutorial.Person") person <- new(desc) person$fileDescriptor() name(person$fileDescriptor()) # [1] "addressbook.proto" as.character(person$fileDescriptor())
# example proto file supplied with this package desc <- P("tutorial.Person") person <- new(desc) person$fileDescriptor() name(person$fileDescriptor()) # [1] "addressbook.proto" as.character(person$fileDescriptor())
Gets the file descriptor of an object
signature(object = "Descriptor")
retrieves the file descriptor associated with this descriptor
signature(object = "Message")
retrieves the file descriptor associated with the descriptor of this message
signature(object = "EnumDescriptor")
retrieves the file descriptor associated with the enum descriptor
signature(object = "FieldDescriptor")
retrieves the file descriptor associated with the field descriptor
signature(object = "ServiceDescriptor")
retrieves the file descriptor associated with the service descriptor
signature(object = "MethodDescriptor")
retrieves the file descriptor associated with the method descriptor
A ZeroCopyInputStream reading from a file
Objects can be created by the FileInputStream function
pointer
: External pointer to the google::protobuf::io::FileInputStream
C++ object
Class "ZeroCopyInputStream"
, directly.
signature(con="FileInputStream")
:
Flushes any buffers and closes the underlying file.
Returns false if an error occurs during the process; use GetErrno
to examine the error
signature(object="FileInputStream")
:
If an I/O error has occurred on this file descriptor, this is the errno from that error.
Otherwise, this is zero. Once an error occurs, the stream is broken and all subsequent operations will fail.
signature(object="FileInputStream")
:
set the close on delete behavior.
See ZeroCopyInputStream for inherited methods
Romain Francois <[email protected]>
The FileInputStream
class from the protobuf C++ library.
ZeroCopyInputStream for methods
Constructor for FileInputStream objects
signature(filename = "character", block_size = "logical", close.on.delete = "logical" )
Creates a FileInputStream reading from the given file.
A ZeroCopyOutputStream reading from a file
Objects can be created by the FileOutputStream function
pointer
: External pointer to the google::protobuf::io::FileOutputStream
C++ object
Class "ZeroCopyOutputStream"
, directly.
signature(con="FileOutputStream")
:
Flushes any buffers and closes the underlying file.
Returns false if an error occurs during the process; use GetErrno
to examine the error
signature(con="FileOutputStream")
:
Flushes FileOutputStream's buffers but does not close the underlying file
signature(object="FileInputStream")
:
If an I/O error has occurred on this file descriptor, this is the errno from that error.
Otherwise, this is zero. Once an error occurs, the stream is broken and all subsequent operations will fail.
signature(object="FileOutputStream")
:
set the close on delete behavior.
See ZeroCopyOutputStream for inherited methods
Romain Francois <[email protected]>
The FileOutputStream
class from the protobuf C++ library.
ZeroCopyOutputStream for methods
Constructor for FileOutputStream objects
signature(filename = "character", block_size = "logical", close.on.delete = "logical" )
Creates a FileOutputStream writing to the given file.
If an I/O error has occurred on this file descriptor, this is the errno from that error
See classes FileInputStream and FileOutputStream for implementations.
This generic method, currently implemented for Message and EnumDescriptor indicates if the message or enum descriptor has the given field set.
For messages and non-repeated fields, a call to the HasField
method of the corresponding Message
is issued.
For messages and repeated fields, a call to the FieldSize
method is issued, and the message is declared to have
the field if the size is greater than 0.
NULL
is returned if the descriptor for the message does not
contain the given field at all.
For EnumDescriptors, a boolean value indicates if the given name is present in the enum definition.
signature(object = "Message")
:
Indicates if the message has a given field.
signature(object = "EnumDescriptor")
:
Indicates if the EnumDescriptor has a given named element.
unitest.proto.file <- system.file("tinytest", "data", "unittest.proto", package = "RProtoBuf" ) readProtoFiles(file = unitest.proto.file) test <- new(protobuf_unittest.TestAllTypes) test$has("optional_int32") # FALSE test$add("repeated_int32", 1:10) test$has("repeated_int32") # TRUE test$has("nonexistant") # NULL has(protobuf_unittest.TestAllTypes$NestedEnum, "FOO") has(protobuf_unittest.TestAllTypes$NestedEnum, "BAR") has(protobuf_unittest.TestAllTypes$NestedEnum, "XXX")
unitest.proto.file <- system.file("tinytest", "data", "unittest.proto", package = "RProtoBuf" ) readProtoFiles(file = unitest.proto.file) test <- new(protobuf_unittest.TestAllTypes) test$has("optional_int32") # FALSE test$add("repeated_int32", 1:10) test$has("repeated_int32") # TRUE test$has("nonexistant") # NULL has(protobuf_unittest.TestAllTypes$NestedEnum, "FOO") has(protobuf_unittest.TestAllTypes$NestedEnum, "BAR") has(protobuf_unittest.TestAllTypes$NestedEnum, "XXX")
Indicates if a field descriptor is an extension
The method is implemented for the FieldDescriptor class
Person <- P( "tutorial.Person" ) is_extension(Person$id)
Person <- P( "tutorial.Person" ) is_extension(Person$id)
Indicates if a Message is initialized. A message is initialized if all its required fields are set.
signature(object = "Message")
is the message initialized
message <- new( tutorial.Person, name = "" ) isInitialized( message ) # FALSE (id is not set) message$isInitialized() # FALSE message <- new( tutorial.Person, name = "", id = 2 ) isInitialized( message ) # TRUE message$isInitialized() # TRUE
message <- new( tutorial.Person, name = "" ) isInitialized( message ) # FALSE (id is not set) message$isInitialized() # FALSE message <- new( tutorial.Person, name = "", id = 2 ) isInitialized( message ) # TRUE message$isInitialized() # TRUE
Gets the label of a field (optional, required, or repeated).
object |
A FieldDescriptor object. |
as.string |
If true, print a string representation of the type. |
The method is implemented for the FieldDescriptor class
## Not run: proto.file <- system.file( "proto", "addressbook.proto", package = "RProtoBuf" ) Person <- P( "tutorial.Person", file = proto.file ) ## End(Not run) label(Person$id) label(Person$email) label(Person$phone) label(Person$id, TRUE) label(Person$email, TRUE) label(Person$phone, TRUE) LABEL_OPTIONAL LABEL_REQUIRED LABEL_REPEATED
## Not run: proto.file <- system.file( "proto", "addressbook.proto", package = "RProtoBuf" ) Person <- P( "tutorial.Person", file = proto.file ) ## End(Not run) label(Person$id) label(Person$email) label(Person$phone) label(Person$id, TRUE) label(Person$email, TRUE) label(Person$phone, TRUE) LABEL_OPTIONAL LABEL_REQUIRED LABEL_REPEATED
Merge two Message objects of the same type.
signature(x = "Message", y = "Message")
merge two messages of the same type
An error of class "IncompatibleType" is thrown if the two messages are not of the same message type.
m1 <- new( tutorial.Person, email = "[email protected]" ) m2 <- new( tutorial.Person, id = 5 ) m3 <- merge( m1, m2 ) writeLines( as.character( m1 ) ) writeLines( as.character( m2 ) ) writeLines( as.character( m3 ) )
m1 <- new( tutorial.Person, email = "[email protected]" ) m2 <- new( tutorial.Person, id = 5 ) m3 <- merge( m1, m2 ) writeLines( as.character( m1 ) ) writeLines( as.character( m2 ) ) writeLines( as.character( m3 ) )
R representation of protocol buffer messages. This is a thin wrapper
around the Message
c++ class that holds the actual message
as an external pointer.
Objects are typically created by the new
function invoked
on a Descriptor object.
pointer
:external pointer to the c++ Message
object
type
:fully qualified name of the message type
signature(x = "Message")
: returns the debug string of the message.
This is built from a call to the DebugString
method of the Message
object
signature(x = "Message")
: same as as.character
signature(x = "Message")
: returns the TextFormat of the message.
This is built from a call to TextFormat::PrintToString
with the Message
object
signature(x = "Message")
: same as as.character
signature(x = "Message")
: returns the JSON representation of the message.
This is built from a call to the
google::protobuf::util::MessageToJsonString
method and
accepts two arguments preserve_proto_field_names
- if FALSE (the default) convert field names to camelCase
always_print_primitive_fields
- whether to return the default
value for missing primitive fields (default false)
signature(x = "Message")
: set the value of a field of the message.
signature(x = "Message")
: gets the value of a field.
Primitive types are brought back to R as R objects of the closest matching R type.
Messages are brought back as instances of the Message
class.
signature(x = "Message")
: extracts a field identified by its name or declared tag number
signature(x = "Message")
: replace the value of a field identified by its name or declared tag number
signature(object = "Message")
: serialize a message. If the
"connection" argument is NULL
, the payload of the message is returned as a raw vector,
if the "connection" argument is a binary writable connection, the payload is written into the
connection. If "connection" is a character vector, the message is sent to
the file (in binary format).
signature(object = "Message")
: displays a short text about the message
signature(object = "Message")
: set several fields of the message at once
signature(x = "Message")
: The number of fields actually contained in the message.
A field counts in these two situations: the field is repeated and the field size is greater than 0,
the field is not repeated and the message has the field.
signature(object = "Message")
: set an
extension field of the Message.
signature(object = "Message")
: get the
value of an extension field of the Message.
signature(object = "Message")
: displays the structure of the message
signature(x = "Message", y = "Message")
: Test if two messages are exactly identical
signature(e1 = "Message", e2 = "Message")
: Same as identical
signature(e1 = "Message", e2 = "Message")
: Negation of identical
signature(e1 = "Message", e2 = "Message")
: Test near equality
signature(x = "Message")
: extracts the names of the message.
Romain Francois <[email protected]>
The Message
class from the C++ proto library.
P
creates objects of class Descriptor that
can be used to create messages.
## Not run: # example proto file supplied with this package proto.file <- system.file( "proto", "addressbook.proto", package = "RProtoBuf" ) # reading a proto file and creating the descriptor Person <- P( "tutorial.Person", file = proto.file ) ## End(Not run) PhoneNumber <- P( "tutorial.Person.PhoneNumber" ) # creating a prototype message from the descriptor p <- new( Person ) p$email # not set, returns default value p$id # not set, returns default value as.character( p ) # empty has( p, "email" ) # is the "email" field set has( p, "phone" ) # is the "email" field set length( p ) # number of fields actually set # update several fields at once romain <- update( new( Person ), email = "[email protected]", id = 1, name = "Romain Francois", phone = new( PhoneNumber , number = "+33(0)...", type = "MOBILE" ) ) # supply parameters to the constructor dirk <- new( Person, email = "[email protected]", id = 2, name = "Dirk Eddelbuettel" ) # update the phone repeated field with a list of PhoneNumber messages dirk$phone <- list( new( PhoneNumber , number = "+01...", type = "MOBILE" ), new( PhoneNumber , number = "+01...", type = "HOME" ) ) # with/within style saptarshi <- within( new(Person), { id <- 3 name <- "Saptarshi Guha" email <- "[email protected]" } ) # make an addressbook book <- new( tutorial.AddressBook, person = list( romain, dirk, saptarshi ) ) # serialize the message to a file tf <- tempfile( ) serialize( book, tf ) # the payload of the message serialize( book, NULL ) # read the file into a new message m <- tutorial.AddressBook$read( tf ) writeLines( as.character( m ) ) sapply( m$person, function(p) p$name )
## Not run: # example proto file supplied with this package proto.file <- system.file( "proto", "addressbook.proto", package = "RProtoBuf" ) # reading a proto file and creating the descriptor Person <- P( "tutorial.Person", file = proto.file ) ## End(Not run) PhoneNumber <- P( "tutorial.Person.PhoneNumber" ) # creating a prototype message from the descriptor p <- new( Person ) p$email # not set, returns default value p$id # not set, returns default value as.character( p ) # empty has( p, "email" ) # is the "email" field set has( p, "phone" ) # is the "email" field set length( p ) # number of fields actually set # update several fields at once romain <- update( new( Person ), email = "[email protected]", id = 1, name = "Romain Francois", phone = new( PhoneNumber , number = "+33(0)...", type = "MOBILE" ) ) # supply parameters to the constructor dirk <- new( Person, email = "[email protected]", id = 2, name = "Dirk Eddelbuettel" ) # update the phone repeated field with a list of PhoneNumber messages dirk$phone <- list( new( PhoneNumber , number = "+01...", type = "MOBILE" ), new( PhoneNumber , number = "+01...", type = "HOME" ) ) # with/within style saptarshi <- within( new(Person), { id <- 3 name <- "Saptarshi Guha" email <- "[email protected]" } ) # make an addressbook book <- new( tutorial.AddressBook, person = list( romain, dirk, saptarshi ) ) # serialize the message to a file tf <- tempfile( ) serialize( book, tf ) # the payload of the message serialize( book, NULL ) # read the file into a new message m <- tutorial.AddressBook$read( tf ) writeLines( as.character( m ) ) sapply( m$person, function(p) p$name )
R representation of Service Descriptors
TODO
pointer
:External pointer to a google::protobuf::MethodDescriptor
C++ object
name
:fully qualified name of the method
service
:fully qualified name of the service that defines this method
signature(x = "MethodDescriptor")
: debug string of the method
signature(x = "MethodDescriptor")
: debug string of the method
signature(x = "MethodDescriptor")
: ...
signature(x = "MethodDescriptor")
: ...
signature(object = "MethodDescriptor")
: the Descriptor of the input type of the method
signature(object = "MethodDescriptor")
: the Descriptor of the output type of the method
Romain Francois <[email protected]>
name or full name of a descriptor
signature(object = "Descriptor")
...
signature(object = "FieldDescriptor")
...
signature(object = "EnumDescriptor")
...
signature(object = "ServiceDescriptor")
...
signature(object = "MethodDescriptor")
...
The number of fields
The method is implemented for the Descriptor class
Extract a Descriptor nested in another Descriptor
The method is implemented for the Descriptor class
Obtains a chunk of data from the stream
ZeroCopyInputStream implements Next.
Gets the declared tag number of a field
The method is implemented for FieldDescriptor and EnumValueDescriptor classes.
## Not run: proto.file <- system.file( "proto", "addressbook.proto", package = "RProtoBuf" ) Person <- P( "tutorial.Person", file = proto.file ) ## End(Not run) number(Person$id) number(Person$email) as.character(Person) number(value(tutorial.Person$PhoneType, name="HOME"))
## Not run: proto.file <- system.file( "proto", "addressbook.proto", package = "RProtoBuf" ) Person <- P( "tutorial.Person", file = proto.file ) ## End(Not run) number(Person$id) number(Person$email) as.character(Person) number(value(tutorial.Person$PhoneType, name="HOME"))
The P
function searches for a protocol message
descriptor in the descriptor pool.
P(type, file)
P(type, file)
type |
Fully qualified type name of the protocol buffer or extension |
file |
optional proto file. If given, the definition contained in the file is first registered with the pool of message descriptors |
An object of class Descriptor for message types or FieldDescriptor for extensions. An error is generated otherwise.
Romain Francois <[email protected]>
## Not run: proto.file <- system.file( "proto", "addressbook.proto", package = "RProtoBuf" ) Person <- P( "tutorial.Person", file = proto.file ) ## End(Not run) cat(as.character( Person ))
## Not run: proto.file <- system.file( "proto", "addressbook.proto", package = "RProtoBuf" ) Person <- P( "tutorial.Person", file = proto.file ) ## End(Not run) cat(as.character( Person ))
Read a Message from a connection using its associated Descriptor
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
# 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 )
# 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 )
Method to read a Message in ASCII format
signature(descriptor = "Descriptor", input = "ANY")
Read the message from a connection (file, etc ...)
signature(descriptor = "Descriptor", input = "character")
Read the message directly from the character string
## Not run: # example file that contains a "tutorial.AddressBook" message book <- system.file( "examples", "addressbook.pb", package = "RProtoBuf" ) # read the message message <- read( tutorial.AddressBook, book ) # Output in text format to a temporary file out.file <- tempfile() writeLines( as.character(message), file(out.file)) # Verify that we can read back in the message from a text file. message2 <- readASCII( tutorial.AddressBook, file(out.file, "rb")) # Verify that we can read back in the message from an unopened file. message3 <- readASCII( tutorial.AddressBook, file(out.file)) \dontshow{ stopifnot( identical( message, message2) ) } ## End(Not run)
## Not run: # example file that contains a "tutorial.AddressBook" message book <- system.file( "examples", "addressbook.pb", package = "RProtoBuf" ) # read the message message <- read( tutorial.AddressBook, book ) # Output in text format to a temporary file out.file <- tempfile() writeLines( as.character(message), file(out.file)) # Verify that we can read back in the message from a text file. message2 <- readASCII( tutorial.AddressBook, file(out.file, "rb")) # Verify that we can read back in the message from an unopened file. message3 <- readASCII( tutorial.AddressBook, file(out.file)) \dontshow{ stopifnot( identical( message, message2) ) } ## End(Not run)
Method to read a Message in JSON format
signature(descriptor = "Descriptor", input = "ANY")
Read the message from a connection (file, etc ...)
signature(descriptor = "Descriptor", input = "character")
Read the message directly from the character string
## Not run: # example file that contains a "tutorial.AddressBook" message book <- system.file( "examples", "addressbook.pb", package = "RProtoBuf" ) # read the message message <- read( tutorial.AddressBook, book ) # Output in text format to a temporary file out.file <- tempfile() writeLines( message$toJSON(), file(out.file)) # Verify that we can read back in the message from a text file. message2 <- readJSON( tutorial.AddressBook, file(out.file, "rb")) # Verify that we can read back in the message from an unopened file. message3 <- readJSON( tutorial.AddressBook, file(out.file)) \dontshow{ stopifnot( identical( message, message2) ) } ## End(Not run)
## Not run: # example file that contains a "tutorial.AddressBook" message book <- system.file( "examples", "addressbook.pb", package = "RProtoBuf" ) # read the message message <- read( tutorial.AddressBook, book ) # Output in text format to a temporary file out.file <- tempfile() writeLines( message$toJSON(), file(out.file)) # Verify that we can read back in the message from a text file. message2 <- readJSON( tutorial.AddressBook, file(out.file, "rb")) # Verify that we can read back in the message from an unopened file. message3 <- readJSON( tutorial.AddressBook, file(out.file)) \dontshow{ stopifnot( identical( message, message2) ) } ## End(Not run)
Imports proto files into the descriptor pool that
is then used by the P
function to resolve
message type names.
readProtoFiles(files, dir, package="RProtoBuf", pattern="\\.proto$", lib.loc=NULL) readProtoFiles2(files, dir=".", pattern="\\.proto$", recursive=FALSE, protoPath=getwd()) resetDescriptorPool()
readProtoFiles(files, dir, package="RProtoBuf", pattern="\\.proto$", lib.loc=NULL) readProtoFiles2(files, dir=".", pattern="\\.proto$", recursive=FALSE, protoPath=getwd()) resetDescriptorPool()
files |
Proto files |
dir |
Directory. If |
package |
R package name. If |
pattern |
A filename pattern to match proto files when using |
recursive |
Whether to descend recursively into |
lib.loc |
Library location. |
protoPath |
Search path for proto file imports. |
readProtoFiles2
is different from readProtoFiles
to be
consistent with the behavior of protoc
command line tool in
being explicit about the search path for proto import statements. In addition,
we also require that both files
and dir
arguments are
interpreted relative to protoPath
, so that there is consistency in
future imports of the same files through import statements of other proto
files.
resetDescriptorPool
clears all imported proto definitions.
NULL
, invisibly.
Romain Francois <[email protected]>
## Not run: # from a package readProtoFiles(package = "RProtoBuf") # from a directory proto.dir <- system.file("proto", package = "RProtoBuf") readProtoFiles(dir = proto.dir) # set of files proto.files <- list.files(proto.dir, full.names = TRUE) readProtoFiles(proto.files) ## End(Not run)
## Not run: # from a package readProtoFiles(package = "RProtoBuf") # from a directory proto.dir <- system.file("proto", package = "RProtoBuf") readProtoFiles(dir = proto.dir) # set of files proto.files <- list.files(proto.dir, full.names = TRUE) readProtoFiles(proto.files) ## End(Not run)
Serializes R objects to a general purpose protobuf message using the same
rexp.proto
descriptor and mapping between R objects and protobuf
mesages as RHIPE.
serialize_pb(object, connection, ...)
serialize_pb(object, connection, ...)
object |
R object to serialize |
connection |
passed on to |
... |
additional arguments passed on to |
Clients need both the message and the rexp.proto
descriptor to parse
serialized R objects. The latter is included in the the package installation
proto
directory: system.file(package="RProtoBuf", "proto/rexp.proto")
The following storage types are natively supported by the descriptor:
character
, raw
, double
, complex
, integer
,
list
, and NULL
. Objects with other storage types, such as
functions, environments, S4 classes, etc, are serialized using base R
serialize
and stored in the proto native
type.
Missing values, attributes and numeric precision will be preserved.
msg <- tempfile(); serialize_pb(iris, msg); obj <- unserialize_pb(msg); identical(iris, obj);
msg <- tempfile(); serialize_pb(iris, msg); obj <- unserialize_pb(msg); identical(iris, obj);
R representation of Service Descriptors
TODO
pointer
:External pointer to a google::protobuf::ServiceDescriptor
C++ object
name
:fully qualified name of the service
signature(x = "ServiceDescriptor")
: debug string of the service
signature(x = "ServiceDescriptor")
: debug string of the service
signature(x = "ServiceDescriptor")
: ...
signature(x = "ServiceDescriptor")
: invoke pseudo methods or retrieve
method descriptors contained in this service descriptor.
signature(x = "ServiceDescriptor")
: extracts methods
descriptors contained in this service descriptor
signature(x = "ServiceDescriptor")
: number of MethodDescriptor
signature(x = "ServiceDescriptor")
: number of MethodDescriptor
signature(x = "ServiceDescriptor")
: retrieves a MethodDescriptor
Romain Francois <[email protected]>
set a subset of values of a repeated field of a message
signature(object = "Message")
set a subset of values of a repeated field of a message
By default, the file descriptor is not closed when a stream is destroyed,
use SetCloseOnDelete( stream, TRUE )
to change that.
See classes FileInputStream and FileOutputStream for implementations.
The number of object currently in a given field of a protocol buffer message.
For non repeated fields, the size is 1 if the message has the field, 0 otherwise.
For repeated fields, the size is the number of objects in the array.
For repeated fields, the size can also be assigned to in order to shrink or grow the vector. Numeric types are given a default value of 0 when the new size is greater than the existing size. Character types are given a default value of "". Growing a repeated field in this way is not supported for message, group, and enum types.
signature(object = "Message")
Number of objects in a message field
unitest.proto.file <- system.file("tinytest", "data", "unittest.proto", package = "RProtoBuf" ) readProtoFiles(file = unitest.proto.file) test <- new(protobuf_unittest.TestAllTypes) test$size("optional_int32") test$add("repeated_int32", 1:10) test$size("repeated_int32") test$repeated_int32 size(test, "repeated_int32") <- 5 test$repeated_int32 size(test, "repeated_int32") <- 15 test$repeated_int32
unitest.proto.file <- system.file("tinytest", "data", "unittest.proto", package = "RProtoBuf" ) readProtoFiles(file = unitest.proto.file) test <- new(protobuf_unittest.TestAllTypes) test$size("optional_int32") test$add("repeated_int32", 1:10) test$size("repeated_int32") test$repeated_int32 size(test, "repeated_int32") <- 5 test$repeated_int32 size(test, "repeated_int32") <- 15 test$repeated_int32
Sets the size of a repeated field.
signature(object = "Message")
sets the size of a message field
swap elements of a repeated field of a message.
signature(object = "Message")
swap elements of a repeated field of a message
See the SwapElements
of the Reflection
class, part of the protobuf library.
Gets the type or the C++ type of a field
object |
A FieldDescriptor object. |
as.string |
If true, print a string representation of the type. |
The method is implemented for the FieldDescriptor class
## Not run: proto.file <- system.file( "proto", "addressbook.proto", package = "RProtoBuf" ) Person <- P( "tutorial.Person", file = proto.file ) ## End(Not run) type(Person$id) type(Person$id, as.string=TRUE) cpp_type(Person$email) cpp_type(Person$email, TRUE)
## Not run: proto.file <- system.file( "proto", "addressbook.proto", package = "RProtoBuf" ) Person <- P( "tutorial.Person", file = proto.file ) ## End(Not run) type(Person$id) type(Person$id, as.string=TRUE) cpp_type(Person$email) cpp_type(Person$email, TRUE)
Convenience wrapper that allow getting and setting fields of protocol buffer messages from within the object
## S3 method for class 'Message' with(data, expr, ...) ## S3 method for class 'Message' within(data, expr, ...)
## S3 method for class 'Message' with(data, expr, ...) ## S3 method for class 'Message' within(data, expr, ...)
data |
A protocol buffer message, instance of Message |
expr |
R expression to evaluate |
... |
ignored |
The expression is evaluated in an environment that allows to set and get fields of the message
The fields of the message are mapped to active bindings (see makeActiveBinding) so that they can be accessed and modified from within the environment.
with
returns the value of the expression and
within
returns the data
argument.
Romain Francois <[email protected]>
## Not run: proto.file <- system.file( "proto", "addressbook.proto", package = "RProtoBuf" ) Person <- P( "tutorial.Person", file = proto.file ) ## End(Not run) romain <- within( new( Person ), { email <- "[email protected]" id <- 10L } )
## Not run: proto.file <- system.file( "proto", "addressbook.proto", package = "RProtoBuf" ) Person <- P( "tutorial.Person", file = proto.file ) ## End(Not run) romain <- within( new( Person ), { email <- "[email protected]" id <- 10L } )
R wrapper for the ZeroCopyInputStream c++ class
This is a virtual class
pointer
:external pointer to the google::protobuf::io::ZeroCopyInputStream
object
signature(x="ZeroCopyInputStream")
: invokes a method
signature(object="ZeroCopyInputStream")
: Get a number of bytes from the stream as a raw vector.
signature(object="ZeroCopyInputStream")
: skip a number of bytes
signature(object="ZeroCopyInputStream")
: Backs up a number of bytes, so that the next call to Next
returns data again that was already returned by the last call to Next
.
signature(object="ZeroCopyInputStream")
: Returns the total number of bytes read since this object was created.
signature(object="ZeroCopyInputStream", size = "integer")
: read raw bytes from the stream
signature(object="ZeroCopyInputStream", size = "numeric")
: read raw bytes from the stream
signature(object="ZeroCopyInputStream", size = "integer")
: same as ReadRaw
but formats the result as a string
signature(object="ZeroCopyInputStream", size = "numeric")
: same as ReadRaw
but formats the result as a string
signature(object="ZeroCopyInputStream")
: Read an unsigned integer with Varint encoding, truncating to 32 bits.
signature(object="ZeroCopyInputStream")
: Read a 32-bit little-endian integer.
signature(object="ZeroCopyInputStream")
: Read a 64-bit little-endian integer. In R the value is stored as a double
which looses some precision (no other way)
signature(object="ZeroCopyInputStream")
: Read a 64-bit integer with varint encoding. In R the value is stored as a double
which looses some precision (no other way)
Romain Francois <[email protected]>
The google::protobuf::io::ZeroCopyInputStream
C++ class.
TODO: add classes that extend
R wrapper for the ZeroCopyOutputStream c++ class
This is a virtual class
pointer
:external pointer to the google::protobuf::io::ZeroCopyOutputStream
object
signature(x="ZeroCopyOutputStream")
: invokes a method
signature(object="ZeroCopyOutputStream", payload = "raw" )
: push the raw vector into the stream. Returns the number of bytes actually written.
signature(object="ZeroCopyOutputStream")
: Backs up a number of bytes, so that the end of the last buffer returned by Next
is not actually written.
signature(object="ZeroCopyOutputStream")
: Returns the total number of bytes written since this object was created.
signature(object="ZeroCopyOuputStream")
, payload = "raw": write the raw bytes to the stream
Romain Francois <[email protected]>
The google::protobuf::io::ZeroCopyOutputStream
C++ class.
TODO: add classes that extend