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.

35 lines
891 B

4 years ago
  1. #pragma once
  2. #include <cstring>
  3. #include "CArrayBuffer.h"
  4. typedef unsigned short uint16;
  5. typedef float float32;
  6. class CDataView {
  7. public:
  8. CArrayBuffer* buffer;
  9. int byteOffset;
  10. int byteLength;
  11. CDataView(CArrayBuffer* pBuffer, int byteOffset, int byteLength) {
  12. this->buffer = pBuffer;
  13. this->byteOffset = byteOffset;
  14. this->byteLength = byteLength;
  15. }
  16. void setFloat32(int offset, float32 value) {
  17. memcpy(this->buffer->pData + (this->byteOffset + offset), &value, sizeof(float32));
  18. }
  19. float32 getFloat32(int offset) {
  20. return *((float32*)(this->buffer->pData + (this->byteOffset + offset)));
  21. }
  22. void setUint16(int offset, uint16 value) {
  23. memcpy(this->buffer->pData + (this->byteOffset + offset), &value, sizeof(uint16));
  24. }
  25. uint16 getUint16(int offset) {
  26. return *((uint16*)(this->buffer->pData + (this->byteOffset + offset)));
  27. }
  28. };