F´ Flight Software - C/C++ Documentation NASA-v1.6.0
A framework for building embedded system applications to NASA flight quality standards.
Loading...
Searching...
No Matches
Serializable.hpp
Go to the documentation of this file.
1#ifndef SERIALIZABLE_HPP
2#define SERIALIZABLE_HPP
3
4#ifdef BUILD_UT
5#include <iostream>
6#endif
7
8#include <FpConfig.hpp>
9
10namespace Fw {
11
12 class StringBase;
13 typedef enum {
22 class SerializeBufferBase;
23
25 public:
26 virtual SerializeStatus serialize(SerializeBufferBase& buffer) const = 0;
28#if FW_SERIALIZABLE_TO_STRING || FW_ENABLE_TEXT_LOGGING || BUILD_UT
29 virtual void toString(StringBase& text) const;
30#endif
31
32#ifdef BUILD_UT
33 friend std::ostream& operator<<(std::ostream& os, const Serializable& val);
34#endif
35
36 protected:
37 Serializable();
38 virtual ~Serializable();
39 };
40
42 public:
43
45
46 virtual ~SerializeBufferBase();
47
48 // Serialization for built-in types
49
52
53#if FW_HAS_16_BIT==1
54 SerializeStatus serialize(U16 val);
55 SerializeStatus serialize(I16 val);
56#endif
57#if FW_HAS_32_BIT==1
58 SerializeStatus serialize(U32 val);
59 SerializeStatus serialize(I32 val);
60#endif
61#if FW_HAS_64_BIT==1
63 SerializeStatus serialize(I64 val);
64#endif
66#if FW_HAS_F64
67 SerializeStatus serialize(F64 val);
68#endif
69 SerializeStatus serialize(bool val);
70
71 SerializeStatus serialize(const void* val);
72
73 SerializeStatus serialize(const U8* buff, NATIVE_UINT_TYPE length, bool noLength = false);
74
76
78
79 // Deserialization for built-in types
80
83
84#if FW_HAS_16_BIT==1
87#endif
88
89#if FW_HAS_32_BIT==1
92#endif
93#if FW_HAS_64_BIT==1
96#endif
98#if FW_HAS_F64
100#endif
101 SerializeStatus deserialize(bool &val);
102
103 SerializeStatus deserialize(void*& val);
104
105 // length should be set to max, returned value is actual size stored. If noLength
106 // is true, use the length variable as the actual number of bytes to deserialize
107 SerializeStatus deserialize(U8* buff, NATIVE_UINT_TYPE& length, bool noLength = false);
108 // serialize/deserialize Serializable
109
110
112
114
115 void resetSer();
116 void resetDeser();
117
119 virtual NATIVE_UINT_TYPE getBuffCapacity() const = 0;
122 virtual U8* getBuffAddr() = 0;
123 virtual const U8* getBuffAddr() const = 0;
124 const U8* getBuffAddrLeft() const;
125 U8* getBuffAddrSer();
126 SerializeStatus setBuff(const U8* src, NATIVE_UINT_TYPE length);
129 // Will increment deserialization pointer
131 // Will increment deserialization pointer
132
133
134#ifdef BUILD_UT
135 bool operator==(const SerializeBufferBase& other) const;
136 friend std::ostream& operator<<(std::ostream& os, const SerializeBufferBase& buff);
137#endif
138 PROTECTED:
139
141
142 PRIVATE:
143 // A no-implementation copy constructor here will prevent the default copy constructor from being called
144 // accidentally, and without an implementation it will create an error for the developer instead.
146
147 void copyFrom(const SerializeBufferBase& src);
148 NATIVE_UINT_TYPE m_serLoc;
149 NATIVE_UINT_TYPE m_deserLoc;
150 };
151
152 // Helper class for building buffers with external storage
153
155 public:
158 void setExtBuffer(U8* buffPtr, NATIVE_UINT_TYPE size);
159 void clear();
160
161 // pure virtual functions
163 U8* getBuffAddr();
164 const U8* getBuffAddr() const ;
165
166 PRIVATE:
167
168 // no copying
171
172 // private data
173 U8* m_buff;
174 NATIVE_UINT_TYPE m_buffSize;
175 };
176
177}
178#endif
int8_t I8
8-bit signed integer
Definition BasicTypes.h:25
float F32
32-bit floating point
Definition BasicTypes.h:45
uint8_t U8
8-bit unsigned integer
Definition BasicTypes.h:26
PlatformUIntType NATIVE_UINT_TYPE
Definition BasicTypes.h:52
C++-compatible configuration header for fprime configuration.
NATIVE_UINT_TYPE getBuffCapacity() const
returns capacity, not current size, of buffer
U8 * getBuffAddr()
gets buffer address for data filling
void setExtBuffer(U8 *buffPtr, NATIVE_UINT_TYPE size)
Set the external buffer.
void clear()
clear external buffer
ExternalSerializeBuffer()
default constructor
forward declaration
Serializable()
Default constructor.
virtual ~Serializable()
destructor
virtual SerializeStatus deserialize(SerializeBufferBase &buffer)=0
deserialize to contents
virtual SerializeStatus serialize(SerializeBufferBase &buffer) const =0
serialize contents
NATIVE_UINT_TYPE getBuffLeft() const
returns how much deserialization buffer is left
void resetDeser()
reset deserialization to beginning
SerializeStatus setBuffLen(NATIVE_UINT_TYPE length)
sets buffer length manually after filling with data
const U8 * getBuffAddrLeft() const
gets address of remaining non-deserialized data.
void resetSer()
reset to beginning of buffer to reuse for serialization
SerializeBufferBase()
default constructor
SerializeStatus setBuff(const U8 *src, NATIVE_UINT_TYPE length)
sets buffer contents and size
SerializeStatus deserializeSkip(NATIVE_UINT_TYPE numBytesToSkip)
Skips the number of specified bytes for deserialization.
SerializeBufferBase & operator=(const SerializeBufferBase &src)
equal operator
virtual const U8 * getBuffAddr() const =0
gets buffer address for data reading, const version
virtual NATIVE_UINT_TYPE getBuffCapacity() const =0
returns capacity, not current size, of buffer
SerializeStatus deserialize(U8 &val)
deserialize 8-bit unsigned int
virtual ~SerializeBufferBase()
destructor
U8 * getBuffAddrSer()
gets address of end of serialization. DANGEROUS! Need to know max buffer size and adjust when done
SerializeStatus serialize(U8 val)
serialize 8-bit unsigned int
SerializeStatus copyRawOffset(SerializeBufferBase &dest, NATIVE_UINT_TYPE size)
directly copies buffer without looking for a size in the stream.
SerializeStatus copyRaw(SerializeBufferBase &dest, NATIVE_UINT_TYPE size)
directly copies buffer without looking for a size in the stream.
virtual U8 * getBuffAddr()=0
gets buffer address for data filling
NATIVE_UINT_TYPE getBuffLength() const
returns current buffer size
Definition Buffer.cpp:21
SerializeStatus
forward declaration for string
@ FW_DESERIALIZE_FORMAT_ERROR
Deserialization data had incorrect values (unexpected data types)
@ FW_DESERIALIZE_BUFFER_EMPTY
Deserialization buffer was empty when trying to read more data.
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.
@ FW_SERIALIZE_FORMAT_ERROR
Data was the wrong format (e.g. wrong packet type)
@ FW_DESERIALIZE_TYPE_MISMATCH
Deserialized type ID didn't match.
@ FW_DESERIALIZE_SIZE_MISMATCH
Data was left in the buffer, but not enough to deserialize.
@ FW_SERIALIZE_NO_ROOM_LEFT
No room left in the buffer to serialize data.
#define U64(C)
Definition sha.h:176