2017-08-05 13:09:50 +00:00
|
|
|
#include <nx/AciBinary.h>
|
2017-07-15 08:28:41 +00:00
|
|
|
|
|
|
|
nx::AciBinary::AciBinary()
|
2017-07-17 08:21:39 +00:00
|
|
|
{
|
|
|
|
clear();
|
|
|
|
}
|
2017-07-15 08:28:41 +00:00
|
|
|
|
|
|
|
nx::AciBinary::AciBinary(const AciBinary & other)
|
|
|
|
{
|
2018-06-24 08:18:54 +00:00
|
|
|
*this = other;
|
2017-07-15 08:28:41 +00:00
|
|
|
}
|
|
|
|
|
2018-06-24 08:18:54 +00:00
|
|
|
void nx::AciBinary::operator=(const AciBinary & other)
|
2017-07-15 08:28:41 +00:00
|
|
|
{
|
2018-06-24 08:18:54 +00:00
|
|
|
if (other.getBytes().size())
|
|
|
|
{
|
|
|
|
fromBytes(other.getBytes().data(), other.getBytes().size());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
AciHeader::operator=(other);
|
|
|
|
mFac = other.mFac;
|
|
|
|
mSac = other.mSac;
|
|
|
|
mKc = other.mKc;
|
|
|
|
}
|
2017-07-15 08:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool nx::AciBinary::operator==(const AciBinary & other) const
|
|
|
|
{
|
2018-06-24 08:18:54 +00:00
|
|
|
return (AciHeader::operator==(other)) \
|
|
|
|
&& (mFac == other.mFac) \
|
|
|
|
&& (mSac == other.mSac) \
|
|
|
|
&& (mKc == other.mKc);
|
2017-07-15 08:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool nx::AciBinary::operator!=(const AciBinary & other) const
|
|
|
|
{
|
2018-06-24 08:18:54 +00:00
|
|
|
return !(*this == other);
|
2017-07-15 08:28:41 +00:00
|
|
|
}
|
|
|
|
|
2018-06-24 08:18:54 +00:00
|
|
|
void nx::AciBinary::toBytes()
|
2017-07-15 08:28:41 +00:00
|
|
|
{
|
|
|
|
// export components
|
2018-06-24 08:18:54 +00:00
|
|
|
mFac.toBytes();
|
|
|
|
mSac.toBytes();
|
|
|
|
mKc.toBytes();
|
2017-07-15 08:28:41 +00:00
|
|
|
|
|
|
|
// set sizes
|
2018-06-24 08:18:54 +00:00
|
|
|
setFacSize(mFac.getBytes().size());
|
|
|
|
setSacSize(mSac.getBytes().size());
|
|
|
|
setKcSize(mKc.getBytes().size());
|
2017-07-15 08:28:41 +00:00
|
|
|
|
|
|
|
// export header
|
2018-06-24 08:18:54 +00:00
|
|
|
AciHeader::toBytes();
|
2017-07-15 08:28:41 +00:00
|
|
|
|
|
|
|
// allocate binary
|
2018-06-24 08:18:54 +00:00
|
|
|
mRawBinary.alloc(getAciSize());
|
2017-07-15 08:28:41 +00:00
|
|
|
|
|
|
|
// copy header
|
2018-06-24 08:18:54 +00:00
|
|
|
memcpy(mRawBinary.data(), AciHeader::getBytes().data(), AciHeader::getBytes().size());
|
2017-07-15 08:28:41 +00:00
|
|
|
|
|
|
|
// copy components
|
2018-06-24 08:18:54 +00:00
|
|
|
memcpy(mRawBinary.data() + getFacPos().offset, mFac.getBytes().data(), mFac.getBytes().size());
|
|
|
|
memcpy(mRawBinary.data() + getSacPos().offset, mSac.getBytes().data(), mSac.getBytes().size());
|
|
|
|
memcpy(mRawBinary.data() + getKcPos().offset, mKc.getBytes().data(), mKc.getBytes().size());
|
2017-07-15 08:28:41 +00:00
|
|
|
}
|
|
|
|
|
2018-06-24 08:18:54 +00:00
|
|
|
void nx::AciBinary::fromBytes(const byte_t * bytes, size_t len)
|
2017-07-15 08:28:41 +00:00
|
|
|
{
|
2018-06-24 08:18:54 +00:00
|
|
|
AciHeader::fromBytes(bytes, len);
|
2017-07-15 08:28:41 +00:00
|
|
|
|
|
|
|
if (getAciSize() > len)
|
|
|
|
{
|
|
|
|
throw fnd::Exception(kModuleName, "ACI binary too small");
|
|
|
|
}
|
|
|
|
|
2018-06-24 08:18:54 +00:00
|
|
|
mRawBinary.alloc(getAciSize());
|
|
|
|
memcpy(mRawBinary.data(), bytes, mRawBinary.size());
|
2017-07-15 08:28:41 +00:00
|
|
|
|
|
|
|
if (getFacPos().size > 0)
|
|
|
|
{
|
2018-06-24 08:18:54 +00:00
|
|
|
mFac.fromBytes(mRawBinary.data() + getFacPos().offset, getFacPos().size);
|
2017-07-15 08:28:41 +00:00
|
|
|
}
|
|
|
|
if (getSacPos().size > 0)
|
|
|
|
{
|
2018-06-24 08:18:54 +00:00
|
|
|
mSac.fromBytes(mRawBinary.data() + getSacPos().offset, getSacPos().size);
|
2017-07-15 08:28:41 +00:00
|
|
|
}
|
|
|
|
if (getKcPos().size > 0)
|
|
|
|
{
|
2018-06-24 08:18:54 +00:00
|
|
|
mKc.fromBytes(mRawBinary.data() + getKcPos().offset, getKcPos().size);
|
2017-07-15 08:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-06-24 08:18:54 +00:00
|
|
|
const fnd::Vec<byte_t>& nx::AciBinary::getBytes() const
|
|
|
|
{
|
|
|
|
return mRawBinary;
|
|
|
|
}
|
|
|
|
|
2017-07-15 08:28:41 +00:00
|
|
|
void nx::AciBinary::clear()
|
|
|
|
{
|
|
|
|
AciHeader::clear();
|
2018-06-24 08:18:54 +00:00
|
|
|
mRawBinary.clear();
|
2017-07-15 08:28:41 +00:00
|
|
|
mFac.clear();
|
|
|
|
mSac.clear();
|
|
|
|
mKc.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
const nx::FacBinary & nx::AciBinary::getFac() const
|
|
|
|
{
|
|
|
|
return mFac;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nx::AciBinary::setFac(const FacBinary & fac)
|
|
|
|
{
|
|
|
|
mFac = fac;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nx::SacBinary & nx::AciBinary::getSac() const
|
|
|
|
{
|
|
|
|
return mSac;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nx::AciBinary::setSac(const SacBinary & sac)
|
|
|
|
{
|
|
|
|
mSac = sac;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nx::KcBinary & nx::AciBinary::getKc() const
|
|
|
|
{
|
|
|
|
return mKc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nx::AciBinary::setKc(const KcBinary & kc)
|
|
|
|
{
|
|
|
|
mKc = kc;
|
2018-06-24 08:18:54 +00:00
|
|
|
}
|