2018-05-29 15:08:17 -04:00
|
|
|
/*******************************************************************************
|
|
|
|
* libretroshare/src/rsitems: rsgxsupdateitems.cc *
|
|
|
|
* *
|
|
|
|
* libretroshare: retroshare core library *
|
|
|
|
* *
|
|
|
|
* Copyright 2012 Christopher Evi-Parker *
|
|
|
|
* *
|
|
|
|
* 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 <https://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
2017-04-30 10:05:37 -04:00
|
|
|
#include "serialiser/rstypeserializer.h"
|
2017-04-28 10:30:33 -04:00
|
|
|
#include "serialiser/rsbaseserial.h"
|
2017-04-28 10:26:59 -04:00
|
|
|
|
2013-11-10 17:27:50 -05:00
|
|
|
#include "rsgxsupdateitems.h"
|
|
|
|
|
2017-04-28 10:26:59 -04:00
|
|
|
/**********************************************************************************************/
|
|
|
|
/* SERIALIZER */
|
|
|
|
/**********************************************************************************************/
|
|
|
|
|
|
|
|
RsItem* RsGxsUpdateSerialiser::create_item(uint16_t service,uint8_t item_subtype) const
|
|
|
|
{
|
|
|
|
if(service != SERVICE_TYPE)
|
|
|
|
return NULL ;
|
|
|
|
|
|
|
|
switch(item_subtype)
|
|
|
|
{
|
|
|
|
case RS_PKT_SUBTYPE_GXS_MSG_UPDATE: return new RsGxsMsgUpdateItem(SERVICE_TYPE);
|
|
|
|
case RS_PKT_SUBTYPE_GXS_GRP_UPDATE: return new RsGxsGrpUpdateItem(SERVICE_TYPE);
|
|
|
|
case RS_PKT_SUBTYPE_GXS_SERVER_GRP_UPDATE: return new RsGxsServerGrpUpdateItem(SERVICE_TYPE);
|
|
|
|
case RS_PKT_SUBTYPE_GXS_SERVER_MSG_UPDATE: return new RsGxsServerMsgUpdateItem(SERVICE_TYPE);
|
|
|
|
case RS_PKT_SUBTYPE_GXS_GRP_CONFIG: return new RsGxsGrpConfigItem(SERVICE_TYPE);
|
|
|
|
default:
|
|
|
|
return NULL ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-06 16:17:03 -05:00
|
|
|
/**********************************************************************************************/
|
|
|
|
/* CLEAR */
|
|
|
|
/**********************************************************************************************/
|
|
|
|
|
2013-11-10 17:27:50 -05:00
|
|
|
void RsGxsGrpUpdateItem::clear()
|
|
|
|
{
|
|
|
|
grpUpdateTS = 0;
|
2016-11-10 18:10:01 -05:00
|
|
|
peerID.clear();
|
2013-11-10 17:27:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void RsGxsMsgUpdateItem::clear()
|
|
|
|
{
|
2015-01-31 13:06:37 -05:00
|
|
|
msgUpdateInfos.clear();
|
2016-11-10 18:10:01 -05:00
|
|
|
peerID.clear();
|
2013-11-10 17:27:50 -05:00
|
|
|
}
|
|
|
|
|
2016-12-06 16:17:03 -05:00
|
|
|
void RsGxsServerMsgUpdateItem::clear()
|
|
|
|
{
|
|
|
|
msgUpdateTS = 0;
|
|
|
|
grpId.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RsGxsServerGrpUpdateItem::clear()
|
|
|
|
{
|
|
|
|
grpUpdateTS = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************************************/
|
2017-04-28 10:26:59 -04:00
|
|
|
/* SERIALISER */
|
2016-12-06 16:17:03 -05:00
|
|
|
/**********************************************************************************************/
|
|
|
|
|
2017-04-28 10:26:59 -04:00
|
|
|
void RsGxsGrpUpdateItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
2013-11-10 17:27:50 -05:00
|
|
|
{
|
2017-04-28 10:26:59 -04:00
|
|
|
RsTypeSerializer::serial_process (j,ctx,peerID,"peerID");
|
|
|
|
RsTypeSerializer::serial_process<uint32_t>(j,ctx,grpUpdateTS,"grpUpdateTS");
|
2013-11-10 17:27:50 -05:00
|
|
|
}
|
|
|
|
|
2017-04-28 10:26:59 -04:00
|
|
|
void RsGxsServerGrpUpdateItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
2013-11-16 08:40:04 -05:00
|
|
|
{
|
2017-04-28 10:26:59 -04:00
|
|
|
RsTypeSerializer::serial_process<uint32_t>(j,ctx,grpUpdateTS,"grpUpdateTS");
|
2013-11-16 08:40:04 -05:00
|
|
|
}
|
|
|
|
|
2017-04-28 10:26:59 -04:00
|
|
|
void RsGxsMsgUpdateItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
2013-11-10 17:27:50 -05:00
|
|
|
{
|
2017-04-28 10:26:59 -04:00
|
|
|
RsTypeSerializer::serial_process(j,ctx,peerID,"peerID");
|
|
|
|
RsTypeSerializer::serial_process(j,ctx,msgUpdateInfos,"msgUpdateInfos");
|
2016-12-06 16:17:03 -05:00
|
|
|
}
|
2013-11-10 17:27:50 -05:00
|
|
|
|
2017-04-28 10:26:59 -04:00
|
|
|
template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const RsGxsMsgUpdateItem::MsgUpdateInfo& info)
|
2016-12-06 16:17:03 -05:00
|
|
|
{
|
2017-04-28 10:26:59 -04:00
|
|
|
bool ok = true ;
|
2013-11-10 17:27:50 -05:00
|
|
|
|
2017-04-28 10:26:59 -04:00
|
|
|
ok = ok && setRawUInt32(data,size,&offset,info.time_stamp);
|
|
|
|
ok = ok && setRawUInt32(data,size,&offset,info.message_count);
|
2013-11-16 08:40:04 -05:00
|
|
|
|
2016-12-06 16:17:03 -05:00
|
|
|
return ok;
|
|
|
|
}
|
2017-04-28 10:26:59 -04:00
|
|
|
template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, RsGxsMsgUpdateItem::MsgUpdateInfo& info)
|
2016-12-06 16:17:03 -05:00
|
|
|
{
|
2017-04-28 10:26:59 -04:00
|
|
|
bool ok = true ;
|
2013-11-16 08:40:04 -05:00
|
|
|
|
2017-04-28 10:26:59 -04:00
|
|
|
ok = ok && getRawUInt32(data,size,&offset,&info.time_stamp);
|
|
|
|
ok = ok && getRawUInt32(data,size,&offset,&info.message_count);
|
2013-11-16 08:40:04 -05:00
|
|
|
|
2016-12-06 16:17:03 -05:00
|
|
|
return ok;
|
|
|
|
}
|
2017-04-28 10:26:59 -04:00
|
|
|
template<> uint32_t RsTypeSerializer::serial_size(const RsGxsMsgUpdateItem::MsgUpdateInfo& /* info */) { return 8; }
|
2016-12-06 16:17:03 -05:00
|
|
|
|
2017-04-28 10:26:59 -04:00
|
|
|
template<> void RsTypeSerializer::print_data(const std::string& name,const RsGxsMsgUpdateItem::MsgUpdateInfo& info)
|
2016-12-06 16:17:03 -05:00
|
|
|
{
|
2017-04-28 10:26:59 -04:00
|
|
|
std::cerr << "[MsgUpdateInfo]: " << name << ": " << info.time_stamp << ", " << info.message_count << std::endl;
|
2016-12-06 16:17:03 -05:00
|
|
|
}
|
|
|
|
|
2017-04-28 10:26:59 -04:00
|
|
|
void RsGxsServerMsgUpdateItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
2016-12-06 16:17:03 -05:00
|
|
|
{
|
2017-04-28 10:26:59 -04:00
|
|
|
RsTypeSerializer::serial_process (j,ctx,grpId,"grpId");
|
|
|
|
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msgUpdateTS,"msgUpdateTS");
|
2013-11-16 08:40:04 -05:00
|
|
|
}
|
2017-04-28 10:26:59 -04:00
|
|
|
void RsGxsGrpConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
2013-11-10 17:27:50 -05:00
|
|
|
{
|
2017-04-28 10:26:59 -04:00
|
|
|
RsTypeSerializer::serial_process (j,ctx,grpId,"grpId") ;
|
|
|
|
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msg_keep_delay,"msg_keep_delay") ;
|
|
|
|
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msg_send_delay,"msg_send_delay") ;
|
|
|
|
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msg_req_delay,"msg_req_delay") ;
|
2013-11-16 08:40:04 -05:00
|
|
|
}
|
2016-12-06 16:17:03 -05:00
|
|
|
|