BytePacketBuilder
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
buildPacket {
listOf(1,2,3).joinTo(this, separator = ",")
}
Constructors
Functions
Append single UTF-8 character
Builds byte packet instance and resets builder's state to be able to build another one packet if needed
Properties
Extensions
Creates OutputStream adapter 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.
Discard all written bytes and prepare to build another packet.
Write bytes directly to packet builder's segment. Generally shouldn't be used in user's code and useful for efficient integration.
Write bytes directly to packet builder's segment. Generally shouldn't be used in user's code and useful for efficient integration.
Write all remaining src buffer bytes and change its position accordingly
Creates Writer that encodes all characters in UTF-8 encoding