[Boulder-Denver Ruby Group] SAX-like serialization in Ruby?

Peter Jones pjones at pmade.org
Wed Oct 11 07:53:16 EDT 2006


On Oct 10, 2006, at 19:43, Tony Arcieri wrote:
> We're using EventMachine to multiplex a number of network  
> connections.  EventMachine has you define a module containing a set  
> of callback methods for handling various events.  When data is  
> received, it passes that data as a string to a receive_data.
>
> We're wanting to serialize Ruby objects across these connections  
> (for now the sockets will be used for IPC between Ruby processes on  
> the same system).  So we're looking for a SAX-like processor of  
> serialized messages that in some way lets us know when a complete  
> message has been received and lets us extract the unserialized Ruby  
> object.  Does anyone know a way to do this with Marshal/YAML/etc?   
> Something like expat's ParseBuffer sort of approach that would let  
> us spoonfeed a deserializer data as it's received that would spit  
> out unserialized objects as they're fully received.


Sounds like you might want to look at DRb.  At the very least, you  
can see how it does serialization across the network.  I know that  
Marshal.load can take an IO object, including a socket/pipe, and  
correctly reads the right amount of data.  You could write some code  
in your receive_data method that parses the Marshal.dump header, and  
then you would know how much data needs to be received before you  
have a complete object.

-p

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/bdrg-members/attachments/20061011/66bbc86f/attachment.html 


More information about the Bdrg-members mailing list