Class: ProtobufDescriptor::FileDescriptor
- Inherits:
-
Object
- Object
- ProtobufDescriptor::FileDescriptor
- Defined in:
- lib/protobuf_descriptor/file_descriptor.rb
Overview
Describes a complete .proto file.
See href="https://code.google.com/p/protobuf/source/browse/trunk/src/google/protobuf/descriptor.proto#56">
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 EnumDescriptors.
-
#file_descriptor_proto ⇒ Object
readonly
The
FileDescriptorProto
thisFileDescriptor
is wrapping. -
#file_descriptor_set ⇒ Object
(also: #parent)
readonly
The parent FileDescriptorSet.
-
#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 MessageDescriptors.
-
#service ⇒ Object
(also: #services)
readonly
List of the services that are defined at the top level of this file, as a NamedCollection of ServiceDescriptors.
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_type
methods. -
#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:
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 35 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 EnumDescriptors
28 29 30 |
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 28 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 FileDescriptorSet
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 MessageDescriptors
23 24 25 |
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 23 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 ServiceDescriptors
33 34 35 |
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 33 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
63 64 65 66 |
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 63 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.
113 114 115 |
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 113 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.
108 109 110 |
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 108 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.
126 127 128 |
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 126 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)
120 121 122 |
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 120 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).
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 95 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.
82 83 84 85 86 87 88 |
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 82 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.
69 70 71 |
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 69 def name file_descriptor_proto.name end |
#package ⇒ Object
The package name defined by the .proto file. E.G. “foo”, “foo.bar”, etc.
74 75 76 |
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 74 def package file_descriptor_proto.package end |