A DRb protocol message chunk loader.
Based on DRb::DRbMessage
Creates a new loader with the given config
Hash. The loader
uses only the :load_limit key to limit the maximum message size.
# File lib/drbdump/loader.rb, line 39 def initialize config @load_limit = config[:load_limit] end
Returns the next component from a DRb message stream
as a
Marshal::Structure object.
# File lib/drbdump/loader.rb, line 47 def load stream begin size = stream.read 4 rescue => e raise SizeError, e.message, e.backtrace end raise SizeError, 'connection closed' unless size raise Premature, 'header' if size.size < 4 size, = size.unpack 'N' raise TooLarge, "#{size} bytes (#{@load_limit} allowed)" if size >= @load_limit begin data = stream.read size rescue => e raise DataError, e.message, e.backtrace end raise DataError, 'connection closed' unless data raise Premature, 'Marshal' if data.bytesize < size Marshal::Structure.new data end