protobuf_descriptor 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.travis.yml +6 -0
  4. data/.yardopts +1 -1
  5. data/ChangeLog.rdoc +12 -0
  6. data/README.md +61 -0
  7. data/Rakefile +114 -0
  8. data/lib/protobuf_descriptor/enum_descriptor.rb +17 -11
  9. data/lib/protobuf_descriptor/enum_value_descriptor.rb +29 -0
  10. data/lib/protobuf_descriptor/field_descriptor.rb +80 -0
  11. data/lib/protobuf_descriptor/file_descriptor.rb +37 -17
  12. data/lib/protobuf_descriptor/has_children.rb +49 -0
  13. data/lib/protobuf_descriptor/has_parent.rb +42 -0
  14. data/lib/protobuf_descriptor/message_descriptor.rb +20 -104
  15. data/lib/protobuf_descriptor/method_descriptor.rb +54 -0
  16. data/lib/protobuf_descriptor/named_child.rb +7 -0
  17. data/lib/protobuf_descriptor/service_descriptor.rb +9 -61
  18. data/lib/protobuf_descriptor/version.rb +1 -1
  19. data/lib/protobuf_descriptor.rb +20 -5
  20. data/protobuf_descriptor.gemspec +3 -2
  21. data/spec/field_descriptor_spec.rb +1 -1
  22. data/spec/file_descriptor_spec.rb +0 -1
  23. data/spec/method_descriptor_spec.rb +1 -1
  24. data/spec/protobuf_descriptor_spec.rb +3 -3
  25. data/spec/protoc_generator_spec.rb +6 -9
  26. data/spec/protos/custom_options/custom_options.proto +53 -0
  27. data/spec/protos/custom_options/google/protobuf/descriptor.proto +620 -0
  28. data/spec/protos/custom_options.desc +0 -0
  29. data/spec/protos/custom_options.java.zip +0 -0
  30. data/spec/protos/custom_options.wire.zip +0 -0
  31. data/spec/protos/generator_test.desc +24 -0
  32. data/spec/protos/generator_test.java.zip +0 -0
  33. data/spec/protos/generator_test.wire.zip +0 -0
  34. data/spec/protos/service_rpc_test.desc +71 -0
  35. data/spec/protos/service_rpc_test.java.zip +0 -0
  36. data/spec/protos/service_rpc_test.wire.zip +0 -0
  37. data/spec/protos/single_file_test.desc +0 -0
  38. data/spec/protos/single_file_test.java.zip +0 -0
  39. data/spec/protos/single_file_test.wire.zip +0 -0
  40. data/spec/protos/source_info/foo.proto +59 -0
  41. data/spec/protos/source_info.desc +22 -0
  42. data/spec/protos/source_info.java.zip +0 -0
  43. data/spec/protos/source_info.srcinfo.desc +0 -0
  44. data/spec/protos/source_info.wire.zip +0 -0
  45. data/spec/service_descriptor_spec.rb +1 -1
  46. data/spec/source_code_info_spec.rb +57 -0
  47. data/spec/spec_helper.rb +29 -57
  48. data/spec/wire_generator_spec.rb +6 -11
  49. metadata +69 -11
  50. data/Gemfile.lock +0 -58
  51. data/README.rdoc +0 -51
@@ -1,94 +1,11 @@
1
- require "protobuf_descriptor/enum_descriptor"
2
- require "protobuf_descriptor/has_parent"
3
- require "protobuf_descriptor/named_child"
4
- require "protobuf_descriptor/named_collection"
5
-
6
- require "active_support"
7
- require "active_support/core_ext/module/delegation"
8
-
9
1
  class ProtobufDescriptor
10
2
  # Describes a message type.
11
3
  #
12
4
  # See DescriptorProto[https://code.google.com/p/protobuf/source/browse/trunk/src/google/protobuf/descriptor.proto#84]
13
5
  class MessageDescriptor
