Class: Protobuf::Field::BytesField
Overview
Field class for +bytes+ type.
Instance Attribute Summary
Attributes inherited from BaseField
#default, #default_value, #message_class, #name, #rule, #tag, #type
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from BaseField
descriptor, #descriptor, #initialize, #initialized?, #max, #merge, #min, #optional?, #packed?, #ready?, #repeated?, #required?, #set, #to_s
Class Method Details
.default ⇒ Object
327
328
329
|
# File 'lib/protobuf/message/field.rb', line 327
def self.default
''
end
|
Instance Method Details
#acceptable?(val) ⇒ Boolean
335
336
337
338
|
# File 'lib/protobuf/message/field.rb', line 335
def acceptable?(val)
raise TypeError unless val.instance_of?(String)
true
end
|
#decode(bytes) ⇒ Object
340
341
342
343
|
# File 'lib/protobuf/message/field.rb', line 340
def decode(bytes)
bytes.force_encoding('ASCII-8BIT') if bytes.respond_to?(:force_encoding)
bytes
end
|
#encode(value) ⇒ Object
345
346
347
348
349
350
|
# File 'lib/protobuf/message/field.rb', line 345
def encode(value)
value = value.dup
value.force_encoding('ASCII-8BIT') if value.respond_to?(:force_encoding)
string_size = VarintField.encode(value.size)
string_size << value
end
|