memio_impl.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //
  2. // Copyright (c) 2017-2026, Manticore Software LTD (https://manticoresearch.com)
  3. // Copyright (c) 2001-2016, Andrew Aksyonoff
  4. // Copyright (c) 2008-2016, Sphinx Technologies Inc
  5. // All rights reserved
  6. //
  7. // This program is free software; you can redistribute it and/or modify
  8. // it under the terms of the GNU General Public License. You should have
  9. // received a copy of the GPL license along with this program; if you
  10. // did not, you can find it at http://www.gnu.org
  11. //
  12. template<typename VECTOR>
  13. inline void GetArray ( VECTOR& dBuf, MemoryReader_c& tIn )
  14. {
  15. int iCount = tIn.GetDword();
  16. if ( !iCount )
  17. return;
  18. dBuf.Resize ( iCount );
  19. tIn.GetBytes ( dBuf.Begin(), (int)dBuf.GetLengthBytes() );
  20. }
  21. inline void GetArray ( CSphVector<CSphString>& dBuf, MemoryReader_c& tIn )
  22. {
  23. int iCount = tIn.GetDword();
  24. if ( !iCount )
  25. return;
  26. dBuf.Resize ( iCount );
  27. for ( CSphString& sVal : dBuf )
  28. sVal = tIn.GetString();
  29. }
  30. template<typename T>
  31. T GetVal ( MemoryReader_c& tReader )
  32. {
  33. T tVal;
  34. tReader.GetBytes ( &tVal, sizeof ( tVal ) );
  35. return tVal;
  36. }
  37. template<typename T>
  38. T MemoryReader_c::GetVal ()
  39. {
  40. return ::GetVal<T> (*this);
  41. }
  42. template<typename T>
  43. void MemoryReader_c::GetVal ( T& tVal )
  44. {
  45. tVal = GetVal<T>();
  46. }
  47. inline SphOffset_t MemoryReader_c::GetOffset()
  48. {
  49. return GetVal<SphOffset_t> ();
  50. }
  51. inline DWORD MemoryReader_c::GetDword()
  52. {
  53. return GetVal<DWORD> ();
  54. }
  55. template<typename T>
  56. void PutVal ( MemoryWriter_c& tWriter, T tVal )
  57. {
  58. tWriter.PutBytes ( (BYTE*)&tVal, sizeof ( tVal ) );
  59. }
  60. template<typename T>
  61. void MemoryWriter_c::PutVal ( T tVal )
  62. {
  63. ::PutVal ( *this, tVal );
  64. }
  65. inline void MemoryWriter_c::PutDword ( DWORD uVal )
  66. {
  67. PutVal ( uVal );
  68. }
  69. inline void MemoryWriter_c::PutOffset ( SphOffset_t uValue )
  70. {
  71. PutVal ( uValue );
  72. }
  73. inline void MemoryWriter_c::PutWord ( WORD uVal )
  74. {
  75. PutVal ( uVal );
  76. }
  77. inline void MemoryWriter_c::PutUint64 ( uint64_t uVal )
  78. {
  79. PutVal ( uVal );
  80. }
  81. template<typename T>
  82. inline void SaveArray ( const VecTraits_T<T>& dBuf, MemoryWriter_c& tOut )
  83. {
  84. tOut.PutDword ( dBuf.GetLength() );
  85. if ( dBuf.GetLength() )
  86. tOut.PutBytes ( dBuf.Begin(), dBuf.GetLengthBytes() );
  87. }
  88. inline void SaveArray ( const VecTraits_T<CSphString>& dBuf, MemoryWriter_c& tOut )
  89. {
  90. tOut.PutDword ( dBuf.GetLength() );
  91. for ( const CSphString& sVal : dBuf )
  92. tOut.PutString ( sVal );
  93. }