Port GxsTrans to new serialization system

RsItem added some comment and more verbose error reporting
RsTypeSerializer added support for RsItem derived classes as members
  added utility macros for better readability of the code and easier
  handling of RsItem derived members
  RS_REGISTER_SERIAL_MEMBER(I)
  RS_REGISTER_SERIAL_MEMBER_TYPED(I, T)
  RS_REGISTER_ITEM_TYPE(T)

RsNxsMsg::serial_process use new macros for better readability and to
 have an exemple of usage with RsTlvItem derived class
Fix undefined reference to RsNxsMsg::print
This commit is contained in:
Gioacchino Mazzurco 2017-05-08 00:19:11 +02:00
parent f7f36f697e
commit ea8f800003
11 changed files with 655 additions and 728 deletions

View file

@ -3,6 +3,7 @@
#include "util/smallobject.h"
#include "retroshare/rstypes.h"
#include "serialiser/rsserializer.h"
#include "util/stacktrace.h"
class RsItem: public RsMemoryManagement::SmallObject
{
@ -15,6 +16,8 @@ class RsItem: public RsMemoryManagement::SmallObject
#endif
virtual ~RsItem();
/// TODO: Do this make sense with the new serialization system?
virtual void clear() = 0;
virtual std::ostream &print(std::ostream &out, uint16_t /* indent */ = 0)
@ -48,21 +51,16 @@ class RsItem: public RsMemoryManagement::SmallObject
inline void setPriorityLevel(uint8_t l) { _priority_level = l ;}
/**
* @brief serialize this object to the given buffer
* @param Job to do: serialise or deserialize.
* @param data Chunk of memory were to dump the serialized data
* @param size Size of memory chunk
* @param offset Readed to determine at witch offset start writing data,
* written to inform caller were written data ends, the updated value
* is usually passed by the caller to serialize of another
* RsSerializable so it can write on the same chunk of memory just
* after where this RsSerializable has been serialized.
* @return true if serialization successed, false otherwise
* TODO: This should be made pure virtual as soon as all the codebase
* is ported to the new serialization system
*/
virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */)
virtual void serial_process(RsGenericSerializer::SerializeJob,
RsGenericSerializer::SerializeContext&)// = 0;
{
std::cerr << "(EE) RsItem::serial_process() called by an item using new serialization classes, but not derived! Class is " << typeid(*this).name() << std::endl;
std::cerr << "(EE) RsItem::serial_process() called by an item using"
<< "new serialization classes, but not derived! Class is "
<< typeid(*this).name() << std::endl;
print_stacktrace();
}
protected:
@ -71,6 +69,7 @@ class RsItem: public RsMemoryManagement::SmallObject
uint8_t _priority_level ;
};
/// TODO: Do this make sense with the new serialization system?
class RsRawItem: public RsItem
{
public:

View file

@ -69,15 +69,18 @@ void RsNxsSyncMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGene
RsTypeSerializer::serial_process (j,ctx,msgId ,"msgId") ;
RsTypeSerializer::serial_process (j,ctx,authorId ,"authorId") ;
}
void RsNxsMsg::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
void RsNxsMsg::serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{
RsTypeSerializer::serial_process<uint32_t> (j,ctx,transactionNumber,"transactionNumber") ;
RsTypeSerializer::serial_process<uint8_t> (j,ctx,pos ,"pos") ;
RsTypeSerializer::serial_process (j,ctx,msgId ,"msgId") ;
RsTypeSerializer::serial_process (j,ctx,grpId ,"grpId") ;
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,msg ,"msg") ;
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,meta ,"meta") ;
RS_REGISTER_SERIAL_MEMBER_TYPED(transactionNumber, uint32_t);
RS_REGISTER_SERIAL_MEMBER_TYPED(pos, uint8_t);
RS_REGISTER_SERIAL_MEMBER(msgId);
RS_REGISTER_SERIAL_MEMBER(grpId);
RS_REGISTER_SERIAL_MEMBER_TYPED(msg, RsTlvItem);
RS_REGISTER_SERIAL_MEMBER_TYPED(meta, RsTlvItem);
}
void RsNxsGrp::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint32_t> (j,ctx,transactionNumber,"transactionNumber") ;
@ -149,11 +152,14 @@ void RsNxsMsg::clear()
meta.TlvClear();
}
std::ostream&RsNxsMsg::print(std::ostream& out, uint16_t /*indent*/)
{ return out; }
void RsNxsGrp::clear()
{
grpId.clear();
grp.TlvClear();
meta.TlvClear();
grpId.clear();
grp.TlvClear();
meta.TlvClear();
}
void RsNxsSyncGrpReqItem::clear()

View file

@ -376,7 +376,7 @@ struct RsNxsMsg : RsNxsItem
RsGenericSerializer::SerializeContext& ctx );
virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent);
virtual std::ostream &print(std::ostream& out, uint16_t indent);
uint8_t pos; /// used for splitting up msg
uint8_t count; /// number of split up messages