2017-08-05 13:09:50 +00:00
|
|
|
#include <nx/NpdmBinary.h>
|
2017-07-17 08:21:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nx::NpdmBinary::NpdmBinary() :
|
|
|
|
mAci(),
|
|
|
|
mAcid()
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
nx::NpdmBinary::NpdmBinary(const NpdmBinary & other) :
|
|
|
|
mAci(),
|
|
|
|
mAcid()
|
|
|
|
{
|
|
|
|
copyFrom(other);
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
nx::NpdmBinary::NpdmBinary(const byte_t * bytes, size_t len) :
|
2017-07-17 08:21:39 +00:00
|
|
|
mAci(),
|
|
|
|
mAcid()
|
|
|
|
{
|
|
|
|
importBinary(bytes, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nx::NpdmBinary::operator==(const NpdmBinary & other) const
|
|
|
|
{
|
|
|
|
return isEqual(other);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nx::NpdmBinary::operator!=(const NpdmBinary & other) const
|
|
|
|
{
|
|
|
|
return !isEqual(other);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nx::NpdmBinary::operator=(const NpdmBinary & other)
|
|
|
|
{
|
|
|
|
copyFrom(other);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nx::NpdmBinary::exportBinary()
|
|
|
|
{
|
|
|
|
mAci.exportBinary();
|
|
|
|
mAcid.exportBinary();
|
|
|
|
|
|
|
|
setAciSize(mAci.getSize());
|
|
|
|
setAcidSize(mAcid.getSize());
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
void nx::NpdmBinary::importBinary(const byte_t * bytes, size_t len)
|
2017-07-17 08:21:39 +00:00
|
|
|
{
|
|
|
|
// clear
|
|
|
|
clear();
|
|
|
|
|
|
|
|
// import header
|
|
|
|
NpdmHeader::importBinary(bytes, len);
|
|
|
|
|
|
|
|
// check size
|
|
|
|
if (getNpdmSize() > len)
|
|
|
|
{
|
|
|
|
throw fnd::Exception(kModuleName, "NPDM binary too small");
|
|
|
|
}
|
|
|
|
|
|
|
|
// save local copy
|
|
|
|
mBinaryBlob.alloc(getNpdmSize());
|
|
|
|
memcpy(mBinaryBlob.getBytes(), bytes, mBinaryBlob.getSize());
|
|
|
|
|
|
|
|
// import Aci/Acid
|
|
|
|
if (getAciPos().size)
|
|
|
|
{
|
|
|
|
mAci.importBinary(mBinaryBlob.getBytes() + getAciPos().offset, getAciPos().size);
|
|
|
|
}
|
|
|
|
if (getAcidPos().size)
|
|
|
|
{
|
|
|
|
mAcid.importBinary(mBinaryBlob.getBytes() + getAcidPos().offset, getAcidPos().size);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void nx::NpdmBinary::clear()
|
|
|
|
{
|
|
|
|
NpdmHeader::clear();
|
|
|
|
mAci.clear();
|
|
|
|
mAcid.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
const nx::AciBinary & nx::NpdmBinary::getAci() const
|
|
|
|
{
|
|
|
|
return mAci;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nx::NpdmBinary::setAci(const AciBinary & aci)
|
|
|
|
{
|
|
|
|
mAci = aci;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nx::AcidBinary & nx::NpdmBinary::getAcid() const
|
|
|
|
{
|
|
|
|
return mAcid;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nx::NpdmBinary::setAcid(const AcidBinary & acid)
|
|
|
|
{
|
|
|
|
mAcid = acid;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nx::NpdmBinary::isEqual(const NpdmBinary & other) const
|
|
|
|
{
|
|
|
|
return (NpdmHeader::operator==(other)) \
|
|
|
|
&& (mAci == other.mAci) \
|
|
|
|
&& (mAcid == other.mAcid);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nx::NpdmBinary::copyFrom(const NpdmBinary & other)
|
|
|
|
{
|
|
|
|
if (other.getSize())
|
|
|
|
{
|
|
|
|
importBinary(other.getBytes(), other.getSize());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NpdmHeader::operator=(other);
|
|
|
|
mAci = other.mAci;
|
|
|
|
mAcid = other.mAcid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
const byte_t * nx::NpdmBinary::getBytes() const
|
2017-07-17 08:21:39 +00:00
|
|
|
{
|
|
|
|
return mBinaryBlob.getBytes();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t nx::NpdmBinary::getSize() const
|
|
|
|
{
|
|
|
|
return mBinaryBlob.getSize();
|
|
|
|
}
|