Sha256: bd0ffb759da1433d0b8bfff12bde3ad209111803aa696e78eda68a074d1e74f5

Contents?: true

Size: 830 Bytes

Versions: 17

Compression:

Stored size: 830 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)

        string_size = ::Protobuf::Field::VarintField.encode(value_to_encode.size)
        string_size << value_to_encode
      end

    end
  end
end

Version data entries

17 entries across 17 versions & 3 rubygems

Version Path
protobuf-core-3.5.0 lib/protobuf/field/string_field.rb
protobuf-3.6.2 lib/protobuf/field/string_field.rb
protobuf-3.6.1 lib/protobuf/field/string_field.rb
protobuf-3.6.0 lib/protobuf/field/string_field.rb
protobuf-3.5.5 lib/protobuf/field/string_field.rb
protobuf-3.5.4 lib/protobuf/field/string_field.rb
protobuf-3.5.3 lib/protobuf/field/string_field.rb
protobuf-3.5.2 lib/protobuf/field/string_field.rb
protobuf-3.5.1 lib/protobuf/field/string_field.rb
prepor-protobuf-3.5.1 lib/protobuf/field/string_field.rb
prepor-protobuf-3.5.0 lib/protobuf/field/string_field.rb
protobuf-3.5.0 lib/protobuf/field/string_field.rb
protobuf-3.4.4 lib/protobuf/field/string_field.rb
protobuf-3.4.3 lib/protobuf/field/string_field.rb
protobuf-3.4.2 lib/protobuf/field/string_field.rb
protobuf-3.4.1 lib/protobuf/field/string_field.rb
protobuf-3.4.0 lib/protobuf/field/string_field.rb