PgByteWriter

class PgByteWriter(initialCapacity: Int = 1024, maxCapacity: Int = 65536)

Optimized buffer for building binary packets for the database. Allows reserving space for size and filling it later without memory copying.

Constructors

Link copied to clipboard
constructor(initialCapacity: Int = 1024, maxCapacity: Int = 65536)

Properties

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
fun clear()

Empties the buffer for the next packet, releasing the backing array if this one grew past maxCapacity.

Link copied to clipboard
fun fillLengthInt(markerIndex: Int)

Calculates the number of bytes added since reserveLengthInt was called and writes this value at the marker. Does not include the 4 bytes of the marker itself (in accordance with many PG structures).

Link copied to clipboard

Leaves 4 bytes of space for a number (e.g. packet size) and returns the index where this size should be written later.

Link copied to clipboard

A copy of what has been written so far.

Link copied to clipboard
fun updatePosition(newPosition: Int)

Moves the write cursor, for the caller that has to go back and rewrite something it already emitted.

Link copied to clipboard
fun writeByte(b: Byte)

Appends one byte.

Link copied to clipboard
fun writeBytes(bytes: ByteArray)

Appends bytes whole, with no length prefix — pair it with reserveLengthInt where the protocol wants one.

Link copied to clipboard

Appends a float8 as its IEEE 754 bit pattern.

Link copied to clipboard

Appends a float4 as its IEEE 754 bit pattern, which is the form PostgreSQL's binary format wants.

Link copied to clipboard
fun writeInt(i: Int)

Appends a 32-bit integer, most significant byte first.

Link copied to clipboard
fun writeLong(l: Long)

Appends a 64-bit integer, most significant byte first.

Link copied to clipboard

Appends a 16-bit integer, most significant byte first.