Return the number of bytes currently written to the buffer.
The result will be <= length.
int writeCount = 0;