1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
9 #include <anna/config/defines.hpp>
11 #include <anna/comm/LargeBinaryCodec.hpp>
12 #include <anna/comm/functions.hpp>
17 void comm::LargeBinaryCodec::decode(const DataBlock& dataBlock)
18 throw(RuntimeException) {
20 comm::Codec::decode(dataBlock);
21 const char* data = a_dataBlock.getData();
25 for(int pos = 0, maxpos = a_dataBlock.getSize(); pos < maxpos;) {
26 if((pos + sizeof(int)) >= maxpos)
27 throw RuntimeException("Iterator out of range", ANNA_FILE_LOCATION);
29 size = comm::functions::decodeInteger(data + pos);
31 if((pos + sizeof(int) + size) > maxpos)
32 throw RuntimeException("Iterator out of range", ANNA_FILE_LOCATION);
34 block = new DataBlock(true);
35 *block = DataBlock(data + sizeof(int) + pos, size, false);
36 a_blocks.push_back(block);
37 pos += sizeof(int) + size;
41 void comm::LargeBinaryCodec::reset()
43 for(iterator ii = a_blocks.begin(), maxii = a_blocks.end(); ii != maxii; ii ++)
49 comm::LargeBinaryCodec& comm::LargeBinaryCodec::operator += (const DataBlock & dataBlock)
50 throw(RuntimeException) {
51 char size [sizeof(int)];
52 a_dataBlock.append(functions::codeInteger(size, dataBlock.getSize()), sizeof(int));
53 a_dataBlock += dataBlock;
54 DataBlock* block = new DataBlock(true);
56 a_blocks.push_back(block);