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:
54  enum class OwnershipState {
55  NOT_OWNED,
56  OWNED,
57  };
58 
59  public:
62 
63  enum {
64  SERIALIZED_SIZE = sizeof(SizeType) + sizeof(U32) + sizeof(U8*),
65  NO_CONTEXT = 0xFFFFFFFF
66  };
67 
72  Buffer();
73 
76  Buffer(const Buffer& src);
77 
85  Buffer(U8* data, FwSizeType size, U32 context = NO_CONTEXT);
86 
89  Buffer& operator=(const Buffer& src);
90 
98  bool operator==(const Buffer& src) const;
99 
100  // ----------------------------------------------------------------------
101  // Serialization functions
102  // ----------------------------------------------------------------------
103 
110  DEPRECATED(SerializeBufferBase& getSerializeRepr(), "Switch to .getSerializer() and .getDeserializer()");
111 
121 
128 
138  Fw::Endianness mode = Fw::Endianness::BIG) const;
139 
149 
150  // ----------------------------------------------------------------------
151  // Accessor functions
152  // ----------------------------------------------------------------------
153 
156  bool isValid() const;
157 
160  U8* getData() const;
161 
164  FwSizeType getSize() const;
165 
168  U32 getContext() const;
169 
172  void setData(U8* data);
173 
176  void setSize(FwSizeType size);
177 
180  void setContext(U32 context);
181 
186  void set(U8* data, FwSizeType size, U32 context = NO_CONTEXT);
187 
188 #if FW_SERIALIZABLE_TO_STRING || BUILD_UT
189  void toString(Fw::StringBase& text) const;
191 #endif
192 
193 #ifdef BUILD_UT
194  friend std::ostream& operator<<(std::ostream& os, const Buffer& obj);
197 #endif
198 
199  private:
200  Fw::ExternalSerializeBuffer m_serialize_repr; //<! Representation for serialization and deserialization functions
201  U8* m_bufferData; //<! data - A pointer to the data
202  FwSizeType m_size; //<! size - The data size in bytes
203  U32 m_context;
204 };
205 } // end namespace Fw
206 #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 deserializeFrom(Fw::SerialBufferBase &buffer, Fw::Endianness mode=Fw::Endianness::BIG)
Definition: Buffer.cpp:139
Fw::SerializeStatus serializeTo(Fw::SerialBufferBase &serialBuffer, Fw::Endianness mode=Fw::Endianness::BIG) const
Definition: Buffer.cpp:116
The buffer is currently not owned.
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.
Size of Fw::Buffer when serialized.
Definition: Buffer.hpp:64
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:53
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:61
OwnershipState
Definition: Buffer.hpp:54
External serialize buffer with member copy semantics.
The buffer is currently owned.
Implementation of malloc based allocator.
Endianness
Value representing no context.
Definition: Buffer.hpp:65
ExternalSerializeBufferWithMemberCopy getSerializer()
Definition: Buffer.cpp:95
Buffer & operator=(const Buffer &src)
Definition: Buffer.cpp:39
Big endian serialization.