MercuryResponse.cpp 1.1 KB

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