CheckSum.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. ///
  11. /// \file CheckSum.cpp
  12. /// \brief [Internal] CheckSum implementation from http://www.flounder.com/checksum.htm
  13. ///
  14. #ifndef __CHECKSUM_H
  15. #define __CHECKSUM_H
  16. #include "RakMemoryOverride.h"
  17. /// Generates and validates checksums
  18. class CheckSum
  19. {
  20. public:
  21. /// Default constructor
  22. CheckSum()
  23. {
  24. Clear();
  25. }
  26. void Clear()
  27. {
  28. sum = 0;
  29. r = 55665;
  30. c1 = 52845;
  31. c2 = 22719;
  32. }
  33. void Add ( unsigned int w );
  34. void Add ( unsigned short w );
  35. void Add ( unsigned char* b, unsigned int length );
  36. void Add ( unsigned char b );
  37. unsigned int Get ()
  38. {
  39. return sum;
  40. }
  41. protected:
  42. unsigned short r;
  43. unsigned short c1;
  44. unsigned short c2;
  45. unsigned int sum;
  46. };
  47. #endif
粤ICP备19079148号