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 26 matching lines...) Expand all Loading... |
37 module Protobuf | 37 module Protobuf |
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 require 'google/protobuf_c' | 47 begin |
| 48 require "google/#{RUBY_VERSION.sub(/\.\d$/, '')}/protobuf_c" |
| 49 rescue LoadError |
| 50 require 'google/protobuf_c' |
| 51 end |
48 end | 52 end |
49 | 53 |
50 require 'google/protobuf/repeated_field' | 54 require 'google/protobuf/repeated_field' |
51 | 55 |
52 module Google | 56 module Google |
53 module Protobuf | 57 module Protobuf |
54 | 58 |
55 def self.encode(msg) | 59 def self.encode(msg) |
56 msg.to_proto | 60 msg.to_proto |
57 end | 61 end |
58 | 62 |
59 def self.encode_json(msg) | 63 def self.encode_json(msg) |
60 msg.to_json | 64 msg.to_json |
61 end | 65 end |
62 | 66 |
63 def self.decode(klass, proto) | 67 def self.decode(klass, proto) |
64 klass.decode(proto) | 68 klass.decode(proto) |
65 end | 69 end |
66 | 70 |
67 def self.decode_json(klass, json) | 71 def self.decode_json(klass, json) |
68 klass.decode_json(json) | 72 klass.decode_json(json) |
69 end | 73 end |
70 | 74 |
71 end | 75 end |
72 end | 76 end |
OLD | NEW |