Module: Boss

Included in:
Formatter
Defined in:
lib/boss-protocol.rb,
lib/boss-protocol/version.rb

Overview

Boss protocol version 1.2 basic implementation

Attn! We removed Bzip2 compression for the sake of compatibility. We may add it back when situation with bz2 implementations on various platforms will be eased

1.4 Stream mode not use caching. Stream mode format is changed (removed unused parameters)

1.3.1 Stream mode added and fixed

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

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.



511
512
513
514
515
# File 'lib/boss-protocol.rb', line 511

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



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

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



488
489
490
491
492
493
494
495
496
497
# File 'lib/boss-protocol.rb', line 488

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



500
501
502
503
504
505
# File 'lib/boss-protocol.rb', line 500

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)


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

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