Sha256: b1b214fba4a8fc34a61c0b150e5e77b3ab8d4cf7a7f9b3272f1849ea259f3c48

Contents?: true

Size: 830 Bytes

Versions: 16

Compression:

Stored size: 830 Bytes

Contents

require 'protobuf/field/bytes_field'

module Protobuf
  module Field
    class StringField < BytesField

      ##
      # Constants
      #

      ENCODING = 'UTF-8'.freeze

      ##
      # 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

16 entries across 16 versions & 2 rubygems

Version Path
protobuffy-3.6.0 lib/protobuf/field/string_field.rb
protobuffy-3.5.1 lib/protobuf/field/string_field.rb
protobuffy-3.4.0 lib/protobuf/field/string_field.rb
protobuffy-3.3.0 lib/protobuf/field/string_field.rb
protobuffy-3.2.0 lib/protobuf/field/string_field.rb
protobuffy-3.1.0 lib/protobuf/field/string_field.rb
protobuf-3.2.0 lib/protobuf/field/string_field.rb
protobuf-3.1.0 lib/protobuf/field/string_field.rb
protobuf-3.0.5 lib/protobuf/field/string_field.rb
protobuf-3.0.4 lib/protobuf/field/string_field.rb
protobuf-3.0.3 lib/protobuf/field/string_field.rb
protobuf-3.0.2 lib/protobuf/field/string_field.rb
protobuf-3.0.1 lib/protobuf/field/string_field.rb
protobuf-3.0.0 lib/protobuf/field/string_field.rb
protobuf-3.0.0.rc2 lib/protobuf/field/string_field.rb
protobuf-3.0.0.rc1 lib/protobuf/field/string_field.rb