proto_buffer.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /******************************************************************************
  2. 版权所有 (C), 2019-2029, SDC OS 开源软件小组所有
  3. ******************************************************************************
  4. 文 件 名 : proto_buffer.h
  5. 版 本 号 : 初稿
  6. 作 者 : athina
  7. 生成日期 : 2020年7月4日
  8. 最近修改 :
  9. 功能描述 : 消息数组封装
  10. 函数列表 :
  11. 修改历史 :
  12. 1.日 期 : 2020年7月4日
  13. 作 者 : athina
  14. 修改内容 : 创建文件
  15. ******************************************************************************/
  16. #ifndef __PROTO_STREAM_H__
  17. #define __PROTO_STREAM_H__
  18. #include <string>
  19. #include <array>
  20. namespace HWYolov3App
  21. {
  22. class ProtoBuffer
  23. {
  24. public:
  25. ProtoBuffer(void);
  26. virtual ~ProtoBuffer(void);
  27. size_t GetUsed(void) const;
  28. size_t GetSize(void) const;
  29. const uint8_t* GetData(void) const;
  30. bool Full(void) const;
  31. bool Empty(void) const;
  32. int32_t WriteBytes(const void *buf, size_t len);
  33. void Clear(void);
  34. friend ProtoBuffer& operator<<(ProtoBuffer &is, uint8_t i);
  35. friend ProtoBuffer& operator<<(ProtoBuffer &is, uint16_t i);
  36. friend ProtoBuffer& operator<<(ProtoBuffer &is, uint32_t i);
  37. friend ProtoBuffer& operator<<(ProtoBuffer &is, uint64_t i);
  38. friend ProtoBuffer& operator<<(ProtoBuffer &is, const std::string &s);
  39. private:
  40. static const int MAX_BUF_SIZE = 4096;
  41. typedef std::array<uint8_t, ProtoBuffer::MAX_BUF_SIZE> Array;
  42. Array m_array;
  43. size_t m_used;
  44. };
  45. }
  46. #endif /* __PROTO_STREAM_H__ */