-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_kv.cpp
More file actions
72 lines (65 loc) · 1.42 KB
/
main_kv.cpp
File metadata and controls
72 lines (65 loc) · 1.42 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <string.h>
#include <stdio.h>
#include "kv.hpp"
//#define D(x,...) printf(x)
#define D(x,...)
/*
const char *get_nth_value(
const char *msg,
const unsigned int msg_size,
const unsigned int n) {
const char *cur_p = msg;
unsigned int idx=0;
unsigned short len_v;
printf("%d<%d %d<%d\n", cur_p - msg + 4, msg_size, idx,n);
while ((cur_p - msg + 4 < msg_size) && idx < n) {
cur_p += 2;
len_v = *((short *)cur_p);
D("len @ %p = %d\n",cur_p, len_v);
cur_p += 2 + len_v;
idx++;
}
if (msg_size < cur_p - msg +4) {
D("null 1\n");
return nullptr;
}
cur_p += 2;
len_v = *((short *)cur_p);
if (cur_p - msg + len_v + 2 > msg_size) {
D("null 2\n");
return nullptr;
}
D("yo\n");
return cur_p;
}
*/
char *add_rec(const char *data, char *dst) {
printf("%p ",dst);
unsigned short len=0x1234;
memcpy(dst, &len,sizeof(len));
dst+=2;
len=strlen(data);
memcpy(dst+2,data,len);
memcpy(dst,&len,sizeof(len));
dst += len + 2;
printf("-(%d)->%p\n",len,dst);
return dst;
}
int main() {
char tab[1000], *p;
const char *z;
unsigned short l;
p = tab;
p = add_rec("aaaaaaaa",p);
p = add_rec("bbbbbbb",p);
p = add_rec("ccccccccc",p);
p = add_rec("dddddddddddd",p);
p = add_rec("eeeeeeee",p);
z = add_rec("ffffffff",p);
l = z - tab;
printf("0: %p / %d\n", tab,l);
z = get_nth_value( tab, l, 4);
printf("4: %p\n", z);
z = get_nth_value( tab, l, 7);
printf("7: %p\n", z);
}