Remote Call Framework 3.2
QByteArray.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2020, Delta V Software. All rights reserved.
6 // http://www.deltavsoft.com
7 //
8 // RCF is distributed under dual licenses - closed source or GPL.
9 // Consult your particular license for conditions of use.
10 //
11 // If you have not purchased a commercial license, you are using RCF
12 // under GPL terms.
13 //
14 // Version: 3.2
15 // Contact: support <at> deltavsoft.com
16 //
17 //******************************************************************************
18 
19 #ifndef INCLUDE_SF_QBYTEARRAY_HPP
20 #define INCLUDE_SF_QBYTEARRAY_HPP
21 
22 #include <QDataStream>
23 #include <QByteArray>
24 
25 #include <boost/config.hpp>
26 
27 #include <SF/Archive.hpp>
28 #include <SF/Stream.hpp>
29 
30 namespace SF {
31 
32  // QByteArray
33  inline void serializeQByteArray(SF::Archive & ar, QByteArray & qba)
34  {
35  if (ar.isRead())
36  {
37  std::uint32_t count = 0;
38  ar & count;
39 
40  qba.resize(count);
41 
42  if (count)
43  {
44  SF::IStream &is = *ar.getIstream();
45 
46  // Size field is verified, so read everything in one go.
47  if ( is.read((char *)qba.data(), count) != count )
48  {
49  RCF::Exception e(RCF::RcfError_SfReadFailure);
50  RCF_THROW(e);
51  }
52  }
53  }
54  else if (ar.isWrite())
55  {
56  std::uint32_t count = static_cast<std::uint32_t >(qba.size());
57  ar & count;
58  ar.getOstream()->writeRaw(qba.constData(), count);
59  }
60 
61  }
62 
63  // QByteArray
64  inline void serialize_vc6(SF::Archive & ar, QByteArray & qba, const unsigned int)
65  {
66  serializeQByteArray(ar, qba);
67  }
68 
69 
70  #define SERIALIZE_QT_OBJECT \
71  QByteArray data; \
72  if (ar.isRead()) \
73  { \
74  serializeQByteArray(ar, data); \
75  QDataStream qdsi(data); /*QIODevice::ReadOnly*/ \
76  qdsi >> qobj; \
77  } \
78  else if (ar.isWrite()) \
79  { \
80  QDataStream qdso(&data, QIODevice::ReadWrite); \
81  qdso << qobj; \
82  serializeQByteArray(ar, data); \
83  }
84 
85 
86 
87 } // namespace SF
88 
89 #endif // ! INCLUDE_SF_QBYTEARRAY_HPP
Represents an archive, in which serialized objects are stored.
Definition: Archive.hpp:32
Base class for all RCF exceptions.
Definition: Exception.hpp:64
Definition: ByteBuffer.hpp:189
bool isWrite() const
Returns true if this archive is being written to.
bool isRead() const
Returns true if this archive is being read from.
Base class for input streams using SF serialization. Use operator >>() to deserialize objects from th...
Definition: Stream.hpp:138