中间件底层,websocket

SerializeArray.hpp 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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_SERIALIZEARRAY_HPP
  18. #define INCLUDE_SF_SERIALIZEARRAY_HPP
  19. #include <cstddef>
  20. #include <RCF/Exception.hpp>
  21. #include <SF/Archive.hpp>
  22. namespace SF {
  23. class Archive;
  24. // Serialization for boost::array<>, std::array<>, etc.
  25. template<typename ArrayType>
  26. void serialize_array_impl(SF::Archive & ar, ArrayType & a)
  27. {
  28. if (ar.isRead())
  29. {
  30. unsigned int count = 0;
  31. ar & count;
  32. if ( static_cast<std::size_t>(count) != a.size() )
  33. {
  34. RCF::Exception e(RCF::RcfError_ArraySizeMismatch, a.size(), count);
  35. RCF_THROW(e);
  36. }
  37. for (std::size_t i=0; i<a.size(); ++i)
  38. {
  39. ar & a[i];
  40. }
  41. }
  42. else if (ar.isWrite())
  43. {
  44. unsigned int count = static_cast<unsigned int>(a.size());
  45. ar & count;
  46. for (std::size_t i=0; i<a.size(); ++i)
  47. {
  48. ar & a[i];
  49. }
  50. }
  51. }
  52. } // namespace SF
  53. #endif // ! INCLUDE_SF_SERIALIZEARRAY_HPP