Functions
rbuffer.c File Reference
#include <assert.h>
#include <stddef.h>
#include <string.h>
#include "nvim/memory.h"
#include "nvim/vim.h"
#include "nvim/rbuffer.h"

Functions

RBufferrbuffer_new (size_t capacity) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_RET
 Creates a new RBuffer instance. More...
 
void rbuffer_free (RBuffer *buf)
 
size_t rbuffer_size (RBuffer *buf) FUNC_ATTR_NONNULL_ALL
 
size_t rbuffer_capacity (RBuffer *buf) FUNC_ATTR_NONNULL_ALL
 
size_t rbuffer_space (RBuffer *buf) FUNC_ATTR_NONNULL_ALL
 
char * rbuffer_write_ptr (RBuffer *buf, size_t *write_count) FUNC_ATTR_NONNULL_ALL
 
void rbuffer_reset (RBuffer *buf) FUNC_ATTR_NONNULL_ALL
 
void rbuffer_produced (RBuffer *buf, size_t count) FUNC_ATTR_NONNULL_ALL
 
char * rbuffer_read_ptr (RBuffer *buf, size_t *read_count) FUNC_ATTR_NONNULL_ALL
 
void rbuffer_consumed (RBuffer *buf, size_t count) FUNC_ATTR_NONNULL_ALL
 
size_t rbuffer_write (RBuffer *buf, const char *src, size_t src_size) FUNC_ATTR_NONNULL_ALL
 
size_t rbuffer_read (RBuffer *buf, char *dst, size_t dst_size) FUNC_ATTR_NONNULL_ALL
 
char * rbuffer_get (RBuffer *buf, size_t index) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET
 
int rbuffer_cmp (RBuffer *buf, const char *str, size_t count) FUNC_ATTR_NONNULL_ALL
 

Function Documentation

size_t rbuffer_capacity ( RBuffer buf)
int rbuffer_cmp ( RBuffer buf,
const char *  str,
size_t  count 
)
void rbuffer_consumed ( RBuffer buf,
size_t  count 
)

Adjust rbuffer read pointer to reflect consumed data. This is called automatically by rbuffer_read, but when using rbuffer_read_ptr directly, this needs to called after the data was copied from the internal buffer. The read pointer will be wrapped if required.

void rbuffer_free ( RBuffer buf)
char* rbuffer_get ( RBuffer buf,
size_t  index 
)
RBuffer* rbuffer_new ( size_t  capacity)

Creates a new RBuffer instance.

void rbuffer_produced ( RBuffer buf,
size_t  count 
)

Adjust rbuffer write pointer to reflect produced data. This is called automatically by rbuffer_write, but when using rbuffer_write_ptr directly, this needs to called after the data was copied to the internal buffer. The write pointer will be wrapped if required.

size_t rbuffer_read ( RBuffer buf,
char *  dst,
size_t  dst_size 
)
char* rbuffer_read_ptr ( RBuffer buf,
size_t *  read_count 
)

Return a pointer to a raw buffer containing the first byte available for reading. The second argument is a pointer to the maximum number of bytes that could be read.

It is necessary to call this function twice to ensure all available bytes were read. See RBUFFER_UNTIL_EMPTY for a macro that simplifies this task.

void rbuffer_reset ( RBuffer buf)
size_t rbuffer_size ( RBuffer buf)
size_t rbuffer_space ( RBuffer buf)
size_t rbuffer_write ( RBuffer buf,
const char *  src,
size_t  src_size 
)
char* rbuffer_write_ptr ( RBuffer buf,
size_t *  write_count 
)

Return a pointer to a raw buffer containing the first empty slot available for writing. The second argument is a pointer to the maximum number of bytes that could be written.

It is necessary to call this function twice to ensure all empty space was used. See RBUFFER_UNTIL_FULL for a macro that simplifies this task.