google-protobuf 3.7.0 → 3.21.5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


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

Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/ext/google/protobuf_c/convert.c +361 -0
  3. data/ext/google/protobuf_c/convert.h +75 -0
  4. data/ext/google/protobuf_c/defs.c +669 -1646
  5. data/ext/google/protobuf_c/defs.h +107 -0
  6. data/ext/google/protobuf_c/extconf.rb +13 -8
  7. data/ext/google/protobuf_c/map.c +330 -477
  8. data/ext/google/protobuf_c/map.h +66 -0
  9. data/ext/google/protobuf_c/message.c +1048 -379
  10. data/ext/google/protobuf_c/message.h +104 -0
  11. data/ext/google/protobuf_c/protobuf.c +413 -54
  12. data/ext/google/protobuf_c/protobuf.h +53 -546
  13. data/ext/google/protobuf_c/repeated_field.c +318 -315
  14. data/ext/google/protobuf_c/repeated_field.h +63 -0
  15. data/ext/google/protobuf_c/ruby-upb.c +11115 -0
  16. data/ext/google/protobuf_c/ruby-upb.h +5612 -0
  17. data/ext/google/protobuf_c/third_party/utf8_range/LICENSE +21 -0
  18. data/ext/google/protobuf_c/third_party/utf8_range/naive.c +92 -0
  19. data/ext/google/protobuf_c/third_party/utf8_range/range2-neon.c +157 -0
  20. data/ext/google/protobuf_c/third_party/utf8_range/range2-sse.c +170 -0
  21. data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.h +9 -0
  22. data/ext/google/protobuf_c/wrap_memcpy.c +4 -3
  23. data/lib/google/protobuf/any_pb.rb +1 -1
  24. data/lib/google/protobuf/api_pb.rb +4 -3
  25. data/lib/google/protobuf/descriptor_dsl.rb +465 -0
  26. data/lib/google/protobuf/descriptor_pb.rb +269 -0
  27. data/lib/google/protobuf/duration_pb.rb +1 -1
  28. data/lib/google/protobuf/empty_pb.rb +1 -1
  29. data/lib/google/protobuf/field_mask_pb.rb +1 -1
  30. data/lib/google/protobuf/message_exts.rb +2 -2
  31. data/lib/google/protobuf/repeated_field.rb +15 -2
  32. data/lib/google/protobuf/source_context_pb.rb +1 -1
  33. data/lib/google/protobuf/struct_pb.rb +4 -4
  34. data/lib/google/protobuf/timestamp_pb.rb +1 -1
  35. data/lib/google/protobuf/type_pb.rb +9 -8
  36. data/lib/google/protobuf/well_known_types.rb +20 -4
  37. data/lib/google/protobuf/wrappers_pb.rb +9 -9
  38. data/lib/google/protobuf.rb +6 -4
  39. data/tests/basic.rb +455 -77
  40. data/tests/generated_code_test.rb +0 -0
  41. data/tests/stress.rb +1 -1
  42. metadata +27 -30
  43. data/ext/google/protobuf_c/encode_decode.c +0 -1574
  44. data/ext/google/protobuf_c/storage.c +0 -1019
  45. data/ext/google/protobuf_c/upb.c +0 -17318
  46. data/ext/google/protobuf_c/upb.h +0 -9755
