Message* Packet::deserialize(std::istream& ifs) { std::vector<char> data; // Get the message header. data.resize(DUNE_IMC_CONST_HEADER_SIZE); ifs.read(&data[0], DUNE_IMC_CONST_HEADER_SIZE); // If we're at the EOF there's nothing more to do. if (ifs.eof()) return 0; if (ifs.gcount() < DUNE_IMC_CONST_HEADER_SIZE) throw BufferTooShort(); Header hdr; deserializeHeader(hdr, (uint8_t*)&data[0], DUNE_IMC_CONST_HEADER_SIZE); // Get remaining data. uint16_t remaining = hdr.size + DUNE_IMC_CONST_FOOTER_SIZE; data.resize(DUNE_IMC_CONST_HEADER_SIZE + remaining); ifs.read(&data[DUNE_IMC_CONST_HEADER_SIZE], remaining); if (ifs.gcount() < remaining) throw BufferTooShort(); return deserializePayload(hdr, (uint8_t*)&data[0], DUNE_IMC_CONST_HEADER_SIZE + remaining, 0); }
Message* Packet::deserialize(std::istream& ifs, Utils::ByteBuffer& bfr) { // Get the message header. bfr.setSize(DUNE_IMC_CONST_HEADER_SIZE); ifs.read(bfr.getBufferSigned(), DUNE_IMC_CONST_HEADER_SIZE); // If we're at the EOF there's nothing more to do. if (ifs.eof()) return 0; if (ifs.gcount() < DUNE_IMC_CONST_HEADER_SIZE) throw BufferTooShort(); Header hdr; deserializeHeader(hdr, bfr.getBuffer(), DUNE_IMC_CONST_HEADER_SIZE); // Get remaining data. uint16_t remaining = hdr.size + DUNE_IMC_CONST_FOOTER_SIZE; bfr.setSize(DUNE_IMC_CONST_HEADER_SIZE + remaining); ifs.read(bfr.getBufferSigned() + DUNE_IMC_CONST_HEADER_SIZE, remaining); if (ifs.gcount() < remaining) throw BufferTooShort(); return deserializePayload(hdr, bfr.getBuffer(), DUNE_IMC_CONST_HEADER_SIZE + remaining, 0); }
const ObjectType* ObjectType::loadFromFile(const string path, const int objectTypeId) { xml_document doc; const xml_parse_result result = doc.load_file(path.c_str()); #ifdef ENABLE_LOGGING LOGGER->info("Loaded [%s]. Result: [%s]", path.c_str(), result.description()); #endif xml_node node = doc.root().child("object"); const xml_node headerNode = node.child("header"); const Header* header = deserializeHeader(headerNode); auto const sequences = new vector<const Sequence*>(1); auto sequenceNodes = node.children("sequence"); for (const xml_node sequenceNode : sequenceNodes) { auto const sequence = deserializeSequence(sequenceNode); const int sequenceId = sequence->getId(); auto size = sequences->size(); // ensure sufficient capacity if (size <= (unsigned int) sequenceId) { const double val = log2((double) sequenceId); const int newSize = 2 << (int) (ceil(val)); sequences->resize(newSize); } sequences->at(sequenceId) = sequence; } return new ObjectType(objectTypeId, header, sequences); }
ssize_t SyncRequestPacket::deserializePacket(const uint8_t* data, uint32_t length) { ssize_t offset = deserializeHeader(data, length); if (offset > 0) { DESERIALIZE_INT64(clientTxLocalTime); } return offset; }
ssize_t MasterAnnouncementPacket::deserializePacket(const uint8_t* data, uint32_t length) { ssize_t offset = deserializeHeader(data, length); if (offset > 0) { uint64_t packed; DESERIALIZE_INT64(packed); deviceID = unpackDeviceID(packed); devicePriority = unpackDevicePriority(packed); } return offset; }
ssize_t SyncResponsePacket::deserializePacket(const uint8_t* data, uint32_t length) { ssize_t offset = deserializeHeader(data, length); if (offset > 0) { DESERIALIZE_INT64(clientTxLocalTime); DESERIALIZE_INT64(masterRxCommonTime); DESERIALIZE_INT64(masterTxCommonTime); DESERIALIZE_INT32(nak); } return offset; }
Message* Packet::deserialize(const uint8_t* bfr, uint16_t bfr_len, Message* msg) { Header hdr; // Get the message header. deserializeHeader(hdr, bfr, bfr_len); // Check if we can unpack the message. if (hdr.size > bfr_len - (DUNE_IMC_CONST_HEADER_SIZE + DUNE_IMC_CONST_FOOTER_SIZE)) throw BufferTooShort(); return deserializePayload(hdr, bfr, bfr_len, msg); }
/** Creates an infoMessage from the stream of bytes starting at source @param source the beginning of the serialized Info Message @param info the infoMessage to create @return the number of bytes deserialized if success, or else an error code < 0 */ int16_t deserializeInfoMessage(unsigned char* source, struct infoMessage* info) { unsigned char* sourcePtr = source; info->header = deserializeHeader(sourcePtr); // First, deserialize the header sourcePtr += (HEADER_SIZE); info->deviceType = *sourcePtr++; // Get the deviceType info->numParameters = *sourcePtr++; // ... and the number of Parameters if (info->numParameters > MAX_KVPS_IN_STATUS_MESSAGE) return -1; int i; for (i=0; i < info->numParameters; i++) //for each Parameter: { info->kvps[i].oid = *sourcePtr++; info->kvps[i].value = CONVERT_TO_INT( (*sourcePtr), (*(sourcePtr+1)) ); sourcePtr += 2; } return (sourcePtr - source); }
UInt8 DeltaThetaVector::deserialize(UInt8* pBuf, UInt8 size) { UInt8 ret = 0; if (size >= MipField::MIN_MIP_FIELD_HEADER_SIZE) { deserializeHeader(pBuf, size); if (size >= m_fieldLength && m_fieldLength == DELTA_THETA_VECTOR_STATIC_SIZE) { m_x = getFloat32(&pBuf[DELTA_THETA_VECTOR_X_OFFSET]); m_y = getFloat32(&pBuf[DELTA_THETA_VECTOR_Y_OFFSET]); m_z = getFloat32(&pBuf[DELTA_THETA_VECTOR_Z_OFFSET]); ret = m_fieldLength; } } return ret; }