Class: Protobuf::Field::BytesField
Instance Attribute Summary
Attributes inherited from BaseField
#default, #message_class, #name, #rule, #tag, #type
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from BaseField
#clear, #default_value, #descriptor, descriptor, #error_message, #get, #initialize, #initialized?, #max, #merge, #merge_array, #merge_value, #min, #optional?, #ready?, #repeated?, #required?, #set, #to_s, #typed_default_value
Class Method Details
.default ⇒ Object
279
|
# File 'lib/protobuf/message/field.rb', line 279
def default; '' end
|
Instance Method Details
#acceptable?(val) ⇒ Boolean
286
287
288
289
|
# File 'lib/protobuf/message/field.rb', line 286
def acceptable?(val)
raise TypeError unless val.instance_of? String
true
end
|
#decode(bytes) ⇒ Object
291
292
293
|
# File 'lib/protobuf/message/field.rb', line 291
def decode(bytes)
bytes.pack('C*')
end
|
#encode(value) ⇒ Object
295
296
297
298
299
300
|
# File 'lib/protobuf/message/field.rb', line 295
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
|