14
- # Describes a field within a message.
15
- #
16
- # See FieldDescriptorProto[https://code.google.com/p/protobuf/source/browse/trunk/src/google/protobuf/descriptor.proto#103]
17
- class FieldDescriptor
18
- # The parent {ProtobufDescriptor::MessageDescriptor}
19
- attr_reader :parent
20
- # The +FieldDescriptorProto+ this +FieldDescriptor+ is wrapping.
21
- attr_reader :field_descriptor_proto
22
-
23
- def initialize(parent, field_descriptor_proto)
24
- @parent = parent
25
- @field_descriptor_proto = field_descriptor_proto
26
- end
27
-
28
- # The +FieldOptions+ for this field
29
- def options
30
- field_descriptor_proto.options
31
- end
32
-
33
- # Default value for this field.
34
- # * For numeric types, contains the original text representation of the
35
- # value.
36
- # * For booleans, "true" or "false".
37
- # * For strings, contains the default text contents (not escaped in any
38
- # way).
39
- # * For bytes, contains the C escaped value. All bytes >= 128 are
40
- # escaped.
41
- def default_value
42
- field_descriptor_proto.default_value
43
- end
44
-
45
- # For extensions, this is the name of the type being extended. It is
46
- # resolved in the same manner as type_name.
47
- def extendee
48
- field_descriptor_proto.extendee
49
- end
50
-
51
- # For message and enum types, this is the name of the type. If the name
52
- # starts with a '.', it is fully-qualified. Otherwise, C++-like scoping
53
- # rules are used to find the type (i.e. first the nested types within this
54
- # message are searched, then within the parent, on up to the root
55
- # namespace).
56
- #
57
- # Note: the protocol buffer compiler always emits the fully qualified name!
58
- def type_name
59
- field_descriptor_proto.type_name
60
- end
61
-
62
- # Whether the field is optional/required/repeated.
63
- def label
64
- field_descriptor_proto.label
65
- end
66
-
67
- # The tag number of this field.
68
- def number
69
- field_descriptor_proto.number
70
- end
71
-
72
- # The name of this field.
73
- def name
74
- field_descriptor_proto.name
75
- end
76
-
77
- include ProtobufDescriptor::HasParent
78
-
79
- # If type_name is set, this need not be set. If both this and type_name
80
- # are set, this must be either TYPE_ENUM or TYPE_MESSAGE.
81
- def field_type
82
- field_descriptor_proto.type
83
- end
84
-
85
- # Resolves the field's +type_name+, returning the
86
- # {ProtobufDescriptor::MessageDescriptor} or
87
- # {ProtobufDescriptor::EnumDescriptor} that this field will represent.
88
- def resolve_type
89
- protobuf_descriptor.resolve_type_name(self.type_name, self.parent)
90
- end
91
- end
6
+ include ProtobufDescriptor::HasParent
7
+ include ProtobufDescriptor::NamedChild
8
+ include ProtobufDescriptor::HasChildren
92
9
 
93
10
  # The containing {ProtobufDescriptor::FileDescriptor}
94
11
  # or {ProtobufDescriptor::MessageDescriptor} that
@@ -101,29 +18,43 @@ class ProtobufDescriptor
101
18
  # The messages that are defined at the top level of this message, as a
102
19
  # NamedCollection of {ProtobufDescriptor::MessageDescriptor}
103
20
  attr_reader :nested_type
21
+ alias_method :nested_types, :nested_type
22
+ alias_method :messages, :nested_type
104
23
 
105
24
  # The enums that are defined at the top level of this message, as a
106
25
  # NamedCollection of {ProtobufDescriptor::EnumDescriptor}
107
26
  attr_reader :enum_type
27
+ alias_method :enum_types, :enum_type
28
+ alias_method :enums, :enum_type
108
29
 
109
30
  # The fields of this message, as a NamedCollection of
110
31
  # {ProtobufDescriptor::MessageDescriptor::FieldDescriptor}
111
32
  attr_reader :field
33
+ alias_method :fields, :field
34
+
35
+ # Field index is hard-coded since these are a bit annoying to grab
36
+ # consistently with the different protocol buffer implementations.
37
+ self.register_children(:field, 2)
38
+ self.register_children(:nested_type, 3)
39
+ self.register_children(:enum_type, 4)
112
40
 
113
41
  def initialize(parent, message_descriptor_proto)
114
42
  @parent = parent
115
43
  @message_descriptor_proto = message_descriptor_proto
44
+
116
45
  @nested_type = ProtobufDescriptor::NamedCollection.new(
117
46
  message_descriptor_proto.nested_type.map { |m|
118
47
  ProtobufDescriptor::MessageDescriptor.new(self, m)
119
48
  })
49
+
120
50
  @enum_type = ProtobufDescriptor::NamedCollection.new(
121
51
  message_descriptor_proto.enum_type.map { |m|
122
52
  ProtobufDescriptor::EnumDescriptor.new(self, m)
123
53
  })
