F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
Buffer.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title Buffer.hpp
3 // \author mstarch
4 // \brief hpp file for Fw::Buffer definition
5 //
6 // \copyright
7 // Copyright 2009-2020, by the California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 //
11 // ======================================================================
12 #ifndef BUFFER_HPP_
13 #define BUFFER_HPP_
14 
15 #include <Fw/FPrimeBasicTypes.hpp>
17 #if FW_SERIALIZABLE_TO_STRING
18 #include <Fw/Types/StringType.hpp>
19 #ifdef BUILD_UT
20 #include <Fw/Types/String.hpp>
21 #include <iostream>
22 #endif
23 #endif
24 
25 // Forward declaration for UTs
26 namespace Fw {
27 class BufferTester;
28 }
29 
30 namespace Fw {
31 
47 class Buffer : public Fw::Serializable {
48  friend class Fw::BufferTester;
49 
50  public:
53 
54  enum {
55  SERIALIZED_SIZE = sizeof(SizeType) + sizeof(U32) + sizeof(U8*),
56  NO_CONTEXT = 0xFFFFFFFF
57  };
58 
63  Buffer();
64 
67  Buffer(const Buffer& src);
68 
76  Buffer(U8* data, FwSizeType size, U32 context = NO_CONTEXT);
77 
80  Buffer& operator=(const Buffer& src);
81 
89  bool operator==(const Buffer& src) const;
90 
91  // ----------------------------------------------------------------------
92  // Serialization functions
93  // ----------------------------------------------------------------------
94 
101  DEPRECATED(SerializeBufferBase& getSerializeRepr(), "Switch to .getSerializer() and .getDeserializer()");
102 
112 
119 
129 
139 
140  // ----------------------------------------------------------------------
141  // Accessor functions
142  // ----------------------------------------------------------------------
143 
146  bool isValid() const;
147 
150  U8* getData() const;
151 
154  FwSizeType getSize() const;
155 
158  U32 getContext() const;
159 
162  void setData(U8* data);
163 
166  void setSize(FwSizeType size);
167 
170  void setContext(U32 context);
171 
176  void set(U8* data, FwSizeType size, U32 context = NO_CONTEXT);
177 
178 #if FW_SERIALIZABLE_TO_STRING || BUILD_UT
179  void toString(Fw::StringBase& text) const;
181 #endif
182 
183 #ifdef BUILD_UT
184  friend std::ostream& operator<<(std::ostream& os, const Buffer& obj);
187 #endif
188 
189  private:
190  Fw::ExternalSerializeBuffer m_serialize_repr; //<! Representation for serialization and deserialization functions
191  U8* m_bufferData; //<! data - A pointer to the data
192  FwSizeType m_size; //<! size - The data size in bytes
193  U32 m_context;
194 };
195 } // end namespace Fw
196 #endif /* BUFFER_HPP_ */
void setData(U8 *data)
Definition: Buffer.cpp:68
PlatformSizeType FwSizeType
void setContext(U32 context)
Definition: Buffer.cpp:82
void setSize(FwSizeType size)
Definition: Buffer.cpp:75
U32 getContext() const
Definition: Buffer.cpp:64
U8 * getData() const
Definition: Buffer.cpp:56
bool operator==(const Buffer &src) const
Definition: Buffer.cpp:47
Fw::SerializeStatus serializeTo(Fw::SerializeBufferBase &serialBuffer) const
Definition: Buffer.cpp:116
SerializeStatus
forward declaration for string
ExternalSerializeBufferWithMemberCopy getDeserializer()
Definition: Buffer.cpp:105
bool isValid() const
Definition: Buffer.cpp:52
External serialize buffer with no copy semantics.
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:53
Value representing no context.
Definition: Buffer.hpp:56
FwSizeType getSize() const
Definition: Buffer.cpp:60
DEPRECATED(SerializeBufferBase &getSerializeRepr(), "Switch to .getSerializer() and .getDeserializer()")
friend class Fw::BufferTester
Definition: Buffer.hpp:48
FwSizeType SizeType
The size type for a buffer - for backwards compatibility.
Definition: Buffer.hpp:52
forward declaration
Fw::SerializeStatus deserializeFrom(Fw::SerializeBufferBase &buffer)
Definition: Buffer.cpp:139
ExternalSerializeBufferWithMemberCopy getSerializer()
Definition: Buffer.cpp:95
Buffer & operator=(const Buffer &src)
Definition: Buffer.cpp:39
Size of Fw::Buffer when serialized.
Definition: Buffer.hpp:55