git.iko.soy/rowtype-yoga/purescript-arraybuffer-builder
on master help sign in
docs and tests
ec26f24James Brock
README.md+8−8
@@ -22,13 +22,6 @@ This package is designed for the case in which we are serializing some data
22to be sent to another program which expects a serialization format
22to be sent to another program which expects a serialization format
23that we don't control.
23that we don't control.
24
24
25−## Deserialization
26−
27−This package is only for writing `ArrayBuffer`s, not reading them.
28−See
29−[__purescript-parsing-dataview__](https://pursuit.purescript.org/packages/purescript-parsing-dataview/)
30−for a way to deserialize from `ArrayBuffer` back to Purescript data.
31−
32## Usage Examples
25## Usage Examples
33
26
34All `ArrayBuffer` building must occur in `Effect`.
27All `ArrayBuffer` building must occur in `Effect`.
@@ -73,7 +66,7 @@ putStringUtf8 s = do
73 putArrayBuffer stringbuf
66 putArrayBuffer stringbuf
74
67
75do
68do
76− arraybuffer <- execPut $ putStringUtf8 "ACAB"
69+ arraybuffer <- execPut $ putStringUtf8 "BLM"
77```
70```
78
71
79### Serialize an `Array Int`
72### Serialize an `Array Int`
@@ -96,6 +89,13 @@ do
96 arraybuffer <- execPut $ putArrayInt32 [1,2,3]
89 arraybuffer <- execPut $ putArrayInt32 [1,2,3]
97```
90```
98
91
92+## Deserialization
93+
94+This package is only for writing `ArrayBuffer`s, not reading them.
95+See
96+[__purescript-parsing-dataview__](https://pursuit.purescript.org/packages/purescript-parsing-dataview/)
97+for a way to deserialize from `ArrayBuffer` back to Purescript data.
98+
99## References
99## References
100
100
101* [MDN `ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
101* [MDN `ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
src/Data/ArrayBuffer/Builder.purs+9−1
@@ -4,6 +4,11 @@
4-- |
4-- |
5-- | Writing to an `ArrayBuffer` is an `Effect`ful activity, so most
5-- | Writing to an `ArrayBuffer` is an `Effect`ful activity, so most
6-- | functions in this module must be run in a `MonadEffect` context.
6-- | functions in this module must be run in a `MonadEffect` context.
7+-- |
8+-- | For operations for working with `ArrayBuffer`, see
9+-- | module
10+-- | [`Data.ArrayBuffer.ArrayBuffer`](https://pursuit.purescript.org/packages/purescript-arraybuffer/docs/Data.ArrayBuffer.ArrayBuffer)
11+-- | in package __purescript-arraybuffer__.
7module Data.ArrayBuffer.Builder
12module Data.ArrayBuffer.Builder
8( PutM
13( PutM
9, Put
14, Put
@@ -395,4 +400,7 @@ putFloat64le = putArrayBuffer <=< encodeFloat64le
395-- https://github.com/haskell-perf/strict-bytestring-builders
400-- https://github.com/haskell-perf/strict-bytestring-builders
396--
401--
397-- We've tried to design the API for this library with minimal assumptions,
402-- We've tried to design the API for this library with minimal assumptions,
398−-- so that if we want to change the Builder implementation later then we can.
403+-- so that if we want to change the Builder implementation later then we can.
404+--
405+-- Another way this could go:
406+-- https://kodimensional.dev/posts/2019-03-25-comonadic-builders
test/Main.purs+24
@@ -56,3 +56,27 @@ main = do
56 b3 <- encodeInt8 3
56 b3 <- encodeInt8 3
57 b4 <- encodeInt8 4
57 b4 <- encodeInt8 4
58 pure $ singleton b1 <> (singleton b2 <> singleton b3) <> singleton b4
58 pure $ singleton b1 <> (singleton b2 <> singleton b3) <> singleton b4
59+
60+ buildTest "Test 6" [1,2,3,4,5,6,7,8] $ do
61+ b1 <- encodeInt8 1
62+ b2 <- encodeInt8 2
63+ b3 <- encodeInt8 3
64+ b4 <- encodeInt8 4
65+ b5 <- encodeInt8 5
66+ b6 <- encodeInt8 6
67+ b7 <- encodeInt8 7
68+ b8 <- encodeInt8 8
69+ pure $ singleton b1 <> (singleton b2 <> singleton b3) <> singleton b4
70+ <> singleton b5 <> (singleton b6 <> singleton b7) <> singleton b8
71+
72+ buildTest "Test 7" [1,2,3,4,5,6,7,8] $ do
73+ b1 <- encodeInt8 1
74+ b2 <- encodeInt8 2
75+ b3 <- encodeInt8 3
76+ b4 <- encodeInt8 4
77+ b5 <- encodeInt8 5
78+ b6 <- encodeInt8 6
79+ b7 <- encodeInt8 7
80+ b8 <- encodeInt8 8
81+ pure $ singleton b1 <> (singleton b2 <> singleton b3) <> (singleton b4
82+ <> singleton b5) <> (singleton b6 <> singleton b7) <> singleton b8