| 1509 | /// The DataView provides a low-level interface for reading/writing multiple |
| 1510 | /// number types in an ArrayBuffer irrespective of the platform's endianness. |
| 1511 | class DataView : public Object { |
| 1512 | public: |
| 1513 | static DataView New(napi_env env, Napi::ArrayBuffer arrayBuffer); |
| 1514 | static DataView New(napi_env env, |
| 1515 | Napi::ArrayBuffer arrayBuffer, |
| 1516 | size_t byteOffset); |
| 1517 | static DataView New(napi_env env, |
| 1518 | Napi::ArrayBuffer arrayBuffer, |
| 1519 | size_t byteOffset, |
| 1520 | size_t byteLength); |
| 1521 | |
| 1522 | #ifdef NODE_API_EXPERIMENTAL_HAS_SHAREDARRAYBUFFER |
| 1523 | static DataView New(napi_env env, Napi::SharedArrayBuffer arrayBuffer); |
| 1524 | static DataView New(napi_env env, |
| 1525 | Napi::SharedArrayBuffer arrayBuffer, |
| 1526 | size_t byteOffset); |
| 1527 | static DataView New(napi_env env, |
| 1528 | Napi::SharedArrayBuffer arrayBuffer, |
| 1529 | size_t byteOffset, |
| 1530 | size_t byteLength); |
| 1531 | #endif |
| 1532 | |
| 1533 | static void CheckCast(napi_env env, napi_value value); |
| 1534 | |
| 1535 | DataView(); ///< Creates a new _empty_ DataView instance. |
| 1536 | DataView(napi_env env, |
| 1537 | napi_value value); ///< Wraps a Node-API value primitive. |
| 1538 | |
| 1539 | // Gets the backing `ArrayBuffer`. |
| 1540 | // |
| 1541 | // If this `DataView` is not backed by an `ArrayBuffer`, this method will |
| 1542 | // terminate the process with a fatal error when using |
| 1543 | // `NODE_ADDON_API_ENABLE_TYPE_CHECK_ON_AS` or exhibit undefined behavior |
| 1544 | // otherwise. Use `Buffer()` instead to get the backing buffer without |
| 1545 | // assuming its type. |
| 1546 | Napi::ArrayBuffer ArrayBuffer() const; |
| 1547 | |
| 1548 | // Gets the backing buffer (an `ArrayBuffer` or `SharedArrayBuffer`). |
| 1549 | // |
| 1550 | // Use `IsArrayBuffer()` or `IsSharedArrayBuffer()` to check the type of the |
| 1551 | // backing buffer prior to casting with `As<T>()`. |
| 1552 | Napi::Value Buffer() const; |
| 1553 | size_t ByteOffset() |
| 1554 | const; ///< Gets the offset into the buffer where the array starts. |
| 1555 | size_t ByteLength() const; ///< Gets the length of the array in bytes. |
| 1556 | |
| 1557 | void* Data() const; |
| 1558 | |
| 1559 | float GetFloat32(size_t byteOffset) const; |
| 1560 | double GetFloat64(size_t byteOffset) const; |
| 1561 | int8_t GetInt8(size_t byteOffset) const; |
| 1562 | int16_t GetInt16(size_t byteOffset) const; |
| 1563 | int32_t GetInt32(size_t byteOffset) const; |
| 1564 | uint8_t GetUint8(size_t byteOffset) const; |
| 1565 | uint16_t GetUint16(size_t byteOffset) const; |
| 1566 | uint32_t GetUint32(size_t byteOffset) const; |
| 1567 | |
| 1568 | void SetFloat32(size_t byteOffset, float value) const; |