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

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.4.3"

Class Method Summary collapse

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.



532
533
534
535
536
# File 'lib/boss-protocol.rb', line 532

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



542
543
544
545
546
# File 'lib/boss-protocol.rb', line 542

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



509
510
511
512
513
514
515
516
517
518
# File 'lib/boss-protocol.rb', line 509

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



521
522
523
524
525
526
# File 'lib/boss-protocol.rb', line 521

def Boss.load_all src
  p   = Parser.new(src)
  res = []
  res << p.get while !p.eof?
  res
end

Instance Method Details

#checkArg(cond, msg = nil) ⇒ Object

Raises:

  • (ArgumentError)


98
99
100
# File 'lib/boss-protocol.rb', line 98

def checkArg(cond, msg=nil)
  raise ArgumentError unless cond
end