test-client-godot/modules/action/action_genericmultipart.cpp
2020-05-02 20:37:08 +02:00

55 lines
No EOL
1.5 KiB
C++

/*
Action Generic Multi Part
Copyright (C) 2019 AleaJactaEst
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "action_genericmultipart.h"
#include "modules/debug/debug.h"
void GenericMultiPart::add(uint16_t Part, PoolByteArray PartCont)
{
if (this->_block.has(Part))
{
this->_block[Part] = PartCont;
return;
}
this->_block[Part] = PartCont;
}
bool GenericMultiPart::is_complete()
{
if ( this->_block.size() != this->_size )
return false;
return true;
}
PoolByteArray GenericMultiPart::get_message()
{
DBG_PRINT("get message " + itos(this->_id));
#ifdef DEBUG_ENABLED
if ( is_complete() == false )
{
ERR_PRINT("Missing some block id:" + itos(this->_id) + " " + itos(this->_block.size()) + "/" + itos(this->_size));
}
#endif
int i;
PoolByteArray out;
for(i = 0; i < this->_size ; ++i)
out.append(this->_block[i]);
return out;
}