Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ML
lib
Binary Storage
Commits
c1be3ccd
Commit
c1be3ccd
authored
Feb 26, 2020
by
Zhukov, Alexander P
Browse files
Swithced to uint types instead unsigned int.
parent
4e081dfc
Changes
2
Hide whitespace changes
Inline
Side-by-side
c-code/binary_storage.c
View file @
c1be3ccd
...
...
@@ -5,8 +5,8 @@
#include
<sys/time.h>
#include
"binary_storage.h"
u
nsigned
long
encodeDbl
(
double
a
){
u
nsigned
long
b
;
u
int64_t
encodeDbl
(
double
a
){
u
int64_t
b
;
unsigned
char
*
src
=
(
unsigned
char
*
)
&
a
,
*
dst
=
(
unsigned
char
*
)
&
b
;
dst
[
0
]
=
src
[
7
];
...
...
@@ -25,7 +25,7 @@ BinaryStorage bs_open(char* filename){
storage
.
file
=
fopen
(
filename
,
"wb"
);
storage
.
buf_size
=
500
;
storage
.
con_idx
=
0
;
storage
.
contents
=
(
long
*
)
malloc
(
sizeof
(
u
nsigned
long
)
*
storage
.
buf_size
);
storage
.
contents
=
(
uint64_t
*
)
malloc
(
sizeof
(
u
int64_t
)
*
storage
.
buf_size
);
char
header
[]
=
"SNS-BIET2020"
;
fwrite
(
header
,
sizeof
(
header
)
-
1
,
1
,
storage
.
file
);
...
...
@@ -39,12 +39,12 @@ int write_record(BinaryStorage *bs, char* name, TSTMP timestamp, double value, T
unsigned
char
name_len
=
strlen
(
name
);
int
i
=
0
;
u
nsigned
in
t
tag_length
=
0
;
u
int32_
t
tag_length
=
0
;
for
(
i
=
0
;
i
<
tags
->
num
;
i
++
){
tag_length
+=
strlen
(
tags
->
data
[
i
])
+
2
;
}
u
nsigned
in
t
total_length
=
bswap_32
(
1
+
1
+
name_len
+
1
+
8
+
1
+
8
+
1
+
tag_length
);
u
int32_
t
total_length
=
bswap_32
(
1
+
1
+
name_len
+
1
+
8
+
1
+
8
+
1
+
tag_length
);
fwrite
(
&
total_length
,
4
,
1
,
bs
->
file
);
/* name */
...
...
@@ -54,14 +54,14 @@ int write_record(BinaryStorage *bs, char* name, TSTMP timestamp, double value, T
/* timestamp */
fputc
(
2
,
bs
->
file
);
u
nsigned
in
t
sec
=
bswap_32
(
timestamp
.
seconds
);
u
nsigned
in
t
nano
=
bswap_32
(
timestamp
.
nanos
);
u
int32_
t
sec
=
bswap_32
(
timestamp
.
seconds
);
u
int32_
t
nano
=
bswap_32
(
timestamp
.
nanos
);
fwrite
(
&
sec
,
4
,
1
,
bs
->
file
);
fwrite
(
&
nano
,
4
,
1
,
bs
->
file
);
/* double scalar */
fputc
(
17
,
bs
->
file
);
u
nsigned
long
rawdata
=
encodeDbl
(
value
);
u
int64_t
rawdata
=
encodeDbl
(
value
);
fwrite
(
&
rawdata
,
8
,
1
,
bs
->
file
);
/* tags */
...
...
@@ -80,7 +80,7 @@ int write_record(BinaryStorage *bs, char* name, TSTMP timestamp, double value, T
}
void
bs_close
(
BinaryStorage
*
bs
){
u
nsigned
in
t
total_length
=
bswap_32
(
1
+
1
);
u
int32_
t
total_length
=
bswap_32
(
1
+
1
);
fwrite
(
&
total_length
,
4
,
1
,
bs
->
file
);
fputc
(
255
,
bs
->
file
);
fputc
(
254
,
bs
->
file
);
...
...
@@ -88,10 +88,10 @@ void bs_close(BinaryStorage *bs){
bs
->
con_idx
++
;
int
i
;
for
(
i
=
0
;
i
<
bs
->
con_idx
;
i
++
){
u
nsigned
long
swapped
=
bswap_64
(
bs
->
contents
[
i
]);
u
int64_t
swapped
=
bswap_64
(
bs
->
contents
[
i
]);
fwrite
(
&
swapped
,
8
,
1
,
bs
->
file
);
}
u
nsigned
in
t
num_of_rec
=
bswap_32
(
bs
->
con_idx
);
u
int32_
t
num_of_rec
=
bswap_32
(
bs
->
con_idx
);
fwrite
(
&
num_of_rec
,
4
,
1
,
bs
->
file
);
fclose
(
bs
->
file
);
...
...
c-code/binary_storage.h
View file @
c1be3ccd
#include
<stdint.h>
typedef
struct
tagset
{
char
**
data
;
size_t
num
;
}
TAGS
;
typedef
struct
timestamp
{
u
nsigned
in
t
seconds
;
u
nsigned
in
t
nanos
;
u
int32_
t
seconds
;
u
int32_
t
nanos
;
}
TSTMP
;
typedef
struct
storage
{
FILE
*
file
;
u
nsigned
long
*
contents
;
u
nsigned
in
t
con_idx
;
u
int64_t
*
contents
;
u
int32_
t
con_idx
;
size_t
buf_size
;
}
BinaryStorage
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment