I'm forwarding to a list too, per request from Mithro :)

-------- Wiadomość oryginalna --------
Temat: Samples
Data: Wed, 19 Sep 2007 18:30:49 +0200
Nadawca: Krzysztof Sobolewski <[EMAIL PROTECTED]>
Adresat: Tim Ansell <[EMAIL PROTECTED]>

It took me so long, because I'm not sure samples of what you expect, so I'm
just going to try everything ;)

First of all, we have this @typefield attribute. Perhaps I should've done it
in XML, not as, let's call some buzzwords, a Domain-Specific Language. You
probably know this quote: "Someone faced with a problem said 'I know, I'll
use regular expressions!'; now he has two problems." That's a blatant lie.
This should be "...'I know, I'll use XML!'" ;) Unfortunately I love regular
expressions, so no wonder this was my first thought when I had to find a way
to describe how to get parameter ids from an order description.

I'll prepare a more XML-ish prototype soon.

Back to the topic.
The use case is this: we receive a frame...

<code>
orderFrame=conn.receiveFrame()
</code>

and it is an Order frame, from which we want to get out the parameters. The
parameters in the generated code are in a OrderParams class hierarchy (this
is the name given in protocol.xml in <parameterset>). So the "orderparams"
attribute of Order frame is of type List<OrderParams>. But, as I noted
before, it is impossible to decode them based on information in the Order
frame alone. So the getter for this property looks like this:

<code>
public List<OrderParams> getOrderparams(OrderDesc template)
</code>

In order to get the parameters we have to pull the OrderDesc frame for
correct order type (parameterset) id and use it as a "template".

<code>
orderDescFrame=conn.receiveFrame() //after sending GetOrderDesc
params=orderFrame.getOrderparams(orderDescFrame)
</code>

The [EMAIL PROTECTED] attribute tells the generator how to implement
getOrderparams(). The typefield in Order frame declares parameters like this:

<code>
otype=OrderDesc[id].parameters:type
</code>

This get converted to something like this (where template is an OrderDesc
frame):

<code>
//sanity check (generated from the "[id]" part)
if this.otype != template.id
        throw IllegalArgumentException

//orderparams field is a blob of bytes
stream=new ByteArrayInputStream(orderparams)
ret=new List()

//traverse the properties as described in typefield:
//the "parameters:" part (':' means a list)
for template0 in template.parameters
        //the "type" part (which is a terminal part)
        ret.add(decodeParameter(stream, template0.type))

return ret
</code>


The object parameters in TP04 get a bit more interesting, because they are
grouped and need one more nested list iteration (and is correct if my
assumptions about the order the parameters are sent are right). The result
is flat and does not mirror the nesting, unfortunately (it's doable, I
think, but would be rather complex).

Is this what you wanted? :)
-- 
KS
"To an engineer, everyone looks like a chimp" - Dilbert




----------------------------------------------------------------------
Tutaj sa Twoi nowi znajomi!
Sprawdz >>> http://link.interia.pl/f1bb7

Attachment: signature.asc
Description: PGP signature

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
tp-devel mailing list
[email protected]
http://www.thousandparsec.net/tp/mailman.php/listinfo/tp-devel

Reply via email to