Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ML
lib
Binary Storage
Commits
52bf241e
Commit
52bf241e
authored
Feb 25, 2020
by
Zhukov, Alexander P
Browse files
WIP
parent
24112e05
Changes
3
Hide whitespace changes
Inline
Side-by-side
LV/TestOneName.vi
View file @
52bf241e
No preview for this file type
c-code/test_code.c
View file @
52bf241e
...
...
@@ -3,6 +3,22 @@
#include <stdlib.h>
#include <byteswap.h>
unsigned
long
encodeDbl
(
double
a
){
unsigned
long
b
;
unsigned
char
*
src
=
(
unsigned
char
*
)
&
a
,
*
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
;
}
typedef
struct
storage
{
FILE
*
file
;
unsigned
long
*
contents
;
...
...
@@ -25,14 +41,20 @@ BinaryStorage bs_open(char* filename){
return
storage
;
}
int
write_record
(
BinaryStorage
*
bs
,
char
*
name
){
int
write_record
(
BinaryStorage
*
bs
,
char
*
name
,
double
value
){
unsigned
char
name_len
=
strlen
(
name
);
unsigned
int
total_length
=
bswap_32
(
1
+
1
+
name_len
+
1
);
unsigned
int
total_length
=
bswap_32
(
1
+
1
+
name_len
+
1
+
8
+
1
);
fwrite
(
&
total_length
,
4
,
1
,
bs
->
file
);
fputc
(
1
,
bs
->
file
);
fwrite
(
&
name_len
,
1
,
1
,
bs
->
file
);
fwrite
(
name
,
1
,
name_len
,
bs
->
file
);
fputc
(
17
,
bs
->
file
);
unsigned
long
rawdata
=
encodeDbl
(
value
);
fwrite
(
&
rawdata
,
8
,
1
,
bs
->
file
);
fputc
(
254
,
bs
->
file
);
bs
->
contents
[
bs
->
con_idx
]
=
ftell
(
bs
->
file
);
...
...
@@ -63,6 +85,6 @@ void bs_close(BinaryStorage *bs){
int
main
(){
printf
(
"Hello World!
\n
"
);
BinaryStorage
storage
=
bs_open
(
"test_c.bin"
);
write_record
(
&
storage
,
"Hello World!"
);
write_record
(
&
storage
,
"Hello World!"
,
314
);
bs_close
(
&
storage
);
}
py/test_read.py
View file @
52bf241e
...
...
@@ -29,7 +29,8 @@ print(args.file,'has',len(file), 'records')
def
show
(
record
):
if
'value'
in
record
:
value
=
record
[
'value'
]
record
[
'value'
]
=
value
[
0
]
if
isinstance
(
value
,(
str
,
list
,
tuple
)):
record
[
'value'
]
=
value
[
0
]
return
record
if
(
not
args
.
index
):
...
...
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