Class: Wiris::Unserializer
- Inherits:
-
Object
- Object
- Wiris::Unserializer
- Defined in:
- lib/src-generic/Unserializer.rb
Class Method Summary collapse
Instance Method Summary collapse
- #buf ⇒ Object
-
#initialize(s) ⇒ Unserializer
constructor
A new instance of Unserializer.
- #pos ⇒ Object
- #readDigits ⇒ Object
- #unserialize ⇒ Object
Constructor Details
#initialize(s) ⇒ Unserializer
Returns a new instance of Unserializer.
11 12 13 14 |
# File 'lib/src-generic/Unserializer.rb', line 11 def initialize(s) @buf = s @pos = 0 end |
Class Method Details
.run(s) ⇒ Object
16 17 18 |
# File 'lib/src-generic/Unserializer.rb', line 16 def self.run(s) return Unserializer.new(s).unserialize() end |
Instance Method Details
#buf ⇒ Object
3 4 5 |
# File 'lib/src-generic/Unserializer.rb', line 3 def buf @buf end |
#pos ⇒ Object
7 8 9 |
# File 'lib/src-generic/Unserializer.rb', line 7 def pos @pos end |
#readDigits ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/src-generic/Unserializer.rb', line 52 def readDigits() n = 0 c = Std.charCodeAt(buf,@pos) minus = false if c == 0x2d # '-' minus = true @pos += 1 c = Std.charCodeAt(buf,@pos) end while (c>=0x30 && c<=0x39) n = n*10 + (c-0x30) @pos += 1 if (@pos >= buf.length()) break end c= Std.charCodeAt(buf,@pos) end ret = (minus ? -n : n) return ret end |
#unserialize ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/src-generic/Unserializer.rb', line 20 def unserialize() c = Std.charCodeAt(buf, @pos) @pos += 1 case c when 0x61 # 'a' for Array a = Array.new() while(true) t = Std.charCodeAt(buf, @pos) if (t == 0x68) # 'h' @pos += 1 break end if (t == 0x75) # 'u' @pos += 1 n = readDigits() a._(a.length()-(n-1), nil) else a.push(unserialize()) end end return a when 0x69 # 'i' for integer return readDigits() when 0x7a # 'z' return 0 when 0x6e #n return nil else raise Exception,'Object class not implemented: " ' + Std.fromCharCode(c) + "." end end |