A builder that provides ability to build byte packets with no knowledge of it's size. Unlike Java's ByteArrayOutputStream it doesn't copy the whole content every time it's internal buffer overflows but chunks buffers instead. Packet building via build function is O(1) operation and only does instantiate a new ByteReadPacket. Once a byte packet has been built via build function call, the builder could be reused again. You also can discard all written bytes via reset or release. Please note that an instance of builder need to be terminated either via build function invocation or via release call otherwise it will cause byte buffer leak so that may have performance impact.
Byte packet builder is also an Appendable so it does append UTF-8 characters to a packet
listOf(1,2,3).joinTo(this, separator = ",")
Append single UTF-8 character
Writes another packet to the end. Please note that the instance packet gets consumed so you don't need to release it
Write exact n bytes from packet to the builder
Creates a temporary packet view of the packet being build without discarding any bytes from the builder. This is similar to
build().copy() except that the builder keeps already written bytes untouched. A temporary view packet is passed as argument to block function and it shouldn't leak outside of this block otherwise an unexpected behaviour may occur.