@@ -1,74 +1,7 @@
11-- | `ArrayBuffer` serialization in the “builder monoid” style.
22-- |
3−-- | This module provides a `Builder` monoid and a `PutM` monad which are roughly
4−-- | equivalent to types of the same name in the Haskell
5−-- | [`Data.Binary.Put`](https://hackage.haskell.org/package/binary/docs/Data-Binary-Put.html)
6−-- | module.
7−-- |
8−-- | This library defines no typeclasses. Typeclass-based
9−-- | serialization/deserialization generally assumes that we are round-tripping
10−-- | some data structures out to storage and then back into our program.
11−-- | This library is designed for the case that we are serializing some data
12−-- | to be sent to another program which expects a certain serialization format
13−-- | that we don't control.
14−-- |
15−-- | ## Deserialization
16−-- |
17−-- | This module is only for writing `ArrayBuffer`s, not reading them.
18−-- | See
19−-- | [__purescript-parsing-dataview__](https://pursuit.purescript.org/packages/purescript-parsing-dataview/)
20−-- | for a way to deserialize from `ArrayBuffer` back to Purescript data.
21−-- |
22−-- | ## Usage Examples
23−-- |
24−-- | All `ArrayBuffer` building must occur in `Effect`.
25−-- |
26−-- | ### Serialize an integer
27−-- |
28−-- | Create a two-byte `arraybuffer :: ArrayBuffer` which contains the number *-2* encoded as big-endian 16-bit two’s-complement.
29−-- | ```purescript
30−-- | do
31−-- | arraybuffer <- execPut $ putInt16be (-2)
32−-- | ```
33−-- |
34−-- | ### Serialize a `String` as UTF8
35−-- |
36−-- | A function which encodes a `String` as UTF8 with a length prefix in a
37−-- | way that's compatible with the
38−-- | [`Binary.Put.putStringUtf8`](https://hackage.haskell.org/package/binary/docs/Data-Binary-Put.html#v:putStringUtf8)
39−-- | function from the Haskell
40−-- | [__binary__](https://hackage.haskell.org/package/binary)
41−-- | library.
42−-- | Uses [`Data.TextEncoding.encodeUtf8`](https://pursuit.purescript.org/packages/purescript-text-encoding/docs/Data.TextEncoding#v:encodeUtf8).
43−-- | ```purescript
44−-- | putStringUtf8 :: forall m. (MonadEffect m) => String -> PutM m Unit
45−-- | putStringUtf8 s = do
46−-- | let stringbuf = Data.ArrayBuffer.Typed.buffer $
47−-- | Data.TextEncoding.encodeUtf8 s
48−-- | -- Put a 64-bit big-endian length prefix for the length of the utf8
49−-- | -- string, in bytes.
50−-- | putUint32be 0
51−-- | putUint32be $ Data.Uint.fromInt $ Data.ArrayBuffer.byteLength stringbuf
52−-- | putArrayBuffer stringbuf
53−-- | ```
54−-- |
55−-- | ### Serialize an `Array Int`
56−-- |
57−-- | A function which encodes an `Array Int` with a length prefix in a
58−-- | way that's compatible with the
59−-- | [`Binary` instance for `[Int32]`](https://hackage.haskell.org/package/binary/docs/Data-Binary.html#t:Binary)
60−-- | from the Haskell
61−-- | [__binary__](https://hackage.haskell.org/package/binary)
62−-- | library.
63−-- | ```purescript
64−-- | putArrayInt32 :: forall m. (MonadEffect m) => Array Int -> PutM m Unit
65−-- | putArrayInt32 xs = do
66−-- | -- Put a 64-bit big-endian length prefix for the length of the
67−-- | -- array, in bytes.
68−-- | putUint32be 0
69−-- | putUint32be $ Data.Uint.fromInt $ Data.Array.length xs
70−-- | traverse_ putInt32be xs
71−-- | ```
3+-- | This module provides a `Builder` monoid and a `PutM` monad
4+-- | for building `ArrayBuffer`s. See the package README for usage examples.
725module Data.ArrayBuffer.Builder
736( PutM
747, Put