GCC Code Coverage Report


Directory: ./
File: Fw/FilePacket/FilePacket.cpp
Date: 2026-09-03 21:13:48
Exec Total Coverage
Lines: 73 88 83.0%
Functions: 13 13 100.0%
Branches: 21 30 70.0%

Line Branch Exec Source
1 // ======================================================================
2 // \title FilePacket.cpp
3 // \author bocchino
4 // \brief cpp file for FilePacket
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 // ----------------------------------------------------------------------
19 // Public instance methods
20 // ----------------------------------------------------------------------
21
22 43 SerializeStatus FilePacket ::fromBuffer(const Buffer& buffer) {
23
3/3
✓ Branch 5 taken 43 times.
✓ Branch 11 taken 43 times.
✓ Branch 14 taken 43 times.
43 SerialBuffer serialBuffer(const_cast<Buffer&>(buffer).getData(), const_cast<Buffer&>(buffer).getSize());
24
1/1
✓ Branch 2 taken 43 times.
43 serialBuffer.fill();
25
1/1
✓ Branch 2 taken 43 times.
43 const SerializeStatus status = this->fromSerialBuffer(serialBuffer);
26 43 return status;
27 43 }
28
29 39 const FilePacket::Header& FilePacket ::asHeader() const {
30 39 return this->m_header;
31 }
32
33 12 const FilePacket::StartPacket& FilePacket ::asStartPacket() const {
34 12 FW_ASSERT(this->m_header.m_type == T_START);
35 12 return this->m_startPacket;
36 }
37
38 16 const FilePacket::DataPacket& FilePacket ::asDataPacket() const {
39 16 FW_ASSERT(this->m_header.m_type == T_DATA);
40 16 return this->m_dataPacket;
41 }
42
43 8 const FilePacket::EndPacket& FilePacket ::asEndPacket() const {
44 8 FW_ASSERT(this->m_header.m_type == T_END);
45 8 return this->m_endPacket;
46 }
47
48 1 const FilePacket::CancelPacket& FilePacket ::asCancelPacket() const {
49 1 FW_ASSERT(this->m_header.m_type == T_CANCEL);
50 1 return this->m_cancelPacket;
51 }
52
53 16 void FilePacket ::fromStartPacket(const StartPacket& startPacket) {
54 16 this->m_startPacket = startPacket;
55 16 this->m_header.m_type = T_START;
56 16 }
57
58 15 void FilePacket ::fromDataPacket(const DataPacket& dataPacket) {
59 15 this->m_dataPacket = dataPacket;
60 15 this->m_header.m_type = T_DATA;
61 15 }
62
63 7 void FilePacket ::fromEndPacket(const EndPacket& endPacket) {
64 7 this->m_endPacket = endPacket;
65 7 this->m_header.m_type = T_END;
66 7 }
67
68 3 void FilePacket ::fromCancelPacket(const CancelPacket& cancelPacket) {
69 3 this->m_cancelPacket = cancelPacket;
70 3 this->m_header.m_type = T_CANCEL;
71 3 }
72
73 42 U32 FilePacket ::bufferSize() const {
74
5/8
✗ Branch 1 not taken.
✓ Branch 2 taken 42 times.
✓ Branch 3 taken 16 times.
✓ Branch 4 taken 15 times.
✓ Branch 5 taken 7 times.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
42 switch (this->m_header.m_type) {
75 16 case T_START:
76 16 return this->m_startPacket.bufferSize();
77 15 case T_DATA:
78 15 return this->m_dataPacket.bufferSize();
79 7 case T_END:
80 7 return this->m_endPacket.bufferSize();
81 4 case T_CANCEL:
82 4 return this->m_cancelPacket.bufferSize();
83 case T_NONE:
84 return 0;
85 default:
86 FW_ASSERT(false);
87 return 0;
88 }
89 }
90
91 41 SerializeStatus FilePacket ::toBuffer(Buffer& buffer) const {
92
5/7
✗ Branch 1 not taken.
✓ Branch 2 taken 41 times.
✓ Branch 3 taken 16 times.
✓ Branch 4 taken 15 times.
✓ Branch 5 taken 7 times.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
41 switch (this->m_header.m_type) {
93 16 case T_START:
94 16 return this->m_startPacket.toBuffer(buffer);
95 15 case T_DATA:
96 15 return this->m_dataPacket.toBuffer(buffer);
97 7 case T_END:
98 7 return this->m_endPacket.toBuffer(buffer);
99 3 case T_CANCEL:
100 3 return this->m_cancelPacket.toBuffer(buffer);
101 default:
102 FW_ASSERT(false);
103 return static_cast<SerializeStatus>(0);
104 }
105 }
106
107 // ----------------------------------------------------------------------
108 // Private instance methods
109 // ----------------------------------------------------------------------
110
111 43 SerializeStatus FilePacket ::fromSerialBuffer(SerialBuffer& serialBuffer) {
112 SerializeStatus status;
113 43 status = this->m_header.fromSerialBuffer(serialBuffer);
114
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
43 if (status != FW_SERIALIZE_OK) {
115 return status;
116 }
117
118
5/8
✗ Branch 1 not taken.
✓ Branch 2 taken 43 times.
✓ Branch 3 taken 16 times.
✓ Branch 4 taken 16 times.
✓ Branch 5 taken 8 times.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
43 switch (this->m_header.m_type) {
119 16 case T_START:
120 16 status = this->m_startPacket.fromSerialBuffer(serialBuffer);
121 16 break;
122 16 case T_DATA:
123 16 status = this->m_dataPacket.fromSerialBuffer(serialBuffer);
124 16 break;
125 8 case T_END:
126 8 status = this->m_endPacket.fromSerialBuffer(serialBuffer);
127 8 break;
128 3 case T_CANCEL:
129 3 status = this->m_cancelPacket.fromSerialBuffer(serialBuffer);
130 3 break;
131 case T_NONE:
132 status = FW_DESERIALIZE_TYPE_MISMATCH;
133 break;
134 default:
135 status = FW_DESERIALIZE_INVALID_DATA;
136 break;
137 }
138 43 return status;
139 }
140
141 } // namespace Fw
142