buffer.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #pragma once
  2. #include <stdint.h>
  3. class Buffer {
  4. public:
  5. Buffer();
  6. ~Buffer();
  7. unsigned int GetLength();
  8. int IndexOf(char c);
  9. void Clear();
  10. const char * Peek();
  11. uint32_t PeekUInt32();
  12. unsigned int Read(unsigned int len, char **dst);
  13. unsigned int Read(unsigned int len, char *dst, unsigned int size);
  14. uint32_t ReadUInt32();
  15. bool Write(const char *data, unsigned int len);
  16. bool Write(const char *data);
  17. bool Write(const unsigned char *data, unsigned int len);
  18. bool WriteUInt8(uint8_t data);
  19. bool WriteInt8(int8_t data);
  20. bool WriteUInt16(uint16_t data);
  21. bool WriteInt16(int16_t data);
  22. bool WriteUInt32(uint32_t data);
  23. bool WriteInt32(int32_t data);
  24. bool WriteUInt64(uint64_t data);
  25. bool WriteInt64(int64_t data);
  26. bool WriteChar(char data);
  27. bool WriteDouble(double data);
  28. bool WriteAt(unsigned int index, const char *data, unsigned int len);
  29. bool WriteAtUInt32(unsigned int index, uint32_t data);
  30. private:
  31. char *buf;
  32. unsigned int capacity;
  33. unsigned int len;
  34. void PeekReadPrimitive(void *buf, unsigned int size, bool peek);
  35. };