Class: Protobuf::Descriptor::FileDescriptor

Inherits:
Object
  • Object
show all
Defined in:
lib/protobuf/descriptor/file_descriptor.rb

Class Method Summary collapse

Class Method Details

.build(proto, opt = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/protobuf/descriptor/file_descriptor.rb', line 9

def build(proto, opt={})
  mod = Object
  if package = proto.package and not package.empty?
    module_names = package.split '::'
    module_names.each do |module_name|
      mod = mod.const_set module_name, Module.new
    end
  end
  proto.message_type.each do |message_proto|
    Protobuf::Message.descriptor.build message_proto, :module => mod
  end
  proto.enum_type.each do |enum_proto|
    Protobuf::Enum.descriptor.build enum_proto, :module => mod
  end
end

.proto_typeObject



5
6
7
# File 'lib/protobuf/descriptor/file_descriptor.rb', line 5

def proto_type
  'Google::Protobuf::FileDescriptorProto'
end

.unbuild(messages) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/protobuf/descriptor/file_descriptor.rb', line 25

def unbuild(messages)
  messages = [messages] unless messages.is_a? Array
  proto = Google::Protobuf::FileDescriptorProto.new
  proto.package = messages.first.to_s.split('::')[0..-2].join('::') if messages.first.to_s =~ /::/
  messages.each do |message|
    message.descriptor.unbuild proto
  end
  proto
end