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