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.6.5-java lib/protobuf/field/string_field.rb
protobuf-2.6.5 lib/protobuf/field/string_field.rb
protobuf-2.6.4-java lib/protobuf/field/string_field.rb
protobuf-2.6.4 lib/protobuf/field/string_field.rb
protobuf-2.6.3-java lib/protobuf/field/string_field.rb
protobuf-2.6.3 lib/protobuf/field/string_field.rb
protobuf-2.6.2-java lib/protobuf/field/string_field.rb
protobuf-2.6.2 lib/protobuf/field/string_field.rb
protobuf-2.6.1-java lib/protobuf/field/string_field.rb
protobuf-2.6.1 lib/protobuf/field/string_field.rb
protobuf-2.6.0-java lib/protobuf/field/string_field.rb
protobuf-2.6.0 lib/protobuf/field/string_field.rb
protobuf-2.5.5-java lib/protobuf/field/string_field.rb
protobuf-2.5.5 lib/protobuf/field/string_field.rb
protobuf-2.5.4-java lib/protobuf/field/string_field.rb
protobuf-2.5.4 lib/protobuf/field/string_field.rb
protobuf-2.5.3 lib/protobuf/field/string_field.rb
protobuf-2.5.2-java lib/protobuf/field/string_field.rb
protobuf-2.5.2 lib/protobuf/field/string_field.rb
protobuf-2.5.1 lib/protobuf/field/string_field.rb