Class: Wiris::Serializer
- Inherits:
-
Object
- Object
- Wiris::Serializer
- Defined in:
- lib/src-generic/Serializer.rb
Class Method Summary collapse
Instance Method Summary collapse
- #buf ⇒ Object
-
#initialize ⇒ Serializer
constructor
A new instance of Serializer.
-
#serialize(o) ⇒ Object
b : hash c : class d : Float e : reserved (float exp) f : false g : object end h : array/list/hash end i : Int j : enum (by index) k : NaN l : list m : -Inf n : null o : object p : +Inf q : inthash r : reference s : bytes (base64) t : true u : array nulls v : date w : enum x : exceptiona y : urlencoded string z : zero C : custom.
- #toString ⇒ Object
Constructor Details
#initialize ⇒ Serializer
Returns a new instance of Serializer.
6 7 8 |
# File 'lib/src-generic/Serializer.rb', line 6 def initialize() @buf = StringBuf.new() end |
Class Method Details
.run(o) ⇒ Object
79 80 81 82 83 |
# File 'lib/src-generic/Serializer.rb', line 79 def self.run(o) s = Serializer.new() s.serialize(o) return s.toString() end |
Instance Method Details
#buf ⇒ Object
3 4 5 |
# File 'lib/src-generic/Serializer.rb', line 3 def buf @buf end |
#serialize(o) ⇒ Object
b : hash c : class d : Float e : reserved (float exp) f : false g : object end h : array/list/hash end i : Int j : enum (by index) k : NaN l : list m : -Inf n : null o : object p : +Inf q : inthash r : reference s : bytes (base64) t : true u : array nulls v : date w : enum x : exceptiona y : urlencoded string z : zero C : custom
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/src-generic/Serializer.rb', line 39 def serialize(o) c = Type.getClass(o) if (c == Type.resolveClass(Array).to_s) buf.add("a") v = o ucount = 0 l = v.length() for i in 0..l if (v._(i) == nil) ucount += 1 else if (ucount > 0) if (ucount == 1) buf.add("n") else buf.add("u") buf.add("" + ucount.to_s) end ucount = 0 end serialize(v._(i)) end end buf.add("h") elsif (o.is_a? Integer) if (o == 0) buf.add("z") else buf.add("i") buf.add("" + o.to_s) end else raise Exception, "Object class not implemented: "+ c end end |
#toString ⇒ Object
75 76 77 |
# File 'lib/src-generic/Serializer.rb', line 75 def toString() return buf.toString() end |