Sha256: 64bb3053bb57ceec0192b2e8653d17f3ccaba42a71530ad9e5c09dd897737b14
Contents?: true
Size: 663 Bytes
Versions: 42
Compression:
Stored size: 663 Bytes
Contents
require 'protobuf/field/bytes_field' module Protobuf module Field class StringField < BytesField ENCODING = 'UTF-8'.freeze def decode(bytes) bytes.force_encoding(::Protobuf::Field::StringField::ENCODING) bytes end def encode(value) # TODO: make replace character configurable? value.encode!(::Protobuf::Field::StringField::ENCODING, :invalid => :replace, :undef => :replace, :replace => "") value.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) string_size = ::Protobuf::Field::VarintField.encode(value.size) string_size << value end end end end
Version data entries
42 entries across 42 versions & 1 rubygems