Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ML
lib
Binary Storage
Commits
dd8f683a
Commit
dd8f683a
authored
Feb 26, 2020
by
Zhukov, Alexander P
Browse files
minor edits for byte swapping
parent
598ffd98
Changes
1
Show whitespace changes
Inline
Side-by-side
c-code/binary_storage.c
View file @
dd8f683a
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <string.h>
#include <stdlib.h>
#include <stdlib.h>
/* #include <byteswap.h> */
#include <sys/time.h>
#include <sys/time.h>
#include "binary_storage.h"
#include "binary_storage.h"
uint64_t
encodeDbl
(
double
a
){
uint64_t
bswap_d
(
double
a
){
uint64_t
b
;
uint64_t
*
b
=
(
uint64_t
*
)
&
a
;
unsigned
char
*
src
=
(
unsigned
char
*
)
&
a
,
return
bswap_64
(
*
b
);
*
dst
=
(
unsigned
char
*
)
&
b
;
dst
[
0
]
=
src
[
7
];
dst
[
1
]
=
src
[
6
];
dst
[
2
]
=
src
[
5
];
dst
[
3
]
=
src
[
4
];
dst
[
4
]
=
src
[
3
];
dst
[
5
]
=
src
[
2
];
dst
[
6
]
=
src
[
1
];
dst
[
7
]
=
src
[
0
];
return
b
;
}
}
BinaryStorage
bs_open
(
char
*
filename
){
BinaryStorage
bs_open
(
char
*
filename
){
...
@@ -61,7 +50,7 @@ int write_record(BinaryStorage *bs, char* name, TSTMP timestamp, double value, T
...
@@ -61,7 +50,7 @@ int write_record(BinaryStorage *bs, char* name, TSTMP timestamp, double value, T
/* double scalar */
/* double scalar */
fputc
(
17
,
bs
->
file
);
fputc
(
17
,
bs
->
file
);
uint64_t
rawdata
=
encodeDbl
(
value
);
uint64_t
rawdata
=
bswap_d
(
value
);
fwrite
(
&
rawdata
,
8
,
1
,
bs
->
file
);
fwrite
(
&
rawdata
,
8
,
1
,
bs
->
file
);
/* tags */
/* tags */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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