GCC Code Coverage Report


Directory: ./
File: DataPacket.cpp
Date: 2026-09-03 22:13:00
Exec Total Coverage
Lines: 12 41 29.3%
Functions: 2 6 33.3%
Branches: 3 16 18.8%

Line Branch Exec Source
1 // ======================================================================
2 // \title DataPacket.cpp
3 // \author bocchino
4 // \brief cpp file for FilePacket::DataPacket
5 //
6 // \copyright
7 // Copyright 2009-2016, by the California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 //
11 // ======================================================================
12
13 #include <Fw/FilePacket/FilePacket.hpp>
14 #include <Fw/Types/Assert.hpp>
15
16 namespace Fw {
17
18 void FilePacket::DataPacket ::initialize(const U32 sequenceIndex,
19 const U32 byteOffset,
20 const U16 dataSize,
21 const U8* const data) {
22 this->m_header.initialize(FilePacket::T_DATA, sequenceIndex);
23 this->m_byteOffset = byteOffset;
24 this->m_dataSize = dataSize;
25 this->m_data = data;
26 }
27
28 U32 FilePacket::DataPacket ::bufferSize() const {
29 return static_cast<U32>(this->m_header.bufferSize() + sizeof(this->m_byteOffset) + sizeof(this->m_dataSize) +
30 this->m_dataSize);
31 }
32
33 SerializeStatus FilePacket::DataPacket ::toBuffer(Buffer& buffer) const {
34 SerialBuffer serialBuffer(buffer.getData(), buffer.getSize());
35 return this->toSerialBuffer(serialBuffer);
36 }
37
38 2 SerializeStatus FilePacket::DataPacket ::fromSerialBuffer(SerialBuffer& serialBuffer) {
39 2 FW_ASSERT(this->m_header.m_type == T_DATA);
40
41 2 SerializeStatus status = serialBuffer.deserializeTo(this->m_byteOffset);
42
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (status != FW_SERIALIZE_OK) {
43 return status;
44 }
45
46 2 status = serialBuffer.deserializeTo(this->m_dataSize);
47
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (status != FW_SERIALIZE_OK) {
48 return status;
49 }
50
51
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if (serialBuffer.getDeserializeSizeLeft() != this->m_dataSize) {
52 return FW_DESERIALIZE_SIZE_MISMATCH;
53 }
54
55 2 U8* const addr = serialBuffer.getBuffAddr();
56 2 this->m_data = &addr[this->fixedLengthSize()];
57
58 2 return FW_SERIALIZE_OK;
59 }
60
61 2 U32 FilePacket::DataPacket ::fixedLengthSize() const {
62 2 return static_cast<U32>(this->m_header.bufferSize() + sizeof(this->m_byteOffset) + sizeof(this->m_dataSize));
63 }
64
65 SerializeStatus FilePacket::DataPacket ::toSerialBuffer(SerialBuffer& serialBuffer) const {
66 FW_ASSERT(this->m_header.m_type == T_DATA);
67
68 SerializeStatus status;
69
70 status = this->m_header.toSerialBuffer(serialBuffer);
71 if (status != FW_SERIALIZE_OK) {
72 return status;
73 }
74
75 status = serialBuffer.serializeFrom(this->m_byteOffset);
76 if (status != FW_SERIALIZE_OK) {
77 return status;
78 }
79
80 status = serialBuffer.serializeFrom(this->m_dataSize);
81 if (status != FW_SERIALIZE_OK) {
82 return status;
83 }
84
85 status = serialBuffer.pushBytes(this->m_data, this->m_dataSize);
86
87 return status;
88 }
89
90 } // namespace Fw
91