2017-08-05 13:09:50 +00:00
|
|
|
#include <nx/SacBinary.h>
|
2017-07-06 10:57:33 +00:00
|
|
|
|
2017-07-06 11:17:21 +00:00
|
|
|
using namespace nx;
|
2017-07-06 10:57:33 +00:00
|
|
|
|
|
|
|
SacBinary::SacBinary()
|
|
|
|
{
|
2018-06-24 08:18:54 +00:00
|
|
|
clear();
|
2017-07-06 10:57:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SacBinary::SacBinary(const SacBinary & other)
|
|
|
|
{
|
2018-06-24 08:18:54 +00:00
|
|
|
*this = other;
|
2017-07-06 10:57:33 +00:00
|
|
|
}
|
|
|
|
|
2018-06-24 08:18:54 +00:00
|
|
|
void SacBinary::operator=(const SacBinary & other)
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
2018-06-24 08:18:54 +00:00
|
|
|
if (other.getBytes().data())
|
|
|
|
{
|
|
|
|
fromBytes(other.getBytes().data(), other.getBytes().size());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
mServices = other.mServices;
|
|
|
|
}
|
2017-07-06 10:57:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SacBinary::operator==(const SacBinary & other) const
|
|
|
|
{
|
2018-06-24 08:18:54 +00:00
|
|
|
return mServices == other.mServices;
|
2017-07-06 10:57:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SacBinary::operator!=(const SacBinary & other) const
|
|
|
|
{
|
2018-06-24 08:18:54 +00:00
|
|
|
return !(*this == other);
|
2017-07-06 10:57:33 +00:00
|
|
|
}
|
|
|
|
|
2018-06-24 08:18:54 +00:00
|
|
|
void SacBinary::toBytes()
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
|
|
|
size_t totalSize = 0;
|
2018-06-24 08:18:54 +00:00
|
|
|
for (size_t i = 0; i < mServices.size(); i++)
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
2018-06-24 08:18:54 +00:00
|
|
|
mServices[i].toBytes();
|
|
|
|
totalSize += mServices[i].getBytes().size();
|
2017-07-06 10:57:33 +00:00
|
|
|
}
|
|
|
|
|
2018-06-24 08:18:54 +00:00
|
|
|
mRawBinary.alloc(totalSize);
|
|
|
|
for (size_t i = 0, pos = 0; i < mServices.size(); pos += mServices[i].getBytes().size(), i++)
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
2018-06-24 08:18:54 +00:00
|
|
|
memcpy((mRawBinary.data() + pos), mServices[i].getBytes().data(), mServices[i].getBytes().size());
|
2017-07-06 10:57:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-24 08:18:54 +00:00
|
|
|
void SacBinary::fromBytes(const byte_t* data, size_t len)
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
2017-07-17 08:21:39 +00:00
|
|
|
clear();
|
2018-06-24 08:18:54 +00:00
|
|
|
mRawBinary.alloc(len);
|
|
|
|
memcpy(mRawBinary.data(), data, mRawBinary.size());
|
2017-07-06 10:57:33 +00:00
|
|
|
|
2018-06-24 08:18:54 +00:00
|
|
|
SacEntry sac;
|
|
|
|
for (size_t pos = 0; pos < len; pos += mServices.atBack().getBytes().size())
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
2018-06-24 08:18:54 +00:00
|
|
|
sac.fromBytes((const byte_t*)(mRawBinary.data() + pos), len - pos);
|
|
|
|
mServices.addElement(sac);
|
2017-07-06 10:57:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-24 08:18:54 +00:00
|
|
|
const fnd::Vec<byte_t>& SacBinary::getBytes() const
|
|
|
|
{
|
|
|
|
return mRawBinary;
|
|
|
|
}
|
|
|
|
|
2017-07-15 08:28:01 +00:00
|
|
|
void nx::SacBinary::clear()
|
|
|
|
{
|
2018-06-24 08:18:54 +00:00
|
|
|
mRawBinary.clear();
|
2017-07-17 08:21:39 +00:00
|
|
|
mServices.clear();
|
2017-07-15 08:28:01 +00:00
|
|
|
}
|
|
|
|
|
2017-07-06 10:57:33 +00:00
|
|
|
const fnd::List<SacEntry>& SacBinary::getServiceList() const
|
|
|
|
{
|
|
|
|
return mServices;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SacBinary::addService(const SacEntry& service)
|
|
|
|
{
|
|
|
|
mServices.addElement(service);
|
2018-06-24 08:18:54 +00:00
|
|
|
}
|