2022-08-08 17:53:42 +02:00
|
|
|
#include "MetadataPduReader.h"
|
2021-12-03 15:37:49 +01:00
|
|
|
|
2023-07-27 14:55:46 +02:00
|
|
|
MetadataPduReader::MetadataPduReader(const uint8_t* pduBuf, size_t maxSize,
|
|
|
|
MetadataGenericInfo& info, cfdp::Tlv* optionsArray,
|
|
|
|
size_t optArrayMaxSize)
|
2023-07-21 16:09:52 +02:00
|
|
|
: FileDirectiveReader(pduBuf, maxSize),
|
|
|
|
info(info),
|
|
|
|
optionArray(optionsArray),
|
|
|
|
optionArrayMaxSize(optArrayMaxSize) {}
|
2021-12-03 15:37:49 +01:00
|
|
|
|
2022-08-08 17:53:42 +02:00
|
|
|
ReturnValue_t MetadataPduReader::parseData() {
|
2023-07-21 16:09:52 +02:00
|
|
|
parsedOptions = 0;
|
2022-08-03 16:00:48 +02:00
|
|
|
ReturnValue_t result = FileDirectiveReader::parseData();
|
2022-08-16 01:08:26 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-02-02 10:29:30 +01:00
|
|
|
return result;
|
|
|
|
}
|
2022-08-03 16:00:48 +02:00
|
|
|
size_t currentIdx = FileDirectiveReader::getHeaderSize();
|
2022-08-08 18:29:32 +02:00
|
|
|
const uint8_t* buf = pointers.rawPtr + currentIdx;
|
2022-08-03 16:00:48 +02:00
|
|
|
size_t remSize = FileDirectiveReader::getWholePduSize() - currentIdx;
|
2022-02-02 10:29:30 +01:00
|
|
|
if (remSize < 1) {
|
|
|
|
return SerializeIF::STREAM_TOO_SHORT;
|
|
|
|
}
|
|
|
|
info.setClosureRequested((*buf >> 6) & 0x01);
|
2022-09-15 18:41:15 +02:00
|
|
|
info.setChecksumType(static_cast<cfdp::ChecksumType>(*buf & 0x0f));
|
2022-02-02 10:29:30 +01:00
|
|
|
remSize -= 1;
|
|
|
|
buf += 1;
|
|
|
|
auto endianness = getEndianness();
|
|
|
|
result = info.getFileSize().deSerialize(&buf, &remSize, endianness);
|
2022-08-16 01:08:26 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-02-02 10:29:30 +01:00
|
|
|
return result;
|
|
|
|
}
|
2023-07-27 14:55:46 +02:00
|
|
|
result = srcFileName.deSerialize(&buf, &remSize, endianness);
|
2022-08-16 01:08:26 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-02-02 10:29:30 +01:00
|
|
|
return result;
|
|
|
|
}
|
2023-07-27 14:55:46 +02:00
|
|
|
result = destFileName.deSerialize(&buf, &remSize, endianness);
|
2022-08-16 01:08:26 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-02-02 10:29:30 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (remSize > 0) {
|
2023-07-21 16:09:52 +02:00
|
|
|
if (optionArrayMaxSize == 0 or optionArray == nullptr) {
|
2022-02-02 10:29:30 +01:00
|
|
|
return cfdp::METADATA_CANT_PARSE_OPTIONS;
|
2021-12-03 15:37:49 +01:00
|
|
|
}
|
2022-02-02 10:29:30 +01:00
|
|
|
size_t optsIdx = 0;
|
|
|
|
while (remSize > 0) {
|
2023-07-21 16:09:52 +02:00
|
|
|
if (optsIdx > optionArrayMaxSize) {
|
2022-02-02 10:29:30 +01:00
|
|
|
return cfdp::METADATA_CANT_PARSE_OPTIONS;
|
|
|
|
}
|
2023-07-21 16:09:52 +02:00
|
|
|
result = optionArray[optsIdx].deSerialize(&buf, &remSize, endianness);
|
2022-08-16 01:08:26 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2021-12-03 15:37:49 +01:00
|
|
|
return result;
|
2022-02-02 10:29:30 +01:00
|
|
|
}
|
|
|
|
optsIdx++;
|
2021-12-03 15:37:49 +01:00
|
|
|
}
|
2023-07-21 16:09:52 +02:00
|
|
|
parsedOptions = optsIdx;
|
2022-02-02 10:29:30 +01:00
|
|
|
}
|
|
|
|
return result;
|
2021-12-03 15:37:49 +01:00
|
|
|
}
|
2023-07-21 16:09:52 +02:00
|
|
|
|
|
|
|
size_t MetadataPduReader::getNumberOfParsedOptions() const { return parsedOptions; }
|
2023-07-27 14:55:46 +02:00
|
|
|
|
|
|
|
const cfdp::StringLv& MetadataPduReader::getSourceFileName() const { return srcFileName; }
|
|
|
|
|
|
|
|
const cfdp::StringLv& MetadataPduReader::getDestFileName() const { return destFileName; }
|