Class: Protobuf::Descriptor::Descriptor
- Inherits:
-
Object
- Object
- Protobuf::Descriptor::Descriptor
- Defined in:
- lib/protobuf/descriptor/descriptor.rb
Instance Method Summary collapse
- #build(proto, opt = {}) ⇒ Object
-
#initialize(message_class) ⇒ Descriptor
constructor
A new instance of Descriptor.
- #proto_type ⇒ Object
- #unbuild(parent_proto) ⇒ Object
Constructor Details
#initialize(message_class) ⇒ Descriptor
Returns a new instance of Descriptor.
4 5 6 |
# File 'lib/protobuf/descriptor/descriptor.rb', line 4 def initialize() @message_class = end |
Instance Method Details
#build(proto, opt = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/protobuf/descriptor/descriptor.rb', line 12 def build(proto, opt={}) mod = opt[:module] cls = mod.const_set(proto.name, Class.new(@message_class)) proto.nested_type.each do || Protobuf::Message.descriptor.build(, :module => cls) end proto.enum_type.each do |enum_proto| Protobuf::Enum.descriptor.build(enum_proto, :module => cls) end proto.field.each do |field_proto| Protobuf::Field::BaseField.descriptor.build(field_proto, :class => cls) end end |
#proto_type ⇒ Object
8 9 10 |
# File 'lib/protobuf/descriptor/descriptor.rb', line 8 def proto_type 'Google::Protobuf::DescriptorProto' end |
#unbuild(parent_proto) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/protobuf/descriptor/descriptor.rb', line 26 def unbuild(parent_proto) = Google::Protobuf::DescriptorProto.new .name = @message_class.to_s.split('::').last @message_class.fields.each do |tag, field| field.descriptor.unbuild() end ObjectSpace.each_object(Class) do |cls| if innerclass?(@message_class, cls) cls.descriptor.unbuild() end end case parent_proto when Google::Protobuf::FileDescriptorProto parent_proto. << when Google::Protobuf::DescriptorProto parent_proto.nested_type << else raise TypeError, parent_proto.class.name end end |