google-protobuf 3.19.1 → 3.25.1

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.

Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/ext/google/protobuf_c/Rakefile +3 -0
  3. data/ext/google/protobuf_c/convert.c +121 -155
  4. data/ext/google/protobuf_c/convert.h +15 -37
  5. data/ext/google/protobuf_c/defs.c +362 -243
  6. data/ext/google/protobuf_c/defs.h +22 -47
  7. data/ext/google/protobuf_c/extconf.rb +13 -5
  8. data/ext/google/protobuf_c/glue.c +56 -0
  9. data/ext/google/protobuf_c/map.c +129 -137
  10. data/ext/google/protobuf_c/map.h +13 -36
  11. data/ext/google/protobuf_c/message.c +486 -389
  12. data/ext/google/protobuf_c/message.h +32 -47
  13. data/ext/google/protobuf_c/protobuf.c +101 -228
  14. data/ext/google/protobuf_c/protobuf.h +37 -42
  15. data/ext/google/protobuf_c/repeated_field.c +110 -113
  16. data/ext/google/protobuf_c/repeated_field.h +12 -34
  17. data/ext/google/protobuf_c/ruby-upb.c +12236 -6993
  18. data/ext/google/protobuf_c/ruby-upb.h +12127 -3787
  19. data/ext/google/protobuf_c/shared_convert.c +64 -0
  20. data/ext/google/protobuf_c/shared_convert.h +26 -0
  21. data/ext/google/protobuf_c/shared_message.c +65 -0
  22. data/ext/google/protobuf_c/shared_message.h +25 -0
  23. data/ext/google/protobuf_c/third_party/utf8_range/LICENSE +22 -0
  24. data/ext/google/protobuf_c/third_party/utf8_range/naive.c +92 -0
  25. data/ext/google/protobuf_c/third_party/utf8_range/range2-neon.c +157 -0
  26. data/ext/google/protobuf_c/third_party/utf8_range/range2-sse.c +170 -0
  27. data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.h +21 -0
  28. data/ext/google/protobuf_c/wrap_memcpy.c +7 -29
  29. data/lib/google/protobuf/any_pb.rb +24 -5
  30. data/lib/google/protobuf/api_pb.rb +26 -23
  31. data/lib/google/protobuf/descriptor_dsl.rb +8 -1
  32. data/lib/google/protobuf/descriptor_pb.rb +43 -225
  33. data/lib/google/protobuf/duration_pb.rb +24 -5
  34. data/lib/google/protobuf/empty_pb.rb +24 -3
  35. data/lib/google/protobuf/ffi/descriptor.rb +165 -0
  36. data/lib/google/protobuf/ffi/descriptor_pool.rb +75 -0
  37. data/lib/google/protobuf/ffi/enum_descriptor.rb +171 -0
  38. data/lib/google/protobuf/ffi/ffi.rb +213 -0
  39. data/lib/google/protobuf/ffi/field_descriptor.rb +319 -0
  40. data/lib/google/protobuf/ffi/file_descriptor.rb +59 -0
  41. data/lib/google/protobuf/ffi/internal/arena.rb +66 -0
  42. data/lib/google/protobuf/ffi/internal/convert.rb +305 -0
  43. data/lib/google/protobuf/ffi/internal/pointer_helper.rb +35 -0
  44. data/lib/google/protobuf/ffi/internal/type_safety.rb +25 -0
  45. data/lib/google/protobuf/ffi/map.rb +407 -0
  46. data/lib/google/protobuf/ffi/message.rb +662 -0
  47. data/lib/google/protobuf/ffi/object_cache.rb +30 -0
  48. data/lib/google/protobuf/ffi/oneof_descriptor.rb +95 -0
  49. data/lib/google/protobuf/ffi/repeated_field.rb +383 -0
  50. data/lib/google/protobuf/field_mask_pb.rb +24 -4
  51. data/lib/google/protobuf/message_exts.rb +10 -28
  52. data/lib/google/protobuf/object_cache.rb +97 -0
  53. data/lib/google/protobuf/plugin_pb.rb +47 -0
  54. data/lib/google/protobuf/repeated_field.rb +18 -28
  55. data/lib/google/protobuf/source_context_pb.rb +24 -4
  56. data/lib/google/protobuf/struct_pb.rb +24 -20
  57. data/lib/google/protobuf/timestamp_pb.rb +24 -5
  58. data/lib/google/protobuf/type_pb.rb +26 -68
  59. data/lib/google/protobuf/well_known_types.rb +16 -40
  60. data/lib/google/protobuf/wrappers_pb.rb +24 -28
  61. data/lib/google/protobuf.rb +32 -50
  62. data/lib/google/protobuf_ffi.rb +50 -0
  63. data/lib/google/protobuf_native.rb +20 -0
  64. data/lib/google/tasks/ffi.rake +102 -0
  65. metadata +82 -20
  66. data/tests/basic.rb +0 -640
  67. data/tests/generated_code_test.rb +0 -23
  68. data/tests/stress.rb +0 -38
