google-protobuf 3.5.0.pre-java → 3.19.1-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of google-protobuf might be problematic. Click here for more details.

@@ -39,6 +39,12 @@ module Google
39
39
  module Protobuf
40
40
 
41
41
  Any.class_eval do
42
+ def self.pack(msg, type_url_prefix='type.googleapis.com/')
43
+ any = self.new
44
+ any.pack(msg, type_url_prefix)
45
+ any
46
+ end
47
+
42
48
  def pack(msg, type_url_prefix='type.googleapis.com/')
43
49
  if type_url_prefix.empty? or type_url_prefix[-1] != '/' then
44
50
  self.type_url = "#{type_url_prefix}/#{msg.class.descriptor.name}"
@@ -66,13 +72,24 @@ module Google
66
72
  end
67
73
 
68
74
  Timestamp.class_eval do
69
- def to_time
70
- Time.at(self.to_f)
75
+ if RUBY_VERSION < "2.5"
76
+ def to_time
77
+ Time.at(self.to_f)
78
+ end
79
+ else
80
+ def to_time
81
+ Time.at(seconds, nanos, :nanosecond)
82
+ end
71
83
  end
72
84
 
73
85
  def from_time(time)
74
86
  self.seconds = time.to_i
75
87
  self.nanos = time.nsec
88
+ self
89
+ end
90
+
91
+ def self.from_time(time)
92
+ new.from_time(time)
76
93
  end
77
94
 
78
95
  def to_i
@@ -149,6 +166,8 @@ module Google
149
166
  Struct.class_eval do
150
167
  def [](key)
151
168
  self.fields[key].to_ruby
169
+ rescue NoMethodError
170
+ nil
152
171
  end
153
172
 
154
173
  def []=(key, value)
@@ -170,6 +189,10 @@ module Google
170
189
  hash.each { |key, val| ret[key] = val }
171
190
  ret
172
191
  end
192
+
193
+ def has_key?(key)
194
+ self.fields.has_key?(key)
195
+ end
173
196
  end
174
197
 
175
198
  ListValue.class_eval do
@@ -4,45 +4,47 @@
4
4
  require 'google/protobuf'
5
5
 
6
6
  Google::Protobuf::DescriptorPool.generated_pool.build do
7
- add_message "google.protobuf.DoubleValue" do
8
- optional :value, :double, 1
9
- end
10
- add_message "google.protobuf.FloatValue" do
11
- optional :value, :float, 1
12
- end
13
- add_message "google.protobuf.Int64Value" do
14
- optional :value, :int64, 1
15
- end
16
- add_message "google.protobuf.UInt64Value" do
17
- optional :value, :uint64, 1
18
- end
19
- add_message "google.protobuf.Int32Value" do
20
- optional :value, :int32, 1
21
- end
22
- add_message "google.protobuf.UInt32Value" do
23
- optional :value, :uint32, 1
24
- end
25
- add_message "google.protobuf.BoolValue" do
26
- optional :value, :bool, 1
27
- end
28
- add_message "google.protobuf.StringValue" do
29
- optional :value, :string, 1
30
- end
31
- add_message "google.protobuf.BytesValue" do
32
- optional :value, :bytes, 1
7
+ add_file("google/protobuf/wrappers.proto", :syntax => :proto3) do
8
+ add_message "google.protobuf.DoubleValue" do
9
+ optional :value, :double, 1
10
+ end
11
+ add_message "google.protobuf.FloatValue" do
12
+ optional :value, :float, 1
13
+ end
14
+ add_message "google.protobuf.Int64Value" do
15
+ optional :value, :int64, 1
16
+ end
17
+ add_message "google.protobuf.UInt64Value" do
18
+ optional :value, :uint64, 1
19
+ end
20
+ add_message "google.protobuf.Int32Value" do
21
+ optional :value, :int32, 1
22
+ end
23
+ add_message "google.protobuf.UInt32Value" do
24
+ optional :value, :uint32, 1
25
+ end
26
+ add_message "google.protobuf.BoolValue" do
27
+ optional :value, :bool, 1
28
+ end
29
+ add_message "google.protobuf.StringValue" do
30
+ optional :value, :string, 1
31
+ end
32
+ add_message "google.protobuf.BytesValue" do
33
+ optional :value, :bytes, 1
34
+ end
33
35
  end
34
36
  end
35
37
 
36
38
  module Google
37
39
  module Protobuf
38
- DoubleValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.DoubleValue").msgclass
39
- FloatValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FloatValue").msgclass
40
- Int64Value = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Int64Value").msgclass
41
- UInt64Value = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.UInt64Value").msgclass
42
- Int32Value = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Int32Value").msgclass
43
- UInt32Value = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.UInt32Value").msgclass
44
- BoolValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.BoolValue").msgclass
45
- StringValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.StringValue").msgclass
46
- BytesValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.BytesValue").msgclass
40
+ DoubleValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.DoubleValue").msgclass
41
+ FloatValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FloatValue").msgclass
42
+ Int64Value = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Int64Value").msgclass
43
+ UInt64Value = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.UInt64Value").msgclass
44
+ Int32Value = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Int32Value").msgclass
45
+ UInt32Value = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.UInt32Value").msgclass
46
+ BoolValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.BoolValue").msgclass
47
+ StringValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.StringValue").msgclass
48
+ BytesValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.BytesValue").msgclass
47
49
  end
48
50
  end
@@ -37,6 +37,7 @@ module Google
37
37
  module Protobuf
38
38
  class Error < StandardError; end
39
39
  class ParseError < Error; end
40
+ class TypeError < ::TypeError; end
40
41
  end
41
42
  end
42
43
 
@@ -49,8 +50,10 @@ else
49
50
  rescue LoadError
50
51
  require 'google/protobuf_c'
51
52
  end
53
+
52
54
  end
53
55
 
56
+ require 'google/protobuf/descriptor_dsl'
54
57
  require 'google/protobuf/repeated_field'
55
58
 
56
59
  module Google
@@ -60,16 +63,16 @@ module Google
60
63
  msg.to_proto
61
64
  end
62
65
 
63
- def self.encode_json(msg)
64
- msg.to_json
66
+ def self.encode_json(msg, options = {})
67
+ msg.to_json(options)
65
68
  end
66
69
 
67
70
  def self.decode(klass, proto)
68
71
  klass.decode(proto)
69
72
  end
70
73
 
71
- def self.decode_json(klass, json)
72
- klass.decode_json(json)
74
+ def self.decode_json(klass, json, options = {})
75
+ klass.decode_json(json, options)
73
76
  end
74
77
 
75
78
  end
Binary file