F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 <FpConfig.hpp>
17 #if FW_SERIALIZABLE_TO_STRING
18  #include <Fw/Types/StringType.hpp>
19  #include <cstdio> // snprintf
20  #ifdef BUILD_UT
21  #include <iostream>
22  #include <Fw/Types/String.hpp>
23  #endif
24 #endif
25 
26 namespace Fw {
27 
43 class Buffer : public Fw::Serializable {
44 
45 public:
46 
47  enum {
48  SERIALIZED_SIZE = sizeof(U32) + sizeof(U32) + sizeof(U8*),
49  NO_CONTEXT = 0xFFFFFFFF
50  };
51 
56  Buffer();
57 
60  Buffer(const Buffer& src);
61 
69  Buffer(U8* data, U32 size, U32 context=NO_CONTEXT);
70 
73  Buffer& operator=(const Buffer& src);
74 
82  bool operator==(const Buffer& src) const;
83 
84  // ----------------------------------------------------------------------
85  // Serialization functions
86  // ----------------------------------------------------------------------
87 
95 
105 
115 
116 
117  // ----------------------------------------------------------------------
118  // Accessor functions
119  // ----------------------------------------------------------------------
120 
123  bool isValid() const;
124 
127  U8* getData() const;
128 
131  U32 getSize() const;
132 
135  U32 getContext() const;
136 
139  void setData(U8* data);
140 
143  void setSize(U32 size);
144 
147  void setContext(U32 context);
148 
153  void set(U8* data, U32 size, U32 context=NO_CONTEXT);
154 
155 #if FW_SERIALIZABLE_TO_STRING || BUILD_UT
157  void toString(Fw::StringBase& text) const;
158 #endif
159 
160 #ifdef BUILD_UT
163  friend std::ostream& operator<<(std::ostream& os, const Buffer& obj);
164 #endif
165 
166 PRIVATE:
167  Fw::ExternalSerializeBuffer m_serialize_repr; //<! Representation for serialization and deserialization functions
168  U8* m_bufferData; //<! data - A pointer to the data
169  U32 m_size; //<! size - The data size in bytes
170  U32 m_context;
171 
172 };
173 } // end namespace Fw
174 #endif /* BUFFER_HPP_ */
175 
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:30
C++-compatible configuration header for fprime configuration.
bool operator==(const Buffer &src) const
Definition: Buffer.cpp:60
U8 * getData() const
Definition: Buffer.cpp:68
void set(U8 *data, U32 size, U32 context=NO_CONTEXT)
Definition: Buffer.cpp:98
bool isValid() const
Definition: Buffer.cpp:64
Fw::SerializeStatus deserialize(Fw::SerializeBufferBase &buffer)
Definition: Buffer.cpp:134
U32 getSize() const
Definition: Buffer.cpp:72
void setData(U8 *data)
Definition: Buffer.cpp:80
void setContext(U32 context)
Definition: Buffer.cpp:94
Fw::SerializeStatus serialize(Fw::SerializeBufferBase &serialBuffer) const
Definition: Buffer.cpp:111
Buffer & operator=(const Buffer &src)
Definition: Buffer.cpp:52
void setSize(U32 size)
Definition: Buffer.cpp:87
U32 getContext() const
Definition: Buffer.cpp:76
@ NO_CONTEXT
Value representing no context.
Definition: Buffer.hpp:49
@ SERIALIZED_SIZE
Size of Fw::Buffer when serialized.
Definition: Buffer.hpp:48
SerializeBufferBase & getSerializeRepr()
Definition: Buffer.cpp:107
External serialize buffer with no copy semantics.
forward declaration
SerializeStatus
forward declaration for string