MemoryRead.h 831 B

123456789101112131415161718
  1. #pragma once
  2. #include <stdint.h>
  3. #include <memory.h>
  4. // unaligned safe reading
  5. namespace il2cpp
  6. {
  7. namespace utils
  8. {
  9. static inline Il2CppChar ReadChar(const char* p) { Il2CppChar val; memcpy(&val, p, sizeof(Il2CppChar)); return val; }
  10. static inline uint16_t Read16(const char* p) { uint16_t val; memcpy(&val, p, sizeof(uint16_t)); return val; }
  11. static inline uint32_t Read32(const char* p) { uint32_t val; memcpy(&val, p, sizeof(uint32_t)); return val; }
  12. static inline uint64_t Read64(const char* p) { uint64_t val; memcpy(&val, p, sizeof(uint64_t)); return val; }
  13. static inline float ReadFloat(const char* p) { float val; memcpy(&val, p, sizeof(float)); return val; }
  14. static inline double ReadDouble(const char* p) { double val; memcpy(&val, p, sizeof(double)); return val; }
  15. } /* utils */
  16. } /* il2cpp */