Module WDDX
In: lib/wddx.rb
lib/wddx/core_ext.rb
lib/wddx/deserializer.rb
lib/wddx/record_set.rb
lib/wddx/serializer.rb
lib/wddx/struct.rb
lib/wddx/wddx_packet.rb

$Id: wddx_packet.rb 94 2006-12-24 13:05:36Z stefan $ Created by Stefan Saasen. Copyright (c) 2006. All rights reserved.

Methods

deserialize   dump   from_file   open   to_wddx   xml_escape  

Classes and Modules

Class WDDX::Binary
Class WDDX::RecordSet
Class WDDX::Struct
Class WDDX::WddxPacket

Constants

PACKET_VERSION = 1.0

External Aliases

open -> load
from_file -> file

Public Class methods

Deserialize WDDX-XML to a WDDX::WddxPacket

 p = WDDX.deserialize(xml_string)
 p.data # => String, Number, Time...

The method dump tries to serialize arbitrary Ruby objects.

 print WDDX.dump("Hello world") # => "<wddxPacket version='1.0'><header/><data><string>Hello world</string></data></wddxPacket>"

You can add a to_wddx_properties method to your class that returns an array of fields an method names (as symbol) that will be serialized as WDDX XML.

 class MyObj
   def initilize(name, price)
     @name, @price = name, price
   end
   def custom_price; @price * 1.05; end

   def to_wddx_properties
     ["@name", :custom_price]
   end
 end

 WDDX.dump(MyObj.new("Klaus Tester", 123))

Reads WDDX-XML from the file filename.

Reads WDDX-XML from obj. Obj can be a String or every Object that responds to a "read" method (File, open-uri…)

 require 'open-uri'
 packet = WDDX.load(open("http://wddx.rubyforge.org/wddx.xml"))

Public Instance methods

The WDDX module can be mixed into arbitrary classes. You can call to_wddx to get a WDDX-XML representation of your object.

 class MyTest
   include WDDX
   def initialize(a,b)
     @a, @b = a, b
   end
 end

 t = MyTest.new("Hello world", Time.now)
 print t.to_wddx # => "<wddxPacket ..."

[Validate]