From 72e280003d21d20aa6b9a2624b0fcea825a90ec3 Mon Sep 17 00:00:00 2001 From: Sven Robertz <sven@cs.lth.se> Date: Thu, 16 May 2013 10:30:34 +0200 Subject: [PATCH] updated wiki-example --- .bzrignore | 5 + examples/wiki_example/example.c | 214 ------------------------ examples/wiki_example/example.encoded | Bin 104 -> 0 bytes examples/wiki_example/example.h | 68 -------- examples/wiki_example/example.py | 18 -- examples/wiki_example/example_encoder.c | 3 +- examples/wiki_example/run | 8 +- 7 files changed, 12 insertions(+), 304 deletions(-) delete mode 100644 examples/wiki_example/example.c delete mode 100644 examples/wiki_example/example.encoded delete mode 100644 examples/wiki_example/example.h delete mode 100644 examples/wiki_example/example.py diff --git a/.bzrignore b/.bzrignore index 97cb9f0..06ec666 100644 --- a/.bzrignore +++ b/.bzrignore @@ -20,3 +20,8 @@ lib/java/se/lth/control/labcomm/LabCommWriter.class gen labcomm.dll labcomm.jar +example.c +example.h +example.py +examples/wiki_example/example.encoded +example.encoded diff --git a/examples/wiki_example/example.c b/examples/wiki_example/example.c deleted file mode 100644 index 827f4e3..0000000 --- a/examples/wiki_example/example.c +++ /dev/null @@ -1,214 +0,0 @@ -#include "labcomm.h" -#include "labcomm_private.h" -#include "example.h" - -static unsigned char signature_bytes_log_message[] = { -// struct { 2 fields -17, - 2, - // int 'sequence' - 8, - 115, 101, 113, 117, 101, 110, 99, 101, - 35, - // array [_] 'line' - 4, - 108, 105, 110, 101, - // array [_] - 16, - 1, - 0, - // struct { 2 fields - 17, - 2, - // boolean 'last' - 4, - 108, 97, 115, 116, - 32, - // string 'data' - 4, - 100, 97, 116, 97, - 39, - // } - // } -// } -}; -labcomm_signature_t labcomm_signature_example_log_message = { - LABCOMM_SAMPLE, "log_message", - (int (*)(void *))labcomm_sizeof_example_log_message, - sizeof(signature_bytes_log_message), - signature_bytes_log_message - }; -static unsigned char signature_bytes_data[] = { -37, -}; -labcomm_signature_t labcomm_signature_example_data = { - LABCOMM_SAMPLE, "data", - (int (*)(void *))labcomm_sizeof_example_data, - sizeof(signature_bytes_data), - signature_bytes_data - }; -static void decode_log_message( - labcomm_decoder_t *d, - void (*handle)( - example_log_message *v, - void *context - ), - void *context -) -{ - example_log_message v; - v.sequence = labcomm_decode_int(d); - v.line.n_0 = labcomm_decode_packed32(d); - v.line.a = malloc(sizeof(v.line.a[0]) * v.line.n_0); - { - int i_0_0; - for (i_0_0 = 0 ; i_0_0 < v.line.n_0 ; i_0_0++) { - int i_0 = i_0_0; - v.line.a[i_0].last = labcomm_decode_boolean(d); - v.line.a[i_0].data = labcomm_decode_string(d); - } - } - handle(&v, context); - { - { - int i_0_0; - for (i_0_0 = 0 ; i_0_0 < v.line.n_0 ; i_0_0++) { - int i_0 = i_0_0; - free(v.line.a[i_0].data); - } - } - free(v.line.a); - } -} -void labcomm_decoder_register_example_log_message( - struct labcomm_decoder *d, - void (*handler)( - example_log_message *v, - void *context - ), - void *context -) -{ - labcomm_internal_decoder_register( - d, - &labcomm_signature_example_log_message, - (labcomm_decoder_typecast_t)decode_log_message, - (labcomm_handler_typecast_t)handler, - context - ); -} -static void encode_log_message( - labcomm_encoder_t *e, - example_log_message *v -) -{ - e->writer.write(&e->writer, labcomm_writer_start); - labcomm_encode_type_index(e, &labcomm_signature_example_log_message); - { - labcomm_encode_int(e, (*v).sequence); - labcomm_encode_packed32(e, (*v).line.n_0); - { - int i_0_0; - for (i_0_0 = 0 ; i_0_0 < (*v).line.n_0 ; i_0_0++) { - int i_0 = i_0_0; - labcomm_encode_boolean(e, (*v).line.a[i_0].last); - labcomm_encode_string(e, (*v).line.a[i_0].data); - } - } - } - e->writer.write(&e->writer, labcomm_writer_end); -} -void labcomm_encode_example_log_message( -labcomm_encoder_t *e, -example_log_message *v -) -{ -labcomm_internal_encode(e, &labcomm_signature_example_log_message, v); -} -void labcomm_encoder_register_example_log_message( - struct labcomm_encoder *e -) -{ - labcomm_internal_encoder_register( - e, - &labcomm_signature_example_log_message, - (labcomm_encode_typecast_t)encode_log_message - ); -} -int labcomm_sizeof_example_log_message(example_log_message *v) -{ - int result = 4; - { - int i_0_0; - for (i_0_0 = 0 ; i_0_0 < (*v).line.n_0 ; i_0_0++) { - int i_0 = i_0_0; - result += 4 + strlen((*v).line.a[i_0].data); - result += 1; - } - } - result += 4; - return result; -} -static void decode_data( - labcomm_decoder_t *d, - void (*handle)( - example_data *v, - void *context - ), - void *context -) -{ - example_data v; - v = labcomm_decode_float(d); - handle(&v, context); -} -void labcomm_decoder_register_example_data( - struct labcomm_decoder *d, - void (*handler)( - example_data *v, - void *context - ), - void *context -) -{ - labcomm_internal_decoder_register( - d, - &labcomm_signature_example_data, - (labcomm_decoder_typecast_t)decode_data, - (labcomm_handler_typecast_t)handler, - context - ); -} -static void encode_data( - labcomm_encoder_t *e, - example_data *v -) -{ - e->writer.write(&e->writer, labcomm_writer_start); - labcomm_encode_type_index(e, &labcomm_signature_example_data); - { - labcomm_encode_float(e, (*v)); - } - e->writer.write(&e->writer, labcomm_writer_end); -} -void labcomm_encode_example_data( -labcomm_encoder_t *e, -example_data *v -) -{ -labcomm_internal_encode(e, &labcomm_signature_example_data, v); -} -void labcomm_encoder_register_example_data( - struct labcomm_encoder *e -) -{ - labcomm_internal_encoder_register( - e, - &labcomm_signature_example_data, - (labcomm_encode_typecast_t)encode_data - ); -} -int labcomm_sizeof_example_data(example_data *v) -{ - return 8; -} diff --git a/examples/wiki_example/example.encoded b/examples/wiki_example/example.encoded deleted file mode 100644 index 6cd2cd814a2721384a24d02bd60685d11b0df634..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 104 zcmW;9K?;B%5QX8H(M8ZEZxBRujJin<HArAeXteF<X`BCjk8JCsTTe-eofvA8T(^Wx r2JMd^9fBe4IptpOoOvStceDV2P)mp^2B}m8m8kL)xqRUHEm?{_g1r|~ diff --git a/examples/wiki_example/example.h b/examples/wiki_example/example.h deleted file mode 100644 index b84b36f..0000000 --- a/examples/wiki_example/example.h +++ /dev/null @@ -1,68 +0,0 @@ -/* LabComm declarations: -sample struct { - int sequence; - struct { - boolean last; - string data; - } line[_]; -} log_message; -sample float data; -*/ - - -#ifndef __LABCOMM_example_H__ -#define __LABCOMM_example_H__ - -#include "labcomm.h" - -#ifndef PREDEFINED_example_log_message -typedef struct { - int sequence; - struct { - int n_0; - struct { - unsigned char last; - char* data; - } *a; - } line; -} example_log_message; -#endif -void labcomm_decoder_register_example_log_message( - struct labcomm_decoder *d, - void (*handler)( - example_log_message *v, - void *context - ), - void *context -); -void labcomm_encoder_register_example_log_message( - struct labcomm_encoder *e); -void labcomm_encode_example_log_message( - struct labcomm_encoder *e, - example_log_message *v -); -extern int labcomm_sizeof_example_log_message(example_log_message *v); - -#ifndef PREDEFINED_example_data -typedef float example_data; -#endif -void labcomm_decoder_register_example_data( - struct labcomm_decoder *d, - void (*handler)( - example_data *v, - void *context - ), - void *context -); -void labcomm_encoder_register_example_data( - struct labcomm_encoder *e); -void labcomm_encode_example_data( - struct labcomm_encoder *e, - example_data *v -); -extern int labcomm_sizeof_example_data(example_data *v); - -#define LABCOMM_FORALL_SAMPLES_example(func, sep) \ - func(log_message, example_log_message) sep \ - func(data, example_data) -#endif diff --git a/examples/wiki_example/example.py b/examples/wiki_example/example.py deleted file mode 100644 index 7ad6b6c..0000000 --- a/examples/wiki_example/example.py +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/python -# Auto generated example - -import labcomm - -class log_message(object): - signature = labcomm.sample('log_message', - labcomm.struct([ - ('sequence', labcomm.INTEGER()), - ('line', labcomm.array([0], - labcomm.struct([ - ('last', labcomm.BOOLEAN()), - ('data', labcomm.STRING())])))])) - -class data(object): - signature = labcomm.sample('data', - labcomm.FLOAT()) - diff --git a/examples/wiki_example/example_encoder.c b/examples/wiki_example/example_encoder.c index c39ab9a..2170239 100644 --- a/examples/wiki_example/example_encoder.c +++ b/examples/wiki_example/example_encoder.c @@ -1,7 +1,8 @@ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> -#include <labcomm_fd_reader_writer.h> +#include <labcomm_fd_reader.h> +#include <labcomm_fd_writer.h> #include "example.h" int main(int argc, char *argv[]) { diff --git a/examples/wiki_example/run b/examples/wiki_example/run index 9d92539..9033181 100755 --- a/examples/wiki_example/run +++ b/examples/wiki_example/run @@ -9,11 +9,13 @@ java -jar ../../compiler/labComm.jar \ example.lc # Compile executables +(cd ../../lib/c; make liblabcomm.a) + gcc -o example_encoder -I ../../lib/c/ \ example_encoder.c \ - example.c \ - ../../lib/c/labcomm.c \ - ../../lib/c//labcomm_fd_reader_writer.c + example.c \ + ../../lib/c/liblabcomm.a + javac -cp ../../lib/java:. *.java # Run through all executables (c->java->Python) -- GitLab