Class: ProtobufDescriptor::FileDescriptor
- Inherits:
-
Object
- Object
- ProtobufDescriptor::FileDescriptor
- Defined in:
- lib/protobuf_descriptor/file_descriptor.rb
Overview
Describes a complete .proto file.
Instance Attribute Summary collapse
-
#enum_type ⇒ Object
(also: #enum_types)
readonly
List of the enum types that are defined at the top level of this file, as a NamedCollection of EnumDescriptor.
-
#file_descriptor_proto ⇒ Object
readonly
The
FileDescriptorProtothisFileDescriptoris wrapping. -
#file_descriptor_set ⇒ Object
(also: #parent)
readonly
The parent ProtobufDescriptor.
-
#message_type ⇒ Object
(also: #message_types, #messages)
readonly
List of the message types that are defined at the top level of this file, as a NamedCollection of MessageDescriptor.
-
#service ⇒ Object
(also: #services)
readonly
List of the services that are defined at the top level of this file, as a NamedCollection of ServiceDescriptor.
Instance Method Summary collapse
-
#children ⇒ Object
Set of all top-level messages, enums and services that are defined inside of this file.
-
#fully_qualified_java_name ⇒ Object
Returns the fully qualified Java class name.
-
#fully_qualified_name ⇒ Object
Returns the fully qualified name, as used by the
resolve_typemethods. -
#fully_qualified_ruby_name ⇒ Object
Returns the fully qualified Ruby class name as generated by various protobuf gems.
-
#fully_qualified_wire_name ⇒ Object
Returns the fully qualified Java name as Wire would generate it.
-
#initialize(file_descriptor_set, file_descriptor_proto) ⇒ FileDescriptor
constructor
:nodoc:.
-
#java_outer_classname ⇒ Object
If set, all the classes from the .proto file are wrapped in a single outer class with the given name.
-
#java_package ⇒ Object
The Java package where classes generated from this .proto will be placed.
-
#name ⇒ Object
Filename relative to root of source tree.
-
#package ⇒ Object
The package name defined by the .proto file.
Constructor Details
#initialize(file_descriptor_set, file_descriptor_proto) ⇒ FileDescriptor
:nodoc:
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 32 def initialize(file_descriptor_set, file_descriptor_proto) #:nodoc: # This is basically a parent pointer. @file_descriptor_set = file_descriptor_set @file_descriptor_proto = file_descriptor_proto @message_type = ProtobufDescriptor::NamedCollection.new( file_descriptor_proto..map { |m| ProtobufDescriptor::MessageDescriptor.new(self, m) }) @enum_type = ProtobufDescriptor::NamedCollection.new( file_descriptor_proto.enum_type.map { |m| ProtobufDescriptor::EnumDescriptor.new(self, m) }) @service = ProtobufDescriptor::NamedCollection.new( file_descriptor_proto.service.map { |m| ProtobufDescriptor::ServiceDescriptor.new(self, m) }) end |
Instance Attribute Details
#enum_type ⇒ Object (readonly) Also known as: enum_types
List of the enum types that are defined at the top level of this file, as a NamedCollection of EnumDescriptor
26 27 28 |
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 26 def enum_type @enum_type end |
#file_descriptor_proto ⇒ Object (readonly)
The FileDescriptorProto this FileDescriptor is wrapping.
18 19 20 |
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 18 def file_descriptor_proto @file_descriptor_proto end |
#file_descriptor_set ⇒ Object (readonly) Also known as: parent
The parent ProtobufDescriptor
15 16 17 |
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 15 def file_descriptor_set @file_descriptor_set end |
#message_type ⇒ Object (readonly) Also known as: message_types, messages
List of the message types that are defined at the top level of this file, as a NamedCollection of MessageDescriptor
22 23 24 |
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 22 def @message_type end |
#service ⇒ Object (readonly) Also known as: services
List of the services that are defined at the top level of this file, as a NamedCollection of ServiceDescriptor
30 31 32 |
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 30 def service @service end |
Instance Method Details
#children ⇒ Object
Set of all top-level messages, enums and services that are defined inside of this file
60 61 62 63 |
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 60 def children @children ||= ProtobufDescriptor::NamedCollection.new( @message_type.collection + @enum_type.collection + @service.collection) end |
#fully_qualified_java_name ⇒ Object
Returns the fully qualified Java class name.
110 111 112 |
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 110 def fully_qualified_java_name return [java_package, java_outer_classname].compact.join('.') end |
#fully_qualified_name ⇒ Object
Returns the fully qualified name, as used by the resolve_type methods.
105 106 107 |
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 105 def fully_qualified_name return ".#{self.package}" end |
#fully_qualified_ruby_name ⇒ Object
Returns the fully qualified Ruby class name as generated by various protobuf gems.
123 124 125 |
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 123 def fully_qualified_ruby_name return "::#{self.package.gsub('.', '::')}" end |
#fully_qualified_wire_name ⇒ Object
Returns the fully qualified Java name as Wire would generate it. Wire never wraps the definitions in a class named after the .proto file (essentially behaving as if java_outer_classname were always true)
117 118 119 |
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 117 def fully_qualified_wire_name return java_package end |
#java_outer_classname ⇒ Object
If set, all the classes from the .proto file are wrapped in a single outer class with the given name. This applies to both Proto1 (equivalent to the old “–one_java_file” option) and Proto2 (where a .proto always translates to a single class, but you may want to explicitly choose the class name).
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 92 def java_outer_classname if file_descriptor_proto.has_field?(:options) && file_descriptor_proto..java_multiple_files.present? return nil elsif file_descriptor_proto.has_field?(:options) && file_descriptor_proto..java_outer_classname.present? return file_descriptor_proto..java_outer_classname else basename = name.split('/').last basename = basename.gsub('.proto', '') return basename.camelize end end |
#java_package ⇒ Object
The Java package where classes generated from this .proto will be placed. By default, the proto package is used, but this is often inappropriate because proto packages do not normally start with backwards domain names.
79 80 81 82 83 84 85 |
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 79 def java_package if file_descriptor_proto.has_field?(:options) && file_descriptor_proto..java_package.present? return file_descriptor_proto..java_package else return file_descriptor_proto.package end end |
#name ⇒ Object
Filename relative to root of source tree.
66 67 68 |
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 66 def name file_descriptor_proto.name end |
#package ⇒ Object
The package name defined by the .proto file. E.G. “foo”, “foo.bar”, etc.
71 72 73 |
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 71 def package file_descriptor_proto.package end |