@@ -1,74 +1,7 @@
1-- | `ArrayBuffer` serialization in the “builder monoid” style.
1-- | `ArrayBuffer` serialization in the “builder monoid” style.
3−-- | This module provides a `Builder` monoid and a `PutM` monad which are roughly
3+-- | This module provides a `Builder` monoid and a `PutM` monad
4−-- | equivalent to types of the same name in the Haskell
4+-- | for building `ArrayBuffer`s. See the package README for usage examples.
5−-- | [`Data.Binary.Put`](https://hackage.haskell.org/package/binary/docs/Data-Binary-Put.html)
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.
15−-- | ## Deserialization
17−-- | This module is only for writing `ArrayBuffer`s, not reading them.
19−-- | [__purescript-parsing-dataview__](https://pursuit.purescript.org/packages/purescript-parsing-dataview/)
20−-- | for a way to deserialize from `ArrayBuffer` back to Purescript data.
22−-- | ## Usage Examples
24−-- | All `ArrayBuffer` building must occur in `Effect`.
26−-- | ### Serialize an integer
28−-- | Create a two-byte `arraybuffer :: ArrayBuffer` which contains the number *-2* encoded as big-endian 16-bit two’s-complement.
31−-- | arraybuffer <- execPut $ putInt16be (-2)
34−-- | ### Serialize a `String` as UTF8
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)
42−-- | Uses [`Data.TextEncoding.encodeUtf8`](https://pursuit.purescript.org/packages/purescript-text-encoding/docs/Data.TextEncoding#v:encodeUtf8).
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.
51−-- | putUint32be $ Data.Uint.fromInt $ Data.ArrayBuffer.byteLength stringbuf
52−-- | putArrayBuffer stringbuf
55−-- | ### Serialize an `Array Int`
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)
61−-- | [__binary__](https://hackage.haskell.org/package/binary)
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.
69−-- | putUint32be $ Data.Uint.fromInt $ Data.Array.length xs
70−-- | traverse_ putInt32be xs
72module Data.ArrayBuffer.Builder
5module Data.ArrayBuffer.Builder