Module: Arachni::RPC::Serializer
Overview
Used for serialization of Arachni::RPC messages.
It's simply a delegator for `MessagePack` with `Zlib` compression for messages that are larger than COMPRESS_LARGER_THAN.
Constant Summary collapse
- COMPRESS_LARGER_THAN =
Compress object dumps larger than 1KB.
1_000
Instance Method Summary collapse
-
#compress(string) ⇒ String
Compressed (or not) `string`.
-
#decompress(string) ⇒ String
Decompressed string.
- #deep_clone(object) ⇒ Object
-
#dump(object) ⇒ String
Compressed `object` dump.
- #load(dump) ⇒ Object
- #rpc_data(object) ⇒ Object
- #serializer ⇒ Object
Instance Method Details
#compress(string) ⇒ String
Note:
Ignores strings smaller than #COMPRESS_LARGER_THAN.
Returns Compressed (or not) `string`.
67 68 69 70 |
# File 'lib/arachni/rpc/serializer.rb', line 67 def compress( string ) return string if string.size < COMPRESS_LARGER_THAN Zlib::Deflate.deflate string end |
#decompress(string) ⇒ String
Note:
Will return the `string` as is if it was not compressed.
Returns Decompressed string.
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/arachni/rpc/serializer.rb', line 79 def decompress( string ) return '' if string.to_s.empty? # Just an ID representing a serialized, empty data structure. return string if string.size == 1 begin Zlib::Inflate.inflate string rescue Zlib::DataError string end end |
#deep_clone(object) ⇒ Object
56 57 58 |
# File 'lib/arachni/rpc/serializer.rb', line 56 def deep_clone( object ) object.class.from_rpc_data rpc_data( object ) end |
#dump(object) ⇒ String
Returns Compressed `object` dump.
29 30 31 32 |
# File 'lib/arachni/rpc/serializer.rb', line 29 def dump( object ) # ap object compress( serializer.dump( object.to_rpc_data_or_self ) ) end |
#load(dump) ⇒ Object
38 39 40 |
# File 'lib/arachni/rpc/serializer.rb', line 38 def load( dump ) serializer.load( decompress( dump ) ) end |
#rpc_data(object) ⇒ Object
49 50 51 |
# File 'lib/arachni/rpc/serializer.rb', line 49 def rpc_data( object ) load( dump( object ) ) end |
#serializer ⇒ Object
92 93 94 |
# File 'lib/arachni/rpc/serializer.rb', line 92 def serializer MessagePack end |