#ifndef BYTE_STREAM_WRAPPER_H #define BYTE_STREAM_WRAPPER_H #include #include #include #include class ByteBufferException : public std::runtime_error { public: ByteBufferException(std::string const &what) : std::runtime_error(what) { } }; class ByteBuffer { public: ByteBuffer(uint8_t *bytes, size_t capacity, size_t size, size_t zero = 0); inline size_t getSize() { return size; } inline size_t getCapacity() { return capacity; } inline size_t getCursor() { return cursor; } inline void setCursor(size_t newCursor) { cursor = newCursor; } ByteBuffer &add8(uint8_t value); ByteBuffer &add16le(uint16_t value); uint8_t get8(size_t index); uint8_t get8(); uint16_t get16le(); void copy(uint8_t *bytes, size_t length); ByteBuffer view(size_t length); std::string toString() const; private: void checkAndUpdateSize(size_t count); void canAccessIndex(size_t count); uint8_t *bytes; size_t zero; size_t size; size_t capacity; size_t cursor; }; #endif