Sha256: 4eadeb7c590ee5fb42ce4f7ea1fb61f62b5885213f12b195508512e296313ee4

Contents?: true

Size: 1.48 KB

Versions: 1

Compression:

Stored size: 1.48 KB

Contents

module Wiris
  class Unserializer
    def buf
      @buf
    end

    def pos
      @pos
    end

    def initialize(s)
      @buf = s
      @pos = 0
    end

    def self.run(s)
      return Unserializer.new(s).unserialize()
    end

    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

    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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wirispluginengine-3.62.0.1322 lib/src-generic/Unserializer.rb