Class: DRbDump::Loader
- Inherits:
-
Object
- Object
- DRbDump::Loader
- Defined in:
- lib/drbdump/loader.rb
Overview
A DRb protocol message chunk loader.
Based on DRb::DRbMessage
Defined Under Namespace
Classes: DataError, Error, Premature, SizeError, TooLarge
Instance Method Summary collapse
-
#initialize(config) ⇒ Loader
constructor
Creates a new loader with the given
config
Hash. -
#load(stream) ⇒ Object
Returns the next component from a DRb message
stream
as a Marshal::Structure object.
Constructor Details
#initialize(config) ⇒ Loader
Creates a new loader with the given config
Hash. The loader uses only the :load_limit key to limit the maximum message size.
39 40 41 |
# File 'lib/drbdump/loader.rb', line 39 def initialize config @load_limit = config[:load_limit] end |
Instance Method Details
#load(stream) ⇒ Object
Returns the next component from a DRb message stream
as a Marshal::Structure object.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/drbdump/loader.rb', line 47 def load stream begin size = stream.read 4 rescue => e raise SizeError, e., 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., e.backtrace end raise DataError, 'connection closed' unless data raise Premature, 'Marshal' if data.bytesize < size Marshal::Structure.new data end |