54
+
124
55
  @field = ProtobufDescriptor::NamedCollection.new(
125
56
  message_descriptor_proto.field.map { |m|
126
- ProtobufDescriptor::MessageDescriptor::FieldDescriptor.new(self, m)
57
+ ProtobufDescriptor::FieldDescriptor.new(self, m)
127
58
  })
128
59
  end
129
60
 
@@ -136,32 +67,17 @@ class ProtobufDescriptor
136
67
  def extension_range
137
68
  message_descriptor_proto.extension_range
138
69
  end
70
+ alias_method :extension_ranges, :extension_range
139
71
 
140
72
  # The extensions defined for this message
141
73
  def extension
142
74
  message_descriptor_proto.extension
143
75
  end
76
+ alias_method :extensions, :extension
144
77
 
145
78
  # The name of the message
146
79
  def name
147
80
  message_descriptor_proto.name
148
81
  end
149
-
150
- alias_method :fields, :field
151
- alias_method :extensions, :extension
152
- alias_method :nested_types, :nested_type
153
- alias_method :messages, :nested_type
154
- alias_method :enum_types, :enum_type
155
- alias_method :enums, :enum_type
156
- alias_method :extension_ranges, :extension_range
157
-
158
- include ProtobufDescriptor::NamedChild
159
-
160
- # Set of all top-level messages ahnd enums that are defined within this
161
- # message.
162
- def children
163
- @children ||= ProtobufDescriptor::NamedCollection.new(
164
- @nested_type.collection + @enum_type.collection)
165
- end
166
82
  end
167
83
  end
@@ -0,0 +1,54 @@
1
+ class ProtobufDescriptor
2
+ # Describes a method of a service.
3
+ #
4
+ # See MethodDescriptorProto[https://code.google.com/p/protobuf/source/browse/trunk/src/google/protobuf/descriptor.proto#196]
5
+ class MethodDescriptor
6
+ include ProtobufDescriptor::HasParent
7
+
8
+ # The parent {ProtobufDescriptor::ServiceDescriptor}
9
+ attr_reader :parent
10
+
11
+ # The +MethodDescriptorProto+ this +MethodDescriptor+ is wrapping
12
+ attr_reader :method_descriptor_proto
13
+
14
+ def initialize(parent, method_descriptor_proto)
15
+ @parent = parent
16
+ @method_descriptor_proto = method_descriptor_proto
17
+ end
18
+
19
+ # The name of the service method
20
+ def name
21
+ method_descriptor_proto.name
22
+ end
23
+
24
+ # The +MethodOptions+ for the service method
25
+ def options
26
+ method_descriptor_proto.options
27
+ end
28
+
29
+ # Input type name for the service method. This is resolved in the same way
30
+ # as FieldDescriptorProto.type_name, but must refer to a message type.
31
+ def input_type_name
32
+ method_descriptor_proto.input_type
33
+ end
34
+
35
+ # Output type name for the service method. This is resolved in the same way
36
+ # as FieldDescriptorProto.type_name, but must refer to a message type.
37
+ def output_type_name
38
+ method_descriptor_proto.output_type
39
+ end
40
+
41
+ # Resolves the method's +input_type_name+, returning the
42
+ # {ProtobufDescriptor::MessageDescriptor} that this method receives.
43
+ def resolve_input_type
44
+ protobuf_descriptor.resolve_type_name(input_type_name, file_descriptor)
45
+ end
46
+
47
+ # Resolves the method's +output_type_name+, returning the
48
+ # {ProtobufDescriptor::MessageDescriptor} that this method
49
+ # returns.
50
+ def resolve_output_type
51
+ protobuf_descriptor.resolve_type_name(output_type_name, file_descriptor)
52
+ end
53
+ end
54
+ end
@@ -1,6 +1,8 @@
1
1
  class ProtobufDescriptor
2
2
  # A mixin module that adds tasty fully qualified name methods to objects that
3
3
  # have a name and a parent.
4
+ #
5
+ # Classes including this module *must* respond_to `name` and `parent`
4
6
  module NamedChild
5
7
  def fully_qualified_name
6
8
  return "#{parent.fully_qualified_name}.#{self.name}"
@@ -17,5 +19,10 @@ class ProtobufDescriptor
17
19
  def fully_qualified_ruby_name
