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.



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

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.



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

def proxy_class
  @proxy_class
end

Instance Method Details

#default_valueObject



599
600
601
# File 'lib/protocol_buffers/runtime/field.rb', line 599

def default_value
  @proxy_class.new
end

#deserialize(io) ⇒ Object



614
615
616
# File 'lib/protocol_buffers/runtime/field.rb', line 614

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.



610
611
612
# File 'lib/protocol_buffers/runtime/field.rb', line 610

def serialize(value)
  value.to_s
end

#valid_type?(value) ⇒ Boolean

Returns:

  • (Boolean)


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

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