/** * Returns the serialized version of this object. * This method is required by stObject interface. * @warning If you don't know how to serialize an object, this methos may * be a good example. */ const stByte * TCity::Serialize(){ double * d; // Is there a seralized version ? if (Serialized == NULL){ // No! Lets build the serialized version. // The first thing we need to do is to allocate resources... Serialized = new stByte[GetSerializedSize()]; // We will organize it in this manner: // +----------+-----------+--------+ // | Latitude | Longitude | Name[] | // +----------+-----------+--------+ // So, write the Longitude and Latitude should be written to serialized // version as follows d = (double *) Serialized; // If you ar not familiar with pointers, this // action may be tricky! Be careful! d[0] = Latitude; d[1] = Longitude; // Now, write the name after the 2 doubles... memcpy(Serialized + (sizeof(double) * 2), Name.c_str(), Name.length()); }//end if return Serialized; }//end TCity::Serialize
uint32_t RrepAckHeader::Deserialize (Buffer::Iterator start ) { Buffer::Iterator i = start; m_reserved = i.ReadU8 (); uint32_t dist = i.GetDistanceFrom (start); NS_ASSERT (dist == GetSerializedSize ()); return dist; }
const stByte * HImagem::Serialize() { stByte *bytes = new stByte[GetSerializedSize()]; memcpy(bytes, _hash.data(), 40); memcpy(bytes + 40, _VC.data(), sizeof(float) * _VC.size()); return bytes; }
const stByte * Image::Serialize(){ double * d; if (Serialized == NULL){ Serialized = new stByte[GetSerializedSize()]; d = (double *) Serialized; for(int i = 0; i< 13;i++){ d[i] = features[i]; } memcpy(Serialized + (sizeof(double) * 13), &nivel, sizeof(int)); memcpy(Serialized + (sizeof(double) * 13)+sizeof(int), nombre.c_str(), nombre.length()); } return Serialized; }
/** * Returns the serialized version of this object. * This method is required by stObject interface. * @warning If you don't know how to serialize an object, this methos may * be a good example. */ const stByte * TNamedArray::Serialize() { if (Serialized == NULL) { Serialized = new stByte[GetSerializedSize()]; memcpy(Serialized, &Length, sizeof(unsigned)); memcpy(Serialized + sizeof(unsigned), Values, Length * sizeof(unsigned)); Values = (unsigned *) (Serialized + sizeof(unsigned)); memcpy(Serialized + (sizeof(unsigned) * (Length + 1)), Name.c_str(), Name.length()); } return Serialized; }//end TNamedArray::Serialize
uint32_t RrepHeader::Deserialize (Buffer::Iterator start) { Buffer::Iterator i = start; m_flags = i.ReadU8 (); m_prefixSize = i.ReadU8 (); m_hopCount = i.ReadU8 (); ReadFrom (i, m_dst); m_dstSeqNo = i.ReadNtohU32 (); ReadFrom (i, m_origin); m_lifeTime = i.ReadNtohU32 (); uint32_t dist = i.GetDistanceFrom (start); NS_ASSERT (dist == GetSerializedSize ()); return dist; }
uint32_t RerrHeader::Deserialize (Buffer::Iterator start ) { Buffer::Iterator i = start; m_flag = i.ReadU8 (); m_reserved = i.ReadU8 (); uint8_t dest = i.ReadU8 (); m_unreachableDstSeqNo.clear (); Ipv4Address address; uint32_t seqNo; for (uint8_t k = 0; k < dest; ++k) { ReadFrom (i, address); seqNo = i.ReadNtohU32 (); m_unreachableDstSeqNo.insert (std::make_pair (address, seqNo)); } uint32_t dist = i.GetDistanceFrom (start); NS_ASSERT (dist == GetSerializedSize ()); return dist; }
uint32_t TypeHeader::Deserialize (Buffer::Iterator start) { Buffer::Iterator i = start; uint8_t type = i.ReadU8 (); m_valid = true; switch (type) { case AODVTYPE_RREQ: case AODVTYPE_RREP: case AODVTYPE_RERR: case AODVTYPE_RREP_ACK: { m_type = (MessageType) type; break; } default: m_valid = false; } uint32_t dist = i.GetDistanceFrom (start); NS_ASSERT (dist == GetSerializedSize ()); return dist; }