use kvSchemaBitSet and ptr member variable here:

    byte[] value = kvSchema.toBytes(tuple, arrayFuncRefs, kvSchemaBitSet, ptr);