Sha256: 72d73637c1fe406b29ec6a590c781064bd243975a7aaa7d60862d22df33daa74

Contents?: true

Size: 952 Bytes

Versions: 39

Compression:

Stored size: 952 Bytes

Contents

class Symbol
  # to_msgpack_ext is supposed to return a binary string.
  # The canonical way to do it for symbols would be:
  #  [to_s].pack('A*')
  # However in this instance we can take a shortcut
  if method_defined?(:name)
    alias_method :to_msgpack_ext, :name
  else
    alias_method :to_msgpack_ext, :to_s
  end

  def self.from_msgpack_ext(data)
    # from_msgpack_ext is supposed to parse a binary string.
    # The canonical way to do it for symbols would be:
    #  data.unpack1('A*').to_sym
    # However in this instance we can take a shortcut

    # We assume the string encoding is UTF-8, and let Ruby create either
    # an ASCII symbol or UTF-8 symbol.
    data.force_encoding(Encoding::UTF_8).to_sym
  rescue EncodingError
    # If somehow the string wasn't valid UTF-8 not valid ASCII, we fallback
    # to what has been the historical behavior of creating a binary symbol
    data.force_encoding(Encoding::BINARY).to_sym
  end
end

Version data entries

39 entries across 39 versions & 5 rubygems

Version Path
msgpack-1.8.0-java lib/msgpack/symbol.rb
msgpack-1.8.0 lib/msgpack/symbol.rb
msgpack-1.7.5 lib/msgpack/symbol.rb
msgpack-1.7.5-java lib/msgpack/symbol.rb
msgpack-1.7.4-java lib/msgpack/symbol.rb
msgpack-1.7.4 lib/msgpack/symbol.rb
msgpack-1.7.3-java lib/msgpack/symbol.rb
msgpack-1.7.3 lib/msgpack/symbol.rb
fluent-plugin-nuopenlineage-light-0.1.0 vendor/bundle/ruby/3.3.0/gems/msgpack-1.7.2/lib/msgpack/symbol.rb
fluent-plugin-openlineage-light-0.1.4 vendor/bundle/ruby/3.3.0/gems/msgpack-1.7.2/lib/msgpack/symbol.rb
fluent-plugin-openlineage-light-0.1.3 vendor/bundle/ruby/3.3.0/gems/msgpack-1.7.2/lib/msgpack/symbol.rb
fluent-plugin-openlineage-0.1.0 vendor/bundle/ruby/3.3.0/gems/msgpack-1.7.2/lib/msgpack/symbol.rb
msgpack-1.7.2-java lib/msgpack/symbol.rb
msgpack-1.7.2 lib/msgpack/symbol.rb
msgpack-1.7.1-java lib/msgpack/symbol.rb
msgpack-1.7.1 lib/msgpack/symbol.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/msgpack-1.7.0/lib/msgpack/symbol.rb
msgpack-1.7.0-java lib/msgpack/symbol.rb
msgpack-1.7.0 lib/msgpack/symbol.rb
msgpack-1.6.1-java lib/msgpack/symbol.rb