Sha256: c755a680055c8f6ca86a5cecfe287ea2a3e9f027c426266fb4bfe212b2509a1e

Contents?: true

Size: 497 Bytes

Versions: 3

Compression:

Stored size: 497 Bytes

Contents

# frozen_string_literal: true

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

      def convert(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 generate(obj)
        obj.to_s
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tjson-0.4.0 lib/tjson/datatype/string.rb
tjson-0.3.0 lib/tjson/datatype/string.rb
tjson-0.2.0 lib/tjson/datatype/string.rb