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



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

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.



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

def proxy_class
  @proxy_class
end

Instance Method Details

#default_valueObject



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

def default_value
  @proxy_class.new
end

#deserialize(io) ⇒ Object



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

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.



606
607
608
# File 'lib/protocol_buffers/runtime/field.rb', line 606

def serialize(value)
  value.to_s
end

#valid_type?(value) ⇒ Boolean



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

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