GCC Code Coverage Report


Directory: ./
File: FilePacket.cpp
Date: 2026-09-03 22:13:00
Exec Total Coverage
Lines: 31 88 35.2%
Functions: 6 13 46.2%
Branches: 9 24 37.5%

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 6 SerializeStatus FilePacket ::fromBuffer(const Buffer& buffer) {
23
3/3
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
6 SerialBuffer serialBuffer(const_cast<Buffer&>(buffer).getData(), const_cast<Buffer&>(buffer).getSize());
24
1/1
✓ Branch 1 taken 6 times.
6 serialBuffer.fill();
25
1/1
✓ Branch 1 taken 6 times.
6 const SerializeStatus status = this->fromSerialBuffer(serialBuffer);
26 6 return status;
27 6 }
28
29 6 const FilePacket::Header& FilePacket ::asHeader() const {
30 6 return this->m_header;
31 }
32
33 2 const FilePacket::StartPacket& FilePacket ::asStartPacket() const {
34 2 FW_ASSERT(this->m_header.m_type == T_START);
35 2 return this->m_startPacket;
36 }
37
38 2 const FilePacket::DataPacket& FilePacket ::asDataPacket() const {
39 2 FW_ASSERT(this->m_header.m_type == T_DATA);
40 2 return this->m_dataPacket;
41 }
42
43 2 const FilePacket::EndPacket& FilePacket ::asEndPacket() const {
44 2 FW_ASSERT(this->m_header.m_type == T_END);
45 2 return this->m_endPacket;
46 }
47
48 const FilePacket::CancelPacket& FilePacket ::asCancelPacket() const {
49 FW_ASSERT(this->m_header.m_type == T_CANCEL);
50 return this->m_cancelPacket;
51 }
52
53 void FilePacket ::fromStartPacket(const StartPacket& startPacket) {
54 this->m_startPacket = startPacket;
55 this->m_header.m_type = T_START;
56 }
57
58 void FilePacket ::fromDataPacket(const DataPacket& dataPacket) {
59 this->m_dataPacket = dataPacket;
60 this->m_header.m_type = T_DATA;
61 }
62
63 void FilePacket ::fromEndPacket(const EndPacket& endPacket) {
64 this->m_endPacket = endPacket;
65 this->m_header.m_type = T_END;
66 }
67
68 void FilePacket ::fromCancelPacket(const CancelPacket& cancelPacket) {
69 this->m_cancelPacket = cancelPacket;
70 this->m_header.m_type = T_CANCEL;
71 }
72
73 U32 FilePacket ::bufferSize() const {
74 switch (this->m_header.m_type) {
75 case T_START:
76 return this->m_startPacket.bufferSize();
77 case T_DATA:
78 return this->m_dataPacket.bufferSize();
79 case T_END:
80 return this->m_endPacket.bufferSize();
81 case T_CANCEL:
82 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 SerializeStatus FilePacket ::toBuffer(Buffer& buffer) const {
92 switch (this->m_header.m_type) {
93 case T_START:
94 return this->m_startPacket.toBuffer(buffer);
95 case T_DATA:
96 return this->m_dataPacket.toBuffer(buffer);
97 case T_END:
98 return this->m_endPacket.toBuffer(buffer);
99 case T_CANCEL:
100 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 6 SerializeStatus FilePacket ::fromSerialBuffer(SerialBuffer& serialBuffer) {
112 SerializeStatus status;
113 6 status = this->m_header.fromSerialBuffer(serialBuffer);
114
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (status != FW_SERIALIZE_OK) {
115 return status;
116 }
117
118
3/6
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
6 switch (this->m_header.m_type) {
119 2 case T_START:
120 2 status = this->m_startPacket.fromSerialBuffer(serialBuffer);
121 2 break;
122 2 case T_DATA:
123 2 status = this->m_dataPacket.fromSerialBuffer(serialBuffer);
124 2 break;
125 2 case T_END:
126 2 status = this->m_endPacket.fromSerialBuffer(serialBuffer);
127 2 break;
128 case T_CANCEL:
129 status = this->m_cancelPacket.fromSerialBuffer(serialBuffer);
130 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 6 return status;
139 }
140
141 } // namespace Fw
142