Sha256: 52a911967c05f49a34194c8ea840304886a53fc0afd6b4d301ed8b2a7b39f403

Contents?: true

Size: 662 Bytes

Versions: 26

Compression:

Stored size: 662 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

26 entries across 26 versions & 1 rubygems

Version Path
protobuf-2.8.3 lib/protobuf/field/string_field.rb
protobuf-2.8.2 lib/protobuf/field/string_field.rb
protobuf-2.8.1 lib/protobuf/field/string_field.rb
protobuf-2.8.0 lib/protobuf/field/string_field.rb
protobuf-2.8.0.beta9-java lib/protobuf/field/string_field.rb
protobuf-2.8.0.beta9 lib/protobuf/field/string_field.rb
protobuf-2.8.0.beta8-java lib/protobuf/field/string_field.rb
protobuf-2.8.0.beta8 lib/protobuf/field/string_field.rb
protobuf-2.8.0.beta6-java lib/protobuf/field/string_field.rb
protobuf-2.8.0.beta6 lib/protobuf/field/string_field.rb
protobuf-2.8.0.beta5-java lib/protobuf/field/string_field.rb
protobuf-2.8.0.beta5 lib/protobuf/field/string_field.rb
protobuf-2.8.0.beta4-java lib/protobuf/field/string_field.rb
protobuf-2.8.0.beta4 lib/protobuf/field/string_field.rb
protobuf-2.8.0.beta3-java lib/protobuf/field/string_field.rb
protobuf-2.8.0.beta3 lib/protobuf/field/string_field.rb
protobuf-2.8.0.beta2-java lib/protobuf/field/string_field.rb
protobuf-2.8.0.beta2 lib/protobuf/field/string_field.rb
protobuf-2.7.11-java lib/protobuf/field/string_field.rb
protobuf-2.7.11 lib/protobuf/field/string_field.rb