Class: ProtocolBuffers::Field::AggregateField

Inherits:
ProtocolBuffers::Field show all
Defined in:
lib/protocol_buffers/runtime/field.rb

Direct Known Subclasses

GroupField, MessageField

Instance Attribute Summary collapse

Attributes inherited from ProtocolBuffers::Field

#name, #otype, #tag

Instance Method Summary collapse

Methods inherited from ProtocolBuffers::Field

#add_methods_to, #add_reader_to, #add_writer_to, #check_valid, #check_value, create, #inspect_value, #packed?, #repeated?

Constructor Details

#initialize(proxy_class, otype, name, tag, opts = {}) ⇒ AggregateField

Returns a new instance of AggregateField.



588
589
590
591
# File 'lib/protocol_buffers/runtime/field.rb', line 588

def initialize(proxy_class, otype, name, tag, opts = {})
  super(otype, name, tag, opts)
  @proxy_class = proxy_class
end

Instance Attribute Details

#proxy_classObject (readonly)

Returns the value of attribute proxy_class.



586
587
588
# File 'lib/protocol_buffers/runtime/field.rb', line 586

def proxy_class
  @proxy_class
end

Instance Method Details

#default_valueObject



593
594
595
# File 'lib/protocol_buffers/runtime/field.rb', line 593

def default_value
  @proxy_class.new
end

#deserialize(io) ⇒ Object



608
609
610
# File 'lib/protocol_buffers/runtime/field.rb', line 608

def deserialize(io)
  @proxy_class.parse(io)
end

#serialize(value) ⇒ Object

TODO: serialize could be more efficient if it used the underlying stream directly rather than string copying, but that would require knowing the length beforehand.



604
605
606
# File 'lib/protocol_buffers/runtime/field.rb', line 604

def serialize(value)
  value.to_s
end

#valid_type?(value) ⇒ Boolean

Returns:

  • (Boolean)


597
598
599
# File 'lib/protocol_buffers/runtime/field.rb', line 597

def valid_type?(value)
  value.is_a?(@proxy_class)
end