mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-12 16:09:37 -05:00
debugged rsnxsitem and serialiser
added test serialiser test suite updated support.cc to handle variable service types and RsTlvBinaryData init_item git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-new_cache_system@5148 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
50a0ed0656
commit
af71acd9ab
@ -51,7 +51,7 @@ RsItem* RsNxsSerialiser::deserialise(void *data, uint32_t *size) {
|
||||
|
||||
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsDistribSerialiser::deserialise()" << std::endl;
|
||||
std::cerr << "RsNxsSerialiser::deserialise()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
@ -62,7 +62,7 @@ RsItem* RsNxsSerialiser::deserialise(void *data, uint32_t *size) {
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
switch(rstype)
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
|
||||
case RS_PKT_SUBTYPE_SYNC_GRP:
|
||||
@ -74,7 +74,7 @@ RsItem* RsNxsSerialiser::deserialise(void *data, uint32_t *size) {
|
||||
case RS_PKT_SUBTYPE_SYNC_MSG_LIST:
|
||||
return deserialSyncGrpMsgList(data, size);
|
||||
case RS_PKT_SUBTYPE_GRPS_RESP:
|
||||
return deserialGrpMsgResp(data, size);
|
||||
return deserialGrpResp(data, size);
|
||||
case RS_PKT_SUBTYPE_MSG_RESP:
|
||||
return deserialGrpMsgResp(data, size);
|
||||
case RS_PKT_SUBTYPE_SEARCH_REQ:
|
||||
@ -169,11 +169,6 @@ bool RsNxsSerialiser::serialiseSynGrpMsgList(RsSyncGrpMsgList *item, void *data,
|
||||
std::map<std::string, std::list<uint32_t> >::iterator mit =
|
||||
item->msgs.begin();
|
||||
|
||||
// number of msgs
|
||||
uint32_t nMsgs = item->msgs.size();
|
||||
|
||||
ok &= setRawUInt32(data, *size, &offset, nMsgs);
|
||||
|
||||
for(; mit != item->msgs.end(); mit++){
|
||||
|
||||
// if not version contains then this
|
||||
@ -187,7 +182,7 @@ bool RsNxsSerialiser::serialiseSynGrpMsgList(RsSyncGrpMsgList *item, void *data,
|
||||
std::list<uint32_t>::iterator lit = mit->second.begin();
|
||||
for(; lit != mit->second.end(); lit++)
|
||||
{
|
||||
ok &= setRawUInt32(data, *size, &offset, *lit);
|
||||
ok &= SetTlvUInt32(data, *size, &offset, TLV_TYPE_UINT32_AGE, *lit);
|
||||
}
|
||||
}
|
||||
|
||||
@ -237,15 +232,11 @@ bool RsNxsSerialiser::serialiseGrpMsgResp(RsGrpMsgResp *item, void *data, uint32
|
||||
|
||||
/* RsSyncGrpMsgList */
|
||||
|
||||
// number of msgs
|
||||
uint32_t nMsgs = item->msgs.size();
|
||||
ok &= setRawUInt32(data, *size, &offset,nMsgs);
|
||||
|
||||
std::list<RsTlvBinaryData>::iterator lit = item->msgs.begin();
|
||||
std::list<RsTlvBinaryData*>::iterator lit = item->msgs.begin();
|
||||
|
||||
for(; lit != item->msgs.end(); lit++){
|
||||
RsTlvBinaryData& b = *lit;
|
||||
b.SetTlv(data, *size, &offset);
|
||||
RsTlvBinaryData*& b = *lit;
|
||||
b->SetTlv(data, *size, &offset);
|
||||
}
|
||||
|
||||
if(offset != tlvsize){
|
||||
@ -269,7 +260,7 @@ bool RsNxsSerialiser::serialiseGrpMsgResp(RsGrpMsgResp *item, void *data, uint32
|
||||
bool RsNxsSerialiser::serialiseGrpResp(RsGrpResp *item, void *data, uint32_t *size){
|
||||
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsNxsSerialiser::serialiseGrpReq()" << std::endl;
|
||||
std::cerr << "RsNxsSerialiser::serialiseGrpResp()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGrpResp(item);
|
||||
@ -277,7 +268,7 @@ bool RsNxsSerialiser::serialiseGrpResp(RsGrpResp *item, void *data, uint32_t *si
|
||||
|
||||
if(*size < tlvsize){
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsNxsSerialiser::serialiseGrpReq()" << std::endl;
|
||||
std::cerr << "RsNxsSerialiser::serialiseGrpResp()" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
@ -291,15 +282,11 @@ bool RsNxsSerialiser::serialiseGrpResp(RsGrpResp *item, void *data, uint32_t *si
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
// number of grps
|
||||
uint32_t nGrps = item->grps.size();
|
||||
ok &= setRawUInt32(data, *size, &offset, nGrps);
|
||||
|
||||
std::list<RsTlvBinaryData>::iterator lit = item->grps.begin();
|
||||
std::list<RsTlvBinaryData*>::iterator lit = item->grps.begin();
|
||||
|
||||
for(; lit != item->grps.end(); lit++){
|
||||
RsTlvBinaryData& b = *lit;
|
||||
b.SetTlv(data, *size, &offset);
|
||||
RsTlvBinaryData*& b = *lit;
|
||||
b->SetTlv(data, *size, &offset);
|
||||
}
|
||||
|
||||
if(offset != tlvsize){
|
||||
@ -378,7 +365,7 @@ bool RsNxsSerialiser::serialiseSyncGrpList(RsSyncGrpList *item, void *data, uint
|
||||
|
||||
if(*size < tlvsize){
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsNxsSerialiser::serialiseSyncGrpList()" << std::endl;
|
||||
std::cerr << "RsNxsSerialiser::serialiseSyncGrpList() size do not match" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
@ -397,17 +384,14 @@ bool RsNxsSerialiser::serialiseSyncGrpList(RsSyncGrpList *item, void *data, uint
|
||||
std::map<std::string, std::list<uint32_t> >::iterator mit =
|
||||
item->grps.begin();
|
||||
|
||||
// number of grps
|
||||
uint32_t nGrps = item->grps.size();
|
||||
|
||||
ok &= setRawUInt8(data, *size, &offset, item->flag);
|
||||
ok &= setRawUInt32(data, *size, &offset, nGrps);
|
||||
|
||||
for(; mit != item->grps.end(); mit++){
|
||||
|
||||
// if not version contains then this
|
||||
// entry is invalid
|
||||
ok &= SetTlvString(data, *size, &offset, TLV_TYPE_STR_MSGID, mit->first);
|
||||
ok &= SetTlvString(data, *size, &offset, TLV_TYPE_STR_GROUPID, mit->first);
|
||||
|
||||
uint32_t nVersions = mit->second.size();
|
||||
|
||||
@ -416,7 +400,7 @@ bool RsNxsSerialiser::serialiseSyncGrpList(RsSyncGrpList *item, void *data, uint
|
||||
std::list<uint32_t>::iterator lit = mit->second.begin();
|
||||
for(; lit != mit->second.end(); lit++)
|
||||
{
|
||||
ok &= setRawUInt32(data, *size, &offset, *lit);
|
||||
ok &= SetTlvUInt32(data, *size, &offset, TLV_TYPE_UINT32_AGE, *lit);
|
||||
}
|
||||
}
|
||||
|
||||
@ -508,7 +492,6 @@ RsGrpResp* RsNxsSerialiser::deserialGrpResp(void *data, uint32_t *size){
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(SERVICE_TYPE != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GRPS_RESP != getRsItemSubType(rstype)))
|
||||
@ -532,14 +515,25 @@ RsGrpResp* RsNxsSerialiser::deserialGrpResp(void *data, uint32_t *size){
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGrpResp* item = new RsGrpResp(getRsItemService(rstype));
|
||||
item->grps;
|
||||
RsGrpResp* item = new RsGrpResp(SERVICE_TYPE);
|
||||
|
||||
while(offset < *size){
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
RsTlvBinaryData b(SERVICE_TYPE);
|
||||
ok &= b.GetTlv(data, *size, &offset);
|
||||
item->grps.push_back(b);
|
||||
while(offset < *size && ok){
|
||||
|
||||
RsTlvBinaryData *b = new RsTlvBinaryData(SERVICE_TYPE);
|
||||
ok &= b->GetTlv(data, *size, &offset);
|
||||
|
||||
if(ok)
|
||||
item->grps.push_back(b);
|
||||
else{
|
||||
delete b;
|
||||
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsNxsSerialiser::deserialGrpResp(): Failure to deserialise binary group!" << std::endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -602,12 +596,23 @@ RsGrpMsgResp* RsNxsSerialiser::deserialGrpMsgResp(void *data, uint32_t *size){
|
||||
bool ok = true;
|
||||
|
||||
RsGrpMsgResp* item = new RsGrpMsgResp(getRsItemService(rstype));
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
while(offset < *size){
|
||||
|
||||
RsTlvBinaryData b(SERVICE_TYPE);
|
||||
ok &= b.GetTlv(data, *size, &offset);
|
||||
item->msgs.push_back(b);
|
||||
RsTlvBinaryData *b = new RsTlvBinaryData(SERVICE_TYPE);
|
||||
ok &= b->GetTlv(data, *size, &offset);
|
||||
|
||||
if(ok)
|
||||
item->msgs.push_back(b);
|
||||
else
|
||||
{
|
||||
delete b;
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsNxsSerialiser::deserialGrpMsgResp(): Failure to deserialise binary message!" << std::endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (offset != rssize)
|
||||
@ -669,6 +674,8 @@ RsSyncGrp* RsNxsSerialiser::deserialSyncGrp(void *data, uint32_t *size){
|
||||
bool ok = true;
|
||||
|
||||
RsSyncGrp* item = new RsSyncGrp(getRsItemService(rstype));
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= getRawUInt8(data, *size, &offset, &(item->flag));
|
||||
ok &= getRawUInt32(data, *size, &offset, &(item->syncAge));
|
||||
@ -732,39 +739,30 @@ RsSyncGrpList* RsNxsSerialiser::deserialSyncGrpList(void *data, uint32_t *size){
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsSyncGrpList* item = new RsSyncGrpList(getRsItemService(rstype));
|
||||
RsSyncGrpList* item = new RsSyncGrpList(SERVICE_TYPE);
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= getRawUInt8(data, *size, &offset, &(item->flag));
|
||||
// now get number of grps
|
||||
|
||||
uint32_t nGroups = 0;
|
||||
ok &= GetTlvUInt32(data, *size, &offset, TLV_TYPE_UINT32_SIZE, &nGroups);
|
||||
|
||||
for(uint32_t i =0; i < nGroups; i++){
|
||||
uint32_t nVersions;
|
||||
ok &= getRawUInt32(data, *size, &offset, &nVersions);
|
||||
|
||||
if(!ok) break;
|
||||
|
||||
while((offset < rssize) && ok)
|
||||
{
|
||||
std::string grpId;
|
||||
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_GROUPID, grpId);
|
||||
|
||||
if(!ok) break;
|
||||
uint32_t nVersions;
|
||||
ok &= getRawUInt32(data, *size, &offset, &nVersions);
|
||||
|
||||
std::list<uint32_t> verL;
|
||||
|
||||
for(uint32_t j =0; j < nVersions; j++){
|
||||
|
||||
uint32_t verCount = 0;
|
||||
while((offset < rssize) && ok && (verCount < nVersions))
|
||||
{
|
||||
uint32_t version;
|
||||
ok &= getRawUInt32(data, *size, &offset, &version);
|
||||
|
||||
if(!ok) break;
|
||||
|
||||
ok &= GetTlvUInt32(data, *size, &offset, TLV_TYPE_UINT32_AGE, &version);
|
||||
verL.push_back(version);
|
||||
|
||||
verCount++;
|
||||
}
|
||||
|
||||
if(!ok) break;
|
||||
item->grps[grpId] = verL;
|
||||
}
|
||||
|
||||
@ -827,40 +825,32 @@ RsSyncGrpMsgList* RsNxsSerialiser::deserialSyncGrpMsgList(void *data, uint32_t *
|
||||
bool ok = true;
|
||||
|
||||
RsSyncGrpMsgList* item = new RsSyncGrpMsgList(getRsItemService(rstype));
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= getRawUInt8(data, *size, &offset, &(item->flag));
|
||||
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_GROUPID, item->grpId);
|
||||
|
||||
// now get number of msgs
|
||||
while((offset < rssize) && ok)
|
||||
{
|
||||
|
||||
uint32_t nMsgs = 0;
|
||||
ok &= getRawUInt32(data, *size, &offset, &nMsgs);
|
||||
std::string msgId;
|
||||
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_MSGID, msgId);
|
||||
|
||||
for(uint32_t i =0; i < nMsgs; i++){
|
||||
uint32_t nVersions;
|
||||
ok &= getRawUInt32(data, *size, &offset, &nVersions);
|
||||
|
||||
if(!ok) break;
|
||||
|
||||
std::string msgId;
|
||||
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_MSGID,msgId);
|
||||
|
||||
if(!ok) break;
|
||||
|
||||
std::list<uint32_t> verL;
|
||||
|
||||
for(uint32_t j =0; j < nVersions; j++){
|
||||
|
||||
uint32_t verCount = 0;
|
||||
while((offset < rssize) && ok && (verCount < nVersions))
|
||||
{
|
||||
uint32_t version;
|
||||
ok &= getRawUInt32(data, *size, &offset, &version);
|
||||
|
||||
if(!ok) break;
|
||||
|
||||
ok &= GetTlvUInt32(data, *size, &offset, TLV_TYPE_UINT32_AGE, &version);
|
||||
verL.push_back(version);
|
||||
|
||||
verCount++;
|
||||
}
|
||||
|
||||
if(!ok) break;
|
||||
item->msgs[msgId] = verL;
|
||||
}
|
||||
|
||||
@ -926,6 +916,9 @@ RsSyncGrpMsg* RsNxsSerialiser::deserialSyncGrpMsg(void *data, uint32_t *size)
|
||||
|
||||
RsSyncGrpMsg* item = new RsSyncGrpMsg(getRsItemService(rstype));
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= getRawUInt8(data, *size, &offset, &(item->flag));
|
||||
ok &= getRawUInt32(data, *size, &offset, &(item->syncAge));
|
||||
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_HASH_SHA1, item->syncHash);
|
||||
@ -975,11 +968,11 @@ uint32_t RsNxsSerialiser::sizeGrpMsgResp(RsGrpMsgResp *item)
|
||||
|
||||
uint32_t s = 8; //header size
|
||||
|
||||
std::list<RsTlvBinaryData>::iterator it =
|
||||
std::list<RsTlvBinaryData*>::iterator it =
|
||||
item->msgs.begin();
|
||||
|
||||
for(; it != item->msgs.end(); it++)
|
||||
s += (*it).TlvSize();
|
||||
s += (*it)->TlvSize();
|
||||
|
||||
return s;
|
||||
}
|
||||
@ -989,11 +982,11 @@ uint32_t RsNxsSerialiser::sizeGrpResp(RsGrpResp *item)
|
||||
|
||||
uint32_t s = 8; // header size
|
||||
|
||||
std::list<RsTlvBinaryData>::iterator it =
|
||||
std::list<RsTlvBinaryData*>::iterator it =
|
||||
item->grps.begin();
|
||||
|
||||
for(; it != item->grps.end(); it++)
|
||||
s += (*it).TlvSize();
|
||||
s += (*it)->TlvSize();
|
||||
|
||||
|
||||
return s;
|
||||
@ -1017,7 +1010,6 @@ uint32_t RsNxsSerialiser::sizeSyncGrpList(RsSyncGrpList *item)
|
||||
uint32_t s = 8; // header size
|
||||
|
||||
s += 1; // flag
|
||||
s += 4; // number of grps
|
||||
|
||||
std::map<std::string, std::list<uint32_t> >::iterator mit
|
||||
= item->grps.begin();
|
||||
@ -1032,9 +1024,10 @@ uint32_t RsNxsSerialiser::sizeSyncGrpList(RsSyncGrpList *item)
|
||||
verL.begin();
|
||||
|
||||
for(; lit != verL.end(); lit++){
|
||||
s += 4; // version
|
||||
s += GetTlvUInt32Size(); // version
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
@ -1057,7 +1050,6 @@ uint32_t RsNxsSerialiser::sizeSyncGrpMsgList(RsSyncGrpMsgList *item)
|
||||
uint32_t s = 8; // header size
|
||||
|
||||
s += 1; // flag
|
||||
s += 4; // number of msgs
|
||||
s += GetTlvStringSize(item->grpId);
|
||||
std::map<std::string, std::list<uint32_t> >::iterator mit
|
||||
= item->msgs.begin();
|
||||
@ -1072,9 +1064,10 @@ uint32_t RsNxsSerialiser::sizeSyncGrpMsgList(RsSyncGrpMsgList *item)
|
||||
verL.begin();
|
||||
|
||||
for(; lit != verL.end(); lit++){
|
||||
s += 4; // version
|
||||
s += GetTlvUInt32Size(); // version
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
@ -1087,3 +1080,186 @@ uint32_t RsNxsSerialiser::sizeNxsSearchResp(RsNxsSearchResp *item)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/** print and clear functions **/
|
||||
|
||||
void RsGrpMsgResp::clear()
|
||||
{
|
||||
|
||||
std::list<RsTlvBinaryData*>::iterator it =
|
||||
msgs.begin();
|
||||
|
||||
for(; it != msgs.end(); it++)
|
||||
(*it)->TlvClear();
|
||||
|
||||
msgs.clear();
|
||||
}
|
||||
|
||||
void RsGrpResp::clear()
|
||||
{
|
||||
std::list<RsTlvBinaryData*>::iterator it =
|
||||
grps.begin();
|
||||
|
||||
for(; it != grps.end(); it++)
|
||||
(*it)->TlvClear();
|
||||
|
||||
grps.clear();
|
||||
}
|
||||
|
||||
void RsSyncGrp::clear()
|
||||
{
|
||||
flag = 0;
|
||||
syncAge = 0;
|
||||
syncHash.clear();
|
||||
}
|
||||
|
||||
void RsSyncGrpMsg::clear()
|
||||
{
|
||||
grpId.clear();
|
||||
flag = 0;
|
||||
syncAge = 0;
|
||||
syncHash.clear();
|
||||
}
|
||||
|
||||
void RsSyncGrpList::clear()
|
||||
{
|
||||
flag = 0;
|
||||
grps.clear();
|
||||
}
|
||||
|
||||
void RsSyncGrpMsgList::clear()
|
||||
{
|
||||
flag = 0;
|
||||
msgs.clear();
|
||||
}
|
||||
|
||||
std::ostream& RsSyncGrp::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
|
||||
printRsItemBase(out, "RsSyncGrp", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out , int_Indent);
|
||||
out << "Hash: " << syncHash << std::endl;
|
||||
printIndent(out , int_Indent);
|
||||
out << "Sync Age: " << syncAge << std::endl;
|
||||
printIndent(out , int_Indent);
|
||||
out << "flag" << flag << std::endl;
|
||||
|
||||
|
||||
printRsItemEnd(out ,"RsSyncGrp", indent);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream& RsSyncGrpMsg::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsSyncGrpMsg", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out , int_Indent);
|
||||
out << "GrpId: " << grpId << std::endl;
|
||||
printIndent(out , int_Indent);
|
||||
out << "syncAge: " << syncAge << std::endl;
|
||||
printIndent(out , int_Indent);
|
||||
out << "syncHash: " << syncHash << std::endl;
|
||||
printIndent(out , int_Indent);
|
||||
out << "flag: " << flag << std::endl;
|
||||
|
||||
printRsItemEnd(out, "RsSyncGrpMsg", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream& RsSyncGrpList::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsSyncGrpList", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out , int_Indent);
|
||||
out << "flag: " << flag << std::endl;
|
||||
printIndent(out , int_Indent);
|
||||
|
||||
std::map<std::string, std::list<uint32_t> >::iterator mit
|
||||
= grps.begin();
|
||||
|
||||
for(; mit != grps.end(); mit++){
|
||||
|
||||
out << "grpId: " << mit->first;
|
||||
printIndent(out , int_Indent);
|
||||
|
||||
const std::list<uint32_t>& verL = mit->second;
|
||||
std::list<uint32_t>::const_iterator lit =
|
||||
verL.begin();
|
||||
|
||||
for(; lit != verL.end(); lit++){
|
||||
out << "version: " << *lit << std::endl;
|
||||
printIndent(out , int_Indent);
|
||||
}
|
||||
}
|
||||
|
||||
printRsItemEnd(out , "RsSyncGrpList", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream& RsSyncGrpMsgList::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsSyncGrpMsgList", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out , int_Indent);
|
||||
out << "flag: " << flag << std::endl;
|
||||
printIndent(out , int_Indent);
|
||||
out << "grpId: " << grpId << std::endl;
|
||||
|
||||
std::map<std::string, std::list<uint32_t> >::iterator mit
|
||||
= msgs.begin();
|
||||
|
||||
for(; mit != msgs.end(); mit++){
|
||||
|
||||
out << "msgId: " << mit->first;
|
||||
printIndent(out , int_Indent);
|
||||
|
||||
const std::list<uint32_t>& verL = mit->second;
|
||||
std::list<uint32_t>::const_iterator lit =
|
||||
verL.begin();
|
||||
|
||||
for(; lit != verL.end(); lit++){
|
||||
out << "version: " << *lit << std::endl;
|
||||
printIndent(out , int_Indent);
|
||||
}
|
||||
}
|
||||
|
||||
printRsItemEnd(out ,"RsSyncGrpMsgList", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream& RsGrpMsgResp::print(std::ostream &out, uint16_t indent){
|
||||
|
||||
printRsItemBase(out, "RsGrpMsgResp", indent);
|
||||
|
||||
std::list<RsTlvBinaryData*>::iterator it =
|
||||
msgs.begin();
|
||||
|
||||
for(; it != msgs.end(); it++)
|
||||
(*it)->print(out, indent);
|
||||
|
||||
|
||||
printRsItemEnd(out, "RsGrpMsgResp", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream& RsGrpResp::print(std::ostream &out, uint16_t indent){
|
||||
|
||||
printRsItemBase(out, "RsGrpResp", indent);
|
||||
|
||||
std::list<RsTlvBinaryData*>::iterator it =
|
||||
grps.begin();
|
||||
|
||||
for(; it != grps.end(); it++)
|
||||
(*it)->print(out, indent);
|
||||
|
||||
|
||||
printRsItemEnd(out ,"RsGrpMsgResp", indent);
|
||||
return out;
|
||||
}
|
@ -53,15 +53,15 @@ const uint8_t RS_PKT_SUBTYPE_SEARCH_RESP = 0x0080;
|
||||
*
|
||||
* Service type is set by plugin service
|
||||
*/
|
||||
class RsNxs : public RsItem
|
||||
class RsNxsItem : public RsItem
|
||||
{
|
||||
|
||||
public:
|
||||
RsNxs(uint16_t servtype, uint8_t subtype)
|
||||
RsNxsItem(uint16_t servtype, uint8_t subtype)
|
||||
: RsItem(RS_PKT_VERSION_SERVICE, servtype, subtype) { return; }
|
||||
|
||||
virtual void clear() { }
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0) { return out; }
|
||||
virtual void clear() = 0;
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0) = 0;
|
||||
};
|
||||
|
||||
|
||||
@ -70,13 +70,16 @@ public:
|
||||
* Server may advise client peer to use sync file
|
||||
* while serving his request. This results
|
||||
*/
|
||||
class RsSyncGrp : public RsNxs {
|
||||
class RsSyncGrp : public RsNxsItem {
|
||||
|
||||
public:
|
||||
|
||||
static const uint8_t FLAG_USE_SYNC_HASH;
|
||||
|
||||
RsSyncGrp(uint16_t servtype) : RsNxs(servtype, RS_PKT_SUBTYPE_SYNC_GRP) { return;}
|
||||
RsSyncGrp(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_SYNC_GRP) { return;}
|
||||
|
||||
virtual void clear();
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
|
||||
uint8_t flag; // advises whether to use sync hash
|
||||
uint32_t syncAge; // how far back to sync data
|
||||
@ -85,23 +88,30 @@ public:
|
||||
|
||||
};
|
||||
|
||||
typedef std::map<std::string, std::list<uint32_t> > SyncList;
|
||||
|
||||
/*!
|
||||
* Use to send to peer list of grps
|
||||
* held by server peer
|
||||
*/
|
||||
class RsSyncGrpList : public RsNxs
|
||||
class RsSyncGrpList : public RsNxsItem
|
||||
{
|
||||
|
||||
public:
|
||||
RsSyncGrpList(uint16_t servtype) : RsNxs(servtype, RS_PKT_SUBTYPE_SYNC_GRP_LIST) { return ; }
|
||||
|
||||
static const uint8_t FLAG_REQUEST;
|
||||
static const uint8_t FLAG_RESPONSE;
|
||||
|
||||
RsSyncGrpList(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_SYNC_GRP_LIST) { return ; }
|
||||
|
||||
virtual void clear();
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
|
||||
|
||||
uint8_t flag; // request or response
|
||||
|
||||
/// groups held by sending peer
|
||||
std::map<std::string, std::list<uint32_t> > grps; // grpId/ n version pair
|
||||
SyncList grps; // grpId/ n version pair
|
||||
|
||||
};
|
||||
|
||||
@ -110,13 +120,17 @@ public:
|
||||
* Each item corresponds to a group which needs to be
|
||||
* deserialised
|
||||
*/
|
||||
class RsGrpResp : public RsNxs
|
||||
class RsGrpResp : public RsNxsItem
|
||||
{
|
||||
|
||||
public:
|
||||
RsGrpResp(uint16_t servtype) : RsNxs(servtype, RS_PKT_SUBTYPE_GRPS_RESP) { return; }
|
||||
RsGrpResp(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_GRPS_RESP) { return; }
|
||||
|
||||
std::list<RsTlvBinaryData> grps; /// each entry corresponds to a group item
|
||||
|
||||
virtual void clear();
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
|
||||
std::list<RsTlvBinaryData*> grps; /// each entry corresponds to a group item
|
||||
|
||||
};
|
||||
|
||||
@ -124,14 +138,18 @@ public:
|
||||
* Use to request list of msg held by peer
|
||||
* for a given group
|
||||
*/
|
||||
class RsSyncGrpMsg : public RsNxs
|
||||
class RsSyncGrpMsg : public RsNxsItem
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
static const uint8_t FLAG_USE_SYNC_HASH;
|
||||
|
||||
RsSyncGrpMsg(uint16_t servtype) : RsNxs(servtype, RS_PKT_SUBTYPE_SYNC_MSG) {return; }
|
||||
RsSyncGrpMsg(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_SYNC_MSG) {return; }
|
||||
|
||||
|
||||
virtual void clear();
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
|
||||
std::string grpId;
|
||||
uint8_t flag;
|
||||
@ -143,18 +161,22 @@ public:
|
||||
* Use to send list msgs for a group held by
|
||||
* a peer
|
||||
*/
|
||||
class RsSyncGrpMsgList : public RsNxs
|
||||
class RsSyncGrpMsgList : public RsNxsItem
|
||||
{
|
||||
public:
|
||||
|
||||
static const uint8_t FLAG_RESPONSE;
|
||||
static const uint8_t FLAG_REQUEST;
|
||||
|
||||
RsSyncGrpMsgList(uint16_t servtype) : RsNxs(servtype, RS_PKT_SUBTYPE_SYNC_MSG_LIST) { return; }
|
||||
RsSyncGrpMsgList(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_SYNC_MSG_LIST) { return; }
|
||||
|
||||
|
||||
virtual void clear();
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
|
||||
uint8_t flag; // response/req
|
||||
std::string grpId;
|
||||
std::map<std::string, std::list<uint32_t> > msgs; // msg/versions pairs
|
||||
SyncList msgs; // msg/versions pairs
|
||||
|
||||
};
|
||||
|
||||
@ -163,23 +185,31 @@ public:
|
||||
* Used to respond to a RsGrpMsgsReq
|
||||
* with message items satisfying request
|
||||
*/
|
||||
class RsGrpMsgResp : public RsNxs
|
||||
class RsGrpMsgResp : public RsNxsItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGrpMsgResp(uint16_t servtype) : RsNxs(servtype, RS_PKT_SUBTYPE_MSG_RESP) { return; }
|
||||
RsGrpMsgResp(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_MSG_RESP) { return; }
|
||||
|
||||
std::list<RsTlvBinaryData> msgs; // each entry corresponds to a message item
|
||||
|
||||
virtual void clear();
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
|
||||
std::list<RsTlvBinaryData*> msgs; // each entry corresponds to a message item
|
||||
};
|
||||
|
||||
/*!
|
||||
* Used to request a search of user data
|
||||
*/
|
||||
class RsNxsSearchReq : public RsNxs
|
||||
class RsNxsSearchReq : public RsNxsItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsNxsSearchReq(uint16_t servtype): RsNxs(servtype, RS_PKT_SUBTYPE_SEARCH_REQ), searchTerm(servtype) { return; }
|
||||
RsNxsSearchReq(uint16_t servtype): RsNxsItem(servtype, RS_PKT_SUBTYPE_SEARCH_REQ), searchTerm(servtype) { return; }
|
||||
|
||||
virtual void clear() {}
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent) { return out; }
|
||||
|
||||
uint16_t token;
|
||||
RsTlvBinaryData searchTerm; // service aware of item class
|
||||
};
|
||||
@ -189,11 +219,15 @@ public:
|
||||
* Used to respond to a RsGrpSearchReq
|
||||
* with grpId/MsgIds that satisfy search request
|
||||
*/
|
||||
class RsNxsSearchResp : public RsNxs
|
||||
class RsNxsSearchResp : public RsNxsItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsNxsSearchResp(uint16_t servtype) : RsNxs(servtype, RS_PKT_SUBTYPE_SEARCH_RESP) { return; }
|
||||
RsNxsSearchResp(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_SEARCH_RESP) { return; }
|
||||
|
||||
|
||||
virtual void clear() {}
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent) { return out; }
|
||||
|
||||
uint16_t token; // search token to be redeemed
|
||||
std::list<RsTlvBinaryData> msgs; // msgs with search terms present
|
||||
@ -203,6 +237,7 @@ public:
|
||||
|
||||
class RsNxsSerialiser : public RsSerialType
|
||||
{
|
||||
public:
|
||||
|
||||
RsNxsSerialiser(uint16_t servtype) :
|
||||
RsSerialType(RS_PKT_VERSION_SERVICE, servtype), SERVICE_TYPE(servtype) { return; }
|
||||
|
222
libretroshare/src/tests/serialiser/rsnxsitems_test.cc
Normal file
222
libretroshare/src/tests/serialiser/rsnxsitems_test.cc
Normal file
@ -0,0 +1,222 @@
|
||||
|
||||
#include "support.h"
|
||||
|
||||
#include "rsnxsitems_test.h"
|
||||
|
||||
INITTEST();
|
||||
|
||||
#define NUM_BIN_OBJECTS 5
|
||||
#define NUM_SYNC_MSGS 8
|
||||
#define NUM_SYNC_GRPS 5
|
||||
|
||||
RsSerialType* init_item(RsGrpResp& rgr)
|
||||
{
|
||||
|
||||
rgr.clear();
|
||||
|
||||
for(int i=0; i < 5; i++){
|
||||
RsTlvBinaryData* b = new RsTlvBinaryData(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
init_item(*b);
|
||||
rgr.grps.push_back(b);
|
||||
}
|
||||
|
||||
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
}
|
||||
|
||||
|
||||
RsSerialType* init_item(RsGrpMsgResp& rgmr)
|
||||
{
|
||||
rgmr.clear();
|
||||
|
||||
for(int i=0; i < 5; i++){
|
||||
RsTlvBinaryData* b = new RsTlvBinaryData(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
init_item(*b);
|
||||
rgmr.msgs.push_back(b);
|
||||
}
|
||||
|
||||
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsSyncGrp& rsg)
|
||||
{
|
||||
rsg.clear();
|
||||
|
||||
rsg.flag = RsSyncGrp::FLAG_USE_SYNC_HASH;
|
||||
rsg.syncAge = rand()%2423;
|
||||
randString(3124,rsg.syncHash);
|
||||
|
||||
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsSyncGrpMsg& rsgm)
|
||||
{
|
||||
rsgm.clear();
|
||||
|
||||
rsgm.flag = RsSyncGrpMsg::FLAG_USE_SYNC_HASH;
|
||||
rsgm.syncAge = rand()%24232;
|
||||
randString(SHORT_STR, rsgm.grpId);
|
||||
randString(SHORT_STR, rsgm.syncHash);
|
||||
|
||||
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsSyncGrpList& rsgl)
|
||||
{
|
||||
rsgl.clear();
|
||||
|
||||
rsgl.flag = RsSyncGrpList::FLAG_RESPONSE;
|
||||
|
||||
for(int i=0; i < NUM_SYNC_GRPS; i++){
|
||||
|
||||
int nVers = rand()%8;
|
||||
std::list<uint32_t> verL;
|
||||
for(int j=0; j < nVers; j++){
|
||||
verL.push_back(rand()%343);
|
||||
}
|
||||
std::string grpId;
|
||||
randString(SHORT_STR, grpId);
|
||||
|
||||
std::pair<std::string, std::list<uint32_t> > p(grpId, verL);
|
||||
rsgl.grps.insert(p);
|
||||
}
|
||||
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsSyncGrpMsgList& rsgml)
|
||||
{
|
||||
rsgml.clear();
|
||||
|
||||
rsgml.flag = RsSyncGrpList::FLAG_RESPONSE;
|
||||
randString(SHORT_STR, rsgml.grpId);
|
||||
|
||||
for(int i=0; i < NUM_SYNC_GRPS; i++){
|
||||
|
||||
int nVers = rand()%8;
|
||||
std::list<uint32_t> verL;
|
||||
for(int j=0; j < nVers; j++){
|
||||
verL.push_back(rand()%343);
|
||||
}
|
||||
std::string msgId;
|
||||
randString(SHORT_STR, msgId);
|
||||
|
||||
std::pair<std::string, std::list<uint32_t> > p(msgId, verL);
|
||||
rsgml.msgs.insert(p);
|
||||
}
|
||||
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
}
|
||||
|
||||
|
||||
bool operator==(const RsGrpResp& l, const RsGrpResp& r){
|
||||
|
||||
if(l.grps.size() != r.grps.size()) return false;
|
||||
|
||||
std::list<RsTlvBinaryData*>::const_iterator lit
|
||||
= l.grps.begin(), rit =
|
||||
r.grps.begin();
|
||||
|
||||
for(; lit != l.grps.end(); lit++, rit++){
|
||||
if(!(*(*lit) == *(*rit))) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator==(const RsGrpMsgResp& l, const RsGrpMsgResp& r){
|
||||
|
||||
if(l.msgs.size() != r.msgs.size()) return false;
|
||||
|
||||
std::list<RsTlvBinaryData*>::const_iterator lit
|
||||
= l.msgs.begin(), rit =
|
||||
r.msgs.begin();
|
||||
|
||||
for(; lit != l.msgs.end(); lit++, rit++){
|
||||
if(!(*(*lit) == *(*rit))) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator==(const RsSyncGrp& l, const RsSyncGrp& r)
|
||||
{
|
||||
|
||||
if(l.syncHash != r.syncHash) return false;
|
||||
if(l.flag != r.flag) return false;
|
||||
if(l.syncAge != r.syncAge) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator==(const RsSyncGrpMsg& l, const RsSyncGrpMsg& r)
|
||||
{
|
||||
|
||||
if(l.flag != r.flag) return false;
|
||||
if(l.syncAge != r.syncAge) return false;
|
||||
if(l.syncHash != r.syncHash) return false;
|
||||
if(l.grpId != r.grpId) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator==(const RsSyncGrpList& l, const RsSyncGrpList& r)
|
||||
{
|
||||
if(l.flag != r.flag) return false;
|
||||
|
||||
SyncList::const_iterator lit = l.grps.begin(), rit= r.grps.begin();
|
||||
|
||||
for(; lit != l.grps.end(); lit++, rit++){
|
||||
|
||||
if(lit->first != rit->first) return false;
|
||||
const std::list<uint32_t>& lList = lit->second, &rList
|
||||
= rit->second;
|
||||
|
||||
std::list<uint32_t>::const_iterator lit2 = lList.begin(), rit2
|
||||
= rList.begin();
|
||||
|
||||
for(; lit2 != lList.end(); lit2++, rit2++){
|
||||
|
||||
if(*lit2 != *rit2) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator==(const RsSyncGrpMsgList& l, const RsSyncGrpMsgList& r)
|
||||
{
|
||||
if(l.flag != r.flag) return false;
|
||||
if(l.grpId != r.grpId) return false;
|
||||
|
||||
SyncList::const_iterator lit = l.msgs.begin(), rit= r.msgs.begin();
|
||||
|
||||
for(; lit != l.msgs.end(); lit++, rit++){
|
||||
|
||||
if(lit->first != rit->first) return false;
|
||||
const std::list<uint32_t>& lList = lit->second, &rList
|
||||
= rit->second;
|
||||
|
||||
std::list<uint32_t>::const_iterator lit2 = lList.begin(), rit2
|
||||
= rList.begin();
|
||||
|
||||
for(; lit2 != lList.end(); lit2++, rit2++){
|
||||
|
||||
if(*lit2 != *rit2) return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cerr << "RsNxsItem Tests" << std::endl;
|
||||
|
||||
test_RsItem<RsGrpResp>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsGrpResp");
|
||||
test_RsItem<RsGrpMsgResp>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsGrpMsgResp");
|
||||
test_RsItem<RsSyncGrp>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsSyncGrp");
|
||||
test_RsItem<RsSyncGrpMsg>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsSyncGrpMsg");
|
||||
test_RsItem<RsSyncGrpList>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsSyncGrpList");
|
||||
test_RsItem<RsSyncGrpMsgList>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsSyncGrpMsgList");
|
||||
|
||||
FINALREPORT("RsNxsItem Tests");
|
||||
|
||||
return TESTRESULT();
|
||||
}
|
22
libretroshare/src/tests/serialiser/rsnxsitems_test.h
Normal file
22
libretroshare/src/tests/serialiser/rsnxsitems_test.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef RSNXSITEMS_TEST_H
|
||||
#define RSNXSITEMS_TEST_H
|
||||
|
||||
#include "serialiser/rsnxsitems.h"
|
||||
|
||||
|
||||
RsSerialType* init_item(RsGrpResp&);
|
||||
RsSerialType* init_item(RsGrpMsgResp&);
|
||||
RsSerialType* init_item(RsSyncGrp&);
|
||||
RsSerialType* init_item(RsSyncGrpMsg&);
|
||||
RsSerialType* init_item(RsSyncGrpList&);
|
||||
RsSerialType* init_item(RsSyncGrpMsgList&);
|
||||
|
||||
bool operator==(const RsGrpResp&, const RsGrpResp&);
|
||||
bool operator==(const RsGrpMsgResp&, const RsGrpMsgResp&);
|
||||
bool operator==(const RsSyncGrp&, const RsSyncGrp&);
|
||||
bool operator==(const RsSyncGrpMsg&, const RsSyncGrpMsg&);
|
||||
bool operator==(const RsSyncGrpList&, const RsSyncGrpList&);
|
||||
bool operator==(const RsSyncGrpMsgList&, const RsSyncGrpMsgList&);
|
||||
|
||||
|
||||
#endif // RSNXSITEMS_TEST_H
|
@ -223,6 +223,13 @@ void init_item(RsTlvFileItem& fi)
|
||||
return;
|
||||
}
|
||||
|
||||
void init_item(RsTlvBinaryData& bd){
|
||||
bd.TlvClear();
|
||||
std::string data;
|
||||
randString(LARGE_STR, data);
|
||||
bd.setBinData(data.data(), data.length());
|
||||
}
|
||||
|
||||
void init_item(RsTlvFileSet& fSet){
|
||||
|
||||
randString(LARGE_STR, fSet.comment);
|
||||
|
@ -157,5 +157,67 @@ template<class T> int test_RsItem()
|
||||
return 1;
|
||||
}
|
||||
|
||||
template<class T> int test_RsItem(uint16_t servtype)
|
||||
{
|
||||
/* make a serialisable RsTurtleItem */
|
||||
|
||||
RsSerialiser srl;
|
||||
|
||||
/* initialise */
|
||||
T rsfi(servtype) ;
|
||||
RsSerialType *rsfis = init_item(rsfi) ;
|
||||
|
||||
/* attempt to serialise it before we add it to the serialiser */
|
||||
|
||||
CHECK(0 == srl.size(&rsfi));
|
||||
|
||||
static const uint32_t MAX_BUFSIZE = 22000 ;
|
||||
|
||||
char *buffer = new char[MAX_BUFSIZE];
|
||||
uint32_t sersize = MAX_BUFSIZE;
|
||||
|
||||
CHECK(false == srl.serialise(&rsfi, (void *) buffer, &sersize));
|
||||
|
||||
/* now add to serialiser */
|
||||
|
||||
srl.addSerialType(rsfis);
|
||||
|
||||
uint32_t size = srl.size(&rsfi);
|
||||
bool done = srl.serialise(&rsfi, (void *) buffer, &sersize);
|
||||
|
||||
std::cerr << "test_Item() size: " << size << std::endl;
|
||||
std::cerr << "test_Item() done: " << done << std::endl;
|
||||
std::cerr << "test_Item() sersize: " << sersize << std::endl;
|
||||
|
||||
std::cerr << "test_Item() serialised:" << std::endl;
|
||||
//displayRawPacket(std::cerr, (void *) buffer, sersize);
|
||||
|
||||
CHECK(done == true);
|
||||
|
||||
uint32_t sersize2 = sersize;
|
||||
RsItem *output = srl.deserialise((void *) buffer, &sersize2);
|
||||
|
||||
CHECK(output != NULL);
|
||||
CHECK(sersize2 == sersize);
|
||||
|
||||
T *outfi = dynamic_cast<T *>(output);
|
||||
|
||||
CHECK(outfi != NULL);
|
||||
|
||||
if (outfi)
|
||||
CHECK(*outfi == rsfi) ;
|
||||
|
||||
sersize2 = MAX_BUFSIZE;
|
||||
bool done2 = srl.serialise(outfi, (void *) &(buffer[16*8]), &sersize2);
|
||||
|
||||
CHECK(done2) ;
|
||||
CHECK(sersize2 == sersize);
|
||||
|
||||
// displayRawPacket(std::cerr, (void *) buffer, 16 * 8 + sersize2);
|
||||
|
||||
delete[] buffer ;
|
||||
//delete rsfis;
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif /* SUPPORT_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user