switched gxscircleitems to new serialization

This commit is contained in:
csoler 2017-04-26 20:57:28 +02:00
parent db645239cb
commit 559137d05b
4 changed files with 118 additions and 108 deletions

View File

@ -34,7 +34,6 @@
std::ostream &operator<<(std::ostream &out, const RsGroupMetaData &meta);
std::ostream &operator<<(std::ostream &out, const RsMsgMetaData &meta);
class RsGxsGrpItem : public RsItem
{

View File

@ -26,11 +26,104 @@
#include <iostream>
#include "rsgxscircleitems.h"
#include "serialiser/rstlvbase.h"
#include "serialiser/rsbaseserial.h"
#include "serialization/rstypeserializer.h"
//#define CIRCLE_DEBUG 1
RsItem *RsGxsCircleSerialiser::create_item(uint16_t service, uint8_t item_sub_id) const
{
if(service != RS_SERVICE_GXS_TYPE_GXSCIRCLE)
return NULL ;
switch(item_sub_id)
{
case RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM: return new RsGxsCircleGroupItem();
case RS_PKT_SUBTYPE_GXSCIRCLE_MSG_ITEM: return new RsGxsCircleMsgItem();
case RS_PKT_SUBTYPE_GXSCIRCLE_SUBSCRIPTION_REQUEST_ITEM: return new RsGxsCircleSubscriptionRequestItem();
default:
return NULL ;
}
}
void RsGxsCircleSubscriptionRequestItem::clear()
{
time_stamp = 0 ;
time_out = 0 ;
subscription_type = SUBSCRIPTION_REQUEST_UNKNOWN;
}
void RsGxsCircleMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG,msg.stuff,"msg.stuff") ;
}
void RsGxsCircleSubscriptionRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint32_t>(j,ctx,time_stamp,"time_stamp") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,time_out ,"time_out") ;
RsTypeSerializer::serial_process<uint8_t> (j,ctx,subscription_type ,"subscription_type") ;
}
void RsGxsCircleGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,pgpIdSet,"pgpIdSet") ;
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,gxsIdSet,"gxsIdSet") ;
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,subCircleSet,"subCircleSet") ;
}
void RsGxsCircleMsgItem::clear()
{
msg.stuff.clear();
}
void RsGxsCircleGroupItem::clear()
{
pgpIdSet.TlvClear();
gxsIdSet.TlvClear();
subCircleSet.TlvClear();
}
bool RsGxsCircleGroupItem::convertFrom(const RsGxsCircleGroup &group)
{
clear();
meta = group.mMeta;
// Enforce the local rules.
if (meta.mCircleType == GXS_CIRCLE_TYPE_LOCAL)
{
pgpIdSet.ids = group.mLocalFriends;
}
else
{
gxsIdSet.ids = group.mInvitedMembers;
}
subCircleSet.ids = group.mSubCircles;
return true;
}
bool RsGxsCircleGroupItem::convertTo(RsGxsCircleGroup &group) const
{
group.mMeta = meta;
// Enforce the local rules.
if (meta.mCircleType == GXS_CIRCLE_TYPE_LOCAL)
{
group.mLocalFriends = pgpIdSet.ids;
}
else
{
group.mInvitedMembers = gxsIdSet.ids;
}
group.mSubCircles = subCircleSet.ids;
return true;
}
#ifdef TO_REMOVE
uint32_t RsGxsCircleSerialiser::size(RsItem *item)
{
RsGxsCircleGroupItem* grp_item = NULL;
@ -115,14 +208,6 @@ RsItem* RsGxsCircleSerialiser::deserialise(void* data, uint32_t* size)
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
void RsGxsCircleSubscriptionRequestItem::clear()
{
time_stamp = 0 ;
time_out = 0 ;
subscription_type = SUBSCRIPTION_REQUEST_UNKNOWN;
}
std::ostream& RsGxsCircleSubscriptionRequestItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsCircleSubscriptionRequestItem", indent);
@ -135,51 +220,6 @@ std::ostream& RsGxsCircleSubscriptionRequestItem::print(std::ostream& out, uint1
return out;
}
void RsGxsCircleGroupItem::clear()
{
pgpIdSet.TlvClear();
gxsIdSet.TlvClear();
subCircleSet.TlvClear();
}
bool RsGxsCircleGroupItem::convertFrom(const RsGxsCircleGroup &group)
{
clear();
meta = group.mMeta;
// Enforce the local rules.
if (meta.mCircleType == GXS_CIRCLE_TYPE_LOCAL)
{
pgpIdSet.ids = group.mLocalFriends;
}
else
{
gxsIdSet.ids = group.mInvitedMembers;
}
subCircleSet.ids = group.mSubCircles;
return true;
}
bool RsGxsCircleGroupItem::convertTo(RsGxsCircleGroup &group) const
{
group.mMeta = meta;
// Enforce the local rules.
if (meta.mCircleType == GXS_CIRCLE_TYPE_LOCAL)
{
group.mLocalFriends = pgpIdSet.ids;
}
else
{
group.mInvitedMembers = gxsIdSet.ids;
}
group.mSubCircles = subCircleSet.ids;
return true;
}
std::ostream& RsGxsCircleGroupItem::print(std::ostream& out, uint16_t indent)
{
@ -275,7 +315,6 @@ bool RsGxsCircleSerialiser::serialiseGxsCircleSubscriptionRequestItem(RsGxsCircl
return ok;
}
bool RsGxsCircleSerialiser::serialiseGxsCircleGroupItem(RsGxsCircleGroupItem *item, void *data, uint32_t *size)
{
@ -324,8 +363,7 @@ bool RsGxsCircleSerialiser::serialiseGxsCircleGroupItem(RsGxsCircleGroupItem *it
#endif
return ok;
}
}
RsGxsCircleSubscriptionRequestItem *RsGxsCircleSerialiser::deserialiseGxsCircleSubscriptionRequestItem(void *data, uint32_t *size)
{
@ -463,13 +501,6 @@ RsGxsCircleGroupItem* RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem(void
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
void RsGxsCircleMsgItem::clear()
{
msg.stuff.clear();
}
std::ostream& RsGxsCircleMsgItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsCircleMsgItem", indent);
@ -494,6 +525,7 @@ uint32_t RsGxsCircleSerialiser::sizeGxsCircleMsgItem(RsGxsCircleMsgItem *item)
return s;
}
bool RsGxsCircleSerialiser::serialiseGxsCircleMsgItem(RsGxsCircleMsgItem *item, void *data, uint32_t *size)
{
@ -610,4 +642,4 @@ RsGxsCircleMsgItem* RsGxsCircleSerialiser::deserialiseGxsCircleMsgItem(void *dat
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
#endif

View File

@ -52,18 +52,12 @@ class RsGxsCircleGroupItem : public RsGxsGrpItem
public:
RsGxsCircleGroupItem(): RsGxsGrpItem(RS_SERVICE_GXS_TYPE_GXSCIRCLE,
RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM)
#if 0
pgpIdSet(GXSCIRCLE_PGPIDSET),
gxsIdSet(GXSCIRCLE_GXSIDSET),
subCircleSet(GXSCIRCLE_SUBCIRCLESET)
#endif
{ return;}
virtual ~RsGxsCircleGroupItem() { return;}
RsGxsCircleGroupItem(): RsGxsGrpItem(RS_SERVICE_GXS_TYPE_GXSCIRCLE, RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM) {}
virtual ~RsGxsCircleGroupItem() {}
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
void clear();
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
bool convertFrom(const RsGxsCircleGroup &group);
bool convertTo(RsGxsCircleGroup &group) const;
@ -78,11 +72,12 @@ class RsGxsCircleMsgItem : public RsGxsMsgItem
{
public:
RsGxsCircleMsgItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_GXSCIRCLE,
RS_PKT_SUBTYPE_GXSCIRCLE_MSG_ITEM) {return; }
virtual ~RsGxsCircleMsgItem() { return;}
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsGxsCircleMsgItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_GXSCIRCLE, RS_PKT_SUBTYPE_GXSCIRCLE_MSG_ITEM) {}
virtual ~RsGxsCircleMsgItem() {}
void clear();
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
RsGxsCircleMsg msg;
};
@ -94,7 +89,6 @@ public:
virtual ~RsGxsCircleSubscriptionRequestItem() {}
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
enum {
SUBSCRIPTION_REQUEST_UNKNOWN = 0x00,
@ -102,37 +96,22 @@ public:
SUBSCRIPTION_REQUEST_UNSUBSCRIBE = 0x02
};
time_t time_stamp ;
time_t time_out ;
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
uint32_t time_stamp ;
uint32_t time_out ;
uint8_t subscription_type ;
};
class RsGxsCircleSerialiser : public RsSerialType
class RsGxsCircleSerialiser : public RsServiceSerializer
{
public:
RsGxsCircleSerialiser()
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXS_TYPE_GXSCIRCLE)
{ return; }
virtual ~RsGxsCircleSerialiser() { return; }
:RsServiceSerializer(RS_SERVICE_GXS_TYPE_GXSCIRCLE) {}
virtual ~RsGxsCircleSerialiser() {}
uint32_t size(RsItem *item);
bool serialise (RsItem *item, void *data, uint32_t *size);
RsItem * deserialise(void *data, uint32_t *size);
private:
uint32_t sizeGxsCircleSubscriptionRequestItem(RsGxsCircleSubscriptionRequestItem *item);
bool serialiseGxsCircleSubscriptionRequestItem (RsGxsCircleSubscriptionRequestItem *item, void *data, uint32_t *size);
RsGxsCircleSubscriptionRequestItem * deserialiseGxsCircleSubscriptionRequestItem(void *data, uint32_t *size);
uint32_t sizeGxsCircleGroupItem(RsGxsCircleGroupItem *item);
bool serialiseGxsCircleGroupItem (RsGxsCircleGroupItem *item, void *data, uint32_t *size);
RsGxsCircleGroupItem * deserialiseGxsCircleGroupItem(void *data, uint32_t *size);
uint32_t sizeGxsCircleMsgItem(RsGxsCircleMsgItem *item);
bool serialiseGxsCircleMsgItem (RsGxsCircleMsgItem *item, void *data, uint32_t *size);
RsGxsCircleMsgItem * deserialiseGxsCircleMsgItem(void *data, uint32_t *size);
virtual RsItem *create_item(uint16_t service, uint8_t item_sub_id) const;
};
#endif /* RS_GXSCIRCLE_ITEMS_H */

View File

@ -24,7 +24,7 @@
*/
#include "services/p3gxschannels.h"
#include "serialiser/rsgxschannelitems.h"
#include "rsitems/rsgxschannelitems.h"
#include "util/radix64.h"
#include "util/rsmemory.h"