Class: ProtocolBuffers::Field::StringField
Constant Summary
collapse
- HAS_ENCODING =
(''.respond_to?(:valid_encoding?) && ''.respond_to?(:force_encoding))
Instance Attribute Summary
#name, #otype, #tag
Instance Method Summary
collapse
Methods inherited from BytesField
#default_value, #valid_type?
#wire_type
#add_methods_to, #add_reader_to, #add_writer_to, #check_valid, create, #initialize, #inspect_value, #packed?, #repeated?, #valid_type?
Instance Method Details
#check_value(value) ⇒ Object
306
307
308
309
310
|
# File 'lib/protocol_buffers/runtime/field.rb', line 306
def check_value(value)
if HAS_ENCODING
value.dup.force_encoding(Encoding::UTF_8).valid_encoding? || raise(ArgumentError, "string value is not valid utf-8")
end
end
|
#deserialize(value) ⇒ Object
321
322
323
324
325
326
327
328
|
# File 'lib/protocol_buffers/runtime/field.rb', line 321
def deserialize(value)
read_value = value.read.to_s
if HAS_ENCODING
read_value.force_encoding(Encoding::UTF_8)
else
read_value
end
end
|
#serialize(value) ⇒ Object
312
313
314
315
316
317
318
319
|
# File 'lib/protocol_buffers/runtime/field.rb', line 312
def serialize(value)
check_value(value)
if HAS_ENCODING
value.dup.force_encoding(Encoding::UTF_8)
else
value
end
end
|