encodeObject

abstract fun encodeObject(buffer: ByteBuffer, obj: T)

Encodes the given object into the provided buffer.

This method writes the binary representation of the object to the buffer using the format defined by this schema. The amount of data written must exactly match the value returned by objSize for the same object.

Buffer Requirements: The buffer must have at least objSize(obj) bytes of remaining capacity. The buffer's position will be advanced by exactly that number of bytes.

Encoding Format: The specific binary format depends on the schema type:

  • Primitives: Direct binary representation (int, long, double, etc.)

  • Strings: Length prefix (4 bytes) + UTF-8 encoded bytes

  • Booleans: Single byte (0x00 for false, 0x01 for true)

  • Arrays: Length prefix + encoded elements

  • Classes: Encoded fields in alphabetical order

Parameters

buffer

The buffer to write object data to

obj

The object to encode

Throws

if the buffer doesn't have enough space