-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuf_example.c
More file actions
47 lines (35 loc) · 759 Bytes
/
buf_example.c
File metadata and controls
47 lines (35 loc) · 759 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
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "sc_buf.h"
#include <stdio.h>
void basic()
{
struct sc_buf buf;
sc_buf_init(&buf, 1024);
sc_buf_put_32(&buf, 16);
sc_buf_put_str(&buf, "test");
sc_buf_put_fmt(&buf, "value is %d", 3);
printf("%d \n", sc_buf_get_32(&buf));
printf("%s \n", sc_buf_get_str(&buf));
printf("%s \n", sc_buf_get_str(&buf));
sc_buf_term(&buf);
}
void error_check()
{
uint32_t val, val2;
struct sc_buf buf;
sc_buf_init(&buf, 1024);
sc_buf_put_32(&buf, 16);
val = sc_buf_get_32(&buf);
val2 = sc_buf_get_32(&buf); // This will set error flag in buffer;
if (sc_buf_valid(&buf) == false) {
printf("buffer is corrupt");
exit(EXIT_FAILURE);
}
printf("%u %u \n", val, val2);
sc_buf_term(&buf);
}
int main()
{
basic();
error_check();
return 0;
}