docs: public static <T> byte[] write(Buffer.Writer<T> writer, T value) {
      Buffer b = Buffer.allocate(writer.sizeInBytes(value));
      try {
        writer.write(value, b);
      } catch (RuntimeException e) {
        byte[] bytes = b.toByteArray();
        int lengthWritten = bytes.length;
        for (int i = 0; i < bytes.length; i++) {
          if (bytes[i] == 0) {
            lengthWritten = i;
            break;
          }
        }
  
        final byte[] bytesWritten;
        if (lengthWritten == bytes.length) {
          bytesWritten = bytes;
        } else {
          bytesWritten = new byte[lengthWritten];
          System.arraycopy(bytes, 0, bytesWritten, 0, lengthWritten);
        }
  
        String written = new String(bytesWritten, UTF_8);
        // Don't use value directly in the message, as its toString might be implemented using this
        // method. If that's the case, we'd stack overflow. Instead, emit what we've written so far.
        String message =
          format(
            "Bug found using %s to write %s as json. Wrote %s/%s bytes: %s",
            writer.getClass().getSimpleName(),
            value.getClass().getSimpleName(),
            lengthWritten,
            bytes.length,
            written);
        throw Platform.get().assertionError(message, e);
      }
      return b.toByteArray();
    }