Sha256: a3501cb0327b33796bc086343ff74526892d3d56cd5f19a701b4ffdac6d1efd9

Contents?: true

Size: 1.4 KB

Versions: 2

Compression:

Stored size: 1.4 KB

Contents

# encoding: utf-8
# frozen_string_literal: true

require "oj"
require "zlib"
require "carbon/concrete/build"
require "carbon/concrete/item"
require "carbon/concrete/index"
require "carbon/concrete/request"
require "carbon/concrete/type"

module Carbon
  # A concrete representation of the global state of a compilation.  All of
  # the things within this module should be serializable, so that libraries
  # may be linked easily back into the process.
  module Concrete
    OPTIONS = { circular: true, class_cache: true }.freeze

    # Loads a dumped object into an instance.  The dumped object should be a
    # Zlib compressed (with Deflate) string.  The dumped object
    # is decompressed and loaded, then passed to {.from}.
    #
    # @api private
    # @see .dump
    # @param source [::String] The dumped object.
    # @return [::Object] The represented object.
    def self.load(source)
      raw = Zlib::Inflate.inflate(source)
      Oj.load(raw, OPTIONS)
    end

    # Dumps an object to a string.  If the object responds to `#to_basic`, the
    # result of that method call is used instead.  The object is then
    # serialized, and then compressed using Zlib (Deflate).
    #
    # @api private
    # @see .load
    # @param index [::Object] The object to dump.
    # @return [::String] The dumped object.
    def self.dump(index)
      raw = Oj.dump(index, OPTIONS)
      Zlib::Deflate.deflate(raw, 9)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
carbon-core-0.2.1 lib/carbon/concrete.rb
carbon-core-0.2.0 lib/carbon/concrete.rb