| OLD | NEW |
| 1 This directory contains the Ruby extension that implements Protocol Buffers | 1 This directory contains the Ruby extension that implements Protocol Buffers |
| 2 functionality in Ruby. | 2 functionality in Ruby. |
| 3 | 3 |
| 4 The Ruby extension makes use of generated Ruby code that defines message and | 4 The Ruby extension makes use of generated Ruby code that defines message and |
| 5 enum types in a Ruby DSL. You may write definitions in this DSL directly, but | 5 enum types in a Ruby DSL. You may write definitions in this DSL directly, but |
| 6 we recommend using protoc's Ruby generation support with .proto files. The | 6 we recommend using protoc's Ruby generation support with .proto files. The |
| 7 build process in this directory only installs the extension; you need to | 7 build process in this directory only installs the extension; you need to |
| 8 install protoc as well to have Ruby code generation functionality. | 8 install protoc as well to have Ruby code generation functionality. |
| 9 | 9 |
| 10 Installation from Gem | 10 Installation from Gem |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 However, if you wish to generate the Ruby DSL from a `.proto` file, you will | 25 However, if you wish to generate the Ruby DSL from a `.proto` file, you will |
| 26 also want to install Protocol Buffers itself, as described in this repository's | 26 also want to install Protocol Buffers itself, as described in this repository's |
| 27 main `README` file. The version of `protoc` included in the latest release | 27 main `README` file. The version of `protoc` included in the latest release |
| 28 supports the `--ruby_out` option to generate Ruby code. | 28 supports the `--ruby_out` option to generate Ruby code. |
| 29 | 29 |
| 30 A simple example of using the Ruby extension follows. More extensive | 30 A simple example of using the Ruby extension follows. More extensive |
| 31 documentation may be found in the RubyDoc comments (`call-seq` tags) in the | 31 documentation may be found in the RubyDoc comments (`call-seq` tags) in the |
| 32 source, and we plan to release separate, more detailed, documentation at a | 32 source, and we plan to release separate, more detailed, documentation at a |
| 33 later date. | 33 later date. |
| 34 | 34 |
| 35 require 'google/protobuf' | 35 ```ruby |
| 36 require 'google/protobuf' |
| 36 | 37 |
| 37 # generated from my_proto_types.proto with protoc: | 38 # generated from my_proto_types.proto with protoc: |
| 38 # $ protoc --ruby_out=. my_proto_types.proto | 39 # $ protoc --ruby_out=. my_proto_types.proto |
| 39 require 'my_proto_types' | 40 require 'my_proto_types' |
| 40 | 41 |
| 41 mymessage = MyTestMessage.new(:field1 => 42, :field2 => ["a", "b", "c"]) | 42 mymessage = MyTestMessage.new(:field1 => 42, :field2 => ["a", "b", "c"]) |
| 42 mymessage.field1 = 43 | 43 mymessage.field1 = 43 |
| 43 mymessage.field2.push("d") | 44 mymessage.field2.push("d") |
| 44 mymessage.field3 = SubMessage.new(:foo => 100) | 45 mymessage.field3 = SubMessage.new(:foo => 100) |
| 45 | 46 |
| 46 encoded_data = MyTestMessage.encode(mymessage) | 47 encoded_data = MyTestMessage.encode(mymessage) |
| 47 decoded = MyTestMessage.decode(encoded_data) | 48 decoded = MyTestMessage.decode(encoded_data) |
| 48 assert decoded == mymessage | 49 assert decoded == mymessage |
| 49 | 50 |
| 50 puts "JSON:" | 51 puts "JSON:" |
| 51 puts MyTestMessage.encode_json(mymessage) | 52 puts MyTestMessage.encode_json(mymessage) |
| 53 ``` |
| 52 | 54 |
| 53 Installation from Source (Building Gem) | 55 Installation from Source (Building Gem) |
| 54 --------------------------------------- | 56 --------------------------------------- |
| 55 | 57 |
| 56 To build this Ruby extension, you will need: | 58 To build this Ruby extension, you will need: |
| 57 | 59 |
| 58 * Rake | 60 * Rake |
| 59 * Bundler | 61 * Bundler |
| 60 * Ruby development headers | 62 * Ruby development headers |
| 61 * a C compiler | 63 * a C compiler |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 to upload a new version of the gem to fix an issue, the version becomes | 105 to upload a new version of the gem to fix an issue, the version becomes |
| 104 "3.0.0.alpha.2.1" or "3.0.0.1". | 106 "3.0.0.alpha.2.1" or "3.0.0.1". |
| 105 * If we are working on a prerelease version, we append a prerelease tag: | 107 * If we are working on a prerelease version, we append a prerelease tag: |
| 106 "3.0.0.alpha.3.0.pre". The prerelease tag comes at the end so that when | 108 "3.0.0.alpha.3.0.pre". The prerelease tag comes at the end so that when |
| 107 version numbers are sorted, any prerelease builds are ordered between the | 109 version numbers are sorted, any prerelease builds are ordered between the |
| 108 prior version and current version. | 110 prior version and current version. |
| 109 | 111 |
| 110 These rules are designed to work with the sorting rules for | 112 These rules are designed to work with the sorting rules for |
| 111 [Gem::Version](http://ruby-doc.org/stdlib-2.0/libdoc/rubygems/rdoc/Gem/Version.h
tml): | 113 [Gem::Version](http://ruby-doc.org/stdlib-2.0/libdoc/rubygems/rdoc/Gem/Version.h
tml): |
| 112 release numbers should sort in actual release order. | 114 release numbers should sort in actual release order. |
| OLD | NEW |