Class: ProtobufDescriptor::FileDescriptor

Inherits:
Object
  • Object
show all
Includes:
HasChildren
Defined in:
lib/protobuf_descriptor/file_descriptor.rb

Overview

Describes a complete .proto file.

See +FileDescriptorProto+[https://code.google.com/p/protobuf/source/browse/trunk/src/google/protobuf/descriptor.proto#56]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HasChildren

#compute_source_code_info_path_component, included, #named_children

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.message_type.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_typeObject (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



20
21
22
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 20

def enum_type
  @enum_type
end

#file_descriptor_protoObject (readonly)

The +FileDescriptorProto+ this +FileDescriptor+ is wrapping.



12
13
14
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 12

def file_descriptor_proto
  @file_descriptor_proto
end

#file_descriptor_setObject (readonly) Also known as: parent

The parent ProtobufDescriptor



9
10
11
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 9

def file_descriptor_set
  @file_descriptor_set
end

#message_typeObject (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



16
17
18
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 16

def message_type
  @message_type
end

#serviceObject (readonly) Also known as: services

List of the services that are defined at the top level of this file, as a NamedCollection of ServiceDescriptor



24
25
26
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 24

def service
  @service
end

Instance Method Details

#fully_qualified_java_nameObject

Returns the fully qualified Java class name.



112
113
114
115
116
117
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 112

def fully_qualified_java_name
  return [
      present?(java_package) ? java_package : nil,
      present?(java_outer_classname) ? java_outer_classname : nil
    ].compact.join('.')
end

#fully_qualified_nameObject

Returns the fully qualified name, as used by the +resolve_type+ methods.



107
108
109
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 107

def fully_qualified_name
  return ".#{self.package}"
end

#fully_qualified_ruby_nameObject

Returns the fully qualified Ruby class name as generated by various protobuf gems.



128
129
130
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 128

def fully_qualified_ruby_name
  return "::#{self.package.gsub('.', '::')}"
end

#fully_qualified_wire_nameObject

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)



122
123
124
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 122

def fully_qualified_wire_name
  return java_package
end

#has_source_code_info?Boolean

Whether source code info is associated with this descriptor

Returns:

  • (Boolean)


59
60
61
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 59

def has_source_code_info?
  file_descriptor_proto.has_field?(:source_code_info)
end

#java_outer_classnameObject

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).



94
95
96
97
98
99
100
101
102
103
104
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 94

def java_outer_classname
  if file_descriptor_proto.has_field?(:options) && present?(file_descriptor_proto.options.java_multiple_files)
    return nil
  elsif file_descriptor_proto.has_field?(:options) && present?(file_descriptor_proto.options.java_outer_classname)
    return file_descriptor_proto.options.java_outer_classname
  else
    basename = name.split('/').last
    basename = basename.gsub('.proto', '')
    return camelize(basename)
  end
end

#java_packageObject

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.



81
82
83
84
85
86
87
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 81

def java_package
  if file_descriptor_proto.has_field?(:options) && present?(file_descriptor_proto.options.java_package)
    return file_descriptor_proto.options.java_package
  else
    return file_descriptor_proto.package
  end
end

#nameObject

Filename relative to root of source tree.



68
69
70
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 68

def name
  file_descriptor_proto.name
end

#packageObject

The package name defined by the .proto file. E.G. "foo", "foo.bar", etc.



73
74
75
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 73

def package
  file_descriptor_proto.package
end

#source_code_infoObject



63
64
65
# File 'lib/protobuf_descriptor/file_descriptor.rb', line 63

def source_code_info
  file_descriptor_proto.source_code_info
end