April 2024 - This site, and Kamaelia are being updated. There is significant work needed, and PRs are welcome.

Kamaelia.Util.Marshalling

Simple Marshalling/demarshalling framework

A pair of components for marshalling and demarshalling data respectively. You supply a class containing methods to marshall and demarshall the data in the way you want.

The idea is that you would place this between your logic and a network socket to transform the data to and from a form suitable for transport.

Example usage

Marshalling and demarshalling a stream of integers:

class SerialiseInt:

    def marshall(int):
        return str(int)
    marshall = staticmethod(marshall)

    def demarshall(string):
        return int(string)
    demarshall = staticmethod(demarshall)

Pipeline( producer(...),
          Marshaller(SerialiseInt),
          sender(...)
        ).activate()

Pipeline( receiver(...),
          DeMarshaller(SerialiseInt),
          consumer(...)
        ).activate()

How does it work?

When instantiating the Marshaller or DeMarshaller components, you provide an object (eg. class) containing these static methods:

  • marshall(item) - returns the item serialised for transmission
  • demarshall(item) - returns the original item, deserialised

Marshaller requires only the marshall(...) static method, and DeMarshaller requires only demarshall(...).

Why static methods? Because marshalling/demarshalling is a stateless activity. This distinguishes marshalling activity from other protocols and other processes that can be implemented with a similar style of framework.

For simplicity this component expects to be given an entire object to marshall or demarshall. This requires the user to deal with the framing and deframing of objects separately.

Any data sent to the Marshaller or DeMarshaller components' "inbox" inbox is passed to the marshall(...) or demarshall(...) method respectively of the class you supplied. The result is immediately sent on out of the components' "outbox" outbox.

If a producerFinished or shutdownMicroprocess message is received on the components' "control" inbox, it is sent on out of the "signal" outbox. The component will then immediately terminate.

Post script

The initial data format this is designed to work with is the MimeDict object.

It is expected that there will be a more complex marshaller that supports receiving that is capable of receiving objects segmented over multiple messages.


Kamaelia.Util.Marshalling.DeMarshaller

class DeMarshaller(Axon.Component.component)

DeMarshaller(klass) -> new DeMarshaller component.

A component for demarshalling data (deserialising it from a string).

Keyword arguments: - klass -- a class with static method: demarshall(data) that returns the data, demarshalled.

Inboxes

  • control : Shutdown signalling
  • inbox : data to be demarshalled

Outboxes

  • outbox : demarshalled data
  • signal : Shutdown signalling

Methods defined here

Warning!

You should be using the inbox/outbox interface, not these methods (except construction). This documentation is designed as a roadmap as to their functionalilty for maintainers and new component developers.

__init__(self, klass)

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

main(self)

Main loop.

Kamaelia.Util.Marshalling.Marshaller

class Marshaller(Axon.Component.component)

Marshaller(klass) -> new Marshaller component.

A component for marshalling data (serialising it to a string).

Keyword arguments:

  • klass -- a class with static method: marshall(data) that returns the data, marshalled.

Inboxes

  • control : Shutdown signalling
  • inbox : data to be marshalled

Outboxes

  • outbox : marshalled data
  • signal : Shutdown signalling

Methods defined here

Warning!

You should be using the inbox/outbox interface, not these methods (except construction). This documentation is designed as a roadmap as to their functionalilty for maintainers and new component developers.

__init__(self, klass)

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

main(self)

Main loop.

Feedback

Got a problem with the documentation? Something unclear that could be clearer? Want to help improve it? Constructive criticism is very welcome - especially if you can suggest a better rewording!

Please leave you feedback here in reply to the documentation thread in the Kamaelia blog.

-- Automatic documentation generator, 05 Jun 2009 at 03:01:38 UTC/GMT