Module: Boss
- Included in:
- Formatter
- Defined in:
- lib/boss-protocol.rb,
lib/boss-protocol/version.rb
Overview
Boss protocol version 1.4 full implementation
Attentionn! Bzip2 compression was removed for the sake of compatibility.
1.4 Stream mode do not use caching anymore (not effective while slow).
Stream mode format is changed (removed unused parameters)
1.3.1 Stream mode added and fixed 1.3
1.2 version adds support for booelans and removes support for python __reduce__ - based objects
as absolutely non portable. It also introduces
1.1 version changes the way to store bignums in header, now it is
encoded <bytes_length> followed by the specified number of bytes
LSB first
No object serialization yet, no callables and bound methods - these appear to be non portable between platoforms.
Please note that most of this code was developed in 2008 so it is kind of old ;) though working.
Defined Under Namespace
Classes: Formatter, NotSupportedException, Parser, UnknownTypeException
Constant Summary collapse
- Bignum =
Integer- Fixnum =
Integer- TYPE_INT =
Basic types
0- TYPE_EXTRA =
1- TYPE_NINT =
2- TYPE_TEXT =
3- TYPE_BIN =
4- TYPE_CREF =
5- TYPE_LIST =
6- TYPE_DICT =
7- DZERO =
Extra types:
0- FZERO =
: float 0.0
1- DONE =
: double 0.0
2- FONE =
: double 1.0
3- DMINUSONE =
: float 1.0
4- FMINUSONE =
: double -1.0
5- TFLOAT =
: float -1.0
6- TDOUBLE =
: 32-bit IEEE float
7- TOBJECT =
: 64-bit IEEE float
8- TMETHOD =
: object record
9- TFUNCTION =
: instance method
10- TGLOBREF =
: callable function
11- TTRUE =
: global reference
12- TFALSE =
13- TCOMPRESSED =
14- TTIME =
15- XT_STREAM_MODE =
16- VERSION =
"1.5.0"
Class Method Summary collapse
-
.dump(*roots) ⇒ Object
convert all arguments into successive BOSS encoeded object, so all them will share same global reference cache.
-
.dump_compressed(*roots) ⇒ Object
Just like Boss.dump but automatically use proper compression depending on the data size.
-
.load(src) ⇒ Object
If block is given, yields all objects from the src (that can be either string or IO), passes it to the block and stores what block returns in the array, unless block returns nil.
-
.load_all(src) ⇒ Object
Load all objects from the src and return them as an array.
-
.pack(object) ⇒ Object
Pack object to the BOSS binary (same as Boss#dump).
-
.pack_compress(object) ⇒ Object
Pack object into compressed Boss representation.
-
.unpack(object) ⇒ Object
Unpack object from the BOSS binary (same as Boss#load(src)).
Instance Method Summary collapse
Class Method Details
.dump(*roots) ⇒ Object
convert all arguments into successive BOSS encoeded object, so all them will share same global reference cache.
537 538 539 540 541 |
# File 'lib/boss-protocol.rb', line 537 def Boss.dump(*roots) f = f = Formatter.new roots.each { |r| f << r } f.string end |
.dump_compressed(*roots) ⇒ Object
Just like Boss.dump but automatically use proper compression depending on the data size. Boss.load or Boss.load_all will automatically decompress the data
547 548 549 550 551 |
# File 'lib/boss-protocol.rb', line 547 def Boss.dump_compressed(*roots) f = f = Formatter.new roots.each { |r| f.put_compressed r } f.string end |
.load(src) ⇒ Object
If block is given, yields all objects from the src (that can be either string or IO), passes it to the block and stores what block returns in the array, unless block returns nil. The array is then returned.
Otherwise, reads and return first object from src
514 515 516 517 518 519 520 521 522 523 |
# File 'lib/boss-protocol.rb', line 514 def Boss.load(src) p = Parser.new(src) if block_given? res = [] res << yield(p.get) while !p.eof? res else p.get end end |
.load_all(src) ⇒ Object
Load all objects from the src and return them as an array
526 527 528 529 530 531 |
# File 'lib/boss-protocol.rb', line 526 def Boss.load_all src p = Parser.new(src) res = [] res << p.get while !p.eof? res end |
.pack(object) ⇒ Object
Pack object to the BOSS binary (same as Boss#dump)
559 560 561 |
# File 'lib/boss-protocol.rb', line 559 def Boss.pack object Boss.dump object end |
.pack_compress(object) ⇒ Object
Pack object into compressed Boss representation
554 555 556 |
# File 'lib/boss-protocol.rb', line 554 def Boss.pack_compress(object) dump_compressed object end |
.unpack(object) ⇒ Object
Unpack object from the BOSS binary (same as Boss#load(src))
564 565 566 |
# File 'lib/boss-protocol.rb', line 564 def Boss.unpack object Boss.load object end |
Instance Method Details
#checkArg(cond, msg = nil) ⇒ Object
104 105 106 |
# File 'lib/boss-protocol.rb', line 104 def checkArg(cond, msg=nil) raise ArgumentError, msg unless cond end |