@@ -0,0 +1,165 @@
1
+ # Protocol Buffers - Google's data interchange format
2
+ # Copyright 2022 Google Inc. All rights reserved.
3
+ #
4
+ # Use of this source code is governed by a BSD-style
5
+ # license that can be found in the LICENSE file or at
6
+ # https://developers.google.com/open-source/licenses/bsd
7
+
8
+ module Google
9
+ module Protobuf
10
+ ##
11
+ # Message Descriptor - Descriptor for short.
12
+ class Descriptor
13
+ attr :descriptor_pool, :msg_class
14
+ include Enumerable
15
+
16
+ # FFI Interface methods and setup
17
+ extend ::FFI::DataConverter
18
+ native_type ::FFI::Type::POINTER
19
+
20
+ class << self
21
+ prepend Google::Protobuf::Internal::TypeSafety
22
+ include Google::Protobuf::Internal::PointerHelper
23
+
24
+ # @param value [Descriptor] Descriptor to convert to an FFI native type
25
+ # @param _ [Object] Unused
26
+ def to_native(value, _ = nil)
27
+ msg_def_ptr = value.nil? ? nil : value.instance_variable_get(:@msg_def)
28
+ return ::FFI::Pointer::NULL if msg_def_ptr.nil?
29
+ raise "Underlying msg_def was null!" if msg_def_ptr.null?
30
+ msg_def_ptr
31
+ end
32
+
33
+ ##
34
+ # @param msg_def [::FFI::Pointer] MsgDef pointer to be wrapped
35
+ # @param _ [Object] Unused
36
+ def from_native(msg_def, _ = nil)
37
+ return nil if msg_def.nil? or msg_def.null?
38
+ file_def = Google::Protobuf::FFI.get_message_file_def msg_def
39
+ descriptor_from_file_def(file_def, msg_def)
40
+ end
41
+ end
42
+
43
+ def to_native
44
+ self.class.to_native(self)
45
+ end
46
+
47
+ ##
48
+ # Great write up of this strategy:
49
+ # See https://blog.appsignal.com/2018/08/07/ruby-magic-changing-the-way-ruby-creates-objects.html
50
+ def self.new(*arguments, &block)
51
+ raise "Descriptor objects may not be created from Ruby."
52
+ end
53
+
54
+ def to_s
55
+ inspect
56
+ end
57
+
58
+ def inspect
59
+ "Descriptor - (not the message class) #{name}"
60
+ end
61
+
62
+ def file_descriptor
63
+ @descriptor_pool.send(:get_file_descriptor, Google::Protobuf::FFI.get_message_file_def(@msg_def))
64
+ end
65
+
66
+ def name
67
+ @name ||= Google::Protobuf::FFI.get_message_fullname(self)
68
+ end
69
+
70
+ def each_oneof &block
71
+ n = Google::Protobuf::FFI.oneof_count(self)
72
+ 0.upto(n-1) do |i|
73
+ yield(Google::Protobuf::FFI.get_oneof_by_index(self, i))
74
+ end
75
+ nil
76
+ end
77
+
78
+ def each &block
79
+ n = Google::Protobuf::FFI.field_count(self)
80
+ 0.upto(n-1) do |i|
81
+ yield(Google::Protobuf::FFI.get_field_by_index(self, i))
82
+ end
83
+ nil
84
+ end
85
+
86
+ def lookup(name)
87
+ Google::Protobuf::FFI.get_field_by_name(self, name, name.size)
88
+ end
89
+
90
+ def lookup_oneof(name)
91
+ Google::Protobuf::FFI.get_oneof_by_name(self, name, name.size)
92
+ end
93
+
94
+ def msgclass
95
+ @msg_class ||= build_message_class
96
+ end
97
+
98
+ def options
99
+ @options ||= begin
100
+ size_ptr = ::FFI::MemoryPointer.new(:size_t, 1)
101
+ temporary_arena = Google::Protobuf::FFI.create_arena
102
+ buffer = Google::Protobuf::FFI.message_options(self, size_ptr, temporary_arena)
103
+ Google::Protobuf::MessageOptions.decode(buffer.read_string_length(size_ptr.read(:size_t)).force_encoding("ASCII-8BIT").freeze).send(:internal_deep_freeze)
104
+ end
105
+ end
106
+
107
+ private
108
+
109
+ extend Google::Protobuf::Internal::Convert
110
+
111
+ def initialize(msg_def, descriptor_pool)
112
+ @msg_def = msg_def
113
+ @msg_class = nil
114
+ @descriptor_pool = descriptor_pool
115
+ end
116
+
117
+ def self.private_constructor(msg_def, descriptor_pool)
118
+ instance = allocate
119
+ instance.send(:initialize, msg_def, descriptor_pool)
120
+ instance
121
+ end
122
+
123
+ def wrapper?
124
+ if defined? @wrapper
125
+ @wrapper
126
+ else
127
+ @wrapper = case Google::Protobuf::FFI.get_well_known_type self
128
+ when :DoubleValue, :FloatValue, :Int64Value, :UInt64Value, :Int32Value, :UInt32Value, :StringValue, :BytesValue, :BoolValue
129
+ true
130
+ else
131
+ false
132
+ end
133
+ end
134
+ end
135
+
136
+ def self.get_message(msg, descriptor, arena)
137
+ return nil if msg.nil? or msg.null?
138
+ message = OBJECT_CACHE.get(msg.address)
139
+ if message.nil?
140
+ message = descriptor.msgclass.send(:private_constructor, arena, msg: msg)
141
+ message.send :internal_deep_freeze if frozen?
142
+ end
143
+ message
144
+ end
145
+
146
+ def pool
147
+ @descriptor_pool
148
+ end
149
+ end
150
+
151
+ class FFI
152
+ # MessageDef
153
+ attach_function :new_message_from_def, :upb_Message_New, [Descriptor, Internal::Arena], :Message
154
+ attach_function :field_count, :upb_MessageDef_FieldCount, [Descriptor], :int
155
+ attach_function :get_message_file_def, :upb_MessageDef_File, [:pointer], :FileDef
156
+ attach_function :get_message_fullname, :upb_MessageDef_FullName, [Descriptor], :string
157
+ attach_function :get_mini_table, :upb_MessageDef_MiniTable, [Descriptor], MiniTable.ptr
158
+ attach_function :oneof_count, :upb_MessageDef_OneofCount, [Descriptor], :int
159
+ attach_function :message_options, :Descriptor_serialized_options, [Descriptor, :pointer, Internal::Arena], :pointer
160
+ attach_function :get_well_known_type, :upb_MessageDef_WellKnownType, [Descriptor], WellKnown
161
+ attach_function :message_def_syntax, :upb_MessageDef_Syntax, [Descriptor], Syntax
162
+ attach_function :find_msg_def_by_name, :upb_MessageDef_FindByNameWithSize, [Descriptor, :string, :size_t, :FieldDefPointer, :OneofDefPointer], :bool
163
+ end
164
+ end
165
+ end
@@ -0,0 +1,75 @@
1
+ # Protocol Buffers - Google's data interchange format
2
+ # Copyright 2022 Google Inc. All rights reserved.
3
+ #
4
+ # Use of this source code is governed by a BSD-style
5
+ # license that can be found in the LICENSE file or at
6
+ # https://developers.google.com/open-source/licenses/bsd
7
+
8
+ module Google
9
+ module Protobuf
10
+ class FFI
11
+ # DefPool
12
+ attach_function :add_serialized_file, :upb_DefPool_AddFile, [:DefPool, :FileDescriptorProto, Status.by_ref], :FileDef
13
+ attach_function :free_descriptor_pool, :upb_DefPool_Free, [:DefPool], :void
14
+ attach_function :create_descriptor_pool,:upb_DefPool_New, [], :DefPool
15
+ attach_function :get_extension_registry,:upb_DefPool_ExtensionRegistry, [:DefPool], :ExtensionRegistry
16
+ attach_function :lookup_enum, :upb_DefPool_FindEnumByName, [:DefPool, :string], EnumDescriptor
17
+ attach_function :lookup_extension, :upb_DefPool_FindExtensionByName,[:DefPool, :string], FieldDescriptor
18
+ attach_function :lookup_msg, :upb_DefPool_FindMessageByName, [:DefPool, :string], Descriptor
19
+
20
+ # FileDescriptorProto
21
+ attach_function :parse, :FileDescriptorProto_parse, [:binary_string, :size_t, Internal::Arena], :FileDescriptorProto
22
+ end
23
+ class DescriptorPool
24
+ attr :descriptor_pool
25
+ attr_accessor :descriptor_class_by_def
26
+
27
+ def initialize
28
+ @descriptor_pool = ::FFI::AutoPointer.new(Google::Protobuf::FFI.create_descriptor_pool, Google::Protobuf::FFI.method(:free_descriptor_pool))
29
+ @descriptor_class_by_def = {}
30
+
31
+ # Should always be the last expression of the initializer to avoid
32
+ # leaking references to this object before construction is complete.
33
+ Google::Protobuf::OBJECT_CACHE.try_add @descriptor_pool.address, self
34
+ end
35
+
36
+ def add_serialized_file(file_contents)
37
+ # Allocate memory sized to file_contents
38
+ memBuf = ::FFI::MemoryPointer.new(:char, file_contents.bytesize)
39
+ # Insert the data
40
+ memBuf.put_bytes(0, file_contents)
41
+ temporary_arena = Google::Protobuf::FFI.create_arena
42
+ file_descriptor_proto = Google::Protobuf::FFI.parse memBuf, file_contents.bytesize, temporary_arena
43
+ raise ArgumentError.new("Unable to parse FileDescriptorProto") if file_descriptor_proto.null?
44
+
45
+ status = Google::Protobuf::FFI::Status.new
46
+ file_descriptor = Google::Protobuf::FFI.add_serialized_file @descriptor_pool, file_descriptor_proto, status
47
+ if file_descriptor.null?
48
+ raise TypeError.new("Unable to build file to DescriptorPool: #{Google::Protobuf::FFI.error_message(status)}")
49
+ else
50
+ @descriptor_class_by_def[file_descriptor.address] = FileDescriptor.new file_descriptor, self
51
+ end
52
+ end
53
+
54
+ def lookup name
55
+ Google::Protobuf::FFI.lookup_msg(@descriptor_pool, name) ||
56
+ Google::Protobuf::FFI.lookup_enum(@descriptor_pool, name) ||
57
+ Google::Protobuf::FFI.lookup_extension(@descriptor_pool, name)
58
+ end
59
+
60
+ def self.generated_pool
61
+ @@generated_pool ||= DescriptorPool.new
62
+ end
63
+
64
+ private
65
+
66
+ # Implementation details below are subject to breaking changes without
67
+ # warning and are intended for use only within the gem.
68
+
69
+ def get_file_descriptor file_def
70
+ return nil if file_def.null?
71
+ @descriptor_class_by_def[file_def.address] ||= FileDescriptor.new(file_def, self)
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,171 @@
1
+ # Protocol Buffers - Google's data interchange format
2
+ # Copyright 2022 Google Inc. All rights reserved.
3
+ #
4
+ # Use of this source code is governed by a BSD-style
5
+ # license that can be found in the LICENSE file or at
6
+ # https://developers.google.com/open-source/licenses/bsd
7
+
8
+ module Google
9
+ module Protobuf
10
+ class EnumDescriptor
11
+ attr :descriptor_pool, :enum_def
12
+ include Enumerable
13
+
14
+ # FFI Interface methods and setup
15
+ extend ::FFI::DataConverter
16
+ native_type ::FFI::Type::POINTER
17
+
18
+ class << self
19
+ prepend Google::Protobuf::Internal::TypeSafety
20
+ include Google::Protobuf::Internal::PointerHelper
21
+
22
+ # @param value [EnumDescriptor] EnumDescriptor to convert to an FFI native type
23
+ # @param _ [Object] Unused
24
+ def to_native(value, _)
25
+ value.instance_variable_get(:@enum_def) || ::FFI::Pointer::NULL
26
+ end
27
+
28
+ ##
29
+ # @param enum_def [::FFI::Pointer] EnumDef pointer to be wrapped
30
+ # @param _ [Object] Unused
31
+ def from_native(enum_def, _)
32
+ return nil if enum_def.nil? or enum_def.null?
33
+ file_def = Google::Protobuf::FFI.get_message_file_def enum_def
34
+ descriptor_from_file_def(file_def, enum_def)
35
+ end
36
+ end
37
+
38
+ def self.new(*arguments, &block)
39
+ raise "Descriptor objects may not be created from Ruby."
40
+ end
41
+
42
+ def file_descriptor
43
+ @descriptor_pool.send(:get_file_descriptor, Google::Protobuf::FFI.get_enum_file_descriptor(self))
44
+ end
45
+
46
+ def name
47
+ Google::Protobuf::FFI.get_enum_fullname(self)
48
+ end
49
+
50
+ def to_s
51
+ inspect
52
+ end
53
+
54
+ def inspect
55
+ "#{self.class.name}: #{name}"
56
+ end
57
+
58
+ def lookup_name(name)
59
+ self.class.send(:lookup_name, self, name)
60
+ end
61
+
62
+ def lookup_value(number)
63
+ self.class.send(:lookup_value, self, number)
64
+ end
65
+
66
+ def each &block
67
+ n = Google::Protobuf::FFI.enum_value_count(self)
68
+ 0.upto(n - 1) do |i|
69
+ enum_value = Google::Protobuf::FFI.enum_value_by_index(self, i)
70
+ yield(Google::Protobuf::FFI.enum_name(enum_value).to_sym, Google::Protobuf::FFI.enum_number(enum_value))
71
+ end
72
+ nil
73
+ end
74
+
75
+ def enummodule
76
+ if @module.nil?
77
+ @module = build_enum_module
78
+ end
79
+ @module
80
+ end
81
+
82
+ def options
83
+ @options ||= begin
84
+ size_ptr = ::FFI::MemoryPointer.new(:size_t, 1)
85
+ temporary_arena = Google::Protobuf::FFI.create_arena
86
+ buffer = Google::Protobuf::FFI.enum_options(self, size_ptr, temporary_arena)
87
+ Google::Protobuf::EnumOptions.decode(buffer.read_string_length(size_ptr.read(:size_t)).force_encoding("ASCII-8BIT").freeze).send(:internal_deep_freeze)
88
+ end
89
+ end
90
+
91
+ private
92
+
93
+ def initialize(enum_def, descriptor_pool)
94
+ @descriptor_pool = descriptor_pool
95
+ @enum_def = enum_def
96
+ @module = nil
97
+ end
98
+
99
+ def self.private_constructor(enum_def, descriptor_pool)
100
+ instance = allocate
101
+ instance.send(:initialize, enum_def, descriptor_pool)
102
+ instance
103
+ end
104
+
105
+ def self.lookup_value(enum_def, number)
106
+ enum_value = Google::Protobuf::FFI.enum_value_by_number(enum_def, number)
107
+ if enum_value.null?
108
+ nil
109
+ else
110
+ Google::Protobuf::FFI.enum_name(enum_value).to_sym
111
+ end
112
+ end
113
+
114
+ def self.lookup_name(enum_def, name)
115
+ enum_value = Google::Protobuf::FFI.enum_value_by_name(enum_def, name.to_s, name.size)
116
+ if enum_value.null?
117
+ nil
118
+ else
119
+ Google::Protobuf::FFI.enum_number(enum_value)
120
+ end
121
+ end
122
+
123
+ def build_enum_module
124
+ descriptor = self
125
+ dynamic_module = Module.new do
126
+ @descriptor = descriptor
127
+
128
+ class << self
129
+ attr_accessor :descriptor
130
+ end
131
+
132
+ def self.lookup(number)
133
+ descriptor.lookup_value number
134
+ end
135
+
136
+ def self.resolve(name)
137
+ descriptor.lookup_name name
138
+ end
139
+ end
140
+
141
+ self.each do |name, value|
142
+ if name[0] < 'A' || name[0] > 'Z'
143
+ if name[0] >= 'a' and name[0] <= 'z'
144
+ name = name[0].upcase + name[1..-1] # auto capitalize
145
+ else
146
+ warn(
147
+ "Enum value '#{name}' does not start with an uppercase letter " +
148
+ "as is required for Ruby constants.")
149
+ next
150
+ end
151
+ end
152
+ dynamic_module.const_set(name.to_sym, value)
153
+ end
154
+ dynamic_module
155
+ end
156
+ end
157
+
158
+ class FFI
159
+ # EnumDescriptor
160
+ attach_function :get_enum_file_descriptor, :upb_EnumDef_File, [EnumDescriptor], :FileDef
161
+ attach_function :enum_value_by_name, :upb_EnumDef_FindValueByNameWithSize,[EnumDescriptor, :string, :size_t], :EnumValueDef
162
+ attach_function :enum_value_by_number, :upb_EnumDef_FindValueByNumber, [EnumDescriptor, :int], :EnumValueDef
163
+ attach_function :get_enum_fullname, :upb_EnumDef_FullName, [EnumDescriptor], :string
164
+ attach_function :enum_options, :EnumDescriptor_serialized_options, [EnumDescriptor, :pointer, Internal::Arena], :pointer
165
+ attach_function :enum_value_by_index, :upb_EnumDef_Value, [EnumDescriptor, :int], :EnumValueDef
166
+ attach_function :enum_value_count, :upb_EnumDef_ValueCount, [EnumDescriptor], :int
167
+ attach_function :enum_name, :upb_EnumValueDef_Name, [:EnumValueDef], :string
168
+ attach_function :enum_number, :upb_EnumValueDef_Number, [:EnumValueDef], :int
169
+ end
170
+ end
171
+ end
@@ -0,0 +1,213 @@
1
+ # Protocol Buffers - Google's data interchange format
2
+ # Copyright 2022 Google Inc. All rights reserved.
3
+ #
4
+ # Use of this source code is governed by a BSD-style
5
+ # license that can be found in the LICENSE file or at
6
+ # https://developers.google.com/open-source/licenses/bsd
7
+
8
+ module Google
9
+ module Protobuf
10
+ class FFI
11
+ extend ::FFI::Library
12
+ # Workaround for Bazel's use of symlinks + JRuby's __FILE__ and `caller`
13
+ # that resolves them.
14
+ if ENV['BAZEL'] == 'true'
15
+ ffi_lib ::FFI::Compiler::Loader.find 'protobuf_c_ffi', ENV['PWD']
16
+ else
17
+ ffi_lib ::FFI::Compiler::Loader.find 'protobuf_c_ffi'
18
+ end
19
+
20
+ ## Map
21
+ Upb_Map_Begin = -1
22
+
23
+ ## Encoding Status
24
+ Upb_Status_MaxMessage = 127
25
+ Upb_Encode_Deterministic = 1
26
+ Upb_Encode_SkipUnknown = 2
27
+
28
+ ## JSON Encoding options
29
+ # When set, emits 0/default values. TODO: proto3 only?
30
+ Upb_JsonEncode_EmitDefaults = 1
31
+ # When set, use normal (snake_case) field names instead of JSON (camelCase) names.
32
+ Upb_JsonEncode_UseProtoNames = 2
33
+ # When set, emits enums as their integer values instead of as their names.
34
+ Upb_JsonEncode_FormatEnumsAsIntegers = 4
35
+
36
+ ## JSON Decoding options
37
+ Upb_JsonDecode_IgnoreUnknown = 1
38
+
39
+ typedef :pointer, :Array
40
+ typedef :pointer, :DefPool
41
+ typedef :pointer, :EnumValueDef
42
+ typedef :pointer, :ExtensionRegistry
43
+ typedef :pointer, :FieldDefPointer
44
+ typedef :pointer, :FileDef
45
+ typedef :pointer, :FileDescriptorProto
46
+ typedef :pointer, :Map
47
+ typedef :pointer, :Message # Instances of a message
48
+ typedef :pointer, :OneofDefPointer
49
+ typedef :pointer, :binary_string
50
+ if ::FFI::Platform::ARCH == "aarch64"
51
+ typedef :u_int8_t, :uint8_t
52
+ typedef :u_int16_t, :uint16_t
53
+ typedef :u_int32_t, :uint32_t
54
+ typedef :u_int64_t, :uint64_t
55
+ end
56
+
57
+ FieldType = enum(
58
+ :double, 1,
59
+ :float,
60
+ :int64,
61
+ :uint64,
62
+ :int32,
63
+ :fixed64,
64
+ :fixed32,
65
+ :bool,
66
+ :string,
67
+ :group,
68
+ :message,
69
+ :bytes,
70
+ :uint32,
71
+ :enum,
72
+ :sfixed32,
73
+ :sfixed64,
74
+ :sint32,
75
+ :sint64
76
+ )
77
+
78
+ CType = enum(
79
+ :bool, 1,
80
+ :float,
81
+ :int32,
82
+ :uint32,
83
+ :enum,
84
+ :message,
85
+ :double,
86
+ :int64,
87
+ :uint64,
88
+ :string,
89
+ :bytes
90
+ )
91
+
92
+ Label = enum(
93
+ :optional, 1,
94
+ :required,
95
+ :repeated
96
+ )
97
+
98
+ Syntax = enum(
99
+ :Proto2, 2,
100
+ :Proto3
101
+ )
102
+
103
+ # All the different kind of well known type messages. For simplicity of check,
104
+ # number wrappers and string wrappers are grouped together. Make sure the
105
+ # order and merber of these groups are not changed.
106
+
107
+ WellKnown = enum(
108
+ :Unspecified,
109
+ :Any,
110
+ :FieldMask,
111
+ :Duration,
112
+ :Timestamp,
113
+ # number wrappers
114
+ :DoubleValue,
115
+ :FloatValue,
116
+ :Int64Value,
117
+ :UInt64Value,
118
+ :Int32Value,
119
+ :UInt32Value,
120
+ # string wrappers
121
+ :StringValue,
122
+ :BytesValue,
123
+ :BoolValue,
124
+ :Value,
125
+ :ListValue,
126
+ :Struct
127
+ )
128
+
129
+ DecodeStatus = enum(
130
+ :Ok,
131
+ :Malformed, # Wire format was corrupt
132
+ :OutOfMemory, # Arena alloc failed
133
+ :BadUtf8, # String field had bad UTF-8
134
+ :MaxDepthExceeded, # Exceeded UPB_DECODE_MAXDEPTH
135
+
136
+ # CheckRequired failed, but the parse otherwise succeeded.
137
+ :MissingRequired,
138
+ )
139
+
140
+ EncodeStatus = enum(
141
+ :Ok,
142
+ :OutOfMemory, # Arena alloc failed
143
+ :MaxDepthExceeded, # Exceeded UPB_DECODE_MAXDEPTH
144
+
145
+ # CheckRequired failed, but the parse otherwise succeeded.
146
+ :MissingRequired,
147
+ )
148
+
149
+ class StringView < ::FFI::Struct
150
+ layout :data, :pointer,
151
+ :size, :size_t
152
+ end
153
+
154
+ class MiniTable < ::FFI::Struct
155
+ layout :subs, :pointer,
156
+ :fields, :pointer,
157
+ :size, :uint16_t,
158
+ :field_count, :uint16_t,
159
+ :ext, :uint8_t, # upb_ExtMode, declared as uint8_t so sizeof(ext) == 1
160
+ :dense_below, :uint8_t,
161
+ :table_mask, :uint8_t,
162
+ :required_count, :uint8_t # Required fields have the lowest hasbits.
163
+ # To statically initialize the tables of variable length, we need a flexible
164
+ # array member, and we need to compile in gnu99 mode (constant initialization
165
+ # of flexible array members is a GNU extension, not in C99 unfortunately. */
166
+ # _upb_FastTable_Entry fasttable[];
167
+ end
168
+
169
+ class Status < ::FFI::Struct
170
+ layout :ok, :bool,
171
+ :msg, [:char, Upb_Status_MaxMessage]
172
+
173
+ def initialize
174
+ super
175
+ FFI.clear self
176
+ end
177
+ end
178
+
179
+ class MessageValue < ::FFI::Union
180
+ layout :bool_val, :bool,
181
+ :float_val, :float,
182
+ :double_val, :double,
183
+ :int32_val, :int32_t,
184
+ :int64_val, :int64_t,
185
+ :uint32_val, :uint32_t,
186
+ :uint64_val,:uint64_t,
187
+ :map_val, :pointer,
188
+ :msg_val, :pointer,
189
+ :array_val,:pointer,
190
+ :str_val, StringView
191
+ end
192
+
193
+ class MutableMessageValue < ::FFI::Union
194
+ layout :map, :Map,
195
+ :msg, :Message,
196
+ :array, :Array
197
+ end
198
+
199
+ # Status
200
+ attach_function :clear, :upb_Status_Clear, [Status.by_ref], :void
201
+ attach_function :error_message, :upb_Status_ErrorMessage, [Status.by_ref], :string
202
+
203
+ # Generic
204
+ attach_function :memcmp, [:pointer, :pointer, :size_t], :int
205
+ attach_function :memcpy, [:pointer, :pointer, :size_t], :int
206
+
207
+ # Alternatives to pre-processor macros
208
+ def self.decode_max_depth(i)
209
+ i << 16
210
+ end
211
+ end
212
+ end
213
+ end