PbReader.h 843 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #ifndef PBREADER_H
  2. #define PBREADER_H
  3. #include <vector>
  4. #include <string>
  5. #include <memory>
  6. #include <PbWireType.h>
  7. class PbReader
  8. {
  9. private:
  10. std::vector<uint8_t> const &rawData;
  11. uint32_t currentWireValue = 0;
  12. uint64_t skipVarIntDump = 0;
  13. uint32_t nextFieldLength = 0;
  14. int64_t decodeZigzag(uint64_t value);
  15. public:
  16. PbReader(std::vector<uint8_t> const &rawData);
  17. uint32_t maxPosition = 0;
  18. PbWireType currentWireType = PbWireType::unknown;
  19. uint32_t currentTag = 0;
  20. uint32_t pos = 0;
  21. template <typename T>
  22. T decodeVarInt();
  23. template <typename T>
  24. T decodeFixed();
  25. template <typename T>
  26. T decodeSVarInt();
  27. void decodeString(std::string &target);
  28. void decodeVector(std::vector<uint8_t> &target);
  29. bool next();
  30. void skip();
  31. void resetMaxPosition();
  32. };
  33. #endif