Hi Guys, I'm hoping you can help because I've exhausted my understanding of this !!
I'm writing a decoder for messages that I receive on a socket. The Messages look like this :
B2t^?\251 cEy]\213\247\3350002900262O0 NL000634286722^F^Q^S\210^F^S^S\
+210
The rough guidance I have is that the format is :
Field Type Len
- Header Alpha 1
- ProtoVer Alpha 1
- MsgLen Num 2
- MsgSeqNum Num 4
- ClOrdID Num 8
- OnBehalfOfCompID Alpha 11
- ...
where "Alpha" is a string
and
Num is a binary field of type "uintx_t" (I guess uint8_t for example)
I'm trying to unpack this and I can't seem to decode the MsgSeqNum and ClOrdID fields properly. I know the value of the messageType, ProtoOrVer and MsgLen fields because I can decode them successfully(verified with another program I have no source code access too)...however whatever I do I can't decode see to decode the MsgSeqNum and ClOrdID fields. I know from the output of the other program that the ClOrdID in this message is "4295075805" but no unpack strings I specify seem to work.
If I use the following unpack statement just to get the field boundaries right :
($messageType,$ProtoOrVer,$MsgLen,$MsgSeqNum,$ClOrdID,$OnBehalfOfCompI
+D,$rest) =unpack "A A n B32 B64 A*",$sourceMsg};
then I get :
08:02:43 : messageType == B
08:02:43 : ProtoOrVer == 2
08:02:43 : MsgLen == 116
08:02:43 : MsgSeqNum == 00000000000000001111111010010101
08:02:43 : ClOrdID == 000001001100011010100010100111101011101011010001
+1110010110111011
08:02:43 : OnBehalfOfCompID == 00029002
08:02:43 : rest == 62O0 NL000634286722^F^Q^S\210^F^S^S\210
(This looks right because OnBehalfOfCompID is in the right place)
Now, given that using "n" works for the MsgLen field(length of 2 from spec and n == 16 bits on pack perldoc page) I tried using n2 on the basis that the field is supposed to be twice as long but I get the following, which is obviously wrong :
07:43:55 : messageType == B
07:43:55 : ProtoOrVer == 2
07:43:55 : MsgLen == 116
07:43:55 : MsgSeqNum == 0
07:43:55 : ClOrdID == 32681
07:43:55 : OnBehalfOfCompID == 8291
07:43:55 : rest == 17785
On the basis that the field has a length of 4 x 8 == 32 I have also tried using combinations of "S", "L" and "N", for example :
($messageType,$ProtoOrVer,$MsgLen,$MsgSeqNum,$ClOrdID,$OnBehalfOfCompI
+D,$rest) =unpack "A A n N N2 A*",$sourceMsg};
to which I get :
08:11:45 : messageType == B
08:11:45 : ProtoOrVer == 2
08:11:45 : MsgLen == 116
08:11:45 : MsgSeqNum == 32681
08:11:45 : ClOrdID == 543376761
08:11:45 : OnBehalfOfCompID == 1569433565
08:11:45 : rest == 00029002
..which is also clearly wrong.
I've had 4 hours hours sleep, I'm at my wit's end and I'm up against the wall to get this nailed today.
Any help
GREATLY appreciated !!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.