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()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SacBinary::SacBinary(const SacBinary & other)
|
|
|
|
{
|
|
|
|
copyFrom(other);
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
SacBinary::SacBinary(const byte_t * bytes, size_t len)
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
|
|
|
importBinary(bytes, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SacBinary::operator==(const SacBinary & other) const
|
|
|
|
{
|
|
|
|
return isEqual(other);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SacBinary::operator!=(const SacBinary & other) const
|
|
|
|
{
|
|
|
|
return !isEqual(other);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SacBinary::operator=(const SacBinary & other)
|
|
|
|
{
|
|
|
|
copyFrom(other);
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
const byte_t * SacBinary::getBytes() const
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
|
|
|
return mBinaryBlob.getBytes();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t SacBinary::getSize() const
|
|
|
|
{
|
|
|
|
return mBinaryBlob.getSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SacBinary::exportBinary()
|
|
|
|
{
|
|
|
|
size_t totalSize = 0;
|
|
|
|
for (size_t i = 0; i < mServices.getSize(); i++)
|
|
|
|
{
|
|
|
|
mServices[i].exportBinary();
|
|
|
|
totalSize += mServices[i].getSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
mBinaryBlob.alloc(totalSize);
|
|
|
|
for (size_t i = 0, pos = 0; i < mServices.getSize(); pos += mServices[i].getSize(), i++)
|
|
|
|
{
|
|
|
|
memcpy((mBinaryBlob.getBytes() + pos), mServices[i].getBytes(), mServices[i].getSize());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
void SacBinary::importBinary(const byte_t * bytes, size_t len)
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
2017-07-17 08:21:39 +00:00
|
|
|
clear();
|
2017-07-06 10:57:33 +00:00
|
|
|
mBinaryBlob.alloc(len);
|
|
|
|
memcpy(mBinaryBlob.getBytes(), bytes, mBinaryBlob.getSize());
|
|
|
|
|
|
|
|
SacEntry svc;
|
|
|
|
for (size_t pos = 0; pos < len; pos += mServices.atBack().getSize())
|
|
|
|
{
|
2018-03-22 05:26:22 +00:00
|
|
|
svc.importBinary((const byte_t*)(mBinaryBlob.getBytes() + pos), len - pos);
|
2017-07-06 10:57:33 +00:00
|
|
|
mServices.addElement(svc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-15 08:28:01 +00:00
|
|
|
void nx::SacBinary::clear()
|
|
|
|
{
|
2017-07-17 08:21:39 +00:00
|
|
|
mBinaryBlob.clear();
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SacBinary::isEqual(const SacBinary & other) const
|
|
|
|
{
|
|
|
|
return mServices == other.mServices;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SacBinary::copyFrom(const SacBinary & other)
|
|
|
|
{
|
|
|
|
if (other.getSize())
|
|
|
|
{
|
|
|
|
importBinary(other.getBytes(), other.getSize());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->mBinaryBlob.clear();
|
|
|
|
this->mServices = other.mServices;
|
|
|
|
}
|
|
|
|
}
|