Better naming for serialization helper macro

This commit is contained in:
Gioacchino Mazzurco 2018-01-21 20:27:49 +01:00
parent 18891645e0
commit 9d40d416f6
8 changed files with 86 additions and 85 deletions

View File

@ -212,4 +212,4 @@ RS_REGISTER_SERIALIZABLE_TYPE_DEF(RsChatMsgItem)
void PrivateOugoingMapItem::serial_process(
RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{ RS_REGISTER_SERIAL_MEMBER(store); }
{ RS_PROCESS_SERIAL_MEMBER(store); }

View File

@ -48,24 +48,24 @@ void OutgoingRecord_deprecated::serial_process(
RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{
RS_REGISTER_SERIAL_MEMBER_TYPED(status, uint8_t);
RS_REGISTER_SERIAL_MEMBER(recipient);
RS_REGISTER_SERIAL_MEMBER(mailItem);
RS_REGISTER_SERIAL_MEMBER(mailData);
RS_REGISTER_SERIAL_MEMBER_TYPED(clientService, uint16_t);
RS_REGISTER_SERIAL_MEMBER(presignedReceipt);
RS_PROCESS_SERIAL_MEMBER_TYPED(status, uint8_t);
RS_PROCESS_SERIAL_MEMBER(recipient);
RS_PROCESS_SERIAL_MEMBER(mailItem);
RS_PROCESS_SERIAL_MEMBER(mailData);
RS_PROCESS_SERIAL_MEMBER_TYPED(clientService, uint16_t);
RS_PROCESS_SERIAL_MEMBER(presignedReceipt);
}
void OutgoingRecord::serial_process(RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx)
{
RS_REGISTER_SERIAL_MEMBER_TYPED(status, uint8_t);
RS_REGISTER_SERIAL_MEMBER(recipient);
RS_REGISTER_SERIAL_MEMBER(author);
RS_REGISTER_SERIAL_MEMBER(group_id);
RS_REGISTER_SERIAL_MEMBER(sent_ts);
RS_REGISTER_SERIAL_MEMBER(mailItem);
RS_REGISTER_SERIAL_MEMBER(mailData);
RS_REGISTER_SERIAL_MEMBER_TYPED(clientService, uint16_t);
RS_REGISTER_SERIAL_MEMBER(presignedReceipt);
RS_PROCESS_SERIAL_MEMBER_TYPED(status, uint8_t);
RS_PROCESS_SERIAL_MEMBER(recipient);
RS_PROCESS_SERIAL_MEMBER(author);
RS_PROCESS_SERIAL_MEMBER(group_id);
RS_PROCESS_SERIAL_MEMBER(sent_ts);
RS_PROCESS_SERIAL_MEMBER(mailItem);
RS_PROCESS_SERIAL_MEMBER(mailData);
RS_PROCESS_SERIAL_MEMBER_TYPED(clientService, uint16_t);
RS_PROCESS_SERIAL_MEMBER(presignedReceipt);
}

View File

@ -55,7 +55,7 @@ public:
void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{ RS_REGISTER_SERIAL_MEMBER_TYPED(mailId, uint64_t); }
{ RS_PROCESS_SERIAL_MEMBER_TYPED(mailId, uint64_t); }
};
class RsGxsTransPresignedReceipt : public RsGxsTransBaseMsgItem
@ -140,9 +140,9 @@ public:
RsGenericSerializer::SerializeContext& ctx )
{
RsGxsTransBaseMsgItem::serial_process(j, ctx);
RS_REGISTER_SERIAL_MEMBER_TYPED(cryptoType, uint8_t);
RS_REGISTER_SERIAL_MEMBER(recipientHint);
RS_REGISTER_SERIAL_MEMBER(payload);
RS_PROCESS_SERIAL_MEMBER_TYPED(cryptoType, uint8_t);
RS_PROCESS_SERIAL_MEMBER(recipientHint);
RS_PROCESS_SERIAL_MEMBER(payload);
}
void clear()

View File

