Class: ProtocolBuffers::Field::MessageField

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

Instance Attribute Summary

Attributes inherited from ProtocolBuffers::Field

#name, #otype, #tag

Instance Method Summary collapse

Methods included from WireFormats::LENGTH_DELIMITED

#wire_type

Methods inherited from ProtocolBuffers::Field

#add_methods_to, #check_valid, #check_value, create, #inspect_value, #repeated?

Constructor Details

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

Returns a new instance of MessageField.



524
525
526
527
# File 'lib/protocol_buffers/runtime/field.rb', line 524

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

Instance Method Details

#default_valueObject



529
530
531
# File 'lib/protocol_buffers/runtime/field.rb', line 529

def default_value
  @proxy_class.new
end

#deserialize(io) ⇒ Object



544
545
546
# File 'lib/protocol_buffers/runtime/field.rb', line 544

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.



540
541
542
# File 'lib/protocol_buffers/runtime/field.rb', line 540

def serialize(value)
  value.to_s
end

#valid_type?(value) ⇒ Boolean

Returns:

  • (Boolean)


533
534
535
# File 'lib/protocol_buffers/runtime/field.rb', line 533

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