F´ Flight Software - C/C++ Documentation  NASA-v1.6.0
A framework for building embedded system applications to NASA flight quality standards.
PathName.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title PathName.cpp
3 // \author bocchino
4 // \brief cpp file for FilePacket::PathName
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 <cstring>
14 
16 #include <Fw/Types/Assert.hpp>
17 
18 namespace Fw {
19 
21  initialize(const char *const value)
22  {
23  const U8 length = static_cast<U8>(::strnlen(value, MAX_LENGTH));
24  this->length = length;
25  this->value = value;
26  }
27 
29  bufferSize() const
30  {
31  return sizeof(this->length) + this->length;
32  }
33 
34  SerializeStatus FilePacket::PathName ::
35  fromSerialBuffer(SerialBuffer& serialBuffer)
36  {
37 
38  {
39  const SerializeStatus status =
40  serialBuffer.deserialize(this->length);
41  if (status != FW_SERIALIZE_OK)
42  return status;
43  }
44 
45  {
46  const U8* addrLeft = serialBuffer.getBuffAddrLeft();
47  U8 bytes[MAX_LENGTH];
48  const SerializeStatus status =
49  serialBuffer.popBytes(bytes, this->length);
50  if (status != FW_SERIALIZE_OK)
51  return status;
52  this->value = reinterpret_cast<const char*>(addrLeft);
53  }
54 
55  return FW_SERIALIZE_OK;
56 
57  }
58 
59  SerializeStatus FilePacket::PathName ::
60  toSerialBuffer(SerialBuffer& serialBuffer) const
61  {
62 
63  {
64  const SerializeStatus status =
65  serialBuffer.serialize(this->length);
66  if (status != FW_SERIALIZE_OK)
67  return status;
68  }
69 
70  {
71  const SerializeStatus status = serialBuffer.pushBytes(
72  reinterpret_cast<const U8 *>(this->value),
73  this->length
74  );
75  if (status != FW_SERIALIZE_OK)
76  return status;
77  }
78 
79  return FW_SERIALIZE_OK;
80 
81  }
82 
83 }
Fw::FilePacket::PathName::bufferSize
U32 bufferSize() const
Compute the buffer size needed to hold this PathName.
Definition: PathName.cpp:29
Fw::SerialBuffer
A variable-length serializable buffer.
Definition: SerialBuffer.hpp:24
Fw::SerializeStatus
SerializeStatus
forward declaration for string
Definition: Serializable.hpp:14
Fw::FilePacket::PathName::initialize
void initialize(const char *const value)
Initialize a PathName.
Definition: PathName.cpp:21
U8
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.hpp:76
Fw::SerializeBufferBase::getBuffAddrLeft
const U8 * getBuffAddrLeft() const
gets address of remaining non-deserialized data.
Fw::FilePacket::PathName::MAX_LENGTH
@ MAX_LENGTH
Definition: FilePacket.hpp:52
Assert.hpp
Fw::FW_SERIALIZE_OK
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.
Definition: Serializable.hpp:15
Fw::FilePacket::PathName::length
U8 length
The length.
Definition: FilePacket.hpp:57
Fw::SerialBuffer::popBytes
SerializeStatus popBytes(U8 *const addr, NATIVE_UINT_TYPE n)
Pop n bytes off the buffer.
Definition: SerialBuffer.cpp:62
Fw::SerializeBufferBase::deserialize
SerializeStatus deserialize(U8 &val)
deserialize 8-bit unsigned int
Definition: Serializable.cpp:290
Fw::FilePacket::PathName::value
const char * value
Pointer to the path value.
Definition: FilePacket.hpp:60
FilePacket.hpp
Fw
Definition: Buffer.cpp:21