/** * Copy size bytes from the current read position of the buffer * into a newly allocated string. If less data is available, * the string will contain the entire remainder of the buffer. */ std::string readString(size_t size) { size = std::min(size, bytesRemaining()); char *stringStart = (char*)data.data()+readIndex; readIndex += size; return std::string(stringStart, size); }
// An estimate of the time remaining, in seconds. uintmax_t BasicTransaction::timeRemaining() const { if (speed()==0) return std::numeric_limits<uintmax_t>::max(); return bytesRemaining()/speed(); }
/** * Copy size bytes from the current read position of the buffer * into the provided array. If less data is available, * as much data as available is copied, and the rest of the * provided array is not changed. The number of bytes * actually read is returned. */ size_t read(uint8_t* out, size_t size) { size = std::min(size, bytesRemaining()); memcpy(out, data.data()+readIndex, size); readIndex += size; return size; }