class Wiris::Unserializer

Public Class Methods

new(s) click to toggle source
# File lib/src-generic/Unserializer.rb, line 11
def initialize(s)
  @buf = s
  @pos = 0
end
run(s) click to toggle source
# File lib/src-generic/Unserializer.rb, line 16
def self.run(s)
  return Unserializer.new(s).unserialize()
end

Public Instance Methods

buf() click to toggle source
# File lib/src-generic/Unserializer.rb, line 3
def buf
  @buf
end
pos() click to toggle source
# File lib/src-generic/Unserializer.rb, line 7
def pos
  @pos
end
readDigits() click to toggle source
# 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() click to toggle source
# 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