F´ Flight Software - C/C++ Documentation  devel
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 #include <Fw/Types/StringUtils.hpp>
18 
19 namespace Fw {
20 
22  initialize(const char *const value)
23  {
24  const U8 length = static_cast<U8>(StringUtils::string_length(value, MAX_LENGTH));
25  this->m_length = length;
26  this->m_value = value;
27  }
28 
30  bufferSize() const
31  {
32  return sizeof(this->m_length) + this->m_length;
33  }
34 
35  SerializeStatus FilePacket::PathName ::
36  fromSerialBuffer(SerialBuffer& serialBuffer)
37  {
38 
39  {
40  const SerializeStatus status =
41  serialBuffer.deserialize(this->m_length);
42  if (status != FW_SERIALIZE_OK)
43  return status;
44  }
45 
46  {
47  const U8* addrLeft = serialBuffer.getBuffAddrLeft();
48  U8 bytes[MAX_LENGTH];
49  const SerializeStatus status =
50  serialBuffer.popBytes(bytes, this->m_length);
51  if (status != FW_SERIALIZE_OK)
52  return status;
53  this->m_value = reinterpret_cast<const char*>(addrLeft);
54  }
55 
56  return FW_SERIALIZE_OK;
57 
58  }
59 
60  SerializeStatus FilePacket::PathName ::
61  toSerialBuffer(SerialBuffer& serialBuffer) const
62  {
63 
64  {
65  const SerializeStatus status =
66  serialBuffer.serialize(this->m_length);
67  if (status != FW_SERIALIZE_OK)
68  return status;
69  }
70 
71  {
72  const SerializeStatus status = serialBuffer.pushBytes(
73  reinterpret_cast<const U8 *>(this->m_value),
74  this->m_length
75  );
76  if (status != FW_SERIALIZE_OK)
77  return status;
78  }
79 
80  return FW_SERIALIZE_OK;
81 
82  }
83 
84 }
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:26
void initialize(const char *const value)
Initialize a PathName.
Definition: PathName.cpp:22
U32 bufferSize() const
Compute the buffer size needed to hold this PathName.
Definition: PathName.cpp:30
A variable-length serializable buffer.
SerializeStatus popBytes(U8 *const addr, NATIVE_UINT_TYPE n)
Pop n bytes off the buffer.
const U8 * getBuffAddrLeft() const
gets address of remaining non-deserialized data.
SerializeStatus deserialize(U8 &val)
deserialize 8-bit unsigned int
U32 string_length(const CHAR *source, U32 max_len)
get the length of the source string or max_len if the string is longer than max_len.
Definition: StringUtils.cpp:20
SerializeStatus
forward declaration for string
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.