summaryrefslogtreecommitdiffstats
path: root/Master/Masterarbeit/src/common/inc/CNetworkStream.h
diff options
context:
space:
mode:
authorSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
committerSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
commit33613a85afc4b1481367fbe92a17ee59c240250b (patch)
tree670b842326116b376b505ec2263878912fca97e2 /Master/Masterarbeit/src/common/inc/CNetworkStream.h
downloadStudium-master.tar.gz
Studium-master.tar.bz2
add new repoHEADmaster
Diffstat (limited to 'Master/Masterarbeit/src/common/inc/CNetworkStream.h')
-rw-r--r--Master/Masterarbeit/src/common/inc/CNetworkStream.h189
1 files changed, 189 insertions, 0 deletions
diff --git a/Master/Masterarbeit/src/common/inc/CNetworkStream.h b/Master/Masterarbeit/src/common/inc/CNetworkStream.h
new file mode 100644
index 0000000..2b94e71
--- /dev/null
+++ b/Master/Masterarbeit/src/common/inc/CNetworkStream.h
@@ -0,0 +1,189 @@
+/*!
+ * \file CNetworkStream.h
+ * \author S. Eisenhauer
+ * \date 12.01.2012
+ * \brief Stream access to network data buffers
+ *
+ * This file defines classes for accessing the data stored in networked buffers as streams
+ *
+ */
+#ifndef CNETWORKSTREAM_H_
+#define CNETWORKSTREAM_H_
+
+#include "global.h"
+#include "protocol.h"
+
+/// enumeration of stream errors
+enum tenStreamError
+{
+ nenStreamOK = 0, //!< stream is ok
+ nenErrorValueOutOfRange = -1, //!< a value in the stream is out of the configured min. max. range
+ nenErrorStreamToShort = -2 //!< no bytes left in stream for reading or writing
+};
+
+/*!
+ * \brief class for read access to a data buffer as stream
+ */
+class CNetworkInStream
+{
+public:
+ /*!
+ * \brief constructor
+ * \param[in] pu8Buffer Pointer to the buffer which is handled by the stream
+ * \param[in] u32BufferSize Size of the buffer in bytes
+ */
+ CNetworkInStream(uint8_t* pu8Buffer, uint32_t u32BufferSize);
+ /*!
+ * \brief read a signed 8 bit integer from the stream
+ * \param[out] i8Val Reference to storage for the value
+ */
+ void vReadInt8(int8_t& i8Val);
+ /*!
+ * \brief read a unsigned 8 bit integer from the stream
+ * \param[out] u8Val Reference to storage for the value
+ */
+ void vReadUint8(uint8_t& u8Val);
+ /*!
+ * \brief read a signed 32 bit integer from the stream
+ * \param[out] i32Val Reference to storage for the value
+ */
+ void vReadInt32(int32_t& i32Val);
+ /*!
+ * \brief read a unsigned 32 bit integer from the stream
+ * \param[out] u32Val Reference to storage for the value
+ */
+ void vReadUint32(uint32_t& u32Val);
+ /*!
+ * \brief read a string from the stream
+ * \param[out] pcVal Reference to storage for the value
+ * \param[in] u32Length Length of the expected string
+ */
+ void vReadString(char* pcVal, const uint32_t u32Length);
+ /*!
+ * \brief get number of bytes used in stream
+ * \return number of bytes used in stream
+ */
+ uint32_t u32GetByteCount() const;
+ /*!
+ * \brief set stream to a position
+ * \param[in] u32Offset position to set stream to as offset from start position (=0)
+ */
+ void vSetPosition(const uint32_t u32Offset);
+ /*!
+ * \brief check if stream is OK
+ * \return TRUE if no error is set for stream, FALSE otherwise
+ */
+ bool boIsOK() const;
+ /*!
+ * \brief get error of stream
+ * \param[out] enError stream error code
+ */
+ void vGetError(tenStreamError& enError) const;
+ /*!
+ * \brief set error code of stream
+ * \param[in] enError error to set for stream
+ */
+ void vSetError(tenStreamError enError);
+ /*!
+ * \brief reset stream. Set position to start and error to nenStreamOK
+ */
+ void vReset();
+private:
+ CNetworkInStream(const CNetworkInStream& rxOther);
+ CNetworkInStream& operator= (const CNetworkInStream& rxOther);
+ /*!
+ * \brief checks that a sufficient number of bytes is left in the stream
+ * \param[in] u32Length number of bytes to check the stream for
+ */
+ bool boCheck(const uint32_t u32Length);
+
+ const uint8_t* m_pu8CurrentPtr;
+ const uint8_t* const m_pru8StartPtr;
+ const uint8_t* const m_pru8EndPtr;
+ tenStreamError m_enError;
+};
+
+/*!
+ * \brief class for write access to a data buffer as stream
+ */
+class CNetworkOutStream
+{
+public:
+ /*!
+ * \brief constructor
+ * \param[in] pu8Buffer Pointer to the buffer which is handled by the stream
+ * \param[in] u32BufferSize Size of the buffer in bytes
+ */
+ CNetworkOutStream(uint8_t* pu8Buffer, uint32_t u32BufferSize);
+ /*!
+ * \brief write a signed 8 bit integer to the stream
+ * \param[in] i8Val Reference to the value to write to the stream
+ */
+ void vWriteInt8(const int8_t i8Val);
+ /*!
+ * \brief write a unsigned 8 bit integer to the stream
+ * \param[in] u8Val Reference to the value to write to the stream
+ */
+ void vWriteUint8(const uint8_t u8Val);
+ /*!
+ * \brief write a signed 32 bit integer to the stream
+ * \param[in] i32Val Reference to the value to write to the stream
+ */
+ void vWriteInt32(const int32_t i32Val);
+ /*!
+ * \brief write a unsigned 32 bit integer to the stream
+ * \param[in] u32Val Reference to the value to write to the stream
+ */
+ void vWriteUint32(const uint32_t u32Val);
+ /*!
+ * \brief write a string to the stream
+ * \param[in] pcVal string to write to the stream
+ * \param[in] u32Length Length of the string
+ */
+ void vWriteString(const char* pcVal, const uint32_t u32Length);
+ /*!
+ * \brief get number of bytes used in stream
+ * \return number of bytes used in stream
+ */
+ uint32_t u32GetByteCount() const;
+ /*!
+ * \brief set stream to a position
+ * \param[in] u32Offset position to set stream to as offset from start position (=0)
+ */
+ void vSetPosition(const uint32_t u32Offset);
+ /*!
+ * \brief check if stream is OK
+ * \return TRUE if no error is set for stream, FALSE otherwise
+ */
+ bool boIsOK() const;
+ /*!
+ * \brief get error of stream
+ * \param[out] enError stream error code
+ */
+ void vGetError(tenStreamError& enError) const;
+ /*!
+ * \brief set error code of stream
+ * \param[in] enError error to set for stream
+ */
+ void vSetError(tenStreamError enError);
+ /*!
+ * \brief reset stream. Set position to start and error to nenStreamOK
+ */
+ void vReset();
+private:
+ CNetworkOutStream(const CNetworkOutStream& rxOther);
+ CNetworkOutStream& operator= (const CNetworkOutStream& rxOther);
+
+ /*!
+ * \brief checks that a sufficient number of bytes is left in the stream
+ * \param[in] u32Length number of bytes to check the stream for
+ */
+ bool boCheck(const uint32_t u32Length);
+
+ uint8_t* m_pu8CurrentPtr;
+ const uint8_t* const m_pru8StartPtr;
+ const uint8_t* const m_pru8EndPtr;
+ tenStreamError m_enError;
+};
+
+#endif /*CNETWORKSTREAM_H_*/