Remote Call Framework 3.3
QByteArray.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2022, Delta V Software. All rights reserved.
6 // https://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 under GPL terms.
12 //
13 // Version: 3.3
14 // Contact: support <at> deltavsoft.com
15 //
16 //******************************************************************************
17 
18 #ifndef INCLUDE_SF_QBYTEARRAY_HPP
19 #define INCLUDE_SF_QBYTEARRAY_HPP
20 
21 #include <QDataStream>
22 #include <QByteArray>
23 
24 #include <boost/config.hpp>
25 
26 #include <SF/Archive.hpp>
27 #include <SF/Stream.hpp>
28 
29 namespace SF {
30 
31  // QByteArray
32  inline void serializeQByteArray(SF::Archive & ar, QByteArray & qba)
33  {
34  if (ar.isRead())
35  {
36  std::uint32_t count = 0;
37  ar & count;
38 
39  qba.resize(count);
40 
41  if (count)
42  {
43  SF::IStream &is = *ar.getIstream();
44 
45  // Size field is verified, so read everything in one go.
46  if ( is.read((char *)qba.data(), count) != count )
47  {
48  RCF::Exception e(RCF::RcfError_SfReadFailure);
49  RCF_THROW(e);
50  }
51  }
52  }
53  else if (ar.isWrite())
54  {
55  std::uint32_t count = static_cast<std::uint32_t >(qba.size());
56  ar & count;
57  ar.getOstream()->writeRaw(qba.constData(), count);
58  }
59 
60  }
61 
62  // QByteArray
63  inline void serialize_vc6(SF::Archive & ar, QByteArray & qba, const unsigned int)
64  {
65  serializeQByteArray(ar, qba);
66  }
67 
68 
69  #define SERIALIZE_QT_OBJECT \
70  QByteArray data; \
71  if (ar.isRead()) \
72  { \
73  serializeQByteArray(ar, data); \
74  QDataStream qdsi(data); /*QIODevice::ReadOnly*/ \
75  qdsi >> qobj; \
76  } \
77  else if (ar.isWrite()) \
78  { \
79  QDataStream qdso(&data, QIODevice::ReadWrite); \
80  qdso << qobj; \
81  serializeQByteArray(ar, data); \
82  }
83 
84 
85 
86 } // namespace SF
87 
88 #endif // ! INCLUDE_SF_QBYTEARRAY_HPP
Represents an archive, in which serialized objects are stored.
Definition: Archive.hpp:31
Base class for all RCF exceptions.
Definition: Exception.hpp:67
Definition: ByteBuffer.hpp:188
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:137