protostar 0.1.0.beta1

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.
Files changed (223) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +60 -0
  3. data/LICENSE.txt +21 -0
  4. data/README.md +647 -0
  5. data/THIRD_PARTY_NOTICES.md +61 -0
  6. data/exe/protoc-gen-protostar +7 -0
  7. data/exe/protostar +7 -0
  8. data/lib/protostar/builder/generator.rb +71 -0
  9. data/lib/protostar/builder/sink.rb +35 -0
  10. data/lib/protostar/builder.rb +965 -0
  11. data/lib/protostar/cli.rb +267 -0
  12. data/lib/protostar/codec/decode_generator.rb +199 -0
  13. data/lib/protostar/codec/decoder.rb +296 -0
  14. data/lib/protostar/codec/encode_generator.rb +224 -0
  15. data/lib/protostar/codec/encoder.rb +121 -0
  16. data/lib/protostar/codec/sizer.rb +91 -0
  17. data/lib/protostar/codec.rb +15 -0
  18. data/lib/protostar/compiler/ast.rb +193 -0
  19. data/lib/protostar/compiler/emitters/descriptor_set.rb +57 -0
  20. data/lib/protostar/compiler/emitters/google_ruby.rb +103 -0
  21. data/lib/protostar/compiler/emitters/grpc.rb +175 -0
  22. data/lib/protostar/compiler/emitters/protostar_rbs.rb +252 -0
  23. data/lib/protostar/compiler/emitters/rbs.rb +394 -0
  24. data/lib/protostar/compiler/emitters/ruby.rb +503 -0
  25. data/lib/protostar/compiler/emitters.rb +268 -0
  26. data/lib/protostar/compiler/include/LICENSE +32 -0
  27. data/lib/protostar/compiler/include/google/protobuf/any.proto +106 -0
  28. data/lib/protostar/compiler/include/google/protobuf/api.proto +229 -0
  29. data/lib/protostar/compiler/include/google/protobuf/compiler/plugin.proto +180 -0
  30. data/lib/protostar/compiler/include/google/protobuf/cpp_features.proto +87 -0
  31. data/lib/protostar/compiler/include/google/protobuf/descriptor.proto +1532 -0
  32. data/lib/protostar/compiler/include/google/protobuf/duration.proto +115 -0
  33. data/lib/protostar/compiler/include/google/protobuf/empty.proto +51 -0
  34. data/lib/protostar/compiler/include/google/protobuf/field_mask.proto +243 -0
  35. data/lib/protostar/compiler/include/google/protobuf/java_features.proto +132 -0
  36. data/lib/protostar/compiler/include/google/protobuf/source_context.proto +48 -0
  37. data/lib/protostar/compiler/include/google/protobuf/struct.proto +111 -0
  38. data/lib/protostar/compiler/include/google/protobuf/timestamp.proto +145 -0
  39. data/lib/protostar/compiler/include/google/protobuf/type.proto +217 -0
  40. data/lib/protostar/compiler/include/google/protobuf/wrappers.proto +157 -0
  41. data/lib/protostar/compiler/lexer.rb +659 -0
  42. data/lib/protostar/compiler/linker.rb +894 -0
  43. data/lib/protostar/compiler/option_interpreter.rb +363 -0
  44. data/lib/protostar/compiler/parser.rb +1696 -0
  45. data/lib/protostar/compiler/retention.rb +104 -0
  46. data/lib/protostar/compiler/run.rb +184 -0
  47. data/lib/protostar/compiler/source_info.rb +161 -0
  48. data/lib/protostar/compiler/symbol_table.rb +223 -0
  49. data/lib/protostar/compiler/text_format.rb +340 -0
  50. data/lib/protostar/compiler/validator.rb +944 -0
  51. data/lib/protostar/compiler.rb +304 -0
  52. data/lib/protostar/diagnostics/codes.rb +1307 -0
  53. data/lib/protostar/diagnostics/formats.rb +64 -0
  54. data/lib/protostar/diagnostics/renderer.rb +240 -0
  55. data/lib/protostar/diagnostics/source.rb +153 -0
  56. data/lib/protostar/diagnostics.rb +117 -0
  57. data/lib/protostar/dsl.rb +367 -0
  58. data/lib/protostar/enum.rb +70 -0
  59. data/lib/protostar/errors.rb +23 -0
  60. data/lib/protostar/google/protobuf/any_pb.rb +90 -0
  61. data/lib/protostar/google/protobuf/api_pb.rb +199 -0
  62. data/lib/protostar/google/protobuf/compiler/plugin_pb.rb +168 -0
  63. data/lib/protostar/google/protobuf/descriptor_pb.rb +1239 -0
  64. data/lib/protostar/google/protobuf/duration_pb.rb +99 -0
  65. data/lib/protostar/google/protobuf/empty_pb.rb +36 -0
  66. data/lib/protostar/google/protobuf/field_mask_pb.rb +228 -0
  67. data/lib/protostar/google/protobuf/source_context_pb.rb +33 -0
  68. data/lib/protostar/google/protobuf/struct_pb.rb +91 -0
  69. data/lib/protostar/google/protobuf/timestamp_pb.rb +129 -0
  70. data/lib/protostar/google/protobuf/type_pb.rb +202 -0
  71. data/lib/protostar/google/protobuf/wrappers_pb.rb +125 -0
  72. data/lib/protostar/google_protobuf_shim.rb +24 -0
  73. data/lib/protostar/json/encoder.rb +340 -0
  74. data/lib/protostar/json/errors.rb +34 -0
  75. data/lib/protostar/json/parser.rb +437 -0
  76. data/lib/protostar/json/path.rb +39 -0
  77. data/lib/protostar/json.rb +95 -0
  78. data/lib/protostar/lint/command.rb +197 -0
  79. data/lib/protostar/lint/config.rb +98 -0
  80. data/lib/protostar/lint/context.rb +126 -0
  81. data/lib/protostar/lint/directives.rb +56 -0
  82. data/lib/protostar/lint/fixer.rb +165 -0
  83. data/lib/protostar/lint/naming.rb +54 -0
  84. data/lib/protostar/lint/rule.rb +120 -0
  85. data/lib/protostar/lint/rules/comment_enum.rb +31 -0
  86. data/lib/protostar/lint/rules/comment_enum_value.rb +32 -0
  87. data/lib/protostar/lint/rules/comment_field.rb +33 -0
  88. data/lib/protostar/lint/rules/comment_message.rb +31 -0
  89. data/lib/protostar/lint/rules/comment_rpc.rb +31 -0
  90. data/lib/protostar/lint/rules/comment_service.rb +31 -0
  91. data/lib/protostar/lint/rules/edition_recommended.rb +31 -0
  92. data/lib/protostar/lint/rules/enum_first_value_zero.rb +34 -0
  93. data/lib/protostar/lint/rules/enum_pascal_case.rb +25 -0
  94. data/lib/protostar/lint/rules/enum_value_prefix.rb +38 -0
  95. data/lib/protostar/lint/rules/enum_value_upper_snake_case.rb +28 -0
  96. data/lib/protostar/lint/rules/enum_zero_value_suffix.rb +41 -0
  97. data/lib/protostar/lint/rules/field_lower_snake_case.rb +34 -0
  98. data/lib/protostar/lint/rules/field_not_required.rb +39 -0
  99. data/lib/protostar/lint/rules/field_number_reuse_risk.rb +45 -0
  100. data/lib/protostar/lint/rules/field_numbers_hot_range.rb +44 -0
  101. data/lib/protostar/lint/rules/file_lower_snake_case.rb +27 -0
  102. data/lib/protostar/lint/rules/import_no_public.rb +29 -0
  103. data/lib/protostar/lint/rules/import_no_weak.rb +28 -0
  104. data/lib/protostar/lint/rules/import_used.rb +33 -0
  105. data/lib/protostar/lint/rules/message_pascal_case.rb +27 -0
  106. data/lib/protostar/lint/rules/no_deprecated_features.rb +50 -0
  107. data/lib/protostar/lint/rules/no_groups.rb +34 -0
  108. data/lib/protostar/lint/rules/oneof_lower_snake_case.rb +27 -0
  109. data/lib/protostar/lint/rules/package_defined.rb +28 -0
  110. data/lib/protostar/lint/rules/package_directory_match.rb +33 -0
  111. data/lib/protostar/lint/rules/package_lower_snake_case.rb +28 -0
  112. data/lib/protostar/lint/rules/package_same_directory.rb +39 -0
  113. data/lib/protostar/lint/rules/package_version_suffix.rb +31 -0
  114. data/lib/protostar/lint/rules/reserved_names_with_numbers.rb +44 -0
  115. data/lib/protostar/lint/rules/rpc_pascal_case.rb +25 -0
  116. data/lib/protostar/lint/rules/rpc_request_response_unique.rb +40 -0
  117. data/lib/protostar/lint/rules/rpc_request_standard_name.rb +32 -0
  118. data/lib/protostar/lint/rules/rpc_response_standard_name.rb +31 -0
  119. data/lib/protostar/lint/rules/service_pascal_case.rb +25 -0
  120. data/lib/protostar/lint/rules/service_suffix.rb +28 -0
  121. data/lib/protostar/lint/rules/syntax_specified.rb +35 -0
  122. data/lib/protostar/lint/runner.rb +135 -0
  123. data/lib/protostar/lint.rb +122 -0
  124. data/lib/protostar/message/accessors.rb +86 -0
  125. data/lib/protostar/message/coercion.rb +171 -0
  126. data/lib/protostar/message/field_info.rb +145 -0
  127. data/lib/protostar/message/reflection.rb +149 -0
  128. data/lib/protostar/message.rb +572 -0
  129. data/lib/protostar/plugin.rb +94 -0
  130. data/lib/protostar/schema/default_value.rb +113 -0
  131. data/lib/protostar/schema/descriptor.rb +41 -0
  132. data/lib/protostar/schema/draft/copy.rb +88 -0
  133. data/lib/protostar/schema/draft/resolution.rb +177 -0
  134. data/lib/protostar/schema/draft.rb +779 -0
  135. data/lib/protostar/schema/enum.rb +106 -0
  136. data/lib/protostar/schema/extension_range.rb +37 -0
  137. data/lib/protostar/schema/features.rb +153 -0
  138. data/lib/protostar/schema/field.rb +201 -0
  139. data/lib/protostar/schema/file.rb +217 -0
  140. data/lib/protostar/schema/freezer.rb +61 -0
  141. data/lib/protostar/schema/message.rb +104 -0
  142. data/lib/protostar/schema/oneof.rb +38 -0
  143. data/lib/protostar/schema/options.rb +367 -0
  144. data/lib/protostar/schema/pool.rb +179 -0
  145. data/lib/protostar/schema/proto.rb +576 -0
  146. data/lib/protostar/schema/resolver.rb +118 -0
  147. data/lib/protostar/schema/service.rb +89 -0
  148. data/lib/protostar/schema/source_info.rb +53 -0
  149. data/lib/protostar/schema.rb +65 -0
  150. data/lib/protostar/short_names/any.rb +7 -0
  151. data/lib/protostar/short_names/duration.rb +7 -0
  152. data/lib/protostar/short_names/empty.rb +7 -0
  153. data/lib/protostar/short_names/field_mask.rb +7 -0
  154. data/lib/protostar/short_names/struct.rb +9 -0
  155. data/lib/protostar/short_names/timestamp.rb +7 -0
  156. data/lib/protostar/short_names/wrappers.rb +15 -0
  157. data/lib/protostar/text/extensions.rb +114 -0
  158. data/lib/protostar/text/parser.rb +439 -0
  159. data/lib/protostar/text/printer.rb +304 -0
  160. data/lib/protostar/text/tokenizer.rb +116 -0
  161. data/lib/protostar/text.rb +67 -0
  162. data/lib/protostar/types.rb +152 -0
  163. data/lib/protostar/unknown_field.rb +58 -0
  164. data/lib/protostar/version.rb +5 -0
  165. data/lib/protostar/view/generator.rb +298 -0
  166. data/lib/protostar/view/map.rb +194 -0
  167. data/lib/protostar/view/repeated.rb +143 -0
  168. data/lib/protostar/view/scan.rb +183 -0
  169. data/lib/protostar/view.rb +283 -0
  170. data/lib/protostar/well_known/any.rb +52 -0
  171. data/lib/protostar/well_known/duration.rb +53 -0
  172. data/lib/protostar/well_known/list_value.rb +63 -0
  173. data/lib/protostar/well_known/struct.rb +55 -0
  174. data/lib/protostar/well_known/timestamp.rb +64 -0
  175. data/lib/protostar/well_known/value.rb +60 -0
  176. data/lib/protostar/well_known.rb +38 -0
  177. data/lib/protostar/wire/io_source.rb +40 -0
  178. data/lib/protostar/wire/reader.rb +254 -0
  179. data/lib/protostar/wire/writer.rb +201 -0
  180. data/lib/protostar/wire.rb +96 -0
  181. data/lib/protostar.rb +95 -0
  182. data/shims/google-protobuf/lib/google/protobuf/any_pb.rb +17 -0
  183. data/shims/google-protobuf/lib/google/protobuf/api_pb.rb +22 -0
  184. data/shims/google-protobuf/lib/google/protobuf/compiler/plugin_pb.rb +25 -0
  185. data/shims/google-protobuf/lib/google/protobuf/descriptor_pb.rb +72 -0
  186. data/shims/google-protobuf/lib/google/protobuf/descriptor_pool.rb +164 -0
  187. data/shims/google-protobuf/lib/google/protobuf/descriptors.rb +553 -0
  188. data/shims/google-protobuf/lib/google/protobuf/duration_pb.rb +17 -0
  189. data/shims/google-protobuf/lib/google/protobuf/empty_pb.rb +17 -0
  190. data/shims/google-protobuf/lib/google/protobuf/field_mask_pb.rb +17 -0
  191. data/shims/google-protobuf/lib/google/protobuf/internal/convert.rb +180 -0
  192. data/shims/google-protobuf/lib/google/protobuf/internal/extensions.rb +154 -0
  193. data/shims/google-protobuf/lib/google/protobuf/internal/json.rb +104 -0
  194. data/shims/google-protobuf/lib/google/protobuf/internal/well_known.rb +140 -0
  195. data/shims/google-protobuf/lib/google/protobuf/map.rb +216 -0
  196. data/shims/google-protobuf/lib/google/protobuf/message.rb +544 -0
  197. data/shims/google-protobuf/lib/google/protobuf/message_exts.rb +41 -0
  198. data/shims/google-protobuf/lib/google/protobuf/plugin_pb.rb +4 -0
  199. data/shims/google-protobuf/lib/google/protobuf/repeated_field.rb +366 -0
  200. data/shims/google-protobuf/lib/google/protobuf/source_context_pb.rb +17 -0
  201. data/shims/google-protobuf/lib/google/protobuf/struct_pb.rb +20 -0
  202. data/shims/google-protobuf/lib/google/protobuf/timestamp_pb.rb +17 -0
  203. data/shims/google-protobuf/lib/google/protobuf/type_pb.rb +27 -0
  204. data/shims/google-protobuf/lib/google/protobuf/well_known_types.rb +37 -0
  205. data/shims/google-protobuf/lib/google/protobuf/wrappers_pb.rb +25 -0
  206. data/shims/google-protobuf/lib/google/protobuf.rb +107 -0
  207. data/shims/google-protobuf/lib/google/protobuf_ffi.rb +5 -0
  208. data/shims/google-protobuf/lib/google/protobuf_native.rb +5 -0
  209. data/sig/protostar/google/protobuf/any_pb.rbs +77 -0
  210. data/sig/protostar/google/protobuf/api_pb.rbs +242 -0
  211. data/sig/protostar/google/protobuf/compiler/plugin_pb.rbs +264 -0
  212. data/sig/protostar/google/protobuf/descriptor_pb.rbs +2220 -0
  213. data/sig/protostar/google/protobuf/duration_pb.rbs +82 -0
  214. data/sig/protostar/google/protobuf/empty_pb.rbs +18 -0
  215. data/sig/protostar/google/protobuf/field_mask_pb.rbs +170 -0
  216. data/sig/protostar/google/protobuf/source_context_pb.rbs +24 -0
  217. data/sig/protostar/google/protobuf/struct_pb.rbs +135 -0
  218. data/sig/protostar/google/protobuf/timestamp_pb.rbs +102 -0
  219. data/sig/protostar/google/protobuf/type_pb.rbs +304 -0
  220. data/sig/protostar/google/protobuf/wrappers_pb.rbs +169 -0
  221. data/sig/protostar/lint.rbs +216 -0
  222. data/sig/protostar.rbs +326 -0
  223. metadata +366 -0
