Hi!

So Locklainn wanted to create a serialization component for his message builder. What the message builder spits out is a MsgData instance which needs to be serialized. A MsgData instance is a generic class which handles all types of packets (you can add blocks and data etc.).

In order to create an adapter it would need some interface. It makes sense to call it IMessageData (or IMsgData) and put the methods into it which the class actually defines.

Then you would write an adapter which implements ISerialization. As you should see from interfaces.py you need to implement 2 things. A serialize() method and a content_type attribute (this is more used for HTTP traffic though, not sure if that really is needed in the UDP case but I guess we can let it return application/llpacket or something dummy like this).

This should be straightforward like it has been done in credentials.py.

Now what this gives us is that we can exchange the serializer in our application if we want to. What we cannot exchange though is the implementation for IMsgData unless we also exchange the class which spits these out. And this was Locklainn's question if I get this right.

So the question indeed is what the advantage is or if you can make it work so that you can also just exchange the MsgData implementation.

In fact you can if you use some factory pattern here and register IMsgData as a utility (each class is actually a factory because if you call it it returns an instance):

class MsgData(object):
    implement(IMsgData)

provideUtility(MsgData)

You can then use it like this:

msgdata = getUtility(IMsgData)()

(at least this should work, haven't tested it yet).

Then you can replace this as well in your code.

The main question is though if we need all this in here and I think we don't. Probably nobody wants to change the implementation and if so we maybe can refactor it like this at that point in time.

Regarding serialization we also probably don't need it. For HTTP request it makes sense because there is still the option to use JSON. For UDP packets though there is not really an alternative format we can use.

That being said I would propose that you implement serialize() directly in the MsgData (when you do that you can actually still add the implements(ISerialization) to MsgData because then this directly is the adapter for itself).

good night,

Christian




--
Christian Scholz                         video blog: http://comlounge.tv
COM.lounge                                   blog: http://mrtopf.de/blog
Luetticher Strasse 10                                    Skype: HerrTopf
52064 Aachen                              Homepage: http://comlounge.net
Tel: +49 241 400 730 0                           E-Mail [EMAIL PROTECTED]
Fax: +49 241 979 00 850                               IRC: MrTopf, Tao_T

neue Show: TOPFtäglich (http://mrtopf.de/blog/category/topf-taglich/)

_______________________________________________
Click here to unsubscribe or manage your list subscription:
https://lists.secondlife.com/cgi-bin/mailman/listinfo/pyogp

Reply via email to