August'24: Kamaelia is in maintenance mode and will recieve periodic updates, about twice a year, primarily targeted around Python 3 and ecosystem compatibility. PRs are always welcome. Latest Release: 1.14.32 (2024/3/24)
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.
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()
When instantiating the Marshaller or DeMarshaller components, you provide an object (eg. class) containing these static methods:
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.
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.
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.
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.
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
Main loop.
Marshaller(klass) -> new Marshaller component.
A component for marshalling data (serialising it to a string).
Keyword arguments:
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.
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
Main loop.
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