18
20
  return "#{parent.fully_qualified_ruby_name}::#{self.name}"
19
21
  end
22
+
23
+ def inspect
24
+ oid = (object_id << 1)
25
+ return "#<%s:0x%x %s>" % [self.class, oid, self.fully_qualified_name]
26
+ end
20
27
  end
21
28
  end
@@ -1,66 +1,11 @@
1
- require "protobuf_descriptor/named_collection"
2
- require "protobuf_descriptor/has_parent"
3
-
4
- require "active_support"
5
- require "active_support/core_ext/module/delegation"
6
-
7
1
  class ProtobufDescriptor
8
2
  # Describes a service.
9
3
  #
10
4
  # See ServiceDescriptorProto[https://code.google.com/p/protobuf/source/browse/trunk/src/google/protobuf/descriptor.proto#188]
11
5
  class ServiceDescriptor
12
- # Describes a method of a service.
13
- #
14
- # See MethodDescriptorProto[https://code.google.com/p/protobuf/source/browse/trunk/src/google/protobuf/descriptor.proto#196]
15
- class MethodDescriptor
16
- # The parent {ProtobufDescriptor::ServiceDescriptor}
17
- attr_reader :parent
18
-
19
- # The +MethodDescriptorProto+ this +MethodDescriptor+ is wrapping
20
- attr_reader :method_descriptor_proto
21
-
22
- def initialize(parent, method_descriptor_proto)
23
- @parent = parent
24
- @method_descriptor_proto = method_descriptor_proto
25
- end
26
-
27
- include ProtobufDescriptor::HasParent
28
-
29
- # The name of the service method
30
- def name
31
- method_descriptor_proto.name
32
- end
33
-
34
- # The +MethodOptions+ for the service method
35
- def options
36
- method_descriptor_proto.options
37
- end
38
-
39
- # Input type name for the service method. This is resolved in the same way
40
- # as FieldDescriptorProto.type_name, but must refer to a message type.
41
- def input_type_name
42
- method_descriptor_proto.input_type
43
- end
44
-
45
- # Output type name for the service method. This is resolved in the same way
46
- # as FieldDescriptorProto.type_name, but must refer to a message type.
47
- def output_type_name
48
- method_descriptor_proto.output_type
49
- end
50
-
51
- # Resolves the method's +input_type_name+, returning the
52
- # {ProtobufDescriptor::MessageDescriptor} that this method receives.
53
- def resolve_input_type
54
- protobuf_descriptor.resolve_type_name(input_type_name, file_descriptor)
55
- end
56
-
57
- # Resolves the method's +output_type_name+, returning the
58
- # {ProtobufDescriptor::MessageDescriptor} that this method
59
- # returns.
60
- def resolve_output_type
61
- protobuf_descriptor.resolve_type_name(output_type_name, file_descriptor)
62
- end
63
- end
6
+ include ProtobufDescriptor::HasParent
7
+ include ProtobufDescriptor::NamedChild
8
+ include ProtobufDescriptor::HasChildren
64
9
 
65
10
  # The parent {ProtobufDescriptor::FileDescriptor}
66
11
  attr_reader :parent
@@ -71,23 +16,26 @@ class ProtobufDescriptor
71
16
  # Set of methods contained within this service, as a NamedCollection of
72
17
  # {ProtobufDescriptor::ServiceDescriptor::MethodDescriptor MethodDescriptors}
73
18
  attr_reader :method
19
+ alias_method :methods, :method
20
+
21
+ # Field index is hard-coded since these are a bit annoying to grab
22
+ # consistently with the different protocol buffer implementations.
23
+ self.register_children(:method, 2)
74
24
 
75
25
  def initialize(parent, service_descriptor_proto)
76
26
  @parent = parent
77
27
  @service_descriptor_proto = service_descriptor_proto
78
28
  @method = ProtobufDescriptor::NamedCollection.new(
79
29
  service_descriptor_proto.method.map { |m|
80
- ProtobufDescriptor::ServiceDescriptor::MethodDescriptor.new(self, m)
30
+ ProtobufDescriptor::MethodDescriptor.new(self, m)
81
31
  })
82
32
  end
83
33
 
84
-
85
34
  # The name of the service
86
35
  def name; service_descriptor_proto.name; end
87
36
 
88
37
  # The +ServiceOptions+ for this service.
89
38
  def options; service_descriptor_proto.options; end
90
39
 
