Re: [Quickfix-developers] Checksum / Charset encoding problem
Brought to you by:
orenmnero
|
From: Lin L. <le...@gm...> - 2006-07-19 15:37:53
|
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
|