@@ -0,0 +1,268 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Protostar
4
+ class Compiler
5
+ # Code generators. Each takes built {Schema::File}s and returns a Hash of
6
+ # output path to contents.
7
+ module Emitters
8
+ # Raised when a file cannot be emitted, with protoc's generator message
9
+ class Error < Protostar::Error; end
10
+
11
+ # The files whose generated Ruby ships with protostar under
12
+ # `protostar/google/protobuf/`, with constants under
13
+ # `Protostar::Google::Protobuf`
14
+ BOOTSTRAP = %w[
15
+ google/protobuf/descriptor.proto google/protobuf/compiler/plugin.proto google/protobuf/any.proto
16
+ google/protobuf/api.proto google/protobuf/duration.proto google/protobuf/empty.proto
17
+ google/protobuf/field_mask.proto google/protobuf/source_context.proto google/protobuf/struct.proto
18
+ google/protobuf/timestamp.proto google/protobuf/type.proto google/protobuf/wrappers.proto
19
+ ].freeze
20
+
21
+ # The Ruby module the bootstrap's `google.protobuf` package lives in
22
+ BOOTSTRAP_NAMESPACE = "Protostar::Google::Protobuf"
23
+
24
+ autoload :Ruby, ::File.expand_path("emitters/ruby", __dir__)
25
+ autoload :DescriptorSet, ::File.expand_path("emitters/descriptor_set", __dir__)
26
+ autoload :GoogleRuby, ::File.expand_path("emitters/google_ruby", __dir__)
27
+ autoload :Rbs, ::File.expand_path("emitters/rbs", __dir__)
28
+ autoload :ProtostarRbs, ::File.expand_path("emitters/protostar_rbs", __dir__)
29
+ autoload :Grpc, ::File.expand_path("emitters/grpc", __dir__)
30
+
31
+ # protoc's Ruby generator naming rules (ruby_generator.cc), which grpc
32
+ # stubs and application code depend on
33
+ module Naming
34
+ # Characters protoc refuses in `ruby_package`
35
+ BANNED_RUBY_PACKAGE = ";`{}()'\"$#=<>|&[]/\\@%\n\r!?*~^,\0"
36
+
37
+ module_function
38
+
39
+ # "foo/bar.proto" to "foo/bar_pb"
40
+ def require_name(proto_file)
41
+ dot = proto_file.rindex(".")
42
+ "#{dot ? proto_file[0, dot] : proto_file}_pb"
43
+ end
44
+
45
+ # snake_case package part to a module name: "foo_bar" to "FooBar"
46
+ def package_to_module(name)
47
+ out = +""
48
+ upper = true
49
+ name.each_char do |c|
50
+ if c == "_"
51
+ upper = true
52
+ else
53
+ out << (upper ? upcase(c) : c)
54
+ upper = false
55
+ end
56
+ end
57
+ out
58
+ end
59
+
60
+ # A message or enum name as a Ruby constant: first letter
61
+ # capitalised, "PB_" prefixed when it does not start with a letter
62
+ def rubify_constant(name)
63
+ return name if name.empty?
64
+ first = name[0]
65
+ if first.between?("a", "z")
66
+ upcase(first) + name[1..]
67
+ elsif !first.between?("A", "Z")
68
+ "PB_#{name}"
69
+ else
70
+ name
71
+ end
72
+ end
73
+
74
+ # The modules a file's constants live in, outermost first: protoc's
75
+ # GeneratePackageModules
76
+ # @param file [Schema::File]
77
+ # @param namespace [String, nil] overrides the package and `ruby_package`
78
+ # @return [Array<String>]
79
+ def module_path(file, namespace = nil)
80
+ return namespace.split("::") if namespace
81
+ convert = true
82
+ if (package = file.options.ruby_package)
83
+ convert = false if package.include?("::")
84
+ else
85
+ package = file.package
86
+ end
87
+ delimiter = convert ? "." : "::"
88
+ parts = []
89
+ until package.empty?
90
+ at = package.index(delimiter)
91
+ if at
92
+ parts << package[0, at]
93
+ package = package[(at + delimiter.size)..]
94
+ else
95
+ parts << package
96
+ package = ""
97
+ end
98
+ end
99
+ convert ? parts.map { |p| package_to_module(p) } : parts
100
+ end
101
+
102
+ # protoc's check on `ruby_package`
103
+ # @raise [Emitters::Error]
104
+ def check_ruby_package(file)
105
+ file.options.ruby_package&.each_char do |c|
106
+ next unless BANNED_RUBY_PACKAGE.include?(c)
107
+ raise Emitters::Error, "Invalid character in ruby_package option: character '#{c}' is not allowed " \
108
+ "because it could enable code injection."
109
+ end
110
+ end
111
+
112
+ # The constant path of a message or enum relative to its file's module
113
+ # @param descriptor [Schema::Message, Schema::Enum]
114
+ def relative_constant(descriptor)
115
+ names = []
116
+ d = descriptor
117
+ while d
118
+ names.unshift(rubify_constant(d.name))
119
+ d = d.containing_message
120
+ end
121
+ names.join("::")
122
+ end
123
+
124
+ def upcase(c)
125
+ c.between?("a", "z") ? c.upcase : c
126
+ end
127
+ end
128
+
129
+ # protoc's io::Printer: text is indented at the start of every line
130
+ # that is not empty
131
+ class Printer
132
+ def initialize
133
+ @out = +""
134
+ @indent = ""
135
+ @at_start = true
136
+ end
137
+
138
+ def print(text)
139
+ text.each_char do |c|
140
+ if c == "\n"
141
+ @at_start = true
142
+ elsif @at_start
143
+ @out << @indent
144
+ @at_start = false
145
+ end
146
+ @out << c
147
+ end
148
+ self
149
+ end
150
+
151
+ def indent
152
+ @indent += " "
153
+ end
154
+
155
+ def outdent
156
+ @indent = @indent[0...-2]
157
+ end
158
+
159
+ def to_s
160
+ @out
161
+ end
162
+ end
163
+
164
+ # Ruby source for literal values: Strings as UTF-8 text or binary with
165
+ # `.b`, floats exactly, Hashes and Arrays broken over lines when long
166
+ module Literal
167
+ WIDTH = 100
168
+ ESCAPES = {"\n" => "\\n", "\t" => "\\t", "\r" => "\\r", "\"" => "\\\"", "\\" => "\\\\", "\e" => "\\e",
169
+ "\a" => "\\a", "\b" => "\\b", "\f" => "\\f", "\v" => "\\v"}.freeze
170
+
171
+ module_function
172
+
173
+ # @param value [Object]
174
+ # @param indent [Integer] the indentation of the line the literal is on
175
+ # @param start [Integer] the column the literal starts on
176
+ # @return [String] on one line when it fits, otherwise one element per line
177
+ def call(value, indent = 0, start = indent)
178
+ flat = flat(value)
179
+ return flat if start + flat.size <= WIDTH || !(value.is_a?(Hash) || value.is_a?(Array)) || value.empty?
180
+ pad = " " * (indent + 2)
181
+ items = if value.is_a?(Array)
182
+ value.map { |v| pad + call(v, indent + 2) }
183
+ else
184
+ value.map { |k, v| pad + key(k) + call(v, indent + 2, indent + 2 + key(k).size) }
185
+ end
186
+ open, close = value.is_a?(Array) ? ["[", "]"] : ["{", "}"]
187
+ "#{open}\n#{items.join(",\n")}\n#{" " * indent}#{close}"
188
+ end
189
+
190
+ def flat(value)
191
+ case value
192
+ when Hash then value.empty? ? "{}" : "{#{value.map { |k, v| key(k) + flat(v) }.join(", ")}}"
193
+ when Array then "[#{value.map { |v| flat(v) }.join(", ")}]"
194
+ when String then string(value)
195
+ when Symbol then value.inspect
196
+ when Float then float(value)
197
+ when Integer, true, false, nil then value.inspect
198
+ when Range then "#{value.begin}..#{value.end}"
199
+ else raise ArgumentError, "no literal for #{value.class}"
200
+ end
201
+ end
202
+
203
+ def key(k)
204
+ if k.is_a?(Symbol) && /\A[A-Za-z_][A-Za-z0-9_]*\z/.match?(k)
205
+ "#{k}: "
206
+ else
207
+ "#{flat(k)} => "
208
+ end
209
+ end
210
+
211
+ def float(value)
212
+ return "Float::NAN" if value.nan?
213
+ return (value > 0) ? "Float::INFINITY" : "-Float::INFINITY" if value.infinite?
214
+ value.inspect
215
+ end
216
+
217
+ # A double-quoted literal; binary Strings, and Strings that are not
218
+ # valid UTF-8, are escaped byte by byte and marked `.b`
219
+ def string(value)
220
+ binary = value.encoding == Encoding::BINARY || !value.dup.force_encoding(Encoding::UTF_8).valid_encoding?
221
+ out = +"\""
222
+ if binary
223
+ value.each_byte { |b| out << byte(b) }
224
+ out << "\".b"
225
+ else
226
+ text = (value.encoding == Encoding::UTF_8) ? value : value.dup.force_encoding(Encoding::UTF_8)
227
+ text.each_char { |c| out << char(c) }
228
+ out << "\""
229
+ end
230
+ out
231
+ end
232
+
233
+ def byte(b)
234
+ c = b.chr
235
+ if (escaped = ESCAPES[c])
236
+ escaped
237
+ elsif b < 0x20 || b >= 0x7F
238
+ format("\\x%02X", b)
239
+ elsif c == "#"
240
+ "\\#"
241
+ else
242
+ c
243
+ end
244
+ end
245
+
246
+ def char(c)
247
+ if (escaped = ESCAPES[c])
248
+ escaped
249
+ elsif c == "#"
250
+ "\\#"
251
+ elsif c.ord < 0x20 || c.ord == 0x7F
252
+ format("\\x%02X", c.ord)
253
+ elsif c.ord >= 0x80 && !printable?(c)
254
+ format("\\u{%X}", c.ord)
255
+ else
256
+ c
257
+ end
258
+ end
259
+
260
+ # Formatting and line-breaking code points are escaped so that a
261
+ # generated line never breaks or reorders visually
262
+ def printable?(c)
263
+ !/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}\p{Cs}\p{Co}\p{Cn}]/.match?(c)
264
+ end
265
+ end
266
+ end
267
+ end
268
+ end
@@ -0,0 +1,32 @@
1
+ Copyright 2008 Google Inc. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions are
5
+ met:
6
+
7
+ * Redistributions of source code must retain the above copyright
8
+ notice, this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above
10
+ copyright notice, this list of conditions and the following disclaimer
11
+ in the documentation and/or other materials provided with the
12
+ distribution.
13
+ * Neither the name of Google Inc. nor the names of its
14
+ contributors may be used to endorse or promote products derived from
15
+ this software without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+
29
+ Code generated by the Protocol Buffer compiler is owned by the owner
30
+ of the input file used when generating it. This code is not
31
+ standalone and requires a support library to be linked with it. This
32
+ support library is itself covered by the above license.
@@ -0,0 +1,106 @@
1
+ // Protocol Buffers - Google's data interchange format
2
+ // Copyright 2008 Google Inc. All rights reserved.
3
+ // https://developers.google.com/protocol-buffers/
4
+ //
5
+ // Redistribution and use in source and binary forms, with or without
6
+ // modification, are permitted provided that the following conditions are
7
+ // met:
8
+ //
9
+ // * Redistributions of source code must retain the above copyright
10
+ // notice, this list of conditions and the following disclaimer.
11
+ // * Redistributions in binary form must reproduce the above
12
+ // copyright notice, this list of conditions and the following disclaimer
13
+ // in the documentation and/or other materials provided with the
14
+ // distribution.
15
+ // * Neither the name of Google Inc. nor the names of its
16
+ // contributors may be used to endorse or promote products derived from
17
+ // this software without specific prior written permission.
18
+ //
19
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+
31
+ syntax = "proto3";
32
+
33
+ package google.protobuf;
34
+
35
+ option go_package = "google.golang.org/protobuf/types/known/anypb";
36
+ option java_package = "com.google.protobuf";
37
+ option java_outer_classname = "AnyProto";
38
+ option java_multiple_files = true;
39
+ option objc_class_prefix = "GPB";
40
+ option csharp_namespace = "Google.Protobuf.WellKnownTypes";
41
+
42
+ // `Any` contains an arbitrary serialized protocol buffer message along with a
43
+ // URL that describes the type of the serialized message.
44
+ //
45
+ // In its binary encoding, an `Any` is an ordinary message; but in other wire
46
+ // forms like JSON, it has a special encoding. The format of the type URL is
47
+ // described on the `type_url` field.
48
+ //
49
+ // Protobuf APIs provide utilities to interact with `Any` values:
50
+ //
51
+ // - A 'pack' operation accepts a message and constructs a generic `Any` wrapper
52
+ // around it.
53
+ // - An 'unpack' operation reads the content of an `Any` message, either into an
54
+ // existing message or a new one. Unpack operations must check the type of the
55
+ // value they unpack against the declared `type_url`.
56
+ // - An 'is' operation decides whether an `Any` contains a message of the given
57
+ // type, i.e. whether it can 'unpack' that type.
58
+ //
59
+ // The JSON format representation of an `Any` follows one of these cases:
60
+ //
61
+ // - For types without special-cased JSON encodings, the JSON format
62
+ // representation of the `Any` is the same as that of the message, with an
63
+ // additional `@type` field which contains the type URL.
64
+ // - For types with special-cased JSON encodings (typically called 'well-known'
65
+ // types, listed in https://protobuf.dev/programming-guides/json/#any), the
66
+ // JSON format representation has a key `@type` which contains the type URL
67
+ // and a key `value` which contains the JSON-serialized value.
68
+ //
69
+ // The text format representation of an `Any` is like a message with one field
70
+ // whose name is the type URL in brackets. For example, an `Any` containing a
71
+ // `foo.Bar` message may be written `[type.googleapis.com/foo.Bar] { a: 2 }`.
72
+ message Any {
73
+ // Identifies the type of the serialized Protobuf message with a URI reference
74
+ // consisting of a prefix ending in a slash and the fully-qualified type name.
75
+ //
76
+ // Example: type.googleapis.com/google.protobuf.StringValue
77
+ //
78
+ // This string must contain at least one `/` character, and the content after
79
+ // the last `/` must be the fully-qualified name of the type in canonical
80
+ // form, without a leading dot. Do not write a scheme on these URI references
81
+ // so that clients do not attempt to contact them.
82
+ //
83
+ // The prefix is arbitrary and Protobuf implementations are expected to
84
+ // simply strip off everything up to and including the last `/` to identify
85
+ // the type. `type.googleapis.com/` is a common default prefix that some
86
+ // legacy implementations require. This prefix does not indicate the origin of
87
+ // the type, and URIs containing it are not expected to respond to any
88
+ // requests.
89
+ //
90
+ // All type URL strings must be legal URI references with the additional
91
+ // restriction (for the text format) that the content of the reference
92
+ // must consist only of alphanumeric characters, percent-encoded escapes, and
93
+ // characters in the following set (not including the outer backticks):
94
+ // `/-.~_!$&()*+,;=`. Despite our allowing percent encodings, implementations
95
+ // should not unescape them to prevent confusion with existing parsers. For
96
+ // example, `type.googleapis.com%2FFoo` should be rejected.
97
+ //
98
+ // In the original design of `Any`, the possibility of launching a type
99
+ // resolution service at these type URLs was considered but Protobuf never
100
+ // implemented one and considers contacting these URLs to be problematic and
101
+ // a potential security issue. Do not attempt to contact type URLs.
102
+ string type_url = 1;
103
+
104
+ // Holds a Protobuf serialization of the type described by type_url.
105
+ bytes value = 2;
106
+ }
@@ -0,0 +1,229 @@
1
+ // Protocol Buffers - Google's data interchange format
2
+ // Copyright 2008 Google Inc. All rights reserved.
3
+ // https://developers.google.com/protocol-buffers/
4
+ //
5
+ // Redistribution and use in source and binary forms, with or without
6
+ // modification, are permitted provided that the following conditions are
7
+ // met:
8
+ //
9
+ // * Redistributions of source code must retain the above copyright
10
+ // notice, this list of conditions and the following disclaimer.
11
+ // * Redistributions in binary form must reproduce the above
12
+ // copyright notice, this list of conditions and the following disclaimer
13
+ // in the documentation and/or other materials provided with the
14
+ // distribution.
15
+ // * Neither the name of Google Inc. nor the names of its
16
+ // contributors may be used to endorse or promote products derived from
17
+ // this software without specific prior written permission.
18
+ //
19
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+
31
+ syntax = "proto3";
32
+
33
+ package google.protobuf;
34
+
35
+ import "google/protobuf/source_context.proto";
36
+ import "google/protobuf/type.proto";
37
+
38
+ option java_package = "com.google.protobuf";
39
+ option java_outer_classname = "ApiProto";
40
+ option java_multiple_files = true;
41
+ option objc_class_prefix = "GPB";
42
+ option csharp_namespace = "Google.Protobuf.WellKnownTypes";
43
+ option go_package = "google.golang.org/protobuf/types/known/apipb";
44
+
45
+ // Api is a light-weight descriptor for an API Interface.
46
+ //
47
+ // Interfaces are also described as "protocol buffer services" in some contexts,
48
+ // such as by the "service" keyword in a .proto file, but they are different
49
+ // from API Services, which represent a concrete implementation of an interface
50
+ // as opposed to simply a description of methods and bindings. They are also
51
+ // sometimes simply referred to as "APIs" in other contexts, such as the name of
52
+ // this message itself. See https://cloud.google.com/apis/design/glossary for
53
+ // detailed terminology.
54
+ //
55
+ // New usages of this message as an alternative to ServiceDescriptorProto are
56
+ // strongly discouraged. This message does not reliability preserve all
57
+ // information necessary to model the schema and preserve semantics. Instead
58
+ // make use of FileDescriptorSet which preserves the necessary information.
59
+ message Api {
60
+ // The fully qualified name of this interface, including package name
61
+ // followed by the interface's simple name.
62
+ string name = 1;
63
+
64
+ // The methods of this interface, in unspecified order.
65
+ repeated Method methods = 2;
66
+
67
+ // Any metadata attached to the interface.
68
+ repeated Option options = 3;
69
+
70
+ // A version string for this interface. If specified, must have the form
71
+ // `major-version.minor-version`, as in `1.10`. If the minor version is
72
+ // omitted, it defaults to zero. If the entire version field is empty, the
73
+ // major version is derived from the package name, as outlined below. If the
74
+ // field is not empty, the version in the package name will be verified to be
75
+ // consistent with what is provided here.
76
+ //
77
+ // The versioning schema uses [semantic
78
+ // versioning](http://semver.org) where the major version number
79
+ // indicates a breaking change and the minor version an additive,
80
+ // non-breaking change. Both version numbers are signals to users
81
+ // what to expect from different versions, and should be carefully
82
+ // chosen based on the product plan.
83
+ //
84
+ // The major version is also reflected in the package name of the
85
+ // interface, which must end in `v<major-version>`, as in
86
+ // `google.feature.v1`. For major versions 0 and 1, the suffix can
87
+ // be omitted. Zero major versions must only be used for
88
+ // experimental, non-GA interfaces.
89
+ //
90
+ string version = 4;
91
+
92
+ // Source context for the protocol buffer service represented by this
93
+ // message.
94
+ SourceContext source_context = 5;
95
+
96
+ // Included interfaces. See [Mixin][].
97
+ repeated Mixin mixins = 6;
98
+
99
+ // The source syntax of the service.
100
+ Syntax syntax = 7;
101
+
102
+ // The source edition string, only valid when syntax is SYNTAX_EDITIONS.
103
+ string edition = 8;
104
+ }
105
+
106
+ // Method represents a method of an API interface.
107
+ //
108
+ // New usages of this message as an alternative to MethodDescriptorProto are
109
+ // strongly discouraged. This message does not reliability preserve all
110
+ // information necessary to model the schema and preserve semantics. Instead
111
+ // make use of FileDescriptorSet which preserves the necessary information.
112
+ message Method {
113
+ // The simple name of this method.
114
+ string name = 1;
115
+
116
+ // A URL of the input message type.
117
+ string request_type_url = 2;
118
+
119
+ // If true, the request is streamed.
120
+ bool request_streaming = 3;
121
+
122
+ // The URL of the output message type.
123
+ string response_type_url = 4;
124
+
125
+ // If true, the response is streamed.
126
+ bool response_streaming = 5;
127
+
128
+ // Any metadata attached to the method.
129
+ repeated Option options = 6;
130
+
131
+ // The source syntax of this method.
132
+ //
133
+ // This field should be ignored, instead the syntax should be inherited from
134
+ // Api. This is similar to Field and EnumValue.
135
+ Syntax syntax = 7 [deprecated = true];
136
+
137
+ // The source edition string, only valid when syntax is SYNTAX_EDITIONS.
138
+ //
139
+ // This field should be ignored, instead the edition should be inherited from
140
+ // Api. This is similar to Field and EnumValue.
141
+ string edition = 8 [deprecated = true];
142
+ }
143
+
144
+ // Declares an API Interface to be included in this interface. The including
145
+ // interface must redeclare all the methods from the included interface, but
146
+ // documentation and options are inherited as follows:
147
+ //
148
+ // - If after comment and whitespace stripping, the documentation
149
+ // string of the redeclared method is empty, it will be inherited
150
+ // from the original method.
151
+ //
152
+ // - Each annotation belonging to the service config (http,
153
+ // visibility) which is not set in the redeclared method will be
154
+ // inherited.
155
+ //
156
+ // - If an http annotation is inherited, the path pattern will be
157
+ // modified as follows. Any version prefix will be replaced by the
158
+ // version of the including interface plus the [root][] path if
159
+ // specified.
160
+ //
161
+ // Example of a simple mixin:
162
+ //
163
+ // package google.acl.v1;
164
+ // service AccessControl {
165
+ // // Get the underlying ACL object.
166
+ // rpc GetAcl(GetAclRequest) returns (Acl) {
167
+ // option (google.api.http).get = "/v1/{resource=**}:getAcl";
168
+ // }
169
+ // }
170
+ //
171
+ // package google.storage.v2;
172
+ // service Storage {
173
+ // rpc GetAcl(GetAclRequest) returns (Acl);
174
+ //
175
+ // // Get a data record.
176
+ // rpc GetData(GetDataRequest) returns (Data) {
177
+ // option (google.api.http).get = "/v2/{resource=**}";
178
+ // }
179
+ // }
180
+ //
181
+ // Example of a mixin configuration:
182
+ //
183
+ // apis:
184
+ // - name: google.storage.v2.Storage
185
+ // mixins:
186
+ // - name: google.acl.v1.AccessControl
187
+ //
188
+ // The mixin construct implies that all methods in `AccessControl` are
189
+ // also declared with same name and request/response types in
190
+ // `Storage`. A documentation generator or annotation processor will
191
+ // see the effective `Storage.GetAcl` method after inheriting
192
+ // documentation and annotations as follows:
193
+ //
194
+ // service Storage {
195
+ // // Get the underlying ACL object.
196
+ // rpc GetAcl(GetAclRequest) returns (Acl) {
197
+ // option (google.api.http).get = "/v2/{resource=**}:getAcl";
198
+ // }
199
+ // ...
200
+ // }
201
+ //
202
+ // Note how the version in the path pattern changed from `v1` to `v2`.
203
+ //
204
+ // If the `root` field in the mixin is specified, it should be a
205
+ // relative path under which inherited HTTP paths are placed. Example:
206
+ //
207
+ // apis:
208
+ // - name: google.storage.v2.Storage
209
+ // mixins:
210
+ // - name: google.acl.v1.AccessControl
211
+ // root: acls
212
+ //
213
+ // This implies the following inherited HTTP annotation:
214
+ //
215
+ // service Storage {
216
+ // // Get the underlying ACL object.
217
+ // rpc GetAcl(GetAclRequest) returns (Acl) {
218
+ // option (google.api.http).get = "/v2/acls/{resource=**}:getAcl";
219
+ // }
220
+ // ...
221
+ // }
222
+ message Mixin {
223
+ // The fully qualified name of the interface which is included.
224
+ string name = 1;
225
+
226
+ // If non-empty specifies a path under which inherited HTTP paths
227
+ // are rooted.
228
+ string root = 2;
229
+ }