ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » General IBM MQ Support » How to read "Message Identifier Bytes" in C code?

Post new topic  Reply to topic Goto page Previous  1, 2, 3  Next
 How to read "Message Identifier Bytes" in C code? « View previous topic :: View next topic » 
Author Message
Vitor
PostPosted: Fri Oct 28, 2011 8:56 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

mattfarney wrote:
I had to add a structure like this to get the conversion to work. Some of the bytes converted to FFFFFF52 instead of 52.


Now why do you think that would be?

I can just about see that you could use this for logging, though IMHO something a bit more business-related would have more value. It's all very well logging the message id, but when some user claims that transaction on customer x didn't make it through the infrastructure how are you going to trace that?

The OP is trying to invent his own assured delivery mechanism based on these ids. It's not impossible, in the same way my brother in law can get a supercharged V8 into his otherwise unmodified & somewhat rusty 2005 Blazer. It doesn't make it a good idea (though if he manages to avoid killing anyone else or hitting anything with value the downsides will be limited)
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
bruce2359
PostPosted: Fri Oct 28, 2011 9:03 am    Post subject: Reply with quote

Poobah

Joined: 05 Jan 2008
Posts: 9475
Location: US: west coast, almost. Otherwise, enroute.

Units of work can't span multiple qmgrs. I've chatted with a few sysadmin/developer types that thought: "Hey, I can write an app that MQCONNects to two different qmgrs concurrently, then MQPUT/MQGET to queues one and/or the other, then MQCMIT/MQBACK both!'

Yes, but what if the first qmgr you MQCMIT works OK; but the 2nd fails? How do you backout what you've already committed? "That's easy," he said; "I'll just write the things I've committed to a file, and replay the file." Sound familiar?

Not so easy, he discovered.
_________________
I like deadlines. I like to wave as they pass by.
ב''ה
Lex Orandi, Lex Credendi, Lex Vivendi. As we Worship, So we Believe, So we Live.
Back to top
View user's profile Send private message
mattfarney
PostPosted: Fri Oct 28, 2011 10:35 am    Post subject: Reply with quote

Disciple

Joined: 17 Jan 2006
Posts: 167
Location: Ohio

This statement is not 100% true.
Quote:
Not all BYTE (hex) characters are printable.

There are ways to encode binary values and have the result be printable (re: Base 64).

Assume I have a byte string of AMQ followed by \01, \04, and \13.
One printable encoding of that byte string is: 414D52010413

-mf
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Fri Oct 28, 2011 10:51 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20763
Location: LI,NY

mattfarney wrote:
This statement is not 100% true.
Quote:
Not all BYTE (hex) characters are printable.

There are ways to encode binary values and have the result be printable (re: Base 64).

Assume I have a byte string of AMQ followed by \01, \04, and \13.
One printable encoding of that byte string is: 414D52010413

-mf

Even easier than base64 encoding: a hex representation of the byte array...
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
bruce2359
PostPosted: Fri Oct 28, 2011 11:03 am    Post subject: Reply with quote

Poobah

Joined: 05 Jan 2008
Posts: 9475
Location: US: west coast, almost. Otherwise, enroute.

We're talking about digital data. Why does it need to be printed anyway?
_________________
I like deadlines. I like to wave as they pass by.
ב''ה
Lex Orandi, Lex Credendi, Lex Vivendi. As we Worship, So we Believe, So we Live.
Back to top
View user's profile Send private message
Vitor
PostPosted: Fri Oct 28, 2011 11:08 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

bruce2359 wrote:
We're talking about digital data. Why does it need to be printed anyway?


Not printed but printable - the OP's trying to use it as a file name in his home spun assured delivery system.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
bruce2359
PostPosted: Fri Oct 28, 2011 11:14 am    Post subject: Reply with quote

Poobah

Joined: 05 Jan 2008
Posts: 9475
Location: US: west coast, almost. Otherwise, enroute.

How about this: His app could create a table of MsgIds and program-generated filenames - like MSG00001, MSG00002, and so on. No need to fiddle with the MsgId.
_________________
I like deadlines. I like to wave as they pass by.
ב''ה
Lex Orandi, Lex Credendi, Lex Vivendi. As we Worship, So we Believe, So we Live.
Back to top
View user's profile Send private message
Vitor
PostPosted: Fri Oct 28, 2011 11:16 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

bruce2359 wrote:
How about this: His app could create a table of MsgIds and program-generated filenames - like MSG00001, MSG00002, and so on. No need to fiddle with the MsgId.


How about this: he uses the inbuilt assured delivery?

I wouldn't do it with files either.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
bruce2359
PostPosted: Fri Oct 28, 2011 12:39 pm    Post subject: Reply with quote

Poobah

Joined: 05 Jan 2008
Posts: 9475
Location: US: west coast, almost. Otherwise, enroute.

Vitor wrote:

How about this: he uses the inbuilt assured delivery?

What's fun about that? And it would be too easy.

