Class: Protobuf::Field::MessageField
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
Instance Method Details
#acceptable?(val) ⇒ Boolean
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
|