-
Notifications
You must be signed in to change notification settings - Fork 9
/
cmp_mem_access.h
47 lines (36 loc) · 1.16 KB
/
cmp_mem_access.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* Memory buffer access functions for cmp (MessagePack)
*
*/
#ifndef CMP_MEM_ACCESS_H
#define CMP_MEM_ACCESS_H
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <cmp/cmp.h>
typedef struct {
char *buf;
size_t index;
size_t size;
} cmp_mem_access_t;
#ifdef __cplusplus
extern "C" {
#endif
// initialize cmp
void cmp_mem_access_init(cmp_ctx_t *cmp, cmp_mem_access_t *m, void *buf, size_t size);
// initialize cmp (read only memory access)
void cmp_mem_access_ro_init(cmp_ctx_t *cmp, cmp_mem_access_t *m, const void *buf, size_t size);
// get current read/write position. this can be used to determine the length of
// the buffer written by MessagePack
size_t cmp_mem_access_get_pos(cmp_mem_access_t *m);
// set current read/write position.
// use cmp_mem_access_get_pos to obtain position.
void cmp_mem_access_set_pos(cmp_mem_access_t *m, size_t pos);
// get a pointer into the buffer at the position pos
void *cmp_mem_access_get_ptr_at_pos(cmp_mem_access_t *m, size_t pos);
// check if the position is inside the buffer
bool cmp_mem_access_pos_is_valid(cmp_mem_access_t *m, size_t pos);
#ifdef __cplusplus
}
#endif
#endif /* CMP_MEM_ACCESS_H */