| OLD | NEW |
| 1 # Protocol Buffers - Google's data interchange format | 1 # Protocol Buffers - Google's data interchange format |
| 2 # Copyright 2008 Google Inc. All rights reserved. | 2 # Copyright 2008 Google Inc. All rights reserved. |
| 3 # https://developers.google.com/protocol-buffers/ | 3 # https://developers.google.com/protocol-buffers/ |
| 4 # | 4 # |
| 5 # Redistribution and use in source and binary forms, with or without | 5 # Redistribution and use in source and binary forms, with or without |
| 6 # modification, are permitted provided that the following conditions are | 6 # modification, are permitted provided that the following conditions are |
| 7 # met: | 7 # met: |
| 8 # | 8 # |
| 9 # * Redistributions of source code must retain the above copyright | 9 # * Redistributions of source code must retain the above copyright |
| 10 # notice, this list of conditions and the following disclaimer. | 10 # notice, this list of conditions and the following disclaimer. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 class Error < StandardError; end | 38 class Error < StandardError; end |
| 39 class ParseError < Error; end | 39 class ParseError < Error; end |
| 40 end | 40 end |
| 41 end | 41 end |
| 42 | 42 |
| 43 if RUBY_PLATFORM == "java" | 43 if RUBY_PLATFORM == "java" |
| 44 require 'json' | 44 require 'json' |
| 45 require 'google/protobuf_java' | 45 require 'google/protobuf_java' |
| 46 else | 46 else |
| 47 begin | 47 begin |
| 48 require "google/#{RUBY_VERSION.sub(/\.\d$/, '')}/protobuf_c" | 48 require "google/#{RUBY_VERSION.sub(/\.\d+$/, '')}/protobuf_c" |
| 49 rescue LoadError | 49 rescue LoadError |
| 50 require 'google/protobuf_c' | 50 require 'google/protobuf_c' |
| 51 end | 51 end |
| 52 end | 52 end |
| 53 | 53 |
| 54 require 'google/protobuf/repeated_field' | 54 require 'google/protobuf/repeated_field' |
| 55 | 55 |
| 56 module Google | 56 module Google |
| 57 module Protobuf | 57 module Protobuf |
| 58 | 58 |
| 59 def self.encode(msg) | 59 def self.encode(msg) |
| 60 msg.to_proto | 60 msg.to_proto |
| 61 end | 61 end |
| 62 | 62 |
| 63 def self.encode_json(msg) | 63 def self.encode_json(msg) |
| 64 msg.to_json | 64 msg.to_json |
| 65 end | 65 end |
| 66 | 66 |
| 67 def self.decode(klass, proto) | 67 def self.decode(klass, proto) |
| 68 klass.decode(proto) | 68 klass.decode(proto) |
| 69 end | 69 end |
| 70 | 70 |
| 71 def self.decode_json(klass, json) | 71 def self.decode_json(klass, json) |
| 72 klass.decode_json(json) | 72 klass.decode_json(json) |
| 73 end | 73 end |
| 74 | 74 |
| 75 end | 75 end |
| 76 end | 76 end |
| OLD | NEW |