nstool/lib/libnx/source/SacBinary.cpp

107 lines
1.9 KiB
C++
Raw Normal View History

#include <nx/SacBinary.h>
2017-07-06 11:17:21 +00:00
using namespace nx;
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)
{
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
{
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)
{
clear();
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);
mServices.addElement(svc);
}
}
void nx::SacBinary::clear()
{
mBinaryBlob.clear();
mServices.clear();
}
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;
}
}