-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuffer_example.c
More file actions
34 lines (29 loc) · 899 Bytes
/
Copy pathbuffer_example.c
File metadata and controls
34 lines (29 loc) · 899 Bytes
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
#include "ppmp.h"
#include "cbuffer.h"
#include <stdio.h>
#include <string.h>
/* The PPMP library does not allocate memory for JSON payloads by
itself. Instead, a PPMP object has to be initialized with a 'write'
function. In this example, we use a simple buffer data
structure, and pass the 'write_buffer' to 'ppmp_init'. */
int write_buffer(void *user_data, const char *data, int len) {
cbuffer *buf = (cbuffer*) user_data;
cbuffer_nappend(buf, data, len);
return 0;
}
int main(int argc, const char *argv[]) {
PPMP ppmpbuf;
PPMP *ppmp = &ppmpbuf;
cbuffer _buf;
cbuffer *buf = &_buf;
cbuffer_create(buf);
cbuffer_alloc(buf, 1000);
ppmp_init(ppmp, buf, write_buffer, PPMP_PRETTY);
ppmp_measurement_payload(ppmp);
ppmp_device(ppmp, "My-Device", "running",
"Manufacture", "Bosch",
NULL);
ppmp_finish(ppmp);
fputs(buf->buf, stdout);
return 0;
}