inline Uint32 ConfigValues::pack(UtilBuffer& buf) const { Uint32 len = getPackedSize(); void * tmp = buf.append(len); if(tmp == 0){ return 0; } return pack(tmp, len); }
inline bool Properties::pack(UtilBuffer &buf) const { Uint32 size = getPackedSize(); void *tmp_buf = buf.append(size); if(tmp_buf == 0) return false; bool ret = pack((Uint32 *)tmp_buf); if(ret == false) return false; return true; }
void Trace::sendTrace(int dest){ int bufsize = getPackedSize(); void *buf = malloc(bufsize); MPI_Comm comm = MPI_COMM_WORLD; int position = 0; if(!buf){ cerr << "Trace::sendTrace(): cannot allocate buffer" << endl; exit(1); } PMPI_Send(&bufsize, 1, MPI_INT, dest, 0, comm); pack(buf, bufsize, &position, comm); PMPI_Send(buf, position, MPI_PACKED, dest, 0, comm); free(buf); }
/** * pack serializes this object into the provided buffer (pack will allocate the * buffer) storing only the data fields (at the moment) and ignoring all the meta- * data within the DataItem object. The format for the packed object will be * direct strings seperated by '\0' charaters. If a given string field is empty * then there will be consectutive '\0' characters. Each of the vector fields will * be preceeded by ::listNameStart:: and followed by ::listNameEnd:: (e.g. the * children vector will be ::childrenStart::\0data\0data\0::childrenEnd::\0). */ unsigned int System::pack( void** buffer ) { u32 ret = getPackedSize( ), length; char* buf; buf = new char[ ret ]; if( buf == NULL ) { string message( "Component.pack( ): new call failed, out of memory." ); Logger l; l.log( message, LOG_ERR ); VpdException ve( message ); throw ve; } memset( buf, '\0', ret ); *buffer = (void*)buf; /* -----------------------------------------------------*/ /* ------------ Load up the buffer with data -----------*/ /* -----------------------------------------------------*/ // The first entry in our buffer is our length in network byte order u32 netOrder = htonl( ret ); memcpy( buf, &netOrder, sizeof( u32 ) ); buf += sizeof( u32 ); // Next is our system CPU count. netOrder = htonl( mCPUCount ); memcpy( buf, &netOrder, sizeof( u32 ) ); buf += sizeof( u32 ); // Pack the individual data items. length = mIdNode.pack( buf ); buf += length; length = mArch.pack( buf ); buf += length; length = deviceTreeNode.pack( buf ); buf += length; length = mDescription.pack( buf ); buf += length; length = mBrand.pack( buf ); buf += length; length = mNodeName.pack( buf ); buf += length; length = mOS.pack( buf ); buf += length; length = mProcessorID.pack( buf ); buf += length; length = mMachineType.pack( buf ); buf += length; length = mMachineModel.pack( buf ); buf += length; length = mFeatureCode.pack( buf ); buf += length; length = mFlagField.pack( buf ); buf += length; length = mRecordType.pack( buf ); buf += length; length = mSerialNum1.pack( buf ); buf += length; length = mSerialNum2.pack( buf ); buf += length; length = mSUID.pack( buf ); buf += length; length = mKeywordVersion.pack( buf ); buf += length; length = mLocationCode.pack( buf ); buf += length; // Pack the child vector. memcpy( buf, CHILD_START.c_str( ), CHILD_START.length( ) ); buf += CHILD_START.length( ); *buf = '\0'; buf++; vector<string>::iterator child, cEnd; vector<DataItem*>::iterator item, dEnd; for( child = mChildren.begin( ), cEnd = mChildren.end( ); child != cEnd; ++child ) { const char* str = (*child).c_str( ); int length = (*child).length( ); memcpy( buf, str, length ); buf+= length; *buf = '\0'; buf++; } memcpy( buf, CHILD_END.c_str( ), CHILD_END.length( ) ); buf += CHILD_END.length( ); *buf = '\0'; buf++; // Pack the Device Specific vector memcpy( buf, DEVICE_START.c_str( ), DEVICE_START.length( ) ); buf += DEVICE_START.length( ); *buf = '\0'; buf++; for( item = mDeviceSpecific.begin( ), dEnd = mDeviceSpecific.end( ); item != dEnd; ++item ) { length = (*item)->pack( buf ); buf+= length; } memcpy( buf, DEVICE_END.c_str( ), DEVICE_END.length( ) ); buf += DEVICE_END.length( ); *buf = '\0'; buf++; // Pack the User Data vector memcpy( buf, USER_START.c_str( ), USER_START.length( ) ); buf += USER_START.length( ); *buf = '\0'; buf++; for( item = mUserData.begin( ), dEnd = mUserData.end( ); item != dEnd; ++item ) { length = (*item)->pack( buf ); buf+= length; } memcpy( buf, USER_END.c_str( ), USER_END.length( ) ); buf += USER_END.length( ); *buf = '\0'; buf++; return ret; }