move parsing steps into parse function
This commit is contained in:
parent
06bea2f621
commit
2f8020baac
@ -7,12 +7,14 @@
|
||||
HeaderReader::HeaderReader(const uint8_t *pduBuf, size_t maxSize) { setData(pduBuf, maxSize); }
|
||||
|
||||
ReturnValue_t HeaderReader::parseData() {
|
||||
if (isNull()) {
|
||||
if (pointers.rawPtr == nullptr) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
if (maxSize < 7) {
|
||||
return SerializeIF::STREAM_TOO_SHORT;
|
||||
}
|
||||
pointers.fixedHeader =
|
||||
reinterpret_cast<PduHeaderFixedStruct *>(const_cast<uint8_t *>(pointers.rawPtr));
|
||||
sourceIdRaw = static_cast<uint8_t *>(&pointers.fixedHeader->variableFieldsStart);
|
||||
cfdp::WidthInBytes widthEntityIds = getLenEntityIds();
|
||||
cfdp::WidthInBytes widthSeqNum = getLenSeqNum();
|
||||
@ -22,11 +24,13 @@ ReturnValue_t HeaderReader::parseData() {
|
||||
}
|
||||
|
||||
ReturnValue_t HeaderReader::setData(uint8_t *dataPtr, size_t maxSize_, void *args) {
|
||||
if (dataPtr == nullptr) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
if (maxSize_ < 7) {
|
||||
return SerializeIF::STREAM_TOO_SHORT;
|
||||
}
|
||||
pointers.rawPtr = dataPtr;
|
||||
pointers.fixedHeader = reinterpret_cast<PduHeaderFixedStruct *>(const_cast<uint8_t *>(dataPtr));
|
||||
maxSize = maxSize_;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
@ -268,8 +268,8 @@ TEST_CASE("CFDP Header", "[cfdp]") {
|
||||
result = headerDeser.parseData();
|
||||
REQUIRE(result == result::OK);
|
||||
|
||||
headerDeser.setData(nullptr, -1);
|
||||
REQUIRE(headerDeser.getHeaderSize() == 0);
|
||||
CHECK(headerDeser.setData(nullptr, -1) != result::OK);
|
||||
REQUIRE(headerDeser.getHeaderSize() == 14);
|
||||
headerDeser.setData(serBuf.data(), serBuf.size());
|
||||
|
||||
serTarget = serBuf.data();
|
||||
|
@ -64,13 +64,15 @@ TEST_CASE("CFDP File Directive", "[cfdp]") {
|
||||
deserTarget = serBuf.data();
|
||||
CHECK(serSize == 8);
|
||||
auto fdDeser = FileDirectiveReader(deserTarget, serBuf.size());
|
||||
REQUIRE(not fdDeser.isNull());
|
||||
REQUIRE(fdDeser);
|
||||
REQUIRE(fdDeser.isNull());
|
||||
REQUIRE(not fdDeser);
|
||||
REQUIRE(fdDeser.getEndianness() == SerializeIF::Endianness::NETWORK);
|
||||
fdDeser.setEndianness(SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE(fdDeser.getEndianness() == SerializeIF::Endianness::MACHINE);
|
||||
fdDeser.setEndianness(SerializeIF::Endianness::NETWORK);
|
||||
REQUIRE(fdDeser.parseData() == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(not fdDeser.isNull());
|
||||
REQUIRE(fdDeser);
|
||||
REQUIRE(fdDeser.getFileDirective() == FileDirectives::ACK);
|
||||
REQUIRE(fdDeser.getPduDataFieldLen() == 5);
|
||||
REQUIRE(fdDeser.getHeaderSize() == 8);
|
||||
|
Loading…
x
Reference in New Issue
Block a user