Much better to write a needlessly and overly-complicated, and fraught-with-problems application program.
_________________
I like deadlines. I like to wave as they pass by.
ב''ה
Lex Orandi, Lex Credendi, Lex Vivendi. As we Worship, So we Believe, So we Live.
Back to top
View user's profile Send private message
gbaddeley
PostPosted: Sun Oct 30, 2011 2:21 pm    Post subject: Reply with quote

Jedi Knight

Joined: 25 Mar 2003
Posts: 2538
Location: Melbourne, Australia

lyntongrice wrote:
Below is a small sample program that produces the "wrong result".....i assune i must use a byte array instead of char?

The output for the following is:
Result: 414D5120514D30312020202020202020FFFFFF4EFFFF6

Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(){   
    char name[41]="AMQ QM01        \275\364\250N\242\243\006";
    char buffer[82]="";
    char *pbuffer = buffer;
   
    int rc = convertStrToHex(buffer, name);
    printf( "Result: %s\n", pbuffer );
    }
    return 0;
}

int convertStrToHex(char *buffer, char str[10]){
    int len = strlen(str);
    int i;

    for( i = 0; i < len ;i++ ){
        sprintf(buffer, "%X", str[i]);
        buffer +=2;
    };
}
Thanks for the help

Lynton


The sprintf needs format specification "%02X" to print 2 hex bytes per array entry.
_________________
Glenn
Back to top
View user's profile Send private message
mvic
PostPosted: Tue Nov 01, 2011 5:53 pm    Post subject: Reply with quote

Jedi

Joined: 09 Mar 2004
Posts: 2080

A few questions:

- Why char str[10] in the parameter list of convertStrToHex()? The code appears to be passing many more bytes than that.

- Why is the code using null-terminated strings? It appears to be intended to deal with non-terminated data that can have nulls in the middle of the data. If I am right about that, you would need to avoid strlen().

- unsigned char is probably needed, in order to make the %02X work the way it seems intended to work. gbaddeley is right to say %02X is needed rather than %X. But if you test it and find that that is not enough, unsigned char might be worth a try.
Back to top
View user's profile Send private message
mvic
PostPosted: Tue Nov 01, 2011 5:59 pm    Post subject: Reply with quote

Jedi

Joined: 09 Mar 2004
Posts: 2080

mattfarney wrote:
I have a logging program that turns the msgId and corId into printable text.

I had to add a structure like this to get the conversion to work. Some of the bytes converted to FFFFFF52 instead of 52.

Code:

char hexValueHold[8];
string msgIdAsHex;
string bufferFix;
      
memcpy(hexValueHold,"        ",8);
sprintf(hexValueHold,"%02X",hold[i]);
bufferFix = hexValueHold;
if (bufferFix.substr(0,6) == "FFFFFF")
   bufferFix = bufferFix.substr(6,2);
msgIdAsHex.append(bufferFix);


-mf

Like lyntongrice I suggest you experiment with using the "unsigned char" type. What type is the variable "hold", by the way? Even if the code you've written works (I cannot be sure it does), I still think it should be unnecessary to write that "if" test.
Back to top
View user's profile Send private message
mattfarney
PostPosted: Thu Nov 03, 2011 1:31 pm    Post subject: Reply with quote

Disciple

Joined: 17 Jan 2006
Posts: 167
Location: Ohio

Quote:
char hold[24];

I think you are correct.
Quote:
unsigned char hold[24];

would probably remove the need for the manual removal of what looks a negative value to me (FFFFFFXX).

-mf
Back to top
View user's profile Send private message
gbaddeley
PostPosted: Thu Nov 03, 2011 2:41 pm    Post subject: Reply with quote

Jedi Knight

Joined: 25 Mar 2003
Posts: 2538
Location: Melbourne, Australia

Its Friday here, I'm feeling generous:
Code:
/* -------------------------------------------------------------
 * Format a fixed length byte array into a null terminated
 * string buffer as hexadecimal representations of the bytes.
 * The size of WorkBuffer needs to be at least DataLen * 2 + 1.
 * Returns pointer to hex characters.
 */
char *FormatHex( void *pData, int DataLen, char *pWorkBuffer )
{
int i;
unsigned char *pUData;
char *pBuffOut;
static char HexDigits[16] = "0123456789ABCDEF";

  pUData = (unsigned char *)pData;
  pBuffOut = pWorkBuffer;
  for( i = 0 ; i < DataLen ; i++ )
    {
      *pBuffOut++ = HexDigits[ *pUData / 16 ];
      *pBuffOut++ = HexDigits[ *pUData++ % 16 ];
    }
  *pBuffOut = '\0';  /* Null terminate */
  return pWorkBuffer;
}


Usage:

char Work[50];

sprintf( "MsgIdHex=%s\n", FormatHex( Mqmd.MsgId, MQ_MSG_ID_LENGTH, Work ) );

_________________
Glenn
Back to top
View user's profile Send private message
rekarm01
PostPosted: Fri Nov 04, 2011 4:10 pm    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 1415

gbaddeley wrote:
The sprintf needs format specification "%02X" to print 2 hex bytes per array entry.

"%.2X" will probably work better.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Goto page Previous  1, 2, 3  Next Page 2 of 3

MQSeries.net Forum Index » General IBM MQ Support » How to read "Message Identifier Bytes" in C code?
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.