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.



537
538
539
540
# File 'lib/protocol_buffers/runtime/field.rb', line 537

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

Instance Method Details

#default_valueObject



542
543
544
# File 'lib/protocol_buffers/runtime/field.rb', line 542

def default_value
  @proxy_class.new
end

#deserialize(io) ⇒ Object



557
558
559
# File 'lib/protocol_buffers/runtime/field.rb', line 557

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.



553
554
555
# File 'lib/protocol_buffers/runtime/field.rb', line 553

def serialize(value)
  value.to_s
end

#valid_type?(value) ⇒ Boolean

Returns:

  • (Boolean)


546
547
548
# File 'lib/protocol_buffers/runtime/field.rb', line 546

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