Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sven Gestegård Robertz
LabComm
Commits
02d82d5d
Commit
02d82d5d
authored
Oct 24, 2014
by
Sven Gestegård Robertz
Browse files
skeleton decoder
parent
91219636
Changes
3
Hide whitespace changes
Inline
Side-by-side
lib/c/labcomm_decoder.c
View file @
02d82d5d
...
...
@@ -86,7 +86,7 @@ void labcomm_decoder_free(struct labcomm_decoder* d)
labcomm_memory_free
(
memory
,
0
,
d
);
}
static
int
decode_sample
(
struct
labcomm_decoder
*
d
,
int
kind
)
static
int
decode_sample
_def
(
struct
labcomm_decoder
*
d
,
int
kind
)
{
int
result
;
struct
labcomm_signature
signature
,
*
local_signature
;
...
...
@@ -189,7 +189,24 @@ static void reader_alloc(struct labcomm_decoder *d)
labcomm_reader_alloc
(
d
->
reader
,
d
->
reader
->
action_context
);
}
}
static
int
decode_version
(
struct
labcomm_decoder
*
d
,
int
remote_index
)
{
int
result
;
char
*
version
=
labcomm_read_string
(
d
->
reader
);
if
(
d
->
reader
->
error
<
0
)
{
result
=
d
->
reader
->
error
;
goto
out
;
}
if
(
strcmp
(
version
,
CURRENT_VERSION
)
==
0
)
{
result
=
LABCOMM_VERSION
;
d
->
version_ok
=
1
;
}
else
{
result
=
-
ECONNRESET
;
}
labcomm_memory_free
(
d
->
memory
,
1
,
version
);
out:
return
result
;
}
int
labcomm_decoder_decode_one
(
struct
labcomm_decoder
*
d
)
{
int
result
,
remote_index
,
length
;
...
...
@@ -206,23 +223,12 @@ int labcomm_decoder_decode_one(struct labcomm_decoder *d)
goto
out
;
}
if
(
remote_index
==
LABCOMM_VERSION
)
{
char
*
version
=
labcomm_read_string
(
d
->
reader
);
if
(
d
->
reader
->
error
<
0
)
{
result
=
d
->
reader
->
error
;
goto
out
;
}
if
(
strcmp
(
version
,
CURRENT_VERSION
)
==
0
)
{
result
=
LABCOMM_VERSION
;
d
->
version_ok
=
1
;
}
else
{
result
=
-
ECONNRESET
;
}
labcomm_memory_free
(
d
->
memory
,
1
,
version
);
result
=
decode_version
(
d
,
remote_index
);
}
else
if
(
!
d
->
version_ok
)
{
fprintf
(
stderr
,
"No VERSION %d %d
\n
"
,
remote_index
,
length
);
result
=
-
ECONNRESET
;
}
else
if
(
remote_index
==
LABCOMM_SAMPLE
)
{
result
=
decode_sample
(
d
,
remote_index
);
}
else
if
(
remote_index
==
LABCOMM_SAMPLE
_DEF
)
{
result
=
decode_sample
_def
(
d
,
remote_index
);
}
else
if
(
remote_index
==
LABCOMM_PRAGMA
&&
0
/* d->pragma_handler*/
)
{
/* d->prama_handler(...); */
}
else
if
(
remote_index
<
LABCOMM_USER
)
{
...
...
lib/c/labcomm_encoder.c
View file @
02d82d5d
...
...
@@ -222,7 +222,7 @@ int labcomm_internal_encoder_register(
index
,
signature
,
NULL
);
if
(
err
==
-
EALREADY
)
{
result
=
0
;
goto
out
;
}
if
(
err
!=
0
)
{
result
=
err
;
goto
out
;
}
labcomm_write_packed32
(
e
->
writer
,
LABCOMM_SAMPLE
);
labcomm_write_packed32
(
e
->
writer
,
LABCOMM_SAMPLE
_DEF
);
length
=
(
labcomm_size_packed32
(
index
)
+
labcomm_size_string
(
signature
->
name
)
+
labcomm_size_packed32
(
signature
->
size
)
+
...
...
lib/c/labcomm_private.h
View file @
02d82d5d
...
...
@@ -39,10 +39,12 @@
/*
* Allowed packet tags
*/
#define LABCOMM_VERSION 0x01
#define LABCOMM_SAMPLE 0x02
#define LABCOMM_PRAGMA 0x3f
#define LABCOMM_USER 0x40
/* ..0xffffffff */
#define LABCOMM_VERSION 0x01
#define LABCOMM_SAMPLE_DEF 0x02
#define LABCOMM_TYPE_DEF 0x03
#define LABCOMM_TYPE_BINDING 0x04
#define LABCOMM_PRAGMA 0x3f
#define LABCOMM_USER 0x40
/* ..0xffffffff */
/*
...
...
Write
Preview
Supports
Markdown
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