Thread: Re: [Quickfix-developers] Checksum / Charset encoding problem
Brought to you by:
orenmnero
From: Lin L. <le...@gm...> - 2006-07-19 16:31:02
|
Hi,Lalonde 8=青 using getBytes() 56 + 61 - 57 - 32 + 1 = 29 ~~~~~~~~~~~~~~~~~~~~ Should not has negative number in above equality. I think it like blown: 56 + 61 +199 +244 + 1 = 561 Because I use unsigned byte value in it. Lejiang On 7/20/06, Lalonde, Francis <fra...@cg...> wrote: > > Hello Lin, > > Interesting question! > > The problem is that QuickFIX uses charAt() to calculate > the message checksum and getBytes() to fill network buffer but the results > dont match. > > I looked at the code, and I think my solution should work with double-byte > charset, because all it does is use getBytes() in both places. > > So in FIX checksum > > 8=青 > > using charAt() : > > 56 + 61 + 38738 + 1 = 38856 > > using getBytes() > > 56 + 61 - 57 - 32 + 1 = 29 > > ------------------------------ > *From:* Lin Lejiang [mailto:le...@gm...] > *Sent:* Wednesday, July 19, 2006 11:38 AM > *To:* Lalonde, Francis > *Cc:* qui...@li... > *Subject:* Re: [Quickfix-developers] Checksum / Charset encoding problem > > > Hi,Lalonde > I get the same problem with you.I use QFJ in GBK encoding platform. > You solution will not work in double byte charset.e.g. GBK.Is it? > In FIX document,checksum function will be: > > char *GenerateCheckSum( char *buf, long bufLen ) > > { > > static char tmpBuf[ 4 ]; > > long idx; > > unsigned int cks; > > > > for( idx = 0L, cks = 0; idx < bufLen; cks += (unsigned int)buf[ > idx++ ] ); > > sprintf( tmpBuf, "%03d", (unsigned int)( cks % 256 ) ); > > return( tmpBuf ); > > } > > In GBK encoding: > "青".charAt(0)=38738 > "青".getBytes()[0]=-57 > "青".getBytes()[1]=-32 > > The chk must be added with unsigned int or byte. > So in java: > chk = ((int)"青".getBytes()[0] )& 0xFF + ((int)"青".getBytes()[1] )& 0xFF > > > Do you think so? > > > Lejiang > > > > On 7/11/06, Lalonde, Francis <fra...@cg...> wrote: > > > > QuickFIX Documentation: http://www.quickfixengine.org/quickfix/doc/html/index.html > > > > QuickFIX Support: http://www.quickfixengine.org/services.html > > > > > > > > > > I haven't found references to this problem in the wiki or elsewhere, so > > I just wanted to share my thoughts. > > > > I've been having checksum problems when trying to send FIX messages > > having an XML payload. The FIX server I was communicating with (an instance > > of the Cameron FIX engine) would report bad checksums ont those messages > > containing XML, but not on other messages (Logon, Heartbeat, etc) > > > > I wrote a parallel program to double-check the checksums of the messages > > waiting in the QuickFIX queue (by parsing the .body file) just to make sure > > that the problem was really on my side, and it was. > > > > I traced the problem down to QuickFIX way of handling the charset > > encoding of the String fields. I fixed the problem by changing the > > Field.getTotal() method from > > > > * > > > > int > > *getTotal() { > > > > calculate(); > > > > * int* sum = 0; > > > > * for* (*int* i = 0; i < data.length(); i++) { > > > > sum += data.charAt(i); > > > > } > > > > * return* sum + 1; > > > > } > > > > to > > * > > > > int > > *getTotal() { > > > > calculate(); > > > > * int* sum = 1; > > > > * byte*[] bytes = data.getBytes(); > > > > * for* (*int* i = 0; i < bytes. length; i++) { > > > > sum += bytes[i]; > > > > } > > > > * return* sum; > > > > } > > > > It seems that charAt(i) and getBytes()[i] dont always return the same > > byte value, and since the MINA message encoder uses getBytes() to prepare > > the wire data, this method should also be used when computing the checksum > > to ensure accurate results. Also, I think the checksumming operation should > > probably moved to the encoding stage, to eliminate the redundancy of the > > relatively expensive getByte() which gets actually get called twice for each > > character in the message, but this required more extensive modifications so > > I left at this for now. > > > > Francis Lalonde > > Treasury Services > > CGI > > > > > > > > > > > > ------------------------------------------------------------------------- > > Using Tomcat but need to do more? Need to support web services, > > security? > > Get stuff done quickly with pre-integrated technology to make your job > > easier > > Download IBM WebSphere Application Server v.1.0.1 based on Apache > > Geronimo > > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > > > > > > _______________________________________________ > > Quickfix-developers mailing list > > Qui...@li... > > https://lists.sourceforge.net/lists/listinfo/quickfix-developers > > > > > > > -- > Lin Lejiang > -- Lin Lejiang |
From: Lin L. <le...@gm...> - 2006-07-21 09:12:28
|
Hi,Lalonde I'm not the QFJ developer too. I think the QFJ not support this feature because the FIX protocol uses the iso8859-1 charset as default.If need put other charset to FIX message,we must use the "Encode" field,such as EncodeText. I must use the FIX message with GBK charset in common field,because I'm working with a FIX Dialects now.Its default charset is GBK. I also wish QFJ can support this. Regard. Lejiang On 7/20/06, Lalonde, Francis <fra...@cg...> wrote: > > > Oh, I understand. My solution was working only because the > special characters in the data are not negative, but it wouldn't have worked > with GBK. Your solution should cover all cases, including UTF-32. I will try > your code in my application. It would be nice to have the unsigned byte[] > native in java like there is in C! > > Can you also submit your fix to the main QuickFIX repository or > developpers? I am not on the developper list, but you seem to be, it would > be nice if this was in the next QuickFIX version. I dont understand why this > wasn't corrected before. > > I also think that the checksum should only be calculated from the > getBytes() in the ProtocolEncoder. The initial checksum value would be > something like "10=000" and at very end, just before sending the bytes, we > replace "000" with the actual checksum. So getBytes() would only be called > once for the message. > > Francis > > ------------------------------ > *From:* Lin Lejiang [mailto:le...@gm...] > *Sent:* Thursday, July 20, 2006 4:22 AM > > *To:* Lalonde, Francis > *Cc:* qui...@li... > *Subject:* Re: [Quickfix-developers] Checksum / Charset encoding problem > > > Hi,Lalonde > > I think you code will not work right because the negative byte value in > GBK or Unicode charset. > I also modify the code here.But I have not test it with other FIX > engine,like Sybase GlobalFIX. > > I add the java files I modified with mail as a reference. > > > Regard. > > Lejiang > > On 7/20/06, Lalonde, Francis <fra...@cg...> wrote: > > > > Yes, you are right, so > > > > 38856 % 256 = 200 (bad checksum) > > > > and > > > > 561 % 256 = 49 (good checksum) > > > > So what I did is in quickfix.Field.java, I replaced the method > > > > > > /*package*/ /*int getTotal() { > > > > calculate(); > > > > int sum = 0; > > > > for (int i = 0; i < data.length(); i++) { > > > > for int > > > > sum += data.charAt(i); > > > > } > > > > return sum+1; > > > > }*/ > > > > *int* getTotal() { > > > > calculate(); > > > > *int* sum = 1; > > > > *byte*[] bytes = data.getBytes(); > > > > *for* (*int* i = 0; i < bytes. length; i++) { > > > > sum += bytes[i]; > > > > } > > > > *return* sum; > > > > } > > This should work with your data too, let me know if it works or not. > > > > Bye! > > > > Francis > > > > > > ------------------------------ > > *From:* Lin Lejiang [mailto:le...@gm...] > > *Sent:* Wednesday, July 19, 2006 12:31 PM > > > > *To:* Lalonde, Francis > > *Cc:* qui...@li... > > *Subject:* Re: [Quickfix-developers] Checksum / Charset encoding problem > > > > > > Hi,Lalonde > > > > 8=青 > > > > using getBytes() > > 56 + 61 - 57 - 32 + 1 = 29 > > ~~~~~~~~~~~~~~~~~~~~ > > Should not has negative number in above equality. > > I think it like blown: > > 56 + 61 +199 +244 + 1 = 561 > > > > Because I use unsigned byte value in it. > > > > > > Lejiang > > > > > > > > > > On 7/20/06, Lalonde, Francis < fra...@cg...> wrote: > > > > > > Hello Lin, > > > > > > Interesting question! > > > > > > The problem is that QuickFIX uses charAt() to calculate > > > the message checksum and getBytes() to fill network buffer but the results > > > dont match. > > > > > > I looked at the code, and I think my solution should work with > > > double-byte charset, because all it does is use getBytes() in both places. > > > > > > So in FIX checksum > > > > > > 8=青 > > > > > > using charAt() : > > > > > > 56 + 61 + 38738 + 1 = 38856 > > > > > > using getBytes() > > > > > > 56 + 61 - 57 - 32 + 1 = 29 > > > > > > ------------------------------ > > > *From:* Lin Lejiang [mailto: le...@gm... ] > > > *Sent:* Wednesday, July 19, 2006 11:38 AM > > > *To:* Lalonde, Francis > > > *Cc:* qui...@li... > > > *Subject:* Re: [Quickfix-developers] Checksum / Charset encoding > > > problem > > > > > > > > > Hi,Lalonde > > > I get the same problem with you.I use QFJ in GBK encoding platform. > > > You solution will not work in double byte charset.e.g. GBK.Is it? > > > In FIX document,checksum function will be: > > > > > > char *GenerateCheckSum( char *buf, long bufLen ) > > > > > > { > > > > > > static char tmpBuf[ 4 ]; > > > > > > long idx; > > > > > > unsigned int cks; > > > > > > > > > > > > for( idx = 0L, cks = 0; idx < bufLen; cks += (unsigned int)buf[ > > > idx++ ] ); > > > > > > sprintf( tmpBuf, "%03d", (unsigned int)( cks % 256 ) ); > > > > > > return( tmpBuf ); > > > > > > } > > > > > > In GBK encoding: > > > "青".charAt(0)=38738 > > > "青".getBytes()[0]=-57 > > > "青".getBytes()[1]=-32 > > > > > > The chk must be added with unsigned int or byte. > > > So in java: > > > chk = ((int)"青".getBytes()[0] )& 0xFF + ((int)"青".getBytes()[1] )& > > > 0xFF > > > > > > > > > Do you think so? > > > > > > > > > Lejiang > > > > > > > > > > > > On 7/11/06, Lalonde, Francis < fra...@cg...> wrote: > > > > > > > > QuickFIX Documentation: http://www.quickfixengine.org/quickfix/doc/html/index.html > > > > > > > > QuickFIX Support: http://www.quickfixengine.org/services.html > > > > > > > > > > > > > > > > > > > > I haven't found references to this problem in the wiki or > > > > elsewhere, so I just wanted to share my thoughts. > > > > > > > > I've been having checksum problems when trying to send FIX messages > > > > having an XML payload. The FIX server I was communicating with (an instance > > > > of the Cameron FIX engine) would report bad checksums ont those messages > > > > containing XML, but not on other messages (Logon, Heartbeat, etc) > > > > > > > > I wrote a parallel program to double-check the checksums of the > > > > messages waiting in the QuickFIX queue (by parsing the .body file) just to > > > > make sure that the problem was really on my side, and it was. > > > > > > > > I traced the problem down to QuickFIX way of handling the charset > > > > encoding of the String fields. I fixed the problem by changing the > > > > Field.getTotal() method from > > > > > > > > * > > > > > > > > int > > > > *getTotal() { > > > > > > > > calculate(); > > > > > > > > * int* sum = 0; > > > > > > > > * for* (*int* i = 0; i < data.length(); i++) { > > > > > > > > sum += data.charAt(i); > > > > > > > > } > > > > > > > > * return* sum + 1; > > > > > > > > } > > > > > > > > to > > > > * > > > > > > > > int > > > > *getTotal() { > > > > > > > > calculate(); > > > > > > > > * int* sum = 1; > > > > > > > > * byte*[] bytes = data.getBytes(); > > > > > > > > * for* (*int* i = 0; i < bytes. length; i++) { > > > > > > > > sum += bytes[i]; > > > > > > > > } > > > > > > > > * return* sum; > > > > > > > > } > > > > > > > > It seems that charAt(i) and getBytes()[i] dont always return the > > > > same byte value, and since the MINA message encoder uses getBytes() to > > > > prepare the wire data, this method should also be used when computing the > > > > checksum to ensure accurate results. Also, I think the > > > > checksumming operation should probably moved to the encoding stage, to > > > > eliminate the redundancy of the relatively expensive getByte() which gets > > > > actually get called twice for each character in the message, but this > > > > required more extensive modifications so I left at this for now. > > > > > > > > Francis Lalonde > > > > Treasury Services > > > > CGI > > > > > > > > > > > > > > > > > > > > > > > > ------------------------------------------------------------------------- > > > > Using Tomcat but need to do more? Need to support web services, > > > > security? > > > > Get stuff done quickly with pre-integrated technology to make your > > > > job easier > > > > Download IBM WebSphere Application Server v.1.0.1 based on Apache > > > > Geronimo > > > > > > > > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > > > > > > > > > > > > _______________________________________________ > > > > Quickfix-developers mailing list > > > > Qui...@li... > > > > https://lists.sourceforge.net/lists/listinfo/quickfix-developers > > > > > > > > > > > > > > > > > -- > > > Lin Lejiang > > > > > > > > > > > -- > > Lin Lejiang > > > > > > -- > Lin Lejiang > -- Lin Lejiang |
From: Steve B. <sb...@sm...> - 2006-07-21 10:49:41
|
Hello Lin, Can you add a feature request to the QFJ issue tracker and attach the files you've been including in the emails? I'll try to integrate these changes for a future release. Thanks, Steve > -----Original Message----- > From: qui...@li...=20 > [mailto:qui...@li...] On=20 > Behalf Of Lin Lejiang > Sent: Friday, July 21, 2006 11:12 AM > To: Lalonde, Francis > Cc: qui...@li... > Subject: Re: [Quickfix-developers] Checksum / Charset encoding problem >=20 > QuickFIX Documentation:=20 > http://www.quickfixengine.org/quickfix/doc/html/index.html > QuickFIX Support: http://www.quickfixengine.org/services.html >=20 >=20 |
From: Lin L. <le...@gm...> - 2006-07-21 11:34:56
|
Hi,Steve I have added this feature request to the QFJ issue tracker. http://www.quickfixj.org/jira/browse/QFJ-38 But I don't know how to attach the file with the request. Can you help to attach the files with it in this mail? Regards. Lejiang On 7/21/06, Steve Bate <sb...@sm...> wrote: > > Hello Lin, > > Can you add a feature request to the QFJ issue tracker and attach > the files you've been including in the emails? I'll try to > integrate these changes for a future release. > > Thanks, > > Steve > > > -----Original Message----- > > From: qui...@li... > > [mailto:qui...@li...] On > > Behalf Of Lin Lejiang > > Sent: Friday, July 21, 2006 11:12 AM > > To: Lalonde, Francis > > Cc: qui...@li... > > Subject: Re: [Quickfix-developers] Checksum / Charset encoding problem > > > > QuickFIX Documentation: > > http://www.quickfixengine.org/quickfix/doc/html/index.html > > QuickFIX Support: http://www.quickfixengine.org/services.html > > > > > -- Lin Lejiang |
From: Joerg T. <Joe...@ma...> - 2006-07-21 11:56:33
|
On 07/21/06 13:34, Lin Lejiang wrote: Hi Lejiang, > I have added this feature request to the QFJ issue tracker. > http://www.quickfixj.org/jira/browse/QFJ-38 > =20 > But I don't know how to attach the file with the request. > =20 > Can you help to attach the files with it in this mail? In JIRA, the Operations section which also includes "Attach file" is only= visible if you are logged=20 in. Please log in (top right corner), and you should be able to attach fi= les. Cheers, J=F6rg --=20 Joerg Thoennes http://macd.com Tel.: +49 (0)241 44597-24 Macdonald Associates GmbH Fax : +49 (0)241 44597-10 Lothringer Str. 52, D-52070 Aachen |
From: Lin L. <le...@gm...> - 2006-07-21 12:10:49
|
Hi,Joery I'm ensure I have logined the JIRA because I can see the "Log Out" button o= n the top. But I cann't see any attach button in the new feature request window. Regards. Lejiang. On 7/21/06, Joerg Thoennes <Joe...@ma...> wrote: > > On 07/21/06 13:34, Lin Lejiang wrote: > > Hi Lejiang, > > > I have added this feature request to the QFJ issue tracker. > > http://www.quickfixj.org/jira/browse/QFJ-38 > > > > But I don't know how to attach the file with the request. > > > > Can you help to attach the files with it in this mail? > > In JIRA, the Operations section which also includes "Attach file" is only > visible if you are logged > in. Please log in (top right corner), and you should be able to attach > files. > > Cheers, J=F6rg > > -- > Joerg Thoennes > http://macd.com > Tel.: +49 (0)241 44597-24 Macdonald Associates GmbH > Fax : +49 (0)241 44597-10 Lothringer Str. 52, D-52070 Aachen > --=20 Lin Lejiang |
From: Caleb E. <cal...@gm...> - 2006-07-21 16:35:45
|
On 7/21/06, Lin Lejiang <le...@gm...> wrote: [ 4 messages included in their entirety ] Leijang, Please limit your quoting when replying to messages. Include only the *relevant* portions of any text you need, not the entire message. -- Caleb Epstein |