2014-03-21 23:53:44 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* libretroshare/src/serialiser: rstlvgenericparam.cc
|
|
|
|
*
|
|
|
|
* RetroShare Serialiser.
|
|
|
|
*
|
|
|
|
* Copyright 2014 by Robert Fernie
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License Version 2.1 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-03-29 11:34:37 -04:00
|
|
|
#include "serialiser/rstlvgenericparam.h"
|
|
|
|
#include "serialiser/rstlvbase.h"
|
2014-03-21 23:53:44 -04:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#define TLV_DEBUG 1
|
|
|
|
|
|
|
|
/* generic print */
|
|
|
|
template<class T>
|
2014-03-29 11:34:37 -04:00
|
|
|
std::ostream & RsTlvParamRef<T>::print(std::ostream &out, uint16_t indent) const
|
2014-03-21 23:53:44 -04:00
|
|
|
{
|
|
|
|
printIndent(out, indent);
|
|
|
|
out << "Type: " << mParamType << " Param: " << mParam;
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***** uint16_t ****/
|
|
|
|
template<>
|
2014-03-29 11:34:37 -04:00
|
|
|
uint32_t RsTlvParamRef<uint16_t>::TlvSize() const
|
2014-03-21 23:53:44 -04:00
|
|
|
{
|
|
|
|
return GetTlvUInt16Size();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
void RsTlvParamRef<uint16_t>::TlvClear()
|
|
|
|
{
|
|
|
|
mParam = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
2014-03-29 11:34:37 -04:00
|
|
|
bool RsTlvParamRef<uint16_t>::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
2014-03-21 23:53:44 -04:00
|
|
|
{
|
|
|
|
uint16_t param = mParam;
|
|
|
|
return SetTlvUInt16(data, size, offset, mParamType, mParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
bool RsTlvParamRef<uint16_t>::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
|
|
|
{
|
|
|
|
uint16_t param;
|
|
|
|
bool retval = GetTlvUInt16(data, size, offset, mParamType, ¶m);
|
|
|
|
mParam = param;
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
2014-03-29 11:34:37 -04:00
|
|
|
std::ostream & RsTlvParamRef<uint16_t>::print(std::ostream &out, uint16_t indent) const
|
2014-03-21 23:53:44 -04:00
|
|
|
{
|
|
|
|
printIndent(out, indent);
|
|
|
|
out << "Type: " << mParamType << "Param: " << mParam;
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***** const uint16_t ****/
|
|
|
|
|
|
|
|
template<>
|
2014-03-29 11:34:37 -04:00
|
|
|
uint32_t RsTlvParamRef<const uint16_t>::TlvSize() const
|
2014-03-21 23:53:44 -04:00
|
|
|
{
|
|
|
|
return GetTlvUInt16Size();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
void RsTlvParamRef<const uint16_t>::TlvClear()
|
|
|
|
{
|
|
|
|
//mParam = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<>
|
2014-03-29 11:34:37 -04:00
|
|
|
bool RsTlvParamRef<const uint16_t>::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
2014-03-21 23:53:44 -04:00
|
|
|
{
|
|
|
|
return SetTlvUInt16(data, size, offset, mParamType, mParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
bool RsTlvParamRef<const uint16_t>::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
|
|
|
{
|
|
|
|
return false; //GetTlvUInt16(data, size, offset, mParamType, &mParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<>
|
2014-03-29 11:34:37 -04:00
|
|
|
std::ostream & RsTlvParamRef<const uint16_t>::print(std::ostream &out, uint16_t indent) const
|
2014-03-21 23:53:44 -04:00
|
|
|
{
|
|
|
|
printIndent(out, indent);
|
|
|
|
out << "Type: " << mParamType << "Param: " << mParam;
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***** uint32_t ****/
|
|
|
|
template<>
|
2014-03-29 11:34:37 -04:00
|
|
|
uint32_t RsTlvParamRef<uint32_t>::TlvSize() const
|
2014-03-21 23:53:44 -04:00
|
|
|
{
|
|
|
|
return GetTlvUInt32Size();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
void RsTlvParamRef<uint32_t>::TlvClear()
|
|
|
|
{
|
|
|
|
mParam = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
2014-03-29 11:34:37 -04:00
|
|
|
bool RsTlvParamRef<uint32_t>::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
2014-03-21 23:53:44 -04:00
|
|
|
{
|
|
|
|
return SetTlvUInt32(data, size, offset, mParamType, mParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
bool RsTlvParamRef<uint32_t>::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
|
|
|
{
|
|
|
|
return GetTlvUInt32(data, size, offset, mParamType, &mParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
2014-03-29 11:34:37 -04:00
|
|
|
std::ostream & RsTlvParamRef<uint32_t>::print(std::ostream &out, uint16_t indent) const
|
2014-03-21 23:53:44 -04:00
|
|
|
{
|
|
|
|
printIndent(out, indent);
|
|
|
|
out << "Type: " << mParamType << "Param: " << mParam;
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***** const uint32_t ****/
|
|
|
|
template<>
|
2014-03-29 11:34:37 -04:00
|
|
|
uint32_t RsTlvParamRef<const uint32_t>::TlvSize() const
|
2014-03-21 23:53:44 -04:00
|
|
|
{
|
|
|
|
return GetTlvUInt32Size();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
void RsTlvParamRef<const uint32_t>::TlvClear()
|
|
|
|
{
|
|
|
|
//mParam = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
2014-03-29 11:34:37 -04:00
|
|
|
bool RsTlvParamRef<const uint32_t>::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
2014-03-21 23:53:44 -04:00
|
|
|
{
|
|
|
|
return SetTlvUInt32(data, size, offset, mParamType, mParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
bool RsTlvParamRef<const uint32_t>::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
//GetTlvUInt32(data, size, offset, mParamType, &mParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
2014-03-29 11:34:37 -04:00
|
|
|
std::ostream & RsTlvParamRef<const uint32_t>::print(std::ostream &out, uint16_t indent) const
|
2014-03-21 23:53:44 -04:00
|
|
|
{
|
|
|
|
printIndent(out, indent);
|
|
|
|
out << "Type: " << mParamType << "Param: " << mParam;
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***** std::string ****/
|
|
|
|
template<>
|
2014-03-29 11:34:37 -04:00
|
|
|
uint32_t RsTlvParamRef<std::string>::TlvSize() const
|
2014-03-21 23:53:44 -04:00
|
|
|
{
|
|
|
|
return GetTlvStringSize(mParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
void RsTlvParamRef<std::string>::TlvClear()
|
|
|
|
{
|
|
|
|
mParam.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
2014-03-29 11:34:37 -04:00
|
|
|
bool RsTlvParamRef<std::string>::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
2014-03-21 23:53:44 -04:00
|
|
|
{
|
|
|
|
return SetTlvString(data, size, offset, mParamType, mParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
bool RsTlvParamRef<std::string>::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
|
|
|
{
|
|
|
|
return GetTlvString(data, size, offset, mParamType, mParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
2014-03-29 11:34:37 -04:00
|
|
|
std::ostream & RsTlvParamRef<std::string>::print(std::ostream &out, uint16_t indent) const
|
2014-03-21 23:53:44 -04:00
|
|
|
{
|
|
|
|
printIndent(out, indent);
|
|
|
|
out << "Type: " << mParamType << "Param: " << mParam;
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
// declare likely combinations.
|
|
|
|
//template class RsTlvParamRef<uint16_t>;
|
|
|
|
//template class RsTlvParamRef<uint32_t>;
|
|
|
|
//template class RsTlvParamRef<std::string>;
|
|
|
|
|
|
|
|
//template class RsTlvParamRef<const uint16_t>;
|
|
|
|
//template class RsTlvParamRef<const uint32_t>;
|
|
|
|
//template class RsTlvParamRef<const std::string>;
|
|
|
|
|