class Chainer::Serializers::MarshalDeserializer

Public Class Methods

load_file(filename, obj, path: '', strict: true) click to toggle source

Loads an object from the file in Marshal format. This is a short-cut function to load from an Marshal file that contains only one object.

@param [string] filename Name of the file to be loaded. @param [object] obj Object to be deserialized. It must support serialization protocol.

# File lib/chainer/serializers/marshal.rb, line 49
def self.load_file(filename, obj, path: '', strict: true)
  File.open(filename) do |f|
    d = self.new(Marshal.load(f), path: path, strict: strict)
    d.load(obj)
  end
end
new(marshalData, path: '', strict: true) click to toggle source
# File lib/chainer/serializers/marshal.rb, line 56
def initialize(marshalData, path: '', strict: true)
  @marshal_data = marshalData
  @path = path
  @strict = strict
end

Public Instance Methods

[](key) click to toggle source
# File lib/chainer/serializers/marshal.rb, line 62
def [](key)
  self.class.new(@marshal_data, path: File.join(@path, key, '/'), strict: @strict)
end
call(key, value) click to toggle source
# File lib/chainer/serializers/marshal.rb, line 66
def call(key, value)
  key = File.join(@path, key)
  if !@strict && !@marshal_data.keys.include?(key)
    return value
  end

  dataset = @marshal_data[key]
  if value.nil?
    return dataset
  elsif value.instance_of?(String)
    return dataset
  elsif Chainer.array?(value)
    value.store(dataset)
    return value
  elsif value.is_a?(TrueClass) || value.is_a?(FalseClass)
    return dataset[0] == 1
  else
    return dataset[0]
  end
end