Sha256: f12a3ee6641b0f3c4170e042524c093bbb03a0682cec926e985b589b67f11a31

Contents?: true

Size: 494 Bytes

Versions: 1

Compression:

Stored size: 494 Bytes

Contents

# frozen_string_literal: true

module TJSON
  class DataType
    # Unicode String type
    class String < Scalar
      def tag
        "s"
      end

      def decode(str)
        raise TJSON::TypeError, "expected String, got #{str.class}: #{str.inspect}" unless str.is_a?(::String)
        raise TJSON::EncodingError, "expected UTF-8, got #{str.encoding.inspect}" unless str.encoding == Encoding::UTF_8
        str
      end

      def encode(obj)
        obj.to_s
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tjson-0.5.0 lib/tjson/datatype/string.rb