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
308
309
310
311
312
|
# File 'lib/protocol_buffers/runtime/field.rb', line 308
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
323
324
325
326
327
328
329
330
|
# File 'lib/protocol_buffers/runtime/field.rb', line 323
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
314
315
316
317
318
319
320
321
|
# File 'lib/protocol_buffers/runtime/field.rb', line 314
def serialize(value)
check_value(value)
if HAS_ENCODING
value.dup.force_encoding(Encoding::UTF_8)
else
value
end
end
|