google-protobuf 4.31.0.rc.1-x86-linux-musl
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.
- checksums.yaml +7 -0
- data/ext/google/protobuf_c/Rakefile +3 -0
- data/ext/google/protobuf_c/convert.c +335 -0
- data/ext/google/protobuf_c/convert.h +50 -0
- data/ext/google/protobuf_c/defs.c +1932 -0
- data/ext/google/protobuf_c/defs.h +82 -0
- data/ext/google/protobuf_c/extconf.rb +44 -0
- data/ext/google/protobuf_c/glue.c +135 -0
- data/ext/google/protobuf_c/map.c +731 -0
- data/ext/google/protobuf_c/map.h +48 -0
- data/ext/google/protobuf_c/message.c +1426 -0
- data/ext/google/protobuf_c/message.h +82 -0
- data/ext/google/protobuf_c/protobuf.c +357 -0
- data/ext/google/protobuf_c/protobuf.h +102 -0
- data/ext/google/protobuf_c/repeated_field.c +691 -0
- data/ext/google/protobuf_c/repeated_field.h +45 -0
- data/ext/google/protobuf_c/ruby-upb.c +18305 -0
- data/ext/google/protobuf_c/ruby-upb.h +16315 -0
- data/ext/google/protobuf_c/shared_convert.c +69 -0
- data/ext/google/protobuf_c/shared_convert.h +26 -0
- data/ext/google/protobuf_c/shared_message.c +37 -0
- data/ext/google/protobuf_c/shared_message.h +21 -0
- data/ext/google/protobuf_c/third_party/utf8_range/LICENSE +22 -0
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.c +207 -0
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.h +22 -0
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range_neon.inc +117 -0
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range_sse.inc +272 -0
- data/ext/google/protobuf_c/wrap_memcpy.c +29 -0
- data/lib/google/3.1/protobuf_c.so +0 -0
- data/lib/google/3.2/protobuf_c.so +0 -0
- data/lib/google/3.3/protobuf_c.so +0 -0
- data/lib/google/3.4/protobuf_c.so +0 -0
- data/lib/google/protobuf/any_pb.rb +17 -0
- data/lib/google/protobuf/api_pb.rb +22 -0
- data/lib/google/protobuf/descriptor_pb.rb +70 -0
- data/lib/google/protobuf/duration_pb.rb +17 -0
- data/lib/google/protobuf/empty_pb.rb +17 -0
- data/lib/google/protobuf/ffi/descriptor.rb +175 -0
- data/lib/google/protobuf/ffi/descriptor_pool.rb +79 -0
- data/lib/google/protobuf/ffi/enum_descriptor.rb +183 -0
- data/lib/google/protobuf/ffi/ffi.rb +214 -0
- data/lib/google/protobuf/ffi/field_descriptor.rb +346 -0
- data/lib/google/protobuf/ffi/file_descriptor.rb +85 -0
- data/lib/google/protobuf/ffi/internal/arena.rb +60 -0
- data/lib/google/protobuf/ffi/internal/convert.rb +292 -0
- data/lib/google/protobuf/ffi/internal/pointer_helper.rb +36 -0
- data/lib/google/protobuf/ffi/internal/type_safety.rb +25 -0
- data/lib/google/protobuf/ffi/map.rb +433 -0
- data/lib/google/protobuf/ffi/message.rb +783 -0
- data/lib/google/protobuf/ffi/method_descriptor.rb +124 -0
- data/lib/google/protobuf/ffi/object_cache.rb +30 -0
- data/lib/google/protobuf/ffi/oneof_descriptor.rb +107 -0
- data/lib/google/protobuf/ffi/repeated_field.rb +411 -0
- data/lib/google/protobuf/ffi/service_descriptor.rb +117 -0
- data/lib/google/protobuf/field_mask_pb.rb +17 -0
- data/lib/google/protobuf/internal/object_cache.rb +99 -0
- data/lib/google/protobuf/message_exts.rb +39 -0
- data/lib/google/protobuf/plugin_pb.rb +25 -0
- data/lib/google/protobuf/repeated_field.rb +177 -0
- data/lib/google/protobuf/source_context_pb.rb +17 -0
- data/lib/google/protobuf/struct_pb.rb +20 -0
- data/lib/google/protobuf/timestamp_pb.rb +17 -0
- data/lib/google/protobuf/type_pb.rb +27 -0
- data/lib/google/protobuf/well_known_types.rb +211 -0
- data/lib/google/protobuf/wrappers_pb.rb +25 -0
- data/lib/google/protobuf.rb +61 -0
- data/lib/google/protobuf_ffi.rb +52 -0
- data/lib/google/protobuf_native.rb +19 -0
- data/lib/google/tasks/ffi.rake +100 -0
- metadata +215 -0
@@ -0,0 +1,117 @@
|
|
1
|
+
# Protocol Buffers - Google's data interchange format
|
2
|
+
# Copyright 2024 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 ServiceDescriptor
|
11
|
+
attr :service_def, :descriptor_pool
|
12
|
+
include Enumerable
|
13
|
+
|
14
|
+
include Google::Protobuf::Internal::Convert
|
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 [ServiceDescriptor] ServiceDescriptor to convert to an FFI native type
|
25
|
+
# @param _ [Object] Unused
|
26
|
+
def to_native(value, _)
|
27
|
+
service_def_ptr = value.nil? ? nil : value.instance_variable_get(:@service_def)
|
28
|
+
return ::FFI::Pointer::NULL if service_def_ptr.nil?
|
29
|
+
raise "Underlying service_def was null!" if service_def_ptr.null?
|
30
|
+
service_def_ptr
|
31
|
+
end
|
32
|
+
|
33
|
+
##
|
34
|
+
# @param service_def [::FFI::Pointer] ServiceDef pointer to be wrapped
|
35
|
+
# @param _ [Object] Unused
|
36
|
+
def from_native(service_def, _ = nil)
|
37
|
+
return nil if service_def.nil? or service_def.null?
|
38
|
+
file_def = Google::Protobuf::FFI.file_def_by_raw_service_def(service_def)
|
39
|
+
descriptor_from_file_def(file_def, service_def)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.new(*arguments, &block)
|
44
|
+
raise "Descriptor objects may not be created from Ruby."
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_s
|
48
|
+
inspect
|
49
|
+
end
|
50
|
+
|
51
|
+
def inspect
|
52
|
+
"#{self.class.name}: #{name}"
|
53
|
+
end
|
54
|
+
|
55
|
+
def name
|
56
|
+
@name ||= Google::Protobuf::FFI.get_service_full_name(self)
|
57
|
+
end
|
58
|
+
|
59
|
+
def file_descriptor
|
60
|
+
@descriptor_pool.send(:get_file_descriptor, Google::Protobuf::FFI.file_def_by_raw_service_def(@service_def))
|
61
|
+
end
|
62
|
+
|
63
|
+
def each &block
|
64
|
+
n = Google::Protobuf::FFI.method_count(self)
|
65
|
+
0.upto(n-1) do |i|
|
66
|
+
yield(Google::Protobuf::FFI.get_method_by_index(self, i))
|
67
|
+
end
|
68
|
+
nil
|
69
|
+
end
|
70
|
+
|
71
|
+
def options
|
72
|
+
@options ||= begin
|
73
|
+
size_ptr = ::FFI::MemoryPointer.new(:size_t, 1)
|
74
|
+
temporary_arena = Google::Protobuf::FFI.create_arena
|
75
|
+
buffer = Google::Protobuf::FFI.service_options(self, size_ptr, temporary_arena)
|
76
|
+
Google::Protobuf::ServiceOptions.decode(buffer.read_string_length(size_ptr.read(:size_t)).force_encoding("ASCII-8BIT").freeze).freeze
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def to_proto
|
81
|
+
@to_proto ||= begin
|
82
|
+
size_ptr = ::FFI::MemoryPointer.new(:size_t, 1)
|
83
|
+
temporary_arena = Google::Protobuf::FFI.create_arena
|
84
|
+
buffer = Google::Protobuf::FFI.service_to_proto(self, size_ptr, temporary_arena)
|
85
|
+
Google::Protobuf::ServiceDescriptorProto.decode(buffer.read_string_length(size_ptr.read(:size_t)).force_encoding("ASCII-8BIT").freeze)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
def initialize(service_def, descriptor_pool)
|
92
|
+
@service_def = service_def
|
93
|
+
@descriptor_pool = descriptor_pool
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.private_constructor(service_def, descriptor_pool)
|
97
|
+
instance = allocate
|
98
|
+
instance.send(:initialize, service_def, descriptor_pool)
|
99
|
+
instance
|
100
|
+
end
|
101
|
+
|
102
|
+
def c_type
|
103
|
+
@c_type ||= Google::Protobuf::FFI.get_c_type(self)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
class FFI
|
108
|
+
# ServiceDef
|
109
|
+
attach_function :file_def_by_raw_service_def, :upb_ServiceDef_File, [:pointer], :FileDef
|
110
|
+
attach_function :get_service_full_name, :upb_ServiceDef_FullName, [ServiceDescriptor], :string
|
111
|
+
attach_function :method_count, :upb_ServiceDef_MethodCount, [ServiceDescriptor], :int
|
112
|
+
attach_function :get_method_by_index, :upb_ServiceDef_Method, [ServiceDescriptor, :int], MethodDescriptor
|
113
|
+
attach_function :service_options, :ServiceDescriptor_serialized_options, [ServiceDescriptor, :pointer, Internal::Arena], :pointer
|
114
|
+
attach_function :service_to_proto, :ServiceDescriptor_serialized_to_proto, [ServiceDescriptor, :pointer, Internal::Arena], :pointer
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
3
|
+
# source: google/protobuf/field_mask.proto
|
4
|
+
|
5
|
+
require 'google/protobuf'
|
6
|
+
|
7
|
+
|
8
|
+
descriptor_data = "\n google/protobuf/field_mask.proto\x12\x0fgoogle.protobuf\"\x1a\n\tFieldMask\x12\r\n\x05paths\x18\x01 \x03(\tB\x85\x01\n\x13\x63om.google.protobufB\x0e\x46ieldMaskProtoP\x01Z2google.golang.org/protobuf/types/known/fieldmaskpb\xf8\x01\x01\xa2\x02\x03GPB\xaa\x02\x1eGoogle.Protobuf.WellKnownTypesb\x06proto3"
|
9
|
+
|
10
|
+
pool = ::Google::Protobuf::DescriptorPool.generated_pool
|
11
|
+
pool.add_serialized_file(descriptor_data)
|
12
|
+
|
13
|
+
module Google
|
14
|
+
module Protobuf
|
15
|
+
FieldMask = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FieldMask").msgclass
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# Protocol Buffers - Google's data interchange format
|
2
|
+
# Copyright 2023 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
|
+
module Internal
|
11
|
+
# A pointer -> Ruby Object cache that keeps references to Ruby wrapper
|
12
|
+
# objects. This allows us to look up any Ruby wrapper object by the address
|
13
|
+
# of the object it is wrapping. That way we can avoid ever creating two
|
14
|
+
# different wrapper objects for the same C object, which saves memory and
|
15
|
+
# preserves object identity.
|
16
|
+
#
|
17
|
+
# We use WeakMap for the cache. If sizeof(long) > sizeof(VALUE), we also
|
18
|
+
# need a secondary Hash to store WeakMap keys, because our pointer keys may
|
19
|
+
# need to be stored as Bignum instead of Fixnum. Since WeakMap is weak for
|
20
|
+
# both keys and values, a Bignum key will cause the WeakMap entry to be
|
21
|
+
# collected immediately unless there is another reference to the Bignum.
|
22
|
+
# This happens on 64-bit Windows, on which pointers are 64 bits but longs
|
23
|
+
# are 32 bits. In this case, we enable the secondary Hash to hold the keys
|
24
|
+
# and prevent them from being collected.
|
25
|
+
class ObjectCache
|
26
|
+
def initialize
|
27
|
+
@map = ObjectSpace::WeakMap.new
|
28
|
+
@mutex = Mutex.new
|
29
|
+
end
|
30
|
+
|
31
|
+
def get(key)
|
32
|
+
@map[key]
|
33
|
+
end
|
34
|
+
|
35
|
+
def try_add(key, value)
|
36
|
+
@map[key] || @mutex.synchronize do
|
37
|
+
@map[key] ||= value
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class LegacyObjectCache
|
43
|
+
def initialize
|
44
|
+
@secondary_map = {}
|
45
|
+
@map = ObjectSpace::WeakMap.new
|
46
|
+
@mutex = Mutex.new
|
47
|
+
end
|
48
|
+
|
49
|
+
def get(key)
|
50
|
+
value = if secondary_key = @secondary_map[key]
|
51
|
+
@map[secondary_key]
|
52
|
+
else
|
53
|
+
@mutex.synchronize do
|
54
|
+
@map[(@secondary_map[key] ||= Object.new)]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# GC if we could remove at least 2000 entries or 20% of the table size
|
59
|
+
# (whichever is greater). Since the cost of the GC pass is O(N), we
|
60
|
+
# want to make sure that we condition this on overall table size, to
|
61
|
+
# avoid O(N^2) CPU costs.
|
62
|
+
cutoff = (@secondary_map.size * 0.2).ceil
|
63
|
+
cutoff = 2_000 if cutoff < 2_000
|
64
|
+
if (@secondary_map.size - @map.size) > cutoff
|
65
|
+
purge
|
66
|
+
end
|
67
|
+
|
68
|
+
value
|
69
|
+
end
|
70
|
+
|
71
|
+
def try_add(key, value)
|
72
|
+
if secondary_key = @secondary_map[key]
|
73
|
+
if old_value = @map[secondary_key]
|
74
|
+
return old_value
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
@mutex.synchronize do
|
79
|
+
secondary_key ||= (@secondary_map[key] ||= Object.new)
|
80
|
+
@map[secondary_key] ||= value
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def purge
|
87
|
+
@mutex.synchronize do
|
88
|
+
@secondary_map.each do |key, secondary_key|
|
89
|
+
unless @map.key?(secondary_key)
|
90
|
+
@secondary_map.delete(key)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
nil
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# Protocol Buffers - Google's data interchange format
|
2
|
+
# Copyright 2008 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
|
+
module MessageExts
|
11
|
+
|
12
|
+
#this is only called in jruby; mri loades the ClassMethods differently
|
13
|
+
def self.included(klass)
|
14
|
+
klass.extend(ClassMethods)
|
15
|
+
end
|
16
|
+
|
17
|
+
module ClassMethods
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_json(options = {})
|
21
|
+
self.class.encode_json(self, options)
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_proto(options = {})
|
25
|
+
self.class.encode(self, options)
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_hash
|
29
|
+
self.to_h
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
class AbstractMessage
|
34
|
+
include MessageExts
|
35
|
+
extend MessageExts::ClassMethods
|
36
|
+
end
|
37
|
+
private_constant :AbstractMessage
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
3
|
+
# source: google/protobuf/compiler/plugin.proto
|
4
|
+
|
5
|
+
require 'google/protobuf'
|
6
|
+
|
7
|
+
require 'google/protobuf/descriptor_pb'
|
8
|
+
|
9
|
+
|
10
|
+
descriptor_data = "\n%google/protobuf/compiler/plugin.proto\x12\x18google.protobuf.compiler\x1a google/protobuf/descriptor.proto\"F\n\x07Version\x12\r\n\x05major\x18\x01 \x01(\x05\x12\r\n\x05minor\x18\x02 \x01(\x05\x12\r\n\x05patch\x18\x03 \x01(\x05\x12\x0e\n\x06suffix\x18\x04 \x01(\t\"\x81\x02\n\x14\x43odeGeneratorRequest\x12\x18\n\x10\x66ile_to_generate\x18\x01 \x03(\t\x12\x11\n\tparameter\x18\x02 \x01(\t\x12\x38\n\nproto_file\x18\x0f \x03(\x0b\x32$.google.protobuf.FileDescriptorProto\x12\x45\n\x17source_file_descriptors\x18\x11 \x03(\x0b\x32$.google.protobuf.FileDescriptorProto\x12;\n\x10\x63ompiler_version\x18\x03 \x01(\x0b\x32!.google.protobuf.compiler.Version\"\x92\x03\n\x15\x43odeGeneratorResponse\x12\r\n\x05\x65rror\x18\x01 \x01(\t\x12\x1a\n\x12supported_features\x18\x02 \x01(\x04\x12\x17\n\x0fminimum_edition\x18\x03 \x01(\x05\x12\x17\n\x0fmaximum_edition\x18\x04 \x01(\x05\x12\x42\n\x04\x66ile\x18\x0f \x03(\x0b\x32\x34.google.protobuf.compiler.CodeGeneratorResponse.File\x1a\x7f\n\x04\x46ile\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x17\n\x0finsertion_point\x18\x02 \x01(\t\x12\x0f\n\x07\x63ontent\x18\x0f \x01(\t\x12?\n\x13generated_code_info\x18\x10 \x01(\x0b\x32\".google.protobuf.GeneratedCodeInfo\"W\n\x07\x46\x65\x61ture\x12\x10\n\x0c\x46\x45\x41TURE_NONE\x10\x00\x12\x1b\n\x17\x46\x45\x41TURE_PROTO3_OPTIONAL\x10\x01\x12\x1d\n\x19\x46\x45\x41TURE_SUPPORTS_EDITIONS\x10\x02\x42r\n\x1c\x63om.google.protobuf.compilerB\x0cPluginProtosZ)google.golang.org/protobuf/types/pluginpb\xaa\x02\x18Google.Protobuf.Compiler"
|
11
|
+
|
12
|
+
pool = ::Google::Protobuf::DescriptorPool.generated_pool
|
13
|
+
pool.add_serialized_file(descriptor_data)
|
14
|
+
|
15
|
+
module Google
|
16
|
+
module Protobuf
|
17
|
+
module Compiler
|
18
|
+
Version = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.compiler.Version").msgclass
|
19
|
+
CodeGeneratorRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.compiler.CodeGeneratorRequest").msgclass
|
20
|
+
CodeGeneratorResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.compiler.CodeGeneratorResponse").msgclass
|
21
|
+
CodeGeneratorResponse::File = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.compiler.CodeGeneratorResponse.File").msgclass
|
22
|
+
CodeGeneratorResponse::Feature = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.compiler.CodeGeneratorResponse.Feature").enummodule
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,177 @@
|
|
1
|
+
# Protocol Buffers - Google's data interchange format
|
2
|
+
# Copyright 2008 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
|
+
require 'forwardable'
|
9
|
+
|
10
|
+
#
|
11
|
+
# This class makes RepeatedField act (almost-) like a Ruby Array.
|
12
|
+
# It has convenience methods that extend the core C or Java based
|
13
|
+
# methods.
|
14
|
+
#
|
15
|
+
# This is a best-effort to mirror Array behavior. Two comments:
|
16
|
+
# 1) patches always welcome :)
|
17
|
+
# 2) if performance is an issue, feel free to rewrite the method
|
18
|
+
# in jruby and C. The source code has plenty of examples
|
19
|
+
#
|
20
|
+
# KNOWN ISSUES
|
21
|
+
# - #[]= doesn't allow less used approaches such as `arr[1, 2] = 'fizz'`
|
22
|
+
# - #concat should return the orig array
|
23
|
+
# - #push should accept multiple arguments and push them all at the same time
|
24
|
+
#
|
25
|
+
module Google
|
26
|
+
module Protobuf
|
27
|
+
class RepeatedField
|
28
|
+
extend Forwardable
|
29
|
+
|
30
|
+
# methods defined in C or Java:
|
31
|
+
# +
|
32
|
+
# [], at
|
33
|
+
# []=
|
34
|
+
# concat
|
35
|
+
# clear
|
36
|
+
# dup, clone
|
37
|
+
# each
|
38
|
+
# push, <<
|
39
|
+
# replace
|
40
|
+
# length, size
|
41
|
+
# ==
|
42
|
+
# to_ary, to_a
|
43
|
+
# also all enumerable
|
44
|
+
#
|
45
|
+
# NOTE: using delegators rather than method_missing to make the
|
46
|
+
# relationship explicit instead of implicit
|
47
|
+
def_delegators :to_ary,
|
48
|
+
:&, :*, :-, :'<=>',
|
49
|
+
:assoc, :bsearch, :bsearch_index, :combination, :compact, :count,
|
50
|
+
:cycle, :difference, :dig, :drop, :drop_while, :eql?, :fetch, :find_index, :flatten,
|
51
|
+
:include?, :index, :inspect, :intersection, :join,
|
52
|
+
:pack, :permutation, :product, :pretty_print, :pretty_print_cycle,
|
53
|
+
:rassoc, :repeated_combination, :repeated_permutation, :reverse,
|
54
|
+
:rindex, :rotate, :sample, :shuffle, :shelljoin,
|
55
|
+
:to_s, :transpose, :union, :uniq, :|
|
56
|
+
|
57
|
+
|
58
|
+
def first(n=nil)
|
59
|
+
if n.nil?
|
60
|
+
return self[0]
|
61
|
+
elsif n < 0
|
62
|
+
raise ArgumentError, "negative array size"
|
63
|
+
else
|
64
|
+
return self[0...n]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
def last(n=nil)
|
70
|
+
if n.nil?
|
71
|
+
return self[-1]
|
72
|
+
elsif n < 0
|
73
|
+
raise ArgumentError, "negative array size"
|
74
|
+
else
|
75
|
+
start = [self.size-n, 0].max
|
76
|
+
return self[start...self.size]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
def pop(n=nil)
|
82
|
+
if n
|
83
|
+
results = []
|
84
|
+
n.times{ results << pop_one }
|
85
|
+
return results
|
86
|
+
else
|
87
|
+
return pop_one
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
def empty?
|
93
|
+
self.size == 0
|
94
|
+
end
|
95
|
+
|
96
|
+
# array aliases into enumerable
|
97
|
+
alias_method :slice, :[]
|
98
|
+
alias_method :values_at, :select
|
99
|
+
alias_method :map, :collect
|
100
|
+
|
101
|
+
|
102
|
+
class << self
|
103
|
+
def define_array_wrapper_method(method_name)
|
104
|
+
define_method(method_name) do |*args, &block|
|
105
|
+
arr = self.to_a
|
106
|
+
result = arr.send(method_name, *args)
|
107
|
+
self.replace(arr)
|
108
|
+
return result if result
|
109
|
+
return block ? block.call : result
|
110
|
+
end
|
111
|
+
end
|
112
|
+
private :define_array_wrapper_method
|
113
|
+
|
114
|
+
|
115
|
+
def define_array_wrapper_with_result_method(method_name)
|
116
|
+
define_method(method_name) do |*args, &block|
|
117
|
+
# result can be an Enumerator, Array, or nil
|
118
|
+
# Enumerator can sometimes be returned if a block is an optional argument and it is not passed in
|
119
|
+
# nil usually specifies that no change was made
|
120
|
+
result = self.to_a.send(method_name, *args, &block)
|
121
|
+
if result
|
122
|
+
new_arr = result.to_a
|
123
|
+
self.replace(new_arr)
|
124
|
+
if result.is_a?(Enumerator)
|
125
|
+
# generate a fresh enum; rewinding the exiting one, in Ruby 2.2, will
|
126
|
+
# reset the enum with the same length, but all the #next calls will
|
127
|
+
# return nil
|
128
|
+
result = new_arr.to_enum
|
129
|
+
# generate a wrapper enum so any changes which occur by a chained
|
130
|
+
# enum can be captured
|
131
|
+
ie = ProxyingEnumerator.new(self, result)
|
132
|
+
result = ie.to_enum
|
133
|
+
end
|
134
|
+
end
|
135
|
+
result
|
136
|
+
end
|
137
|
+
end
|
138
|
+
private :define_array_wrapper_with_result_method
|
139
|
+
end
|
140
|
+
|
141
|
+
|
142
|
+
%w(delete delete_at shift slice! unshift).each do |method_name|
|
143
|
+
define_array_wrapper_method(method_name)
|
144
|
+
end
|
145
|
+
|
146
|
+
|
147
|
+
%w(collect! compact! delete_if each_index fill flatten! insert reverse!
|
148
|
+
rotate! select! shuffle! sort! sort_by! uniq!).each do |method_name|
|
149
|
+
define_array_wrapper_with_result_method(method_name)
|
150
|
+
end
|
151
|
+
alias_method :keep_if, :select!
|
152
|
+
alias_method :map!, :collect!
|
153
|
+
alias_method :reject!, :delete_if
|
154
|
+
|
155
|
+
|
156
|
+
# propagates changes made by user of enumerator back to the original repeated field.
|
157
|
+
# This only applies in cases where the calling function which created the enumerator,
|
158
|
+
# such as #sort!, modifies itself rather than a new array, such as #sort
|
159
|
+
class ProxyingEnumerator < Struct.new(:repeated_field, :external_enumerator)
|
160
|
+
def each(*args, &block)
|
161
|
+
results = []
|
162
|
+
external_enumerator.each_with_index do |val, i|
|
163
|
+
result = yield(val)
|
164
|
+
results << result
|
165
|
+
#nil means no change occurred from yield; usually occurs when #to_a is called
|
166
|
+
if result
|
167
|
+
repeated_field[i] = result if result != val
|
168
|
+
end
|
169
|
+
end
|
170
|
+
results
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
3
|
+
# source: google/protobuf/source_context.proto
|
4
|
+
|
5
|
+
require 'google/protobuf'
|
6
|
+
|
7
|
+
|
8
|
+
descriptor_data = "\n$google/protobuf/source_context.proto\x12\x0fgoogle.protobuf\"\"\n\rSourceContext\x12\x11\n\tfile_name\x18\x01 \x01(\tB\x8a\x01\n\x13\x63om.google.protobufB\x12SourceContextProtoP\x01Z6google.golang.org/protobuf/types/known/sourcecontextpb\xa2\x02\x03GPB\xaa\x02\x1eGoogle.Protobuf.WellKnownTypesb\x06proto3"
|
9
|
+
|
10
|
+
pool = ::Google::Protobuf::DescriptorPool.generated_pool
|
11
|
+
pool.add_serialized_file(descriptor_data)
|
12
|
+
|
13
|
+
module Google
|
14
|
+
module Protobuf
|
15
|
+
SourceContext = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.SourceContext").msgclass
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
3
|
+
# source: google/protobuf/struct.proto
|
4
|
+
|
5
|
+
require 'google/protobuf'
|
6
|
+
|
7
|
+
|
8
|
+
descriptor_data = "\n\x1cgoogle/protobuf/struct.proto\x12\x0fgoogle.protobuf\"\x84\x01\n\x06Struct\x12\x33\n\x06\x66ields\x18\x01 \x03(\x0b\x32#.google.protobuf.Struct.FieldsEntry\x1a\x45\n\x0b\x46ieldsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12%\n\x05value\x18\x02 \x01(\x0b\x32\x16.google.protobuf.Value:\x02\x38\x01\"\xea\x01\n\x05Value\x12\x30\n\nnull_value\x18\x01 \x01(\x0e\x32\x1a.google.protobuf.NullValueH\x00\x12\x16\n\x0cnumber_value\x18\x02 \x01(\x01H\x00\x12\x16\n\x0cstring_value\x18\x03 \x01(\tH\x00\x12\x14\n\nbool_value\x18\x04 \x01(\x08H\x00\x12/\n\x0cstruct_value\x18\x05 \x01(\x0b\x32\x17.google.protobuf.StructH\x00\x12\x30\n\nlist_value\x18\x06 \x01(\x0b\x32\x1a.google.protobuf.ListValueH\x00\x42\x06\n\x04kind\"3\n\tListValue\x12&\n\x06values\x18\x01 \x03(\x0b\x32\x16.google.protobuf.Value*\x1b\n\tNullValue\x12\x0e\n\nNULL_VALUE\x10\x00\x42\x7f\n\x13\x63om.google.protobufB\x0bStructProtoP\x01Z/google.golang.org/protobuf/types/known/structpb\xf8\x01\x01\xa2\x02\x03GPB\xaa\x02\x1eGoogle.Protobuf.WellKnownTypesb\x06proto3"
|
9
|
+
|
10
|
+
pool = ::Google::Protobuf::DescriptorPool.generated_pool
|
11
|
+
pool.add_serialized_file(descriptor_data)
|
12
|
+
|
13
|
+
module Google
|
14
|
+
module Protobuf
|
15
|
+
Struct = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Struct").msgclass
|
16
|
+
Value = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Value").msgclass
|
17
|
+
ListValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.ListValue").msgclass
|
18
|
+
NullValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.NullValue").enummodule
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
3
|
+
# source: google/protobuf/timestamp.proto
|
4
|
+
|
5
|
+
require 'google/protobuf'
|
6
|
+
|
7
|
+
|
8
|
+
descriptor_data = "\n\x1fgoogle/protobuf/timestamp.proto\x12\x0fgoogle.protobuf\"+\n\tTimestamp\x12\x0f\n\x07seconds\x18\x01 \x01(\x03\x12\r\n\x05nanos\x18\x02 \x01(\x05\x42\x85\x01\n\x13\x63om.google.protobufB\x0eTimestampProtoP\x01Z2google.golang.org/protobuf/types/known/timestamppb\xf8\x01\x01\xa2\x02\x03GPB\xaa\x02\x1eGoogle.Protobuf.WellKnownTypesb\x06proto3"
|
9
|
+
|
10
|
+
pool = ::Google::Protobuf::DescriptorPool.generated_pool
|
11
|
+
pool.add_serialized_file(descriptor_data)
|
12
|
+
|
13
|
+
module Google
|
14
|
+
module Protobuf
|
15
|
+
Timestamp = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Timestamp").msgclass
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
3
|
+
# source: google/protobuf/type.proto
|
4
|
+
|
5
|
+
require 'google/protobuf'
|
6
|
+
|
7
|
+
require 'google/protobuf/any_pb'
|
8
|
+
require 'google/protobuf/source_context_pb'
|
9
|
+
|
10
|
+
|
11
|
+
descriptor_data = "\n\x1agoogle/protobuf/type.proto\x12\x0fgoogle.protobuf\x1a\x19google/protobuf/any.proto\x1a$google/protobuf/source_context.proto\"\xe8\x01\n\x04Type\x12\x0c\n\x04name\x18\x01 \x01(\t\x12&\n\x06\x66ields\x18\x02 \x03(\x0b\x32\x16.google.protobuf.Field\x12\x0e\n\x06oneofs\x18\x03 \x03(\t\x12(\n\x07options\x18\x04 \x03(\x0b\x32\x17.google.protobuf.Option\x12\x36\n\x0esource_context\x18\x05 \x01(\x0b\x32\x1e.google.protobuf.SourceContext\x12\'\n\x06syntax\x18\x06 \x01(\x0e\x32\x17.google.protobuf.Syntax\x12\x0f\n\x07\x65\x64ition\x18\x07 \x01(\t\"\xd5\x05\n\x05\x46ield\x12)\n\x04kind\x18\x01 \x01(\x0e\x32\x1b.google.protobuf.Field.Kind\x12\x37\n\x0b\x63\x61rdinality\x18\x02 \x01(\x0e\x32\".google.protobuf.Field.Cardinality\x12\x0e\n\x06number\x18\x03 \x01(\x05\x12\x0c\n\x04name\x18\x04 \x01(\t\x12\x10\n\x08type_url\x18\x06 \x01(\t\x12\x13\n\x0boneof_index\x18\x07 \x01(\x05\x12\x0e\n\x06packed\x18\x08 \x01(\x08\x12(\n\x07options\x18\t \x03(\x0b\x32\x17.google.protobuf.Option\x12\x11\n\tjson_name\x18\n \x01(\t\x12\x15\n\rdefault_value\x18\x0b \x01(\t\"\xc8\x02\n\x04Kind\x12\x10\n\x0cTYPE_UNKNOWN\x10\x00\x12\x0f\n\x0bTYPE_DOUBLE\x10\x01\x12\x0e\n\nTYPE_FLOAT\x10\x02\x12\x0e\n\nTYPE_INT64\x10\x03\x12\x0f\n\x0bTYPE_UINT64\x10\x04\x12\x0e\n\nTYPE_INT32\x10\x05\x12\x10\n\x0cTYPE_FIXED64\x10\x06\x12\x10\n\x0cTYPE_FIXED32\x10\x07\x12\r\n\tTYPE_BOOL\x10\x08\x12\x0f\n\x0bTYPE_STRING\x10\t\x12\x0e\n\nTYPE_GROUP\x10\n\x12\x10\n\x0cTYPE_MESSAGE\x10\x0b\x12\x0e\n\nTYPE_BYTES\x10\x0c\x12\x0f\n\x0bTYPE_UINT32\x10\r\x12\r\n\tTYPE_ENUM\x10\x0e\x12\x11\n\rTYPE_SFIXED32\x10\x0f\x12\x11\n\rTYPE_SFIXED64\x10\x10\x12\x0f\n\x0bTYPE_SINT32\x10\x11\x12\x0f\n\x0bTYPE_SINT64\x10\x12\"t\n\x0b\x43\x61rdinality\x12\x17\n\x13\x43\x41RDINALITY_UNKNOWN\x10\x00\x12\x18\n\x14\x43\x41RDINALITY_OPTIONAL\x10\x01\x12\x18\n\x14\x43\x41RDINALITY_REQUIRED\x10\x02\x12\x18\n\x14\x43\x41RDINALITY_REPEATED\x10\x03\"\xdf\x01\n\x04\x45num\x12\x0c\n\x04name\x18\x01 \x01(\t\x12-\n\tenumvalue\x18\x02 \x03(\x0b\x32\x1a.google.protobuf.EnumValue\x12(\n\x07options\x18\x03 \x03(\x0b\x32\x17.google.protobuf.Option\x12\x36\n\x0esource_context\x18\x04 \x01(\x0b\x32\x1e.google.protobuf.SourceContext\x12\'\n\x06syntax\x18\x05 \x01(\x0e\x32\x17.google.protobuf.Syntax\x12\x0f\n\x07\x65\x64ition\x18\x06 \x01(\t\"S\n\tEnumValue\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0e\n\x06number\x18\x02 \x01(\x05\x12(\n\x07options\x18\x03 \x03(\x0b\x32\x17.google.protobuf.Option\";\n\x06Option\x12\x0c\n\x04name\x18\x01 \x01(\t\x12#\n\x05value\x18\x02 \x01(\x0b\x32\x14.google.protobuf.Any*C\n\x06Syntax\x12\x11\n\rSYNTAX_PROTO2\x10\x00\x12\x11\n\rSYNTAX_PROTO3\x10\x01\x12\x13\n\x0fSYNTAX_EDITIONS\x10\x02\x42{\n\x13\x63om.google.protobufB\tTypeProtoP\x01Z-google.golang.org/protobuf/types/known/typepb\xf8\x01\x01\xa2\x02\x03GPB\xaa\x02\x1eGoogle.Protobuf.WellKnownTypesb\x06proto3"
|
12
|
+
|
13
|
+
pool = ::Google::Protobuf::DescriptorPool.generated_pool
|
14
|
+
pool.add_serialized_file(descriptor_data)
|
15
|
+
|
16
|
+
module Google
|
17
|
+
module Protobuf
|
18
|
+
Type = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Type").msgclass
|
19
|
+
Field = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Field").msgclass
|
20
|
+
Field::Kind = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Field.Kind").enummodule
|
21
|
+
Field::Cardinality = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Field.Cardinality").enummodule
|
22
|
+
Enum = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Enum").msgclass
|
23
|
+
EnumValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.EnumValue").msgclass
|
24
|
+
Option = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Option").msgclass
|
25
|
+
Syntax = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Syntax").enummodule
|
26
|
+
end
|
27
|
+
end
|