From da1b6ac8457ead53b37395e9fb1629e865e3784e Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 27 Dec 2013 20:02:25 +0000 Subject: [PATCH] added serialisation methods for SSLId and time_t git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6969 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/serialiser/rsbaseserial.cc | 43 ++++++++++++++++++++ libretroshare/src/serialiser/rsbaseserial.h | 7 ++++ 2 files changed, 50 insertions(+) diff --git a/libretroshare/src/serialiser/rsbaseserial.cc b/libretroshare/src/serialiser/rsbaseserial.cc index f9ebde8f9..72be54e0b 100644 --- a/libretroshare/src/serialiser/rsbaseserial.cc +++ b/libretroshare/src/serialiser/rsbaseserial.cc @@ -256,7 +256,38 @@ bool setRawSha1(void *data,uint32_t size,uint32_t *offset,const Sha1CheckSum& cs return true ; } +bool getRawSSLId(void *data,uint32_t size,uint32_t *offset,SSLIdType& cs) +{ + uint32_t len = 16 ; // SSL id type + /* check there is space for string */ + if (size < *offset + len) + { + std::cerr << "getRawSha1() not enough size" << std::endl; + return false; + } + bool ok = true ; + + cs = SSLIdType(&((uint8_t*)data)[*offset]) ; + *offset += 16 ; + + return ok ; +} +bool setRawSSLId(void *data,uint32_t size,uint32_t *offset,const SSLIdType& cs) +{ + uint32_t len = 16 ; // SHA1 length in bytes + + if (size < *offset + len) + { + std::cerr << "setRawSha1() Not enough size" << std::endl; + return false; + } + + memcpy((void *) &(((uint8_t *) data)[*offset]), cs.toByteArray(), 16); + *offset += 16 ; + + return true ; +} bool getRawString(void *data, uint32_t size, uint32_t *offset, std::string &outStr) { uint32_t len = 0; @@ -309,3 +340,15 @@ bool setRawString(void *data, uint32_t size, uint32_t *offset, const std::string return true; } +bool getRawTimeT(void *data,uint32_t size,uint32_t *offset,time_t& t) +{ + uint64_t T ; + bool res = getRawUInt64(data,size,offset,&T) ; + t = T ; + + return res ; +} +bool setRawTimeT(void *data,uint32_t size,uint32_t *offset,const time_t& t) +{ + return setRawUInt64(data,size,offset,t) ; +} diff --git a/libretroshare/src/serialiser/rsbaseserial.h b/libretroshare/src/serialiser/rsbaseserial.h index 4fe9d834e..e5dab6feb 100644 --- a/libretroshare/src/serialiser/rsbaseserial.h +++ b/libretroshare/src/serialiser/rsbaseserial.h @@ -29,6 +29,7 @@ #include #include #include +#include /******************************************************************* * This is at the lowlevel packing routines. They are usually @@ -70,5 +71,11 @@ bool setRawString(void *data, uint32_t size, uint32_t *offset, const std::string bool getRawSha1(void *data, uint32_t size, uint32_t *offset, Sha1CheckSum& outStr); bool setRawSha1(void *data, uint32_t size, uint32_t *offset, const Sha1CheckSum& inStr); +bool setRawSSLId(void *data, uint32_t size, uint32_t *offset, const SSLIdType& inStr); +bool getRawSSLId(void *data, uint32_t size, uint32_t *offset, SSLIdType& outStr); + +bool setRawTimeT(void *data, uint32_t size, uint32_t *offset, const time_t& inStr); +bool getRawTimeT(void *data, uint32_t size, uint32_t *offset, time_t& outStr); + #endif