91
- alias_method :methods, :method
92
40
  end
93
41
  end
@@ -1,4 +1,4 @@
1
1
  class ProtobufDescriptor
2
2
  # protobuf_descriptor version
3
- VERSION = "1.0.0"
3
+ VERSION = "1.1.0"
4
4
  end
@@ -1,7 +1,4 @@
1
1
  require "protobuf_descriptor/version"
2
- require "protobuf_descriptor/file_descriptor"
3
- require "protobuf_descriptor/message_descriptor"
4
- require "protobuf_descriptor/named_collection"
5
2
 
6
3
  require "stringio"
7
4
  require "protobuf"
@@ -11,6 +8,19 @@ require "protobuf/descriptors/google/protobuf/descriptor.pb.rb"
11
8
  # {+FileDescriptorSet+}[https://code.google.com/p/protobuf/source/browse/trunk/src/google/protobuf/descriptor.proto#49]
12
9
  # proto. This acts as the root from which name resolution occurs.
13
10
  class ProtobufDescriptor
11
+ autoload :EnumDescriptor, "protobuf_descriptor/enum_descriptor"
12
+ autoload :EnumValueDescriptor, "protobuf_descriptor/enum_value_descriptor"
13
+ autoload :FieldDescriptor, "protobuf_descriptor/field_descriptor"
14
+ autoload :FileDescriptor, "protobuf_descriptor/file_descriptor"
15
+ autoload :MethodDescriptor, "protobuf_descriptor/method_descriptor"
16
+ autoload :MessageDescriptor, "protobuf_descriptor/message_descriptor"
17
+ autoload :ServiceDescriptor, "protobuf_descriptor/service_descriptor"
18
+
19
+ autoload :HasParent, "protobuf_descriptor/has_parent"
20
+ autoload :HasChildren, "protobuf_descriptor/has_children"
21
+ autoload :NamedChild, "protobuf_descriptor/named_child"
22
+ autoload :NamedCollection, "protobuf_descriptor/named_collection"
23
+
14
24
  # Decode a ProtobufDescriptor from bytes
15
25
  #
16
26
  # ProtobufDescriptor.decode(File.read("descriptor.desc"))
@@ -56,10 +66,10 @@ class ProtobufDescriptor
56
66
  seeds = files.to_a.dup
57
67
  children = Set.new
58
68
  while !seeds.empty?
59
- seeds.pop.children.each do |child|
69
+ seeds.pop.named_children.each do |child|
60
70
  children << child
61
71
 
62
- seeds << child if child.respond_to?(:children)
72
+ seeds << child if child.is_a?(HasChildren)
63
73
  end
64
74
  end
65
75
  children
@@ -93,4 +103,9 @@ class ProtobufDescriptor
93
103
  def [](index)
94
104
  return files[index]
95
105
  end
106
+
107
+ # Returns whether all files have source code info attached
108
+ def has_source_code_info?
109
+ return files.all? { |f| f.has_source_code_info? }
110
+ end
96
111
  end
@@ -18,10 +18,11 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ['lib']
19
19
 
20
20
  gem.add_dependency 'protobuf', '~> 3.0.0'
21
- gem.add_dependency 'activesupport', '>= 3.0.0'
21
+ gem.add_dependency 'rubyzip', '~> 1.1.3'
22
22
 
23
+ gem.add_development_dependency 'rake', '~> 10.3'
23
24
  gem.add_development_dependency 'pry', '~> 0.9.12.6'
24
- gem.add_development_dependency 'rspec', '~> 2.4'
25
+ gem.add_development_dependency 'rspec', '~> 3.0.0.beta2'
25
26
  gem.add_development_dependency 'rubygems-tasks', '~> 0.2'
26
27
  gem.add_development_dependency 'yard', '~> 0.8'
27
28
  end
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- describe ProtobufDescriptor::MessageDescriptor::FieldDescriptor do
3
+ describe ProtobufDescriptor::FieldDescriptor do
4
4
  describe "#type_name" do
5
5
  it "is sane" do
6
6
  with_descriptor("single_file_test") do |descriptor|
@@ -4,7 +4,6 @@ describe ProtobufDescriptor::FileDescriptor do
4
4
  describe "#files" do
5
5
  it "has the right size" do
6
6
  with_descriptor("single_file_test") do |descriptor|
7
- expect(descriptor.files).to have(1).items
8
7
  expect(descriptor.files.size).to eq(1)
