中间件底层,websocket

QByteArray.hpp 2.6KB

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