2017-08-05 13:09:50 +00:00
|
|
|
#include <nx/SacBinary.h>
|
2017-07-06 10:57:33 +00:00
|
|
|
|
2018-06-24 15:01:16 +00:00
|
|
|
nx::SacBinary::SacBinary()
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
2018-06-24 08:18:54 +00:00
|
|
|
clear();
|
2017-07-06 10:57:33 +00:00
|
|
|
}
|
|
|
|
|
2018-06-24 15:01:16 +00:00
|
|
|
nx::SacBinary::SacBinary(const SacBinary & other)
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
2018-06-24 08:18:54 +00:00
|
|
|
*this = other;
|
2017-07-06 10:57:33 +00:00
|
|
|
}
|
|
|
|
|
2018-06-24 15:01:16 +00:00
|
|
|
void nx::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
|
|
|
}
|
|
|
|
|
2018-06-24 15:01:16 +00:00
|
|
|
bool nx::SacBinary::operator==(const SacBinary & other) const
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
2018-06-24 15:01:16 +00:00
|
|
|
return (mServices == other.mServices);
|
2017-07-06 10:57:33 +00:00
|
|
|
}
|
|
|
|
|
2018-06-24 15:01:16 +00:00
|
|
|
bool nx::SacBinary::operator!=(const SacBinary & other) const
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
2018-06-24 08:18:54 +00:00
|
|
|
return !(*this == other);
|
2017-07-06 10:57:33 +00:00
|
|
|
}
|
|
|
|
|
2018-06-24 15:01:16 +00:00
|
|
|
void nx::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 15:01:16 +00:00
|
|
|
void nx::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 15:01:16 +00:00
|
|
|
const fnd::Vec<byte_t>& nx::SacBinary::getBytes() const
|
2018-06-24 08:18:54 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-06-24 15:01:16 +00:00
|
|
|
const fnd::List<nx::SacEntry>& nx::SacBinary::getServiceList() const
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
|
|
|
return mServices;
|
|
|
|
}
|
|
|
|
|
2018-06-24 15:01:16 +00:00
|
|
|
void nx::SacBinary::addService(const SacEntry& service)
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
|
|
|
mServices.addElement(service);
|
2018-06-24 08:18:54 +00:00
|
|
|
}
|