FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
tinybits/example/example.c at main · oldmoe/tinybits · GitHub
oldmoe
/
tinybits
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
13
Code
Issues
1
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
tinybits
/
example
/
example.c
Copy path
More file actions
More file actions
Latest commit
History
History
History
103 lines (92 loc) · 2.58 KB
Breadcrumbs
tinybits
/
example
/
example.c
Copy path
File metadata and controls
103 lines (92 loc) · 2.58 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include
"../dist/tinybits.h"
#include
<stdio.h>
void
unpack
(
tiny_bits_unpacker
*
unpacker
){
tiny_bits_value
value
;
enum
tiny_bits_type
type
=
unpack_value
(
unpacker
,
&
value
);
switch
(
type
){
case
TINY_BITS_STR
: {
printf
(
"\"%.*s\""
, (
int
)
value
.
str_blob_val
.
length
,
value
.
str_blob_val
.
data
);
break
;
}
case
TINY_BITS_MAP
: {
printf
(
"{"
);
for
(
int
i
=
0
;
i
<
value
.
length
;
i
++
){
unpack
(
unpacker
);
// key
//printf(": ");
printf
(
" => "
);
unpack
(
unpacker
);
// value
if
(
i
<
value
.
length
-
1
)
printf
(
", "
);
}
printf
(
"}"
);
break
;
}
case
TINY_BITS_ARRAY
: {
printf
(
"["
);
for
(
int
i
=
0
;
i
<
value
.
length
;
i
++
){
unpack
(
unpacker
);
if
(
i
<
value
.
length
-
1
)
printf
(
", "
);
}
printf
(
"]"
);
break
;
}
case
TINY_BITS_NAN
: {
printf
(
"NaN"
);
break
;
}
case
TINY_BITS_INF
: {
printf
(
"Inf"
);
break
;
}
case
TINY_BITS_N_INF
: {
printf
(
"-Inf"
);
break
;
}
case
TINY_BITS_DOUBLE
: {
printf
(
"%g"
,
value
.
double_val
);
break
;
}
case
TINY_BITS_INT
: {
printf
(
"%ld"
,
value
.
int_val
);
break
;
}
case
TINY_BITS_FINISHED
: {
printf
(
"\n"
);
return
;
}
defult
:
return
;
}
}
int
main
() {
// Create a packer
tiny_bits_packer
*
packer
=
tiny_bits_packer_create
(
1024
,
TB_FEATURE_STRING_DEDUPE
|
TB_FEATURE_COMPRESS_FLOATS
);
// Pack some values
pack_map
(
packer
,
4
);
// Add a string key-value pair
pack_str
(
packer
,
"name"
,
4
);
pack_str
(
packer
,
"TinyBits Library"
,
16
);
// Add a number key-value pair
pack_str
(
packer
,
"version"
,
7
);
pack_double
(
packer
,
0.5
);
// Add a nested array
pack_str
(
packer
,
"features"
,
8
);
pack_arr
(
packer
,
3
);
pack_str
(
packer
,
"compact"
,
7
);
pack_str
(
packer
,
"fast"
,
4
);
pack_str
(
packer
,
"flexible"
,
8
);
pack_str
(
packer
,
"users"
,
5
);
pack_int
(
packer
,
1234567890
);
// Create unpacker and set buffer
tiny_bits_unpacker
*
unpacker
=
tiny_bits_unpacker_create
();
tiny_bits_unpacker_set_buffer
(
unpacker
,
packer
->
buffer
,
packer
->
current_pos
);
// Unpack and process values
//tiny_bits_value value;
//enum tiny_bits_type type = unpack_value(unpacker, &value);
// Process the data...
unpack
(
unpacker
);
// Clean up
tiny_bits_packer_destroy
(
packer
);
tiny_bits_unpacker_destroy
(
unpacker
);
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL