put request serializable now

This commit is contained in:
Robin Müller 2023-07-24 11:33:37 +02:00
parent 7bf7336d4a
commit 2585028e75
Signed by: muellerr
GPG Key ID: 407F9B00F858F270
2 changed files with 79 additions and 15 deletions

View File

@ -6,6 +6,7 @@ cfdp::PutRequest::PutRequest(cfdp::EntityId destId, const uint8_t *msgsToUser,
size_t msgsToUserTotalSize, const uint8_t *fsRequests, size_t msgsToUserTotalSize, const uint8_t *fsRequests,
size_t fsRequestsSize) size_t fsRequestsSize)
: destId(std::move(destId)), : destId(std::move(destId)),
destIdWidth(destId.getWidth()),
metadataOnly(true), metadataOnly(true),
msgsToUsersTotalSize(msgsToUserTotalSize), msgsToUsersTotalSize(msgsToUserTotalSize),
msgsToUserStartPtr(msgsToUser), msgsToUserStartPtr(msgsToUser),
@ -23,8 +24,10 @@ ReturnValue_t cfdp::PutRequest::serialize(uint8_t **buffer, size_t *size, size_t
if (*size + getSerializedSize() > maxSize) { if (*size + getSerializedSize() > maxSize) {
return SerializeIF::BUFFER_TOO_SHORT; return SerializeIF::BUFFER_TOO_SHORT;
} }
**buffer = metadataOnly; result = SerializeAdapter::serialize(&metadataOnly, buffer, size, maxSize, streamEndianness);
*size += 1; if (result != OK) {
return result;
}
if (!metadataOnly) { if (!metadataOnly) {
result = SerializeAdapter::serialize(&sourceNameSize, buffer, size, maxSize, streamEndianness); result = SerializeAdapter::serialize(&sourceNameSize, buffer, size, maxSize, streamEndianness);
if (result != OK) { if (result != OK) {
@ -40,15 +43,15 @@ ReturnValue_t cfdp::PutRequest::serialize(uint8_t **buffer, size_t *size, size_t
std::memcpy(*buffer, destName, destNameSize); std::memcpy(*buffer, destName, destNameSize);
*buffer += destNameSize; *buffer += destNameSize;
*size += destNameSize; *size += destNameSize;
if (*size + 1 > maxSize) { result =
**buffer = transmissionMode; SerializeAdapter::serialize(&transmissionMode, buffer, size, maxSize, streamEndianness);
*size += 1; if (result != OK) {
*buffer += 1; return result;
} }
if (*size + 1 > maxSize) { result =
**buffer = closureRequested; SerializeAdapter::serialize(&closureRequested, buffer, size, maxSize, streamEndianness);
*size += 1; if (result != OK) {
*buffer += 1; return result;
} }
} }
result = result =
@ -73,8 +76,63 @@ ReturnValue_t cfdp::PutRequest::serialize(uint8_t **buffer, size_t *size, size_t
ReturnValue_t cfdp::PutRequest::deSerialize(const uint8_t **buffer, size_t *size, ReturnValue_t cfdp::PutRequest::deSerialize(const uint8_t **buffer, size_t *size,
SerializeIF::Endianness streamEndianness) { SerializeIF::Endianness streamEndianness) {
ReturnValue_t result =
SerializeAdapter::deSerialize(&destIdWidth, buffer, size, streamEndianness);
if (result != OK) {
return result;
}
result = destId.deSerialize(static_cast<cfdp::WidthInBytes>(destIdWidth), buffer, size,
streamEndianness);
if (result != OK) {
return result;
}
result = SerializeAdapter::deSerialize(&metadataOnly, buffer, size, streamEndianness);
if (result != OK) {
return result;
}
if (!metadataOnly) {
result = SerializeAdapter::deSerialize(&sourceNameSize, buffer, size, streamEndianness);
if (result != OK) {
return result;
}
sourceName = reinterpret_cast<const char *>(*buffer);
*buffer += sourceNameSize;
*size += sourceNameSize;
result = SerializeAdapter::deSerialize(&destNameSize, buffer, size, streamEndianness);
if (result != OK) {
return result;
}
destName = reinterpret_cast<const char *>(*buffer);
*buffer += destNameSize;
*size += destNameSize;
result = SerializeAdapter::deSerialize(&transmissionMode, buffer, size, streamEndianness);
if (result != OK) {
return result;
}
result = SerializeAdapter::deSerialize(&closureRequested, buffer, size, streamEndianness);
if (result != OK) {
return result;
}
}
result = SerializeAdapter::deSerialize(&msgsToUsersTotalSize, buffer, size, streamEndianness);
if (result != OK) {
return result;
}
msgsToUserStartPtr = *buffer;
*buffer += msgsToUsersTotalSize;
*size += msgsToUsersTotalSize;
result = SerializeAdapter::deSerialize(&fsRequestsTotalSize, buffer, size, streamEndianness);
if (result != OK) {
return result;
}
fsRequestStartPtr = *buffer;
*buffer += fsRequestsTotalSize;
*size += fsRequestsTotalSize;
return OK; return OK;
} }
size_t cfdp::PutRequest::getSerializedSize() const { size_t cfdp::PutRequest::getSerializedSize() const {
size_t baseSize = destId.getSerializedSize() + 1; size_t baseSize = destId.getSerializedSize() + 1;
if (!metadataOnly) { if (!metadataOnly) {

View File

@ -23,6 +23,11 @@ class PutRequest : public SerializeIF {
*/ */
PutRequest(EntityId destId, const uint8_t* msgsToUser, size_t msgsToUserTotalSize, PutRequest(EntityId destId, const uint8_t* msgsToUser, size_t msgsToUserTotalSize,
const uint8_t* fsRequests, size_t fsRequestsSize); const uint8_t* fsRequests, size_t fsRequestsSize);
/**
* Default constructor for deserialization.
*/
PutRequest() = default;
[[nodiscard]] ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, [[nodiscard]] ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
Endianness streamEndianness) const override; Endianness streamEndianness) const override;
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
@ -31,14 +36,15 @@ class PutRequest : public SerializeIF {
[[nodiscard]] bool isMetadataOnly() const; [[nodiscard]] bool isMetadataOnly() const;
private: private:
bool metadataOnly = true; uint8_t destIdWidth;
uint8_t metadataOnly = true;
// Transaction parameters. Omitted if the put request is metadata only. // Transaction parameters. Omitted if the put request is metadata only.
char* destName = nullptr; const char* destName = nullptr;
uint64_t destNameSize = 0; uint64_t destNameSize = 0;
char* sourceName = nullptr; const char* sourceName = nullptr;
uint64_t sourceNameSize = 0; uint64_t sourceNameSize = 0;
TransmissionMode transmissionMode = TransmissionMode::UNACKNOWLEDGED; uint8_t transmissionMode = TransmissionMode::UNACKNOWLEDGED;
bool closureRequested = false; uint8_t closureRequested = false;
// Metadata // Metadata
size_t msgsToUsersTotalSize = 0; size_t msgsToUsersTotalSize = 0;
const uint8_t* msgsToUserStartPtr = nullptr; const uint8_t* msgsToUserStartPtr = nullptr;