中间件底层,websocket

SerializeFundamental.hpp 1.9KB

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_SERIALIZEFUNDAMENTAL_HPP
  18. #define INCLUDE_SF_SERIALIZEFUNDAMENTAL_HPP
  19. #include <SF/Archive.hpp>
  20. #include <SF/DataPtr.hpp>
  21. #include <SF/I_Stream.hpp>
  22. #include <SF/Stream.hpp>
  23. #include <RCF/Tools.hpp>
  24. namespace SF {
  25. // serialize fundamental types
  26. template<typename T>
  27. inline void serializeFundamental(
  28. SF::Archive &ar,
  29. T &t,
  30. unsigned int count = 1)
  31. {
  32. typedef typename RCF::RemoveCv<T>::type U;
  33. static_assert( RCF::IsFundamental<U>::value, "" );
  34. U * pt = const_cast<U *>(&t);
  35. if (ar.isRead())
  36. {
  37. I_Encoding &encoding = ar.getIstream()->getEncoding();
  38. DataPtr data;
  39. ar.getIstream()->get(data);
  40. if (count > 1 && count != encoding.getCount(data, pt) )
  41. {
  42. // static array size mismatch
  43. RCF::Exception e(RCF::RcfError_SfDataFormat);
  44. RCF_THROW(e);
  45. }
  46. encoding.toObject(data, pt, count);
  47. }
  48. else if (ar.isWrite())
  49. {
  50. I_Encoding &encoding = ar.getOstream()->getEncoding();
  51. DataPtr data;
  52. encoding.toData(data, pt, count );
  53. ar.getOstream()->put(data);
  54. }
  55. }
  56. } // namespace SF
  57. #endif // ! INCLUDE_SF_SERIALIZEFUNDAMENTAL_HPP