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 
53 class Buffer : public Fw::Serializable {
54  friend class Fw::BufferTester;
55 
56  public:
60  enum class OwnershipState {
61  NOT_OWNED,
62  OWNED,
63  };
64 
65  public:
68 
69  enum {
70  SERIALIZED_SIZE = 3 * sizeof(SizeType) + sizeof(U32) + sizeof(U8*),
71  NO_CONTEXT = 0xFFFFFFFF
72  };
73 
78  Buffer();
79 
82  Buffer(const Buffer& src);
83 
91  Buffer(U8* data, FwSizeType size, U32 context = NO_CONTEXT);
92 
95  Buffer& operator=(const Buffer& src);
96 
104  bool operator==(const Buffer& src) const;
105 
106  // ----------------------------------------------------------------------
107  // Serialization functions
108  // ----------------------------------------------------------------------
109 
116  DEPRECATED(LinearBufferBase& getSerializeRepr(), "Switch to .getSerializer() and .getDeserializer()");
117 
127 
134 
144  Fw::Endianness mode = Fw::Endianness::BIG) const;
145 
155 
156  // ----------------------------------------------------------------------
157  // Accessor functions
158  // ----------------------------------------------------------------------
159 
162  bool isValid() const;
163 
166  U8* getData() const;
167 
170  U8* getOriginalData() const;
171 
174  FwSizeType getSize() const;
175 
178  FwSizeType getCapacity() const;
179 
182  FwSizeType getOffset() const;
183 
186  U32 getContext() const;
187 
193  void advance(FwSignedSizeType amount);
194 
202  void setData(U8* data);
203 
208  void setSize(FwSizeType size);
209 
212  void setContext(U32 context);
213 
218  void set(U8* data, FwSizeType size, U32 context = NO_CONTEXT);
219 
220 #if FW_SERIALIZABLE_TO_STRING || BUILD_UT
221  void toString(Fw::StringBase& text) const;
223 #endif
224 
225 #ifdef BUILD_UT
226  friend std::ostream& operator<<(std::ostream& os, const Buffer& obj);
229 #endif
230 
231  private:
232  Fw::ExternalSerializeBuffer m_serialize_repr; //<! Representation for serialization and deserialization functions
233  U8* m_bufferData; //<! data - A pointer to the original allocation
234  FwSizeType m_offset; //<! offset - Offset of the current data within the allocation
235  FwSizeType m_size; //<! size - The data size in bytes
236  FwSizeType m_capacity; //<! capacity - Size of the original allocation in bytes
237  U32 m_context;
238 };
239 } // end namespace Fw
240 #endif /* BUFFER_HPP_ */
void setData(U8 *data)
Definition: Buffer.cpp:125
PlatformSizeType FwSizeType
void setContext(U32 context)
Definition: Buffer.cpp:140
void setSize(FwSizeType size)
Definition: Buffer.cpp:131
U32 getContext() const
Definition: Buffer.cpp:102
U8 * getData() const
Definition: Buffer.cpp:82
void advance(FwSignedSizeType amount)
Definition: Buffer.cpp:106
bool operator==(const Buffer &src) const
Definition: Buffer.cpp:73
PlatformSignedSizeType FwSignedSizeType
DEPRECATED(LinearBufferBase &getSerializeRepr(), "Switch to .getSerializer() and .getDeserializer()")
Fw::SerializeStatus deserializeFrom(Fw::SerialBufferBase &buffer, Fw::Endianness mode=Fw::Endianness::BIG)
Definition: Buffer.cpp:201
Fw::SerializeStatus serializeTo(Fw::SerialBufferBase &serialBuffer, Fw::Endianness mode=Fw::Endianness::BIG) const
Definition: Buffer.cpp:176
FwSizeType getCapacity() const
Definition: Buffer.cpp:94
The buffer is currently not owned.
SerializeStatus
forward declaration for string
ExternalSerializeBufferWithMemberCopy getDeserializer()
Definition: Buffer.cpp:165
Value representing no context.
Definition: Buffer.hpp:71
bool isValid() const
Definition: Buffer.cpp:78
External serialize buffer with no copy semantics.
FwSizeType getOffset() const
Definition: Buffer.cpp:98
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:54
FwSizeType getSize() const
Definition: Buffer.cpp:90
friend class Fw::BufferTester
Definition: Buffer.hpp:54
FwSizeType SizeType
The size type for a buffer - for backwards compatibility.
Definition: Buffer.hpp:67
OwnershipState
Definition: Buffer.hpp:60
External serialize buffer with member copy semantics.
The buffer is currently owned.
Implementation of malloc based allocator.
Endianness
ExternalSerializeBufferWithMemberCopy getSerializer()
Definition: Buffer.cpp:155
Size of Fw::Buffer when serialized.
Definition: Buffer.hpp:70
Buffer & operator=(const Buffer &src)
Definition: Buffer.cpp:58
Big endian serialization.
U8 * getOriginalData() const
Definition: Buffer.cpp:86