123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- #ifndef STREAM_H
- #define STREAM_H
- #include <cstddef>
- #include <stdint.h>
- class Stream
- {
- public:
- Stream(size_t minSize = 1);
- virtual ~Stream();
- Stream(const Stream& other) = delete;
- Stream& operator=(const Stream& other) = delete;
- void readSocket(int socket);
- void sendToSocket(int socket);
-
- bool hasData() const;
-
- void write(const void* writeData, size_t length);
- void write(const char* writeData);
- void writeChar(char c);
- void writeShort(int16_t s);
- void writeInt(int32_t i);
- void writeLong(int64_t l);
- void writeUnsignedChar(uint8_t uc);
- void writeUnsignedShort(uint16_t us);
- void writeUnsignedInt(uint32_t ui);
- void writeUnsignedLong(uint64_t ul);
-
- bool read(void* buffer, size_t length);
- char readChar(char error);
- int16_t readShort(int16_t error);
- int32_t readInt(int32_t error);
- int64_t readLong(int64_t error);
- unsigned char readUnsignedChar(unsigned char error);
- uint16_t readUnsignedShort(uint16_t error);
- uint32_t readUnsignedInt(uint32_t error);
- uint64_t readUnsignedLong(uint64_t error);
-
- private:
- bool resize(size_t minSize);
- size_t getSize(size_t minSize) const;
-
- // limit to 50 mbyte
- static constexpr size_t MAX_SIZE = 1024 * 1024 * 50;
-
- size_t dataLength;
- unsigned char* data;
-
- size_t writeIndex = 0;
- size_t readIndex = 0;
- };
- #endif
|