Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
2.6 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 2000.
  5. //
  6. // File: SizeSer.cxx
  7. //
  8. // Contents: Class to compute size of serialized structure.
  9. //
  10. // History: 28-Jul-94 KyleP Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #include <pch.cxx>
  14. #pragma hdrstop
  15. #include <sizeser.hxx>
  16. CSizeSerStream::CSizeSerStream()
  17. : _cb( 0 )
  18. {
  19. }
  20. CSizeSerStream::~CSizeSerStream()
  21. {
  22. }
  23. void CSizeSerStream::PutByte( BYTE b )
  24. {
  25. Win4Assert( sizeof(BYTE) == 1 );
  26. _cb += 1;
  27. }
  28. void CSizeSerStream::PutChar( char const * pc, ULONG cc )
  29. {
  30. Win4Assert( sizeof(char) == 1 );
  31. _cb += cc;
  32. }
  33. void CSizeSerStream::PutWChar( WCHAR const * pwc, ULONG cc )
  34. {
  35. Win4Assert( sizeof(WCHAR) == 2 );
  36. _cb = (unsigned)((ULONG_PTR)AlignWCHAR((BYTE *) UIntToPtr( _cb ) )) + sizeof(WCHAR) * cc;
  37. }
  38. void CSizeSerStream::PutUShort( USHORT us )
  39. {
  40. Win4Assert( sizeof(USHORT) == 2 );
  41. _cb = (unsigned)((ULONG_PTR)AlignUSHORT((BYTE *) UIntToPtr( _cb ) )) + sizeof(USHORT);
  42. }
  43. void CSizeSerStream::PutULong( ULONG ul )
  44. {
  45. Win4Assert( sizeof(ULONG) == 4 );
  46. _cb = (unsigned)((ULONG_PTR)AlignULONG((BYTE *) UIntToPtr( _cb ) )) + sizeof(ULONG);
  47. }
  48. void CSizeSerStream::PutLong( long l )
  49. {
  50. Win4Assert( sizeof(long) == 4 );
  51. _cb = (unsigned)((ULONG_PTR)AlignLong((BYTE *) UIntToPtr( _cb ) )) + sizeof(long);
  52. }
  53. void CSizeSerStream::PutFloat( float f )
  54. {
  55. Win4Assert( sizeof(float) == 4 );
  56. _cb = (unsigned)((ULONG_PTR)AlignFloat((BYTE *) UIntToPtr( _cb ) )) + sizeof(float);
  57. }
  58. void CSizeSerStream::PutDouble( double d )
  59. {
  60. Win4Assert( sizeof(double) == 8 );
  61. _cb = (unsigned)((ULONG_PTR)AlignDouble((BYTE *) UIntToPtr( _cb ) )) + sizeof(double);
  62. }
  63. void CSizeSerStream::PutString( char const * psz )
  64. {
  65. Win4Assert( sizeof(char) == 1 );
  66. Win4Assert( sizeof(ULONG) == 4 );
  67. _cb = (unsigned)((ULONG_PTR)AlignULONG((BYTE *) UIntToPtr( _cb ) )) + sizeof(ULONG) + strlen(psz);
  68. }
  69. void CSizeSerStream::PutWString( WCHAR const * pwsz )
  70. {
  71. Win4Assert( sizeof(WCHAR) == 2 );
  72. Win4Assert( sizeof(ULONG) == 4 );
  73. _cb = (unsigned)((ULONG_PTR)AlignULONG((BYTE *) UIntToPtr( _cb ) )) + sizeof(ULONG) +
  74. wcslen(pwsz) * sizeof(WCHAR);
  75. }
  76. void CSizeSerStream::PutBlob( BYTE const * pb, ULONG cb )
  77. {
  78. Win4Assert( sizeof(BYTE) == 1 );
  79. _cb += cb;
  80. }
  81. void CSizeSerStream::PutGUID( GUID const & guid )
  82. {
  83. Win4Assert( sizeof(GUID) == 16 );
  84. _cb = (unsigned)((ULONG_PTR)AlignGUID((BYTE *) UIntToPtr( _cb ) )) + sizeof(GUID);
  85. }