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
Anders Blomdell
LabComm
Commits
576f596c
Commit
576f596c
authored
Apr 15, 2013
by
Sven Robertz
Browse files
extended simple example to use typedef
parent
75a92c86
Changes
5
Hide whitespace changes
Inline
Side-by-side
examples/simple/Decoder.java
View file @
576f596c
...
...
@@ -5,7 +5,7 @@ import java.io.InputStream;
import
se.lth.control.labcomm.LabCommDecoderChannel
;
public
class
Decoder
implements
TwoInts
.
Handler
,
IntString
.
Handler
,
TwoArrays
.
Handler
,
TwoFixedArrays
.
Handler
implements
theTwoInts
.
Handler
,
another
TwoInts
.
Handler
,
IntString
.
Handler
,
TwoArrays
.
Handler
,
TwoFixedArrays
.
Handler
{
...
...
@@ -15,7 +15,8 @@ public class Decoder
throws
Exception
{
decoder
=
new
LabCommDecoderChannel
(
in
);
TwoInts
.
register
(
decoder
,
this
);
theTwoInts
.
register
(
decoder
,
this
);
anotherTwoInts
.
register
(
decoder
,
this
);
IntString
.
register
(
decoder
,
this
);
TwoArrays
.
register
(
decoder
,
this
);
TwoFixedArrays
.
register
(
decoder
,
this
);
...
...
@@ -28,8 +29,18 @@ public class Decoder
}
}
public
void
handle_TwoInts
(
TwoInts
d
)
throws
java
.
io
.
IOException
{
System
.
out
.
println
(
"Got TwoInts, a="
+
d
.
a
+
", b="
+
d
.
b
);
public
void
printTwoInts
(
TwoInts
d
)
throws
java
.
io
.
IOException
{
System
.
out
.
println
(
"a="
+
d
.
a
+
", b="
+
d
.
b
);
}
public
void
handle_theTwoInts
(
TwoInts
d
)
throws
java
.
io
.
IOException
{
System
.
out
.
print
(
"Got theTwoInts: "
);
printTwoInts
(
d
);
}
public
void
handle_anotherTwoInts
(
TwoInts
d
)
throws
java
.
io
.
IOException
{
System
.
out
.
print
(
"Got anotherheTwoInts: "
);
printTwoInts
(
d
);
}
public
void
handle_IntString
(
IntString
d
)
throws
java
.
io
.
IOException
{
...
...
examples/simple/Encoder.java
View file @
576f596c
...
...
@@ -16,7 +16,7 @@ public class Encoder
throws
Exception
{
encoder
=
new
LabCommEncoderChannel
(
out
);
TwoInts
.
register
(
encoder
);
the
TwoInts
.
register
(
encoder
);
IntString
.
register
(
encoder
);
}
...
...
@@ -29,8 +29,8 @@ public class Encoder
y
.
x
=
37
;
y
.
s
=
"Testing, testing"
;
System
.
out
.
println
(
"Encoding TwoInts, a="
+
x
.
a
+
", b="
+
x
.
b
);
TwoInts
.
encode
(
encoder
,
x
);
System
.
out
.
println
(
"Encoding
the
TwoInts, a="
+
x
.
a
+
", b="
+
x
.
b
);
the
TwoInts
.
encode
(
encoder
,
x
);
System
.
out
.
println
(
"Encoding IntString, x="
+
y
.
x
+
", s="
+
y
.
s
);
IntString
.
encode
(
encoder
,
y
);
...
...
examples/simple/example_decoder.c
View file @
576f596c
...
...
@@ -4,8 +4,12 @@
#include
<labcomm_fd_reader_writer.h>
#include
"gen/simple.h"
static
void
handle_simple_TwoInts
(
simple_TwoInts
*
v
,
void
*
context
)
{
printf
(
"Got TwoInts. a=%d, b=%d
\n
"
,
v
->
a
,
v
->
b
);
static
void
handle_simple_theTwoInts
(
simple_TwoInts
*
v
,
void
*
context
)
{
printf
(
"Got theTwoInts. a=%d, b=%d
\n
"
,
v
->
a
,
v
->
b
);
}
static
void
handle_simple_anotherTwoInts
(
simple_TwoInts
*
v
,
void
*
context
)
{
printf
(
"Got anotherTwoInts. a=%d, b=%d
\n
"
,
v
->
a
,
v
->
b
);
}
static
void
handle_simple_IntString
(
simple_IntString
*
v
,
void
*
context
)
{
...
...
@@ -55,7 +59,8 @@ int main(int argc, char *argv[]) {
return
1
;
}
labcomm_decoder_register_simple_TwoInts
(
decoder
,
handle_simple_TwoInts
,
context
);
labcomm_decoder_register_simple_theTwoInts
(
decoder
,
handle_simple_theTwoInts
,
context
);
labcomm_decoder_register_simple_anotherTwoInts
(
decoder
,
handle_simple_anotherTwoInts
,
context
);
labcomm_decoder_register_simple_IntString
(
decoder
,
handle_simple_IntString
,
context
);
labcomm_decoder_register_simple_TwoArrays
(
decoder
,
handle_simple_TwoArrays
,
context
);
labcomm_decoder_register_simple_TwoFixedArrays
(
decoder
,
handle_simple_TwoFixedArrays
,
context
);
...
...
examples/simple/example_encoder.c
View file @
576f596c
...
...
@@ -13,7 +13,8 @@ int main(int argc, char *argv[]) {
printf
(
"C encoder writing to %s
\n
"
,
filename
);
fd
=
open
(
filename
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
0644
);
encoder
=
labcomm_encoder_new
(
labcomm_fd_writer
,
&
fd
);
labcomm_encoder_register_simple_TwoInts
(
encoder
);
labcomm_encoder_register_simple_theTwoInts
(
encoder
);
labcomm_encoder_register_simple_anotherTwoInts
(
encoder
);
labcomm_encoder_register_simple_IntString
(
encoder
);
simple_IntString
is
;
is
.
x
=
24
;
...
...
@@ -21,11 +22,17 @@ int main(int argc, char *argv[]) {
printf
(
"Encoding IntString, x=%d, s=%s
\n
"
,
is
.
x
,
is
.
s
);
labcomm_encode_simple_IntString
(
encoder
,
&
is
);
simple_TwoInts
ti
;
simple_
the
TwoInts
ti
;
ti
.
a
=
13
;
ti
.
b
=
37
;
printf
(
"Encoding TwoInts, a=%d, b=%d
\n
"
,
ti
.
a
,
ti
.
b
);
labcomm_encode_simple_TwoInts
(
encoder
,
&
ti
);
printf
(
"Encoding theTwoInts, a=%d, b=%d
\n
"
,
ti
.
a
,
ti
.
b
);
labcomm_encode_simple_theTwoInts
(
encoder
,
&
ti
);
simple_anotherTwoInts
ati
;
ati
.
a
=
23
;
ati
.
b
=
47
;
printf
(
"Encoding anotherTwoInts, a=%d, b=%d
\n
"
,
ati
.
a
,
ati
.
b
);
labcomm_encode_simple_anotherTwoInts
(
encoder
,
&
ati
);
int
foo
[
20
];
...
...
@@ -47,8 +54,8 @@ int main(int argc, char *argv[]) {
ti
.
a
=
23
;
ti
.
b
=
47
;
printf
(
"Encoding TwoInts, a=%d, b=%d
\n
"
,
ti
.
a
,
ti
.
b
);
labcomm_encode_simple_TwoInts
(
encoder
,
&
ti
);
printf
(
"Encoding
the
TwoInts, a=%d, b=%d
\n
"
,
ti
.
a
,
ti
.
b
);
labcomm_encode_simple_
the
TwoInts
(
encoder
,
&
ti
);
simple_TwoFixedArrays
tfa
;
...
...
examples/simple/simple.lc
View file @
576f596c
sample
struct {
typedef
struct {
int a;
int b;
} TwoInts;
sample TwoInts theTwoInts;
sample TwoInts anotherTwoInts;
sample struct {
int x;
string s;
...
...
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