I2PEndian.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #include "I2PEndian.h"
  2. // http://habrahabr.ru/post/121811/
  3. // http://codepad.org/2ycmkz2y
  4. #include "LittleBigEndian.h"
  5. #ifdef NEEDS_LOCAL_ENDIAN
  6. uint16_t htobe16(uint16_t int16)
  7. {
  8. BigEndian<uint16_t> u16(int16);
  9. return u16.raw_value;
  10. }
  11. uint32_t htobe32(uint32_t int32)
  12. {
  13. BigEndian<uint32_t> u32(int32);
  14. return u32.raw_value;
  15. }
  16. uint64_t htobe64(uint64_t int64)
  17. {
  18. BigEndian<uint64_t> u64(int64);
  19. return u64.raw_value;
  20. }
  21. uint16_t be16toh(uint16_t big16)
  22. {
  23. LittleEndian<uint16_t> u16(big16);
  24. return u16.raw_value;
  25. }
  26. uint32_t be32toh(uint32_t big32)
  27. {
  28. LittleEndian<uint32_t> u32(big32);
  29. return u32.raw_value;
  30. }
  31. uint64_t be64toh(uint64_t big64)
  32. {
  33. LittleEndian<uint64_t> u64(big64);
  34. return u64.raw_value;
  35. }
  36. #endif
  37. /* it can be used in Windows 8
  38. #include <Winsock2.h>
  39. uint16_t htobe16(uint16_t int16)
  40. {
  41. return htons(int16);
  42. }
  43. uint32_t htobe32(uint32_t int32)
  44. {
  45. return htonl(int32);
  46. }
  47. uint64_t htobe64(uint64_t int64)
  48. {
  49. // http://msdn.microsoft.com/en-us/library/windows/desktop/jj710199%28v=vs.85%29.aspx
  50. //return htonll(int64);
  51. return 0;
  52. }
  53. uint16_t be16toh(uint16_t big16)
  54. {
  55. return ntohs(big16);
  56. }
  57. uint32_t be32toh(uint32_t big32)
  58. {
  59. return ntohl(big32);
  60. }
  61. uint64_t be64toh(uint64_t big64)
  62. {
  63. // http://msdn.microsoft.com/en-us/library/windows/desktop/jj710199%28v=vs.85%29.aspx
  64. //return ntohll(big64);
  65. return 0;
  66. }
  67. */