Skip to content

Commit 1bef891

Browse files
htooothcknitt
andauthored
Stdlib: add DataView with littleEndian get/set (#7881)
* Stdlib: add DataView with littleEndian get/set * Stdlib: refactor DataView methods to support optional little-endian parameter * Update packages/@rescript/runtime/Stdlib_DataView.resi Co-authored-by: Christoph Knittel <[email protected]> * add deprecated * update example and doc * fix resi error * add test * make format * update artifacts.json * update ChangeLog --------- Co-authored-by: Christoph Knittel <[email protected]> Co-authored-by: Christoph Knittel <[email protected]>
1 parent 34cb6b8 commit 1bef891

File tree

4 files changed

+525
-17
lines changed

4 files changed

+525
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#### :rocket: New Feature
4343

4444
- Add `Array.filterMapWithIndex` to Stdlib. https://github.com/rescript-lang/rescript/pull/7876
45+
- Add `littleEndian` feature for `DataView` to Stdlib. https://github.com/rescript-lang/rescript/pull/7881
4546

4647
#### :bug: Bug fix
4748

packages/@rescript/runtime/Stdlib_DataView.res

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
@notUndefined
22
type t
33

4-
@new external fromBuffer: Stdlib_ArrayBuffer.t => t = "DataView"
4+
@new
5+
external fromBuffer: (Stdlib_ArrayBuffer.t, ~byteOffset: int=?, ~length: int=?) => t = "DataView"
56
@new external fromBufferToEnd: (Stdlib_ArrayBuffer.t, ~byteOffset: int) => t = "DataView"
67
@new
78
external fromBufferWithRange: (Stdlib_ArrayBuffer.t, ~byteOffset: int, ~length: int) => t =
@@ -13,29 +14,35 @@ external fromBufferWithRange: (Stdlib_ArrayBuffer.t, ~byteOffset: int, ~length:
1314

1415
@send external getInt8: (t, int) => int = "getInt8"
1516
@send external getUint8: (t, int) => int = "getUint8"
16-
@send external getInt16: (t, int) => int = "getInt16"
17-
@send external getUint16: (t, int) => int = "getUint16"
18-
@send external getInt32: (t, int) => int = "getInt32"
19-
@send external getUint32: (t, int) => int = "getUint32"
2017

21-
@send external getFloat32: (t, int) => float = "getFloat32"
22-
@send external getFloat64: (t, int) => float = "getFloat64"
18+
@send external getInt16: (t, int, ~littleEndian: bool=?) => int = "getInt16"
19+
@send external getUint16: (t, int, ~littleEndian: bool=?) => int = "getUint16"
20+
21+
@send external getInt32: (t, int, ~littleEndian: bool=?) => int = "getInt32"
22+
@send external getUint32: (t, int, ~littleEndian: bool=?) => int = "getUint32"
23+
24+
@send external getFloat16: (t, int, ~littleEndian: bool=?) => float = "getFloat16"
25+
@send external getFloat32: (t, int, ~littleEndian: bool=?) => float = "getFloat32"
26+
@send external getFloat64: (t, int, ~littleEndian: bool=?) => float = "getFloat64"
2327

24-
@send external getBigInt64: (t, int) => bigint = "getBigInt64"
25-
@send external getBigUint64: (t, int) => bigint = "getBigUint64"
28+
@send external getBigInt64: (t, int, ~littleEndian: bool=?) => bigint = "getBigInt64"
29+
@send external getBigUint64: (t, int, ~littleEndian: bool=?) => bigint = "getBigUint64"
2630

2731
@send external setInt8: (t, int, int) => unit = "setInt8"
2832
@send external setUint8: (t, int, int) => unit = "setUint8"
29-
@send external setInt16: (t, int, int) => unit = "setInt16"
30-
@send external setUint16: (t, int, int) => unit = "setUint16"
31-
@send external setInt32: (t, int, int) => unit = "setInt32"
32-
@send external setUint32: (t, int, int) => unit = "setUint32"
3333

34-
@send external setFloat32: (t, int, float) => unit = "setFloat32"
35-
@send external setFloat64: (t, int, float) => unit = "setFloat64"
34+
@send external setInt16: (t, int, int, ~littleEndian: bool=?) => unit = "setInt16"
35+
@send external setUint16: (t, int, int, ~littleEndian: bool=?) => unit = "setUint16"
36+
37+
@send external setInt32: (t, int, int, ~littleEndian: bool=?) => unit = "setInt32"
38+
@send external setUint32: (t, int, int, ~littleEndian: bool=?) => unit = "setUint32"
39+
40+
@send external setFloat16: (t, int, float, ~littleEndian: bool=?) => unit = "setFloat16"
41+
@send external setFloat32: (t, int, float, ~littleEndian: bool=?) => unit = "setFloat32"
42+
@send external setFloat64: (t, int, float, ~littleEndian: bool=?) => unit = "setFloat64"
3643

37-
@send external setBigInt64: (t, int, bigint) => unit = "setBigInt64"
38-
@send external setBigUint64: (t, int, bigint) => unit = "setBigUint64"
44+
@send external setBigInt64: (t, int, bigint, ~littleEndian: bool=?) => unit = "setBigInt64"
45+
@send external setBigUint64: (t, int, bigint, ~littleEndian: bool=?) => unit = "setBigUint64"
3946

4047
/**
4148
`ignore(dataView)` ignores the provided dataView and returns unit.

0 commit comments

Comments
 (0)