Sha256: 64bb3053bb57ceec0192b2e8653d17f3ccaba42a71530ad9e5c09dd897737b14

Contents?: true

Size: 663 Bytes

Versions: 42

Compression:

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

42 entries across 42 versions & 1 rubygems

Version Path
protobuf-2.7.7-java lib/protobuf/field/string_field.rb
protobuf-2.7.7 lib/protobuf/field/string_field.rb
protobuf-2.7.6-java lib/protobuf/field/string_field.rb
protobuf-2.7.6 lib/protobuf/field/string_field.rb
protobuf-2.7.5-java lib/protobuf/field/string_field.rb
protobuf-2.7.5 lib/protobuf/field/string_field.rb
protobuf-2.7.4-java lib/protobuf/field/string_field.rb
protobuf-2.7.4 lib/protobuf/field/string_field.rb
protobuf-2.7.3-java lib/protobuf/field/string_field.rb
protobuf-2.7.3 lib/protobuf/field/string_field.rb
protobuf-2.7.2-java lib/protobuf/field/string_field.rb
protobuf-2.7.2 lib/protobuf/field/string_field.rb
protobuf-2.7.1-java lib/protobuf/field/string_field.rb
protobuf-2.7.1 lib/protobuf/field/string_field.rb
protobuf-2.7.0-java lib/protobuf/field/string_field.rb
protobuf-2.7.0 lib/protobuf/field/string_field.rb
protobuf-2.7.0.rc1-java lib/protobuf/field/string_field.rb
protobuf-2.7.0.rc1 lib/protobuf/field/string_field.rb
protobuf-2.6.6-java lib/protobuf/field/string_field.rb
protobuf-2.6.6 lib/protobuf/field/string_field.rb