aboutsummaryrefslogtreecommitdiff
path: root/c++-qt/src/gatsstream.h
blob: f1c0625d8f17e244d2318c16f6aceed0a1f718a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef GATS_STREAM_H
#define GATS_STREAM_H

#include <QIODevice>
#include <QByteArray>

namespace Gats
{
	class Object;

	class GatsStream : public QObject
	{
		Q_OBJECT;
	public:
		GatsStream( QIODevice &rStream );
		virtual ~GatsStream();

	public slots:
		/**
		 * Read an object packet from the assosiated stream.  This will make
		 * every effort to only read exactly enough data to describe one packet,
		 * in case you want to do other things with your stream.  It will
		 * automatically skip NULL byte spacing between packets, which makes
		 * a convinient padding method for encrypted data streams.  Since
		 * sizing information is available in the packet header exact amounts
		 * of data can be read, however this function doesn't assume that it
		 * can read the entire object in one operation.  If it fails to read
		 * a complete packet in one call, it will keep the data it's read so
		 * far buffered and return NULL, ready for another attempt.  You can
		 * use the function hasReadBuffer() to deterimne if readObject()
		 * has read part of an object packet or not.  If readObject returns
		 * non-null then hasReadBuffer should return false on it's next call.
		 */
		Gats::Object *readObject();

	public:
		/**
		 * Write an object 
		 */
		void writeObject( Gats::Object *pObject );

		/**
		 * Tells you if there is data still in the read buffer, i.e. that a
		 * packet is part way through being read.  If readObject has returned
		 * non-null in the most recent call, this should always be false.
		 */
		bool hasReadBuffer() { return qbRead.size() > 0; }
		int getReadBufferSize() { return qbRead.size(); }

		QIODevice &getIODevice() { return rStream; }

	signals:
		void objectRead( Gats::Object *pObj );

	private:
		bool skipReadNulls();

	private:
		QIODevice &rStream;
		QByteArray qbRead;
	};
};

#endif