diff options
author | Adam Greene <adam.greene@gmail.com> | 2015-05-03 10:55:10 -0700 |
---|---|---|
committer | Adam Greene <adam.greene@gmail.com> | 2015-05-13 10:03:56 -0700 |
commit | d1b52a00e002fd7a4adbcdeafa0634de6088a88f (patch) | |
tree | fe21dea8131562f7ff974edaf3c92edb4a5b465f /ruby/lib/google/protobuf.rb | |
parent | 23bb79d4a32a77e8349d6c49052be1e56a8b8153 (diff) | |
download | protobuf-d1b52a00e002fd7a4adbcdeafa0634de6088a88f.tar.gz protobuf-d1b52a00e002fd7a4adbcdeafa0634de6088a88f.tar.bz2 protobuf-d1b52a00e002fd7a4adbcdeafa0634de6088a88f.zip |
adding and simplifying encoders/decoders
* make consistent between mri and jruby
* create a #to_h and have it use symbols for keys
* add #to_json and #to_proto helpers on the Google::Protobuf message classes
Diffstat (limited to 'ruby/lib/google/protobuf.rb')
-rw-r--r-- | ruby/lib/google/protobuf.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/ruby/lib/google/protobuf.rb b/ruby/lib/google/protobuf.rb index 72797245..99b17929 100644 --- a/ruby/lib/google/protobuf.rb +++ b/ruby/lib/google/protobuf.rb @@ -28,6 +28,9 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# require mixins before we hook them into the java & c code +require 'google/protobuf/message_exts' + if RUBY_PLATFORM == "java" require 'json' require 'google/protobuf_java' @@ -36,3 +39,25 @@ else end require 'google/protobuf/repeated_field' + +module Google + module Protobuf + + def self.encode(msg) + msg.to_proto + end + + def self.encode_json(msg) + msg.to_json + end + + def self.decode(klass, proto) + klass.decode(proto) + end + + def self.decode_json(klass, json) + klass.decode_json(json) + end + + end +end |