ACE 类学习2: ACE_InputCDR 和 ACE_OutputCDR

仅仅是自学时,尝试学习两个类的用法,实际使用时不是这么用的,切勿照搬。详见C++NPv1 4.3

 

#include <iostream> #include "ace/OS.h" #include "ace/Message_Block.h" #include "ace/CDR_Stream.h" #define CDRBUFSIZE 32 using namespace std; int main(int argc, char * argv[]) { int input = 501; ACE_CDR::ULong uLong_input = ACE_CDR::ULong(input); ACE_CDR::ULong uLong_output; //output to CDR ACE_OutputCDR output_CDR(CDRBUFSIZE); output_CDR << ACE_CDR::ULong(uLong_input); //Use memcpy to copy from OutputCDR to Message_Block ACE_Message_Block payload(CDRBUFSIZE); if( NULL != memcpy(payload.wr_ptr(), output_CDR.begin()->rd_ptr(), sizeof(ACE_CDR::ULong))) { payload.wr_ptr(sizeof(ACE_CDR::ULong)); } //use Message_Block to construct InputCDR ACE_InputCDR input_CDR(&payload); input_CDR >> uLong_output; cout << "input is:" << input << endl << "output is:" << uLong_output << endl; return 0; }

你可能感兴趣的:(ACE 类学习2: ACE_InputCDR 和 ACE_OutputCDR)