MercuryResponse.cpp 1003 B

123456789101112131415161718192021222324252627282930313233
  1. #include "MercuryResponse.h"
  2. MercuryResponse::MercuryResponse(std::vector<uint8_t> &data)
  3. {
  4. // this->mercuryHeader = std::make_unique<Header>();
  5. this->parts = mercuryParts(0);
  6. this->parseResponse(data);
  7. }
  8. void MercuryResponse::parseResponse(std::vector<uint8_t> &data)
  9. {
  10. auto sequenceLength = ntohs(extract<uint16_t>(data, 0));
  11. this->sequenceId = hton64(extract<uint64_t>(data, 2));
  12. auto partsNumber = ntohs(extract<uint16_t>(data, 11));
  13. auto headerSize = ntohs(extract<uint16_t>(data, 13));
  14. auto headerBytes = std::vector<uint8_t>(data.begin() + 15, data.begin() + 15 + headerSize);
  15. auto pos = 15 + headerSize;
  16. while (pos < data.size())
  17. {
  18. auto partSize = ntohs(extract<uint16_t>(data, pos));
  19. this->parts.push_back(
  20. std::vector<uint8_t>(
  21. data.begin() + pos + 2,
  22. data.begin() + pos + 2 + partSize));
  23. pos += 2 + partSize;
  24. }
  25. this->mercuryHeader = decodePb<Header>(headerBytes);
  26. }