9
8
  end
10
9
  end
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- describe ProtobufDescriptor::ServiceDescriptor::MethodDescriptor do
3
+ describe ProtobufDescriptor::MethodDescriptor do
4
4
  it "is sane" do
5
5
  with_descriptor("service_rpc_test") do |descriptor|
6
6
  file_descriptor = descriptor["wearabouts_api/user"]
@@ -45,7 +45,7 @@ describe ProtobufDescriptor do
45
45
 
46
46
  descriptor = ProtobufDescriptor.load(f.path)
47
47
 
48
- expect(descriptor.files).to have(1).item
48
+ expect(descriptor.files.size).to eq(1)
49
49
  end
50
50
  end
51
51
  end
@@ -56,7 +56,7 @@ describe ProtobufDescriptor do
56
56
 
57
57
  descriptor = ProtobufDescriptor.decode_from(f)
58
58
 
59
- expect(descriptor.files).to have(1).item
59
+ expect(descriptor.files.size).to eq(1)
60
60
  end
61
61
  end
62
62
  end
@@ -67,7 +67,7 @@ describe ProtobufDescriptor do
67
67
 
68
68
  descriptor = ProtobufDescriptor.decode(f.read)
69
69
 
70
- expect(descriptor.files).to have(1).item
70
+ expect(descriptor.files.size).to eq(1)
71
71
  end
72
72
  end
73
73
  end
@@ -5,16 +5,13 @@ describe "ProtocJavaCompiler" do
5
5
  # Compile the contents of the generator_tests proto dir, and then assert
6
6
  # everything is where it should be.
7
7
  it "computes fully-qualified class names correctly" do
8
- Dir.mktmpdir do |dir|
9
- with_descriptor("generator_test", plugin: "java", plugin_out: dir) do |descriptor|
10
- generated_classes = ghetto_parse_java_package(dir)
8
+ with_descriptor("generator_test") do |descriptor|
9
+ generated_classes = ghetto_parse_java_package(find_generated_files("generator_test", :java))
11
10
 
12
- children = descriptor.all_descendants
13
-
14
- children.each do |child|
15
- expect(child.fully_qualified_java_name).to eq(generated_classes[child.name])
16
- end
17
- end
11
+ children = descriptor.all_descendants.map { |child|
12
+ [child.name, child.fully_qualified_java_name]
13
+ }
14
+ expect(children).to contain_exactly(*generated_classes.to_a)
18
15
  end
19
16
  end
20
17
  end
@@ -0,0 +1,53 @@
1
+ import "google/protobuf/descriptor.proto";
2
+
3
+ extend google.protobuf.FileOptions {
4
+ optional string my_file_option = 50000;
5
+ }
6
+ extend google.protobuf.MessageOptions {
7
+ optional int32 my_message_option = 50001;
8
+ }
9
+ extend google.protobuf.FieldOptions {
10
+ optional float my_field_option = 50002;
11
+ }
12
+ extend google.protobuf.EnumOptions {
13
+ optional bool my_enum_option = 50003;
14
+ }
15
+ extend google.protobuf.EnumValueOptions {
16
+ optional uint32 my_enum_value_option = 50004;
17
+ }
18
+ extend google.protobuf.ServiceOptions {
19
+ optional MyEnum my_service_option = 50005;
20
+ }
21
+ extend google.protobuf.MethodOptions {
22
+ optional MyMessage my_method_option = 50006;
23
+ }
24
+
25
+ option (my_file_option) = "Hello world!";
26
+
27
+ message MyMessage {
28
+ option (my_message_option) = 1234;
29
+
30
+ optional int32 foo = 1 [(my_field_option) = 4.5];
31
+ optional string bar = 2;
32
+ }
33
+
34
+ enum MyEnum {
35
+ option (my_enum_option) = true;
36
+
37
+ FOO = 1 [(my_enum_value_option) = 321];
38
+ BAR = 2;
39
+ }
40
+
41
+ message RequestType {}
42
+ message ResponseType {}
43
+
44
+ service MyService {
45
+ option (my_service_option) = FOO;
46
+
47
+ rpc MyMethod(RequestType) returns(ResponseType) {
48
+ // Note: my_method_option has type MyMessage. We can set each field
49
+ // within it using a separate "option" line.
50
+ option (my_method_option).foo = 567;
51
+ option (my_method_option).bar = "Some string";
52
+ }
53
+ }