Sha256: 6fa91a6889f87bf6b97d25d28119f35cca8c46557ff7f0ef6f4dc7038ca602cf

Contents?: true

Size: 483 Bytes

Versions: 7

Compression:

Stored size: 483 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)
        value.force_encoding(::Protobuf::Field::StringField::ENCODING) 
        string_size = ::Protobuf::Field::VarintField.encode(value.size)
        string_size << value
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
protobuf-2.4.6 lib/protobuf/field/string_field.rb
protobuf-2.4.5-java lib/protobuf/field/string_field.rb
protobuf-2.4.5 lib/protobuf/field/string_field.rb
protobuf-2.4.4-java lib/protobuf/field/string_field.rb
protobuf-2.4.4 lib/protobuf/field/string_field.rb
protobuf-2.4.3-java lib/protobuf/field/string_field.rb
protobuf-2.4.3 lib/protobuf/field/string_field.rb