This directory contains the Ruby extension that implements Protocol Buffers functionality in Ruby.
The Ruby extension makes use of generated Ruby code that defines message and enum types in a Ruby DSL. You may write definitions in this DSL directly, but we recommend using protoc's Ruby generation support with .proto files. The build process in this directory only installs the extension; you need to install protoc as well to have Ruby code generation functionality.
In Gemfile (Please check a version of Protocol Buffers you needed RubyGems):
Or for using this pre-packaged gem, simply install it as you would any other gem:
$ gem install [--prerelease] google-protobuf
Once the gem is installed, you may or may not need
protoc. If you write your message type descriptions directly in the Ruby DSL, you do not need it. However, if you wish to generate the Ruby DSL from a
.proto file, you will also want to install Protocol Buffers itself, as described in this repository's main
README file. The version of
protoc included in the latest release supports the
--ruby_out option to generate Ruby code.
A simple example of using the Ruby extension follows. More extensive documentation may be found in the RubyDoc comments (
call-seq tags) in the source, and we plan to release separate, more detailed, documentation at a later date.
'google/protobuf' require # generated from my_proto_types.proto with protoc: # $ protoc --ruby_out=. my_proto_types.proto 'my_proto_types' require MyTestMessage.new(:field1 => 42, :field2 => ["a", "b", "c"]) mymessage = 43 mymessage.field1 = "d") mymessage.field2.push(SubMessage.new(:foo => 100) mymessage.field3 = MyTestMessage.encode(mymessage) encoded_data = MyTestMessage.decode(encoded_data) decoded = assert decoded == mymessage "JSON:" puts MyTestMessage.encode_json(mymessage)puts
To build this Ruby extension, you will need:
To Build the JRuby extension, you will need:
First switch to the desired platform with rbenv or RVM.
Then install the required Ruby gems:
$ gem install bundler $ bundle
Then build the Gem:
$ rake $ rake clobber_package gem $ gem install `ls pkg/google-protobuf-*.gem`
To run the specs:
$ rake test
This gem includes the upb parsing and serialization library as a single-file amalgamation. It is up-to-date with upb git commit
We are using a version number scheme that is a hybrid of Protocol Buffers' overall version number and some Ruby-specific rules. Gem does not allow re-uploads of a gem with the same version number, so we add a sequence number ("upload version") to the version. We also format alphabetical tags (alpha, pre, ...) slightly differently, and we avoid hyphens. In more detail:
These rules are designed to work with the sorting rules for Gem::Version: release numbers should sort in actual release order.