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.



620
621
622
623
# File 'lib/protocol_buffers/runtime/field.rb', line 620

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.



618
619
620
# File 'lib/protocol_buffers/runtime/field.rb', line 618

def proxy_class
  @proxy_class
end

Instance Method Details

#default_valueObject



625
626
627
# File 'lib/protocol_buffers/runtime/field.rb', line 625

def default_value
  @proxy_class.new
end

#deserialize(io) ⇒ Object



640
641
642
# File 'lib/protocol_buffers/runtime/field.rb', line 640

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.



636
637
638
# File 'lib/protocol_buffers/runtime/field.rb', line 636

def serialize(value)
  value.to_s
end

#text_format(io, value, options = nil) ⇒ Object



644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
# File 'lib/protocol_buffers/runtime/field.rb', line 644

def text_format(io, value, options = nil)
  options = options.dup
  options[:nest] ||= 0
  if options[:short]
    indent = ""
    newline = " "
  else
    indent = "  " * options[:nest]
    newline = "\n"
  end
  options[:nest] += 1

  io.write "{#{newline}"
  value.text_format(io, options)
  io.write " " if options[:short]
  io.write "#{indent}}"
end

#valid_type?(value) ⇒ Boolean

Returns:

  • (Boolean)


629
630
631
# File 'lib/protocol_buffers/runtime/field.rb', line 629

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