|
测试程序如下- #include <ace/ACE.h>
- #include <ace/CDR_Stream.h>
- #include <ace/Message_Block.h>
- #include <ace/Log_Msg.h>
- #include <ace/OS.h>
- #pragma pack(1)
- typedef struct tagMsgHeader
- {
- unsigned int startFlag;
- unsigned short bodyLength;
- unsigned int messageSequence;
- unsigned char messageCmdCode;
- }MsgHeader;
- #pragma pack()
- int ACE_TMAIN(int, ACE_TCHAR *[])
- {
- MsgHeader h;
- memset(&h, 0, sizeof(MsgHeader));
- h.startFlag = 0xdbdbdbdb;
- h.bodyLength = 0xeeff;
- h.messageSequence = 0xadcdef;
- h.messageCmdCode = 0x08;
-
- int hlen = sizeof(h);
- int slen = sizeof(MsgHeader);
-
- ACE_InputCDR cdr((const char *)&h, sizeof(h));
- ACE_CDR::ULong startFlag;
- ACE_CDR::Short bodyLength;
- ACE_CDR::ULong messageSequence;
- ACE_CDR::Char messageCmdCode;
- cdr >> startFlag;
- cdr >> bodyLength;
- cdr >> messageSequence;
- cdr >> messageCmdCode;
-
- MsgHeader h2;
- h2.startFlag = startFlag;
- h2.bodyLength = bodyLength;
- h2.messageCmdCode = messageCmdCode;
- h2.messageSequence = messageSequence;
- return 0;
- }
复制代码
调试时出现问题,得不到正确的结果0xadcdef,而是无效的0xcccccccc,跟踪进去,发电 good_bit()返回值为false,而- h2.messageSequence = messageSequence;
复制代码 却得到了messageCmdCode的首字节0xef,这是怎么回事?是不是在字节对齐方面ACE_InputCdr需要做特殊的处理? |
|