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

57 lines
1.1 KiB
C

7 years ago
#ifndef LLARP_BUFFER_H_
#define LLARP_BUFFER_H_
6 years ago
#include <llarp/common.h>
6 years ago
#include <llarp/mem.h>
#include <stdbool.h>
6 years ago
#include <stdio.h>
7 years ago
#include <stdlib.h>
6 years ago
#include <string.h>
6 years ago
/**
* buffer.h
*
* buffer used for bencoding
*/
7 years ago
#ifdef __cplusplus
extern "C" {
#endif
typedef uint8_t byte_t;
typedef struct llarp_buffer_t
{
6 years ago
/// starting memory address
byte_t *base;
6 years ago
/// memory address of stream position
byte_t *cur;
6 years ago
/// max size of buffer
7 years ago
size_t sz;
} llarp_buffer_t;
6 years ago
/// how much room is left in buffer
size_t
llarp_buffer_size_left(llarp_buffer_t *buff);
6 years ago
6 years ago
/// write a chunk of data size "sz"
bool
llarp_buffer_write(llarp_buffer_t *buff, const void *data, size_t sz);
7 years ago
6 years ago
/// write multiple strings
bool
llarp_buffer_writef(llarp_buffer_t *buff, const char *fmt, ...);
6 years ago
6 years ago
/// read buffer upto character delimiter
size_t
llarp_buffer_read_until(llarp_buffer_t *buff, char delim, byte_t *result,
size_t resultlen);
6 years ago
/// compare buffers, true if equal else false
bool
llarp_buffer_eq(llarp_buffer_t buff, const char *data);
6 years ago
7 years ago
#ifdef __cplusplus
}
#endif
7 years ago
7 years ago
#endif