nstool/lib/libes/source/SectionHeader_V2.cpp

162 lines
3.3 KiB
C++
Raw Normal View History

2018-06-06 12:38:42 +00:00
#include <es/SectionHeader_V2.h>
2017-07-22 08:59:06 +00:00
2018-06-06 12:38:42 +00:00
es::SectionHeader_V2::SectionHeader_V2()
2017-07-22 08:59:06 +00:00
{}
2018-06-06 12:38:42 +00:00
es::SectionHeader_V2::SectionHeader_V2(const SectionHeader_V2 & other)
2017-07-22 08:59:06 +00:00
{
copyFrom(other);
}
2018-06-06 12:38:42 +00:00
es::SectionHeader_V2::SectionHeader_V2(const byte_t * bytes, size_t len)
2017-07-22 08:59:06 +00:00
{
importBinary(bytes, len);
}
2018-06-06 12:38:42 +00:00
bool es::SectionHeader_V2::operator==(const SectionHeader_V2 & other) const
2017-07-22 08:59:06 +00:00
{
return isEqual(other);
}
2018-06-06 12:38:42 +00:00
bool es::SectionHeader_V2::operator!=(const SectionHeader_V2 & other) const
2017-07-22 08:59:06 +00:00
{
return !isEqual(other);
}
2018-06-06 12:38:42 +00:00
void es::SectionHeader_V2::operator=(const SectionHeader_V2 & other)
2017-07-22 08:59:06 +00:00
{
copyFrom(other);
}
2018-06-06 12:38:42 +00:00
const byte_t * es::SectionHeader_V2::getBytes() const
2017-07-22 08:59:06 +00:00
{
return mBinaryBlob.getBytes();
}
2018-06-06 12:38:42 +00:00
size_t es::SectionHeader_V2::getSize() const
2017-07-22 08:59:06 +00:00
{
return mBinaryBlob.getSize();
}
2018-06-06 12:38:42 +00:00
void es::SectionHeader_V2::exportBinary()
2017-07-22 08:59:06 +00:00
{
mBinaryBlob.alloc(sizeof(sSectionHeader_v2));
sSectionHeader_v2* hdr = (sSectionHeader_v2*)mBinaryBlob.getBytes();
hdr->section_offset = (mSectionOffset);
hdr->record_size = (mRecordSize);
hdr->section_size = (mSectionSize);
hdr->record_num = (mRecordNum);
hdr->section_type = (mSectionType);
2017-07-22 08:59:06 +00:00
}
2018-06-06 12:38:42 +00:00
void es::SectionHeader_V2::importBinary(const byte_t * bytes, size_t len)
2017-07-22 08:59:06 +00:00
{
if (len < sizeof(sSectionHeader_v2))
{
throw fnd::Exception(kModuleName, "Binary too small");
}
clear();
mBinaryBlob.alloc(sizeof(sSectionHeader_v2));
memcpy(mBinaryBlob.getBytes(), bytes, mBinaryBlob.getSize());
sSectionHeader_v2* hdr = (sSectionHeader_v2*)mBinaryBlob.getBytes();
mSectionOffset = hdr->section_offset.get();
mRecordSize = hdr->record_size.get();
mSectionSize = hdr->section_size.get();
mRecordNum = hdr->record_num.get();
2018-06-06 12:38:42 +00:00
mSectionType = (ticket::SectionType)hdr->section_type.get();
2017-07-22 08:59:06 +00:00
}
2018-06-06 12:38:42 +00:00
bool es::SectionHeader_V2::isEqual(const SectionHeader_V2 & other) const
2017-07-22 08:59:06 +00:00
{
return (mSectionOffset == other.mSectionOffset) \
&& (mRecordSize == other.mRecordSize) \
&& (mSectionSize == other.mSectionSize) \
&& (mRecordNum == other.mRecordNum) \
&& (mSectionType == other.mSectionType);
}
2018-06-06 12:38:42 +00:00
void es::SectionHeader_V2::copyFrom(const SectionHeader_V2 & other)
2017-07-22 08:59:06 +00:00
{
if (other.getSize())
{
importBinary(other.getBytes(), other.getSize());
}
else
{
mBinaryBlob.clear();
mSectionOffset = other.mSectionOffset;
mRecordSize = other.mRecordSize;
mSectionSize = other.mSectionSize;
mRecordNum = other.mRecordNum;
mSectionType = other.mSectionType;
}
}
2018-06-06 12:38:42 +00:00
void es::SectionHeader_V2::clear()
2017-07-22 08:59:06 +00:00
{
mBinaryBlob.clear();
mSectionOffset = 0;
mRecordSize = 0;
mSectionSize = 0;
mRecordNum = 0;
2018-06-06 12:38:42 +00:00
mSectionType = ticket::SECTION_PERMANENT;
2017-07-22 08:59:06 +00:00
}
2018-06-06 12:38:42 +00:00
uint32_t es::SectionHeader_V2::getSectionOffset() const
2017-07-22 08:59:06 +00:00
{
return mSectionOffset;
}
2018-06-06 12:38:42 +00:00
void es::SectionHeader_V2::setSectionOffset(uint32_t offset)
2017-07-22 08:59:06 +00:00
{
mSectionOffset = offset;
}
2018-06-06 12:38:42 +00:00
uint32_t es::SectionHeader_V2::getRecordSize() const
2017-07-22 08:59:06 +00:00
{
return mRecordSize;
}
2018-06-06 12:38:42 +00:00
void es::SectionHeader_V2::setRecordSize(uint32_t size)
2017-07-22 08:59:06 +00:00
{
mRecordSize = size;
}
2018-06-06 12:38:42 +00:00
uint32_t es::SectionHeader_V2::getSectionSize() const
2017-07-22 08:59:06 +00:00
{
return mSectionSize;
}
2018-06-06 12:38:42 +00:00
void es::SectionHeader_V2::getSectionSize(uint32_t size)
2017-07-22 08:59:06 +00:00
{
mSectionSize = size;
}
2018-06-06 12:38:42 +00:00
uint16_t es::SectionHeader_V2::getRecordNum() const
2017-07-22 08:59:06 +00:00
{
return mRecordNum;
}
2018-06-06 12:38:42 +00:00
void es::SectionHeader_V2::setRecordNum(uint16_t record_num)
2017-07-22 08:59:06 +00:00
{
mRecordNum = record_num;
}
2018-06-06 12:38:42 +00:00
es::ticket::SectionType es::SectionHeader_V2::getSectionType() const
2017-07-22 08:59:06 +00:00
{
return mSectionType;
}
2018-06-06 12:38:42 +00:00
void es::SectionHeader_V2::setSectionType(ticket::SectionType type)
2017-07-22 08:59:06 +00:00
{
mSectionType = type;
}