Sha256: ff57d41a2fcf50565e7bce61d895f7eb3958ffc74826fbc76eada7ed7b20885f

Contents?: true

Size: 800 Bytes

Versions: 11

Compression:

Stored size: 800 Bytes

Contents

require 'protobuf/field/bytes_field'

module Protobuf
  module Field
    class StringField < BytesField

      ##
      # Constants
      #

      ENCODING = Encoding::UTF_8

      ##
      # Public Instance Methods
      #

      def decode(bytes)
        bytes_to_decode = bytes.dup
        bytes_to_decode.force_encoding(::Protobuf::Field::StringField::ENCODING)
        bytes_to_decode
      end

      def encode(value)
        value_to_encode = value.dup
        value_to_encode.encode!(::Protobuf::Field::StringField::ENCODING, :invalid => :replace, :undef => :replace, :replace => "")
        value_to_encode.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING)

        "#{::Protobuf::Field::VarintField.encode(value_to_encode.size)}#{value_to_encode}"
      end

    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
protobuffy-4.0.1 lib/protobuf/field/string_field.rb
protobuffy-4.0.0 lib/protobuf/field/string_field.rb
protobuf-3.6.12 lib/protobuf/field/string_field.rb
protobuf-3.6.11 lib/protobuf/field/string_field.rb
protobuf-3.6.10 lib/protobuf/field/string_field.rb
protobuf-3.7.0.pre2 lib/protobuf/field/string_field.rb
protobuf-3.6.9 lib/protobuf/field/string_field.rb
protobuf-3.7.0.pre1 lib/protobuf/field/string_field.rb
protobuf-3.7.0.pre0 lib/protobuf/field/string_field.rb
protobuf-3.6.7 lib/protobuf/field/string_field.rb
protobuf-3.6.6 lib/protobuf/field/string_field.rb