Write data to the ring buffer.

        This advances the write index after writing;
        calling :meth:`advance_write_index` is *not* necessary.

        :param data: Data to write to the buffer.
        :type data: CData pointer or buffer or bytes
        :param size: The number of elements to be written.
        :type size: int, optional

        :returns: The number of elements written.
        :rtype: int

def write(self, data, size=-1):
        """Write data to the ring buffer.

        This advances the write index after writing;
        calling :meth:`advance_write_index` is *not* necessary.

        :param data: Data to write to the buffer.
        :type data: CData pointer or buffer or bytes
        :param size: The number of elements to be written.
        :type size: int, optional

        :returns: The number of elements written.
        :rtype: int

        """
        try:
            data = self._ffi.from_buffer(data)
        except TypeError:
            pass  # input is not a buffer
        if size < 0:
            size, rest = divmod(self._ffi.sizeof(data), self.elementsize)
            if rest:
                raise ValueError('data size must be multiple of elementsize')
        return self._lib.PaUtil_WriteRingBuffer(self._ptr, data, size)