You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lokinet/include/llarp/buffer.h

44 lines
769 B
C

7 years ago
#ifndef LLARP_BUFFER_H_
#define LLARP_BUFFER_H_
#include <stdbool.h>
7 years ago
#include <stdlib.h>
6 years ago
#include <string.h>
7 years ago
#ifdef __cplusplus
extern "C" {
#endif
7 years ago
typedef struct llarp_buffer_t {
char *base;
size_t sz;
char *cur;
} llarp_buffer_t;
6 years ago
inline size_t llarp_buffer_size_left(llarp_buffer_t *buff)
{
size_t diff = buff->cur - buff->base;
if ( diff > buff->sz) return 0;
else return buff->sz - diff;
}
inline bool llarp_buffer_write(llarp_buffer_t *buff, const void *data, size_t sz)
{
size_t left = llarp_buffer_size_left(buff);
if (left >= sz)
{
memcpy(buff->cur, data, sz);
buff->cur += sz;
return true;
}
return false;
}
bool llarp_buffer_writef(llarp_buffer_t *buff, const char * fmt, ...);
7 years ago
6 years ago
7 years ago
#ifdef __cplusplus
}
#endif
7 years ago
7 years ago
#endif