Class: Protobuf::Field::MessageField

Inherits:
BaseField
  • Object
show all
Defined in:
lib/protobuf/message/field.rb

Instance Attribute Summary

Attributes inherited from BaseField

#default, #default_value, #message_class, #name, #rule, #tag, #type

Instance Method Summary collapse

Methods inherited from BaseField

default, descriptor, #descriptor, #initialize, #initialized?, #max, #merge, #min, #optional?, #packed?, #ready?, #repeated?, #required?, #set, #to_s

Constructor Details

This class inherits a constructor from Protobuf::Field::BaseField

Instance Method Details

#acceptable?(val) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (TypeError)


604
605
606
607
# File 'lib/protobuf/message/field.rb', line 604

def acceptable?(val)
  raise TypeError unless val.instance_of?(type) || val.instance_of?(Hash)
  true
end

#decode(bytes) ⇒ Object



609
610
611
612
613
# File 'lib/protobuf/message/field.rb', line 609

def decode(bytes)
  message = type.new
  message.parse_from_string(bytes)
  message
end

#encode(value) ⇒ Object



615
616
617
618
619
# File 'lib/protobuf/message/field.rb', line 615

def encode(value)
  bytes = value.serialize_to_string
  result = VarintField.encode(bytes.size)
  result << bytes
end

#wire_typeObject



600
601
602
# File 'lib/protobuf/message/field.rb', line 600

def wire_type
  WireType::LENGTH_DELIMITED
end