@@ -0,0 +1,269 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: google/protobuf/descriptor.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ descriptor_data = File.binread(__FILE__).split("\n__END__\n", 2)[1]
7
+ Google::Protobuf::DescriptorPool.generated_pool.add_serialized_file(descriptor_data)
8
+
9
+ module Google
10
+ module Protobuf
11
+ FileDescriptorSet = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FileDescriptorSet").msgclass
12
+ FileDescriptorProto = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FileDescriptorProto").msgclass
13
+ DescriptorProto = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.DescriptorProto").msgclass
14
+ DescriptorProto::ExtensionRange = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.DescriptorProto.ExtensionRange").msgclass
15
+ DescriptorProto::ReservedRange = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.DescriptorProto.ReservedRange").msgclass
16
+ ExtensionRangeOptions = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.ExtensionRangeOptions").msgclass
17
+ FieldDescriptorProto = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FieldDescriptorProto").msgclass
18
+ FieldDescriptorProto::Type = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FieldDescriptorProto.Type").enummodule
19
+ FieldDescriptorProto::Label = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FieldDescriptorProto.Label").enummodule
20
+ OneofDescriptorProto = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.OneofDescriptorProto").msgclass
21
+ EnumDescriptorProto = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.EnumDescriptorProto").msgclass
22
+ EnumDescriptorProto::EnumReservedRange = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.EnumDescriptorProto.EnumReservedRange").msgclass
23
+ EnumValueDescriptorProto = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.EnumValueDescriptorProto").msgclass
24
+ ServiceDescriptorProto = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.ServiceDescriptorProto").msgclass
25
+ MethodDescriptorProto = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.MethodDescriptorProto").msgclass
26
+ FileOptions = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FileOptions").msgclass
27
+ FileOptions::OptimizeMode = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FileOptions.OptimizeMode").enummodule
28
+ MessageOptions = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.MessageOptions").msgclass
29
+ FieldOptions = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FieldOptions").msgclass
30
+ FieldOptions::CType = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FieldOptions.CType").enummodule
31
+ FieldOptions::JSType = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FieldOptions.JSType").enummodule
32
+ OneofOptions = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.OneofOptions").msgclass
33
+ EnumOptions = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.EnumOptions").msgclass
34
+ EnumValueOptions = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.EnumValueOptions").msgclass
35
+ ServiceOptions = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.ServiceOptions").msgclass
36
+ MethodOptions = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.MethodOptions").msgclass
37
+ MethodOptions::IdempotencyLevel = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.MethodOptions.IdempotencyLevel").enummodule
38
+ UninterpretedOption = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.UninterpretedOption").msgclass
39
+ UninterpretedOption::NamePart = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.UninterpretedOption.NamePart").msgclass
40
+ SourceCodeInfo = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.SourceCodeInfo").msgclass
41
+ SourceCodeInfo::Location = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.SourceCodeInfo.Location").msgclass
42
+ GeneratedCodeInfo = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.GeneratedCodeInfo").msgclass
43
+ GeneratedCodeInfo::Annotation = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.GeneratedCodeInfo.Annotation").msgclass
44
+ end
45
+ end
46
+
47
+ __END__
48
+
49
+ google/protobuf/descriptor.protogoogle.protobuf"G
50
+ FileDescriptorSet2
51
+ file ( 2$.google.protobuf.FileDescriptorProto"�
52
+ FileDescriptorProto
53
+ name ( 
54
+ package ( 
55
+
56
+ dependency ( 
57
+ public_dependency
58
+ (
59
+ weak_dependency (6
60
+ message_type ( 2 .google.protobuf.DescriptorProto7
61
+ enum_type ( 2$.google.protobuf.EnumDescriptorProto8
62
+ service ( 2'.google.protobuf.ServiceDescriptorProto8
63
+ extension ( 2%.google.protobuf.FieldDescriptorProto-
64
+ options ( 2.google.protobuf.FileOptions9
65
+ source_code_info ( 2.google.protobuf.SourceCodeInfo
66
+ syntax ( "�
67
+ DescriptorProto
68
+ name ( 4
69
+ field ( 2%.google.protobuf.FieldDescriptorProto8
70
+ extension ( 2%.google.protobuf.FieldDescriptorProto5
71
+ nested_type ( 2 .google.protobuf.DescriptorProto7
72
+ enum_type ( 2$.google.protobuf.EnumDescriptorProtoH
73
+ extension_range ( 2/.google.protobuf.DescriptorProto.ExtensionRange9
74
+
75
+ oneof_decl ( 2%.google.protobuf.OneofDescriptorProto0
76
+ options ( 2.google.protobuf.MessageOptionsF
77
+ reserved_range ( 2..google.protobuf.DescriptorProto.ReservedRange
78
+
79
+ ( e
80
+ ExtensionRange
81
+ start (
82
+ end (7
83
+ options ( 2&.google.protobuf.ExtensionRangeOptions+
84
+
85
+ start (
86
+ end ("g
87
+ ExtensionRangeOptionsC
88
+ uninterpreted_option� ( 2$.google.protobuf.UninterpretedOption* �����"�
89
+ FieldDescriptorProto
90
+ name ( 
91
+ number (:
92
+ label (2+.google.protobuf.FieldDescriptorProto.Label8
93
+ type (2*.google.protobuf.FieldDescriptorProto.Type
94
+ type_name ( 
95
+ extendee ( 
96
+
97
+ oneof_index (
98
+ json_name
99
+ ( .
100
+ options ( 2.google.protobuf.FieldOptions
101
+ proto3_optional ("�
102
+ Type
103
+ TYPE_DOUBLE
104
+
105
+ TYPE_FLOAT
106
+
107
+ TYPE_INT64
108
+ TYPE_UINT64
109
+
110
+ TYPE_INT32
111
+ TYPE_FIXED64
112
+ TYPE_FIXED32
113
+ TYPE_BOOL
114
+ TYPE_STRING 
115
+
116
+ TYPE_GROUP
117
+ 
118
+ TYPE_MESSAGE 
119
+
120
+ TYPE_BYTES 
121
+ TYPE_UINT32
122
+ TYPE_ENUM
123
+
124
+
125
+ TYPE_SINT32
126
+ TYPE_SINT64"C
127
+ Label
128
+ LABEL_OPTIONAL
129
+ LABEL_REQUIRED
130
+ LABEL_REPEATED"T
131
+ OneofDescriptorProto
132
+ name ( .
133
+ options ( 2.google.protobuf.OneofOptions"�
134
+ EnumDescriptorProto
135
+ name ( 8
136
+ value ( 2).google.protobuf.EnumValueDescriptorProto-
137
+ options ( 2.google.protobuf.EnumOptionsN
138
+ reserved_range ( 26.google.protobuf.EnumDescriptorProto.EnumReservedRange
139
+
140
+ EnumReservedRange
141
+ start (
142
+ end ("l
143
+ EnumValueDescriptorProto
144
+ name ( 
145
+ number (2
146
+ options ( 2!.google.protobuf.EnumValueOptions"�
147
+ ServiceDescriptorProto
148
+ name ( 6
149
+ method ( 2&.google.protobuf.MethodDescriptorProto0
150
+ options ( 2.google.protobuf.ServiceOptions"�
151
+ MethodDescriptorProto
152
+ name ( 
153
+
154
+ input_type ( 
155
+ output_type ( /
156
+ options ( 2.google.protobuf.MethodOptions
157
+ client_streaming (:false
158
+ server_streaming (:false"�
159
+ FileOptions
160
+ java_package ( 
161
+ java_outer_classname ( "
162
+ java_multiple_files
163
+ (:false)
164
+ java_generate_equals_and_hash (B%
165
+ java_string_check_utf8 (:falseF
166
+ optimize_for (2).google.protobuf.FileOptions.OptimizeMode:SPEED
167
+
168
+ go_package ( "
169
+ cc_generic_services (:false$
170
+ java_generic_services (:false"
171
+ py_generic_services (:false#
172
+ php_generic_services* (:false
173
+
174
+ deprecated (:false
175
+ cc_enable_arenas (:true
176
+ objc_class_prefix$ ( 
177
+ csharp_namespace% ( 
178
+ swift_prefix' ( 
179
+ php_class_prefix( ( 
180
+
181
+ php_metadata_namespace, ( 
182
+ ruby_package- ( C
183
+ uninterpreted_option� ( 2$.google.protobuf.UninterpretedOption":
184
+ OptimizeMode
185
+ SPEED
186
+ CODE_SIZE
187
+ LITE_RUNTIME* �����J&'"�
188
+ MessageOptions&
189
+ message_set_wire_format (:false.
190
+ no_standard_descriptor_accessor (:false
191
+
192
+ deprecated (:false
193
+ map_entry (C
194
+ uninterpreted_option� ( 2$.google.protobuf.UninterpretedOption* �����JJJJ J 
195
+ "�
196
+ FieldOptions:
197
+ ctype (2#.google.protobuf.FieldOptions.CType:STRING
198
+ packed (?
199
+ jstype (2$.google.protobuf.FieldOptions.JSType: JS_NORMAL
200
+ lazy (:false
201
+ unverified_lazy (:false
202
+
203
+ deprecated (:false
204
+ weak
205
+ (:falseC
206
+ uninterpreted_option� ( 2$.google.protobuf.UninterpretedOption"/
207
+ CType
208
+
209
+ STRING
210
+ CORD
211
+ STRING_PIECE"5
212
+ JSType
213
+ JS_NORMAL
214
+ JS_STRING
215
+ JS_NUMBER* �����J"^
216
+ OneofOptionsC
217
+ uninterpreted_option� ( 2$.google.protobuf.UninterpretedOption* �����"�
218
+ EnumOptions
219
+ allow_alias (
220
+
221
+ deprecated (:falseC
222
+ uninterpreted_option� ( 2$.google.protobuf.UninterpretedOption* �����J"}
223
+ EnumValueOptions
224
+
225
+ deprecated (:falseC
226
+ uninterpreted_option� ( 2$.google.protobuf.UninterpretedOption* �����"{
227
+ ServiceOptions
228
+
229
+ deprecated! (:falseC
230
+ uninterpreted_option� ( 2$.google.protobuf.UninterpretedOption* �����"�
231
+
232
+
233
+ deprecated! (:false_
234
+ idempotency_level" (2/.google.protobuf.MethodOptions.IdempotencyLevel:IDEMPOTENCY_UNKNOWNC
235
+ uninterpreted_option� ( 2$.google.protobuf.UninterpretedOption"P
236
+ IdempotencyLevel
237
+ IDEMPOTENCY_UNKNOWN
238
+ NO_SIDE_EFFECTS
239
+
240
+ IDEMPOTENT* �����"�
241
+ UninterpretedOption;
242
+ name ( 2-.google.protobuf.UninterpretedOption.NamePart
243
+ identifier_value ( 
244
+ positive_int_value (
245
+ negative_int_value (
246
+ double_value (
247
+ string_value ( 
248
+ aggregate_value ( 3
249
+ NamePart
250
+ name_part ( 
251
+ is_extension ("�
252
+ SourceCodeInfo:
253
+ location ( 2(.google.protobuf.SourceCodeInfo.Location�
254
+ Location
255
+ path (B
256
+ span (B
257
+ leading_comments ( 
258
+ trailing_comments ( !
259
+ leading_detached_comments ( "�
260
+ GeneratedCodeInfoA
261
+
262
+ annotation ( 2-.google.protobuf.GeneratedCodeInfo.AnnotationO
263
+
264
+ Annotation
265
+ path (B
266
+ source_file ( 
267
+ begin (
268
+ end (B~
269
+ com.google.protobufBDescriptorProtosHZ-google.golang.org/protobuf/types/descriptorpb��GPB�Google.Protobuf.Reflection
@@ -14,6 +14,6 @@ end
14
14
 
15
15
  module Google
16
16
  module Protobuf
17
- Duration = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Duration").msgclass
17
+ Duration = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Duration").msgclass
18
18
  end
19
19
  end
@@ -12,6 +12,6 @@ end
12
12
 
13
13
  module Google
14
14
  module Protobuf
15
- Empty = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Empty").msgclass
15
+ Empty = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Empty").msgclass
16
16
  end
17
17
  end
@@ -13,6 +13,6 @@ end
13
13
 
14
14
  module Google
15
15
  module Protobuf
16
- FieldMask = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FieldMask").msgclass
16
+ FieldMask = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FieldMask").msgclass
17
17
  end
18
18
  end
@@ -44,8 +44,8 @@ module Google
44
44
  self.class.encode_json(self, options)
45
45
  end
46
46
 
47
- def to_proto
48
- self.class.encode(self)
47
+ def to_proto(options = {})
48
+ self.class.encode(self, options)
49
49
  end
50
50
 
51
51
  end
@@ -79,12 +79,25 @@ module Google
79
79
 
80
80
 
81
81
  def first(n=nil)
82
- n ? self[0...n] : self[0]
82
+ if n.nil?
83
+ return self[0]
84
+ elsif n < 0
85
+ raise ArgumentError, "negative array size"
86
+ else
87
+ return self[0...n]
88
+ end
83
89
  end
84
90
 
85
91
 
86
92
  def last(n=nil)
87
- n ? self[(self.size-n-1)..-1] : self[-1]
93
+ if n.nil?
94
+ return self[-1]
95
+ elsif n < 0
96
+ raise ArgumentError, "negative array size"
97
+ else
98
+ start = [self.size-n, 0].max
99
+ return self[start...self.size]
100
+ end
88
101
  end
89
102
 
90
103
 
@@ -13,6 +13,6 @@ end
13
13
 
14
14
  module Google
15
15
  module Protobuf
16
- SourceContext = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.SourceContext").msgclass
16
+ SourceContext = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.SourceContext").msgclass
17
17
  end
18
18
  end
@@ -29,9 +29,9 @@ end
29
29
 
30
30
  module Google
31
31
  module Protobuf
32
- Struct = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Struct").msgclass
33
- Value = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Value").msgclass
34
- ListValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.ListValue").msgclass
35
- NullValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.NullValue").enummodule
32
+ Struct = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Struct").msgclass
33
+ Value = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Value").msgclass
34
+ ListValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.ListValue").msgclass
35
+ NullValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.NullValue").enummodule
36
36
  end
37
37
  end
@@ -14,6 +14,6 @@ end
14
14
 
15
15
  module Google
16
16
  module Protobuf
17
- Timestamp = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Timestamp").msgclass
17
+ Timestamp = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Timestamp").msgclass
18
18
  end
19
19
  end
@@ -5,6 +5,7 @@ require 'google/protobuf'
5
5
 
6
6
  require 'google/protobuf/any_pb'
7
7
  require 'google/protobuf/source_context_pb'
8
+
8
9
  Google::Protobuf::DescriptorPool.generated_pool.build do
9
10
  add_file("google/protobuf/type.proto", :syntax => :proto3) do
10
11
  add_message "google.protobuf.Type" do
@@ -79,13 +80,13 @@ end
79
80
 
80
81
  module Google
81
82
  module Protobuf
82
- Type = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Type").msgclass
83
- Field = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Field").msgclass
84
- Field::Kind = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Field.Kind").enummodule
85
- Field::Cardinality = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Field.Cardinality").enummodule
86
- Enum = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Enum").msgclass
87
- EnumValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.EnumValue").msgclass
88
- Option = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Option").msgclass
89
- Syntax = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Syntax").enummodule
83
+ Type = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Type").msgclass
84
+ Field = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Field").msgclass
85
+ Field::Kind = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Field.Kind").enummodule
86
+ Field::Cardinality = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Field.Cardinality").enummodule
87
+ Enum = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Enum").msgclass
88
+ EnumValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.EnumValue").msgclass
89
+ Option = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Option").msgclass
90
+ Syntax = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Syntax").enummodule
90
91
  end
91
92
  end
@@ -72,13 +72,24 @@ module Google
72
72
  end
73
73
 
74
74
  Timestamp.class_eval do
75
- def to_time
76
- 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
83
+ end
84
+
85
+ def self.from_time(time)
86
+ new.from_time(time)
77
87
  end
78
88
 
79
89
  def from_time(time)
80
90
  self.seconds = time.to_i
81
91
  self.nanos = time.nsec
92
+ self
82
93
  end
83
94
 
84
95
  def to_i
@@ -126,10 +137,14 @@ module Google
126
137
  end
127
138
  end
128
139
 
140
+ def self.from_ruby(value)
141
+ self.new.from_ruby(value)
142
+ end
143
+
129
144
  def from_ruby(value)
130
145
  case value
131
146
  when NilClass
132
- self.null_value = 0
147
+ self.null_value = :NULL_VALUE
133
148
  when Numeric
134
149
  self.number_value = value
135
150
  when String
@@ -149,6 +164,8 @@ module Google
149
164
  else
150
165
  raise UnexpectedStructType
151
166
  end
167
+
168
+ self
152
169
  end
153
170
  end
154
171
 
@@ -219,6 +236,5 @@ module Google
219
236
  ret
220
237
  end
221
238
  end
222
-
223
239
  end
224
240
  end
@@ -37,14 +37,14 @@ end
37
37
 
38
38
  module Google
39
39
  module Protobuf
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
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
49
49
  end
50
50
  end
@@ -50,23 +50,25 @@ else
50
50
  rescue LoadError
51
51
  require 'google/protobuf_c'
52
52
  end
53
+
53
54
  end
54
55
 
56
+ require 'google/protobuf/descriptor_dsl'
55
57
  require 'google/protobuf/repeated_field'
56
58
 
57
59
  module Google
58
60
  module Protobuf
59
61
 
60
- def self.encode(msg)
61
- msg.to_proto
62
+ def self.encode(msg, options = {})
63
+ msg.to_proto(options)
62
64
  end
63
65
 
64
66
  def self.encode_json(msg, options = {})
65
67
  msg.to_json(options)
66
68
  end
67
69
 
68
- def self.decode(klass, proto)
69
- klass.decode(proto)
70
+ def self.decode(klass, proto, options = {})
71
+ klass.decode(proto, options)
70
72
  end
71
73
 
72
74
  def self.decode_json(klass, json, options = {})