|
INET Framework for OMNeT++/OMNEST
|
00001 // 00002 // (C) 2005 Vojtech Janota 00003 // 00004 // This library is free software, you can redistribute it 00005 // and/or modify 00006 // it under the terms of the GNU Lesser General Public License 00007 // as published by the Free Software Foundation; 00008 // either version 2 of the License, or any later version. 00009 // The library is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00012 // See the GNU Lesser General Public License for more details. 00013 // 00014 00015 #include "ByteArrayMessage.h" 00016 00017 void ByteArrayMessage::setDataFromBuffer(const void *ptr, int length) 00018 { 00019 ASSERT(length > 0); 00020 00021 delete[] data_var; 00022 data_var = new char[length]; 00023 data_arraysize = length; 00024 memcpy(data_var, ptr, length); 00025 } 00026 00027 void ByteArrayMessage::copyDataToBuffer(void *ptr, int length) 00028 { 00029 ASSERT((uint)length <= data_arraysize); 00030 00031 memcpy(ptr, data_var, length); 00032 } 00033 00034 void ByteArrayMessage::removePrefix(int length) 00035 { 00036 ASSERT(data_arraysize > (uint)length); 00037 ASSERT(length > 0); 00038 00039 int nlength = data_arraysize - length; 00040 char *data_var2 = new char[nlength]; 00041 memcpy(data_var2, data_var+length, nlength); 00042 delete[] data_var; 00043 data_var = data_var2; 00044 data_arraysize = nlength; 00045 } 00046 00047