diff --git a/src/test/main_codec.old b/src/test/main_codec.old deleted file mode 100644 index 8e4158b..0000000 --- a/src/test/main_codec.old +++ /dev/null @@ -1,259 +0,0 @@ -/* - * Copyright (C) 2007-2011 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.5 - * @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.exi out/test/sessionSetupReq.xml.exi

- ********************************************************************/ - -#include -#include - -#include "EXIDecoder.h" -#include "StringTable.h" -#include "EXIEncoder.h" -#include "EXITypes.h" -#include "ByteStream.h" - -#define BUFFER_SIZE 1000 - -#define ARRAY_SIZE_BYTES 100 -#define ARRAY_SIZE_STRINGS 100 - -/* avoids warning: initializer element is not computable at load time */ -uint8_t bufferIn[BUFFER_SIZE]; -uint8_t bufferOut[BUFFER_SIZE]; -uint8_t data[ARRAY_SIZE_BYTES]; -uint32_t codepoints[ARRAY_SIZE_STRINGS]; - -int main_codec(int argc, char *argv[]) { - - int errn = 0; - unsigned int i; - - bitstream_t iStream, oStream; - uint16_t posDecode; - uint16_t 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 setup */ - bytes_t bytes = { ARRAY_SIZE_BYTES, data, 0 }; - - /* STRING memory setup */ - string_ucs_t string = { ARRAY_SIZE_STRINGS, codepoints, 0 }; - - const char * localName; - const char * namespaceURI; - - int noEndOfDocument = 1; /* true */ - - if (argc != 3) { - printf("Usage: %s exiInput exiOutput\n", argv[0]); - return -1; - } - - /* input pos */ - posDecode = 0; - - /* parse EXI stream to internal byte structures */ - readBytesFromFile(argv[1], bufferIn, BUFFER_SIZE, posDecode); - - /* setup input stream */ - iStream.size = BUFFER_SIZE; - iStream.data = bufferIn; - iStream.pos = &posDecode; - iStream.buffer = 0; - iStream.capacity = 0; - - /* setup output stream */ - posEncode = 0; - oStream.size = BUFFER_SIZE; - oStream.data = bufferOut; - 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", errn); - return errn; - } - - errn = exiDecodeNextEvent(&iStream, &stateDecode, &event); - if (errn < 0) { - printf("[Decode-ERROR] %d \n", errn); - return errn; - } - - switch (event) { - case START_DOCUMENT: - /* decode */ - errn = exiDecodeStartDocument(&iStream, &stateDecode); - if (errn < 0) { - printf("[Decode-ERROR] %d \n", errn); - 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", errn); - 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", errn); - return errn; - } - - /* EVSEStatus - * if(eqn.localPart=1 && eqn.namespaceURI=3) { - - send CAN message... - - /* ResponseCode - } else if(eqn.localPart=2 && eqn.namespaceURI=3) { - - send CAN message... - - } else { - - - } */ - - exiGetLocalName(eqn.namespaceURI, eqn.localPart, &localName); - exiGetUri(eqn.namespaceURI, &namespaceURI); - printf(">> SE {%s}%s \n", namespaceURI, localName); - /*fflush(stdout); */ - - - /* encode */ - errn = exiEncodeStartElement(&oStream, &stateEncode, &eqn); - break; - - case START_ELEMENT_GENERIC: - /* unknown element */ - - /* read the element content as usual (element name, value, type, etc.) */ - - break; - - case END_ELEMENT: - /* decode */ - errn = exiDecodeEndElement(&iStream, &stateDecode, &eqn); - if (errn < 0) { - printf("[Decode-ERROR] %d \n", errn); - 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", errn); - return errn; - } - if (val.type == INTEGER_BIG) { - printf(" CH int64 : %ld \n", (long int)val.int64); - } else if (val.type == BINARY_BASE64 || val.type == BINARY_HEX) { - printf(" CH Binary (len == %d) : ", val.binary.len); - for(i=0; i