@ -100,24 +100,24 @@ struct RsGroupMetaData : RsSerializable
void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{
RS_REGISTER_SERIAL_MEMBER(mGroupId);
RS_REGISTER_SERIAL_MEMBER(mGroupName);
RS_REGISTER_SERIAL_MEMBER(mGroupFlags);
RS_REGISTER_SERIAL_MEMBER(mSignFlags);
RS_REGISTER_SERIAL_MEMBER(mPublishTs);
RS_REGISTER_SERIAL_MEMBER(mAuthorId);
RS_REGISTER_SERIAL_MEMBER(mCircleId);
RS_REGISTER_SERIAL_MEMBER(mCircleType);
RS_REGISTER_SERIAL_MEMBER(mAuthenFlags);
RS_REGISTER_SERIAL_MEMBER(mParentGrpId);
RS_REGISTER_SERIAL_MEMBER(mSubscribeFlags);
RS_REGISTER_SERIAL_MEMBER(mPop);
RS_REGISTER_SERIAL_MEMBER(mVisibleMsgCount);
RS_REGISTER_SERIAL_MEMBER(mLastPost);
RS_REGISTER_SERIAL_MEMBER(mGroupStatus);
RS_REGISTER_SERIAL_MEMBER(mServiceString);
RS_REGISTER_SERIAL_MEMBER(mOriginator);
RS_REGISTER_SERIAL_MEMBER(mInternalCircle);
RS_PROCESS_SERIAL_MEMBER(mGroupId);
RS_PROCESS_SERIAL_MEMBER(mGroupName);
RS_PROCESS_SERIAL_MEMBER(mGroupFlags);
RS_PROCESS_SERIAL_MEMBER(mSignFlags);
RS_PROCESS_SERIAL_MEMBER(mPublishTs);
RS_PROCESS_SERIAL_MEMBER(mAuthorId);
RS_PROCESS_SERIAL_MEMBER(mCircleId);
RS_PROCESS_SERIAL_MEMBER(mCircleType);
RS_PROCESS_SERIAL_MEMBER(mAuthenFlags);
RS_PROCESS_SERIAL_MEMBER(mParentGrpId);
RS_PROCESS_SERIAL_MEMBER(mSubscribeFlags);
RS_PROCESS_SERIAL_MEMBER(mPop);
RS_PROCESS_SERIAL_MEMBER(mVisibleMsgCount);
RS_PROCESS_SERIAL_MEMBER(mLastPost);
RS_PROCESS_SERIAL_MEMBER(mGroupStatus);
RS_PROCESS_SERIAL_MEMBER(mServiceString);
RS_PROCESS_SERIAL_MEMBER(mOriginator);
RS_PROCESS_SERIAL_MEMBER(mInternalCircle);
}
};

View File

@ -98,10 +98,10 @@ struct GxsReputation : RsSerializable
void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{
RS_REGISTER_SERIAL_MEMBER(mOverallScore);
RS_REGISTER_SERIAL_MEMBER(mIdScore);
RS_REGISTER_SERIAL_MEMBER(mOwnOpinion);
RS_REGISTER_SERIAL_MEMBER(mPeerOpinion);
RS_PROCESS_SERIAL_MEMBER(mOverallScore);
RS_PROCESS_SERIAL_MEMBER(mIdScore);
RS_PROCESS_SERIAL_MEMBER(mOwnOpinion);
RS_PROCESS_SERIAL_MEMBER(mPeerOpinion);
}
};
@ -278,13 +278,13 @@ struct RsIdentityUsage : RsSerializable
void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{
RS_REGISTER_SERIAL_MEMBER(mServiceId);
RS_REGISTER_SERIAL_MEMBER_TYPED(mUsageCode, uint8_t);
RS_REGISTER_SERIAL_MEMBER(mGrpId);
RS_REGISTER_SERIAL_MEMBER(mMsgId);
RS_REGISTER_SERIAL_MEMBER(mAdditionalId);
RS_REGISTER_SERIAL_MEMBER(mComment);
RS_REGISTER_SERIAL_MEMBER(mHash);
RS_PROCESS_SERIAL_MEMBER(mServiceId);
RS_PROCESS_SERIAL_MEMBER_TYPED(mUsageCode, uint8_t);
RS_PROCESS_SERIAL_MEMBER(mGrpId);
RS_PROCESS_SERIAL_MEMBER(mMsgId);
RS_PROCESS_SERIAL_MEMBER(mAdditionalId);
RS_PROCESS_SERIAL_MEMBER(mComment);
RS_PROCESS_SERIAL_MEMBER(mHash);
}
friend class RsTypeSerializer;
@ -329,14 +329,14 @@ struct RsIdentityDetails : RsSerializable
virtual void serial_process(RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx)
{
RS_REGISTER_SERIAL_MEMBER(mId);
RS_REGISTER_SERIAL_MEMBER(mNickname);
RS_REGISTER_SERIAL_MEMBER(mFlags);
RS_REGISTER_SERIAL_MEMBER(mPgpId);
//RS_REGISTER_SERIAL_MEMBER_TYPED(mReputation, RsSerializable);
//RS_REGISTER_SERIAL_MEMBER_TYPED(mAvatar, RsSerializable);
RS_REGISTER_SERIAL_MEMBER(mLastUsageTS);
RS_REGISTER_SERIAL_MEMBER(mUseCases);
RS_PROCESS_SERIAL_MEMBER(mId);
RS_PROCESS_SERIAL_MEMBER(mNickname);
RS_PROCESS_SERIAL_MEMBER(mFlags);
RS_PROCESS_SERIAL_MEMBER(mPgpId);
//RS_PROCESS_SERIAL_MEMBER_TYPED(mReputation, RsSerializable);
//RS_PROCESS_SERIAL_MEMBER_TYPED(mAvatar, RsSerializable);
RS_PROCESS_SERIAL_MEMBER(mLastUsageTS);
RS_PROCESS_SERIAL_MEMBER(mUseCases);
}
};

View File

@ -73,12 +73,12 @@ void RsNxsSyncMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGene
void RsNxsMsg::serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{
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);
RS_PROCESS_SERIAL_MEMBER_TYPED(transactionNumber, uint32_t);
RS_PROCESS_SERIAL_MEMBER_TYPED(pos, uint8_t);
RS_PROCESS_SERIAL_MEMBER(msgId);
RS_PROCESS_SERIAL_MEMBER(grpId);
RS_PROCESS_SERIAL_MEMBER_TYPED(msg, RsTlvItem);
RS_PROCESS_SERIAL_MEMBER_TYPED(meta, RsTlvItem);
}
void RsNxsGrp::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)

View File

@ -22,32 +22,33 @@
/** @brief Minimal ancestor for all serializable structs in RetroShare
* If you want your struct to be easly serializable you should inherit from this
* struct.
* If you want your struct to be serializable as part of a container like an
* `std::vector<T>` @see RS_REGISTER_SERIALIZABLE_TYPE(T)
*/
struct RsSerializable
{
/** Register struct members to serialize in this method taking advantage of
* the helper macros
* @see RS_REGISTER_SERIAL_MEMBER(I)
* @see RS_REGISTER_SERIAL_MEMBER_TYPED(I, T)
* @see RS_REGISTER_SERIALIZABLE_TYPE(T)
* @see RS_PROCESS_SERIAL_MEMBER(I)
* @see RS_PROCESS_SERIAL_MEMBER_TYPED(I, T)
*/
virtual void serial_process(RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx) = 0;
};
/** @def RS_REGISTER_SERIAL_MEMBER(I)
/** @def RS_PROCESS_SERIAL_MEMBER(I)
* Use this macro to register the members of `YourSerializable` for serial
* processing inside `YourSerializable::serial_process(j, ctx)`
*
* Inspired by http://stackoverflow.com/a/39345864
*/
#define RS_REGISTER_SERIAL_MEMBER(I) \
#define RS_PROCESS_SERIAL_MEMBER(I) \
do { RsTypeSerializer::serial_process(j, ctx, I, #I); } while(0)
/** @def RS_REGISTER_SERIAL_MEMBER_TYPED(I, T)
* This macro usage is similar to @see RS_REGISTER_SERIAL_MEMBER(I) but it
/** @def RS_PROCESS_SERIAL_MEMBER_TYPED(I, T)
* This macro usage is similar to @see RS_PROCESS_SERIAL_MEMBER(I) but it
* permit to force serialization/deserialization type, it is expecially useful
* with enum class members or RsTlvItem derivative members, be very careful with
* the type you pass, as reinterpret_cast on a reference is used that is
@ -56,14 +57,14 @@ struct RsSerializable
* If you are using this with an RsSerializable derivative (so passing
* RsSerializable as T) consider to register your item type with
* @see RS_REGISTER_SERIALIZABLE_TYPE(T) in
* association with @see RS_REGISTER_SERIAL_MEMBER(I) that rely on template
* association with @see RS_PROCESS_SERIAL_MEMBER(I) that rely on template
* function generation, as in this particular case
* RS_REGISTER_SERIAL_MEMBER_TYPED(I, T) would cause the serial code rely on
* RS_PROCESS_SERIAL_MEMBER_TYPED(I, T) would cause the serial code rely on
* C++ dynamic dispatching that may have a noticeable impact on runtime
* performances.
*/
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#define RS_REGISTER_SERIAL_MEMBER_TYPED(I, T) do {\
#define RS_PROCESS_SERIAL_MEMBER_TYPED(I, T) do {\
RsTypeSerializer::serial_process<T>(j, ctx, reinterpret_cast<T&>(I), #I);\
} while(0)
#pragma GCC diagnostic pop
@ -96,13 +97,13 @@ void PrivateOugoingMapItem::serial_process(
RsGenericSerializer::SerializeContext& ctx )
{
// store is of type
RS_REGISTER_SERIAL_MEMBER(store);
RS_PROCESS_SERIAL_MEMBER(store);
}
* @endcode
*
* If you use this macro with a lot of different item types this can cause the
* generated binary grow in size, consider the usage of
* @see RS_REGISTER_SERIAL_MEMBER_TYPED(I, T) passing RsSerializable as type in
* @see RS_PROCESS_SERIAL_MEMBER_TYPED(I, T) passing RsSerializable as type in
* that case.
*/
#define RS_REGISTER_SERIALIZABLE_TYPE_DEF(T) template<> /*static*/\

View File

@ -4510,16 +4510,16 @@ void RsGxsIdGroup::serial_process(
RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{
RS_REGISTER_SERIAL_MEMBER_TYPED(mMeta, RsSerializable);
RS_REGISTER_SERIAL_MEMBER(mPgpIdHash);
//RS_REGISTER_SERIAL_MEMBER(mPgpIdSign);
RS_REGISTER_SERIAL_MEMBER(mRecognTags);
//RS_REGISTER_SERIAL_MEMBER(mImage);
RS_REGISTER_SERIAL_MEMBER(mLastUsageTS);
RS_REGISTER_SERIAL_MEMBER(mPgpKnown);
RS_REGISTER_SERIAL_MEMBER(mIsAContact);
RS_REGISTER_SERIAL_MEMBER(mPgpId);
RS_REGISTER_SERIAL_MEMBER_TYPED(mReputation, RsSerializable);
RS_PROCESS_SERIAL_MEMBER_TYPED(mMeta, RsSerializable);
RS_PROCESS_SERIAL_MEMBER(mPgpIdHash);
//RS_PROCESS_SERIAL_MEMBER(mPgpIdSign);
RS_PROCESS_SERIAL_MEMBER(mRecognTags);
//RS_PROCESS_SERIAL_MEMBER(mImage);
RS_PROCESS_SERIAL_MEMBER(mLastUsageTS);
RS_PROCESS_SERIAL_MEMBER(mPgpKnown);
RS_PROCESS_SERIAL_MEMBER(mIsAContact);
RS_PROCESS_SERIAL_MEMBER(mPgpId);
RS_PROCESS_SERIAL_MEMBER_TYPED(mReputation, RsSerializable);
}
RsIdentityUsage::RsIdentityUsage(