len; i++) {
+ outASCII[i] = (char)string->codepoints[i];
+ }
+ outASCII[string->len] = '\0';
+
+ return 0;
+}
+
+#endif
+
diff --git a/src/codec/UCSString.h b/src/codec/UCSString.h
new file mode 100644
index 0000000..0dbcc8f
--- /dev/null
+++ b/src/codec/UCSString.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2007-2010 Siemens AG
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+/*******************************************************************
+ *
+ * @author Daniel.Peintner.EXT@siemens.com
+ * @version 0.1
+ * @contact Joerg.Heuer@siemens.com
+ *
+ ********************************************************************/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "EXITypes.h"
+
+// TODO utf8/cstring//wchar_t/char16_t/char32_t methods
+
+
+#ifndef UCS_STRING_H
+#define UCS_STRING_H
+
+int toUCSString(char* chars, string_ucs_t* s);
+
+// Note: fails if string contains non ASCII characters
+int toASCIIString(string_ucs_t* string, char* outASCII);
+
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/src/test/main_codec.c b/src/test/main_codec.c
new file mode 100644
index 0000000..f710ff0
--- /dev/null
+++ b/src/test/main_codec.c
@@ -0,0 +1,218 @@
+/*
+ * Copyright (C) 2007-2010 Siemens AG
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+/*******************************************************************
+ *
+ * @author Daniel.Peintner.EXT@siemens.com
+ * @version 0.1
+ * @contact Joerg.Heuer@siemens.com
+ *
+ * Sample program to illustrate how to read an EXI stream and
+ * directly write it again to an output
+ *
+ * e.g., data/test/sessionSetupReq.xml_SCHEMA.exi out/test/sessionSetupReq.xml_SCHEMA.exi
+ ********************************************************************/
+
+#include
+#include
+
+#include "EXIDecoder.h"
+#include "StringTable.h"
+#include "EXIEncoder.h"
+#include "EXITypes.h"
+#include "Bitstream.h"
+
+
+int main(int argc, char *argv[]) {
+
+ int errn = 0;
+ unsigned int i;
+
+ bitstream_t iStream, oStream;
+ size_t posDecode, posEncode;
+
+ // EXI set-up
+ exi_state_t stateDecode;
+ exi_state_t stateEncode;
+ exi_event_t event;
+ eqname_t eqn;
+ exi_value_t val;
+
+ // BINARY memory allocation
+ uint8_t data[10];
+ bytes_t bytes = { 10, data };
+
+ // STRING memory allocation
+ uint32_t codepoints[50];
+ string_ucs_t string = { 50, codepoints };
+
+ const char * localName;
+ const char * namespaceURI;
+
+ int noEndOfDocument = 1; /* true */
+
+ if (argc != 3) {
+ printf("Usage: %s exiInput exiOutput\n", argv[0]);
+ return -1;
+ }
+
+ /* parse EXI stream to internal byte structures */
+ toBitstream(argv[1], &iStream);
+
+ // input
+ posDecode = 0;
+ iStream.pos = &posDecode;
+ iStream.buffer = 0;
+ iStream.capacity = 0;
+
+ // output
+ posEncode = 0;
+ oStream.data = malloc(sizeof(uint8_t)*iStream.size);
+ oStream.size = iStream.size;
+ oStream.pos = &posEncode;
+ oStream.buffer = 0;
+ oStream.capacity = 8;
+
+ val.binary = bytes;
+ val.string = string;
+
+ /* init decoder (read header, set initial state) */
+ exiInitDecoder(&iStream, &stateDecode);
+
+ /* init encoder (write header, set initial state) */
+ exiInitEncoder(&oStream, &stateEncode);
+
+ printf("[DECODE] >>> EXI >>> [ENCODE] \n");
+
+ do {
+ if (errn < 0) {
+ printf("[Encode-ERROR] %d \n", errno);
+ return errn;
+ }
+
+ errn = exiDecodeNextEvent(&iStream, &stateDecode, &event);
+ if (errn < 0) {
+ printf("[Decode-ERROR] %d \n", errno);
+ return errn;
+ }
+
+ switch (event) {
+ case START_DOCUMENT:
+ // decode
+ errn = exiDecodeStartDocument(&iStream, &stateDecode);
+ if (errn < 0) {
+ printf("[Decode-ERROR] %d \n", errno);
+ return errn;
+ }
+ printf(">> START_DOCUMENT \n");
+ // encode
+ errn = exiEncodeStartDocument(&oStream, &stateEncode);
+ break;
+ case END_DOCUMENT:
+ // decode
+ errn = exiDecodeEndDocument(&iStream, &stateDecode);
+ if (errn < 0) {
+ printf("[Decode-ERROR] %d \n", errno);
+ return errn;
+ }
+ printf(">> END_DOCUMENT \n");
+ // encode
+ errn = exiEncodeEndDocument(&oStream, &stateEncode);
+ /* signalize end of document */
+ noEndOfDocument = 0; /* false */
+ break;
+ case START_ELEMENT:
+ // decode
+ errn = exiDecodeStartElement(&iStream, &stateDecode, &eqn);
+ if (errn < 0) {
+ printf("[Decode-ERROR] %d \n", errno);
+ return errn;
+ }
+ exiGetLocalName(eqn.namespaceURI, eqn.localPart, &localName);
+ exiGetUri(eqn.namespaceURI, &namespaceURI);
+ printf(">> SE {%s}%s \n", namespaceURI, localName);
+ // encode
+ errn = exiEncodeStartElement(&oStream, &stateEncode, &eqn);
+ break;
+ case END_ELEMENT:
+ // decode
+ errn = exiDecodeEndElement(&iStream, &stateDecode, &eqn);
+ if (errn < 0) {
+ printf("[Decode-ERROR] %d \n", errno);
+ return errn;
+ }
+ exiGetLocalName(eqn.namespaceURI, eqn.localPart, &localName);
+ exiGetUri(eqn.namespaceURI, &namespaceURI);
+ printf("<< EE {%s}%s \n", namespaceURI, localName);
+ // encode
+ errn = exiEncodeEndElement(&oStream, &stateEncode, &eqn);
+ break;
+ case CHARACTERS:
+ // decode
+ errn = exiDecodeCharacters(&iStream, &stateDecode, &val);
+ if (errn < 0) {
+ printf("[Decode-ERROR] %d \n", errno);
+ return errn;
+ }
+ if (val.type == INTEGER_BIG) {
+ printf(" CH int64 : %lld \n", val.int64);
+ } else if (val.type == BINARY_BASE64 || val.type == BINARY_HEX) {
+ printf(" CH Binary (len == %d) : ", val.binary.len);
+ for(i=0; i