git.iko.soy/rowtype-yoga/purescript-parsing-dataview
on master help sign in
README
commit092262955e89b9b413af2ff6d32186d1a972c15f authorJames Brock <jamesbrock@gmail.com> dateMon 27 Jul 2020, 22:51 (6 years ago) parent3b5ca4c
1 file changed+7−4
README.md+7−4
README.md+7−4
@@ -14,7 +14,7 @@ able to roughly match the built-in stream support of __Megaparsec__:
1414|----|-----|----|
1515| UTF-16 strings | String | Text |
1616| Listy strings | Token | String |
17−| Binary blobs | __Text.Parsing.Parser.DataView__ | Bytestring |
17+| Binary blobs | __Text.Parsing.Parser.DataView__ | ByteString |
1818
1919## Usage examples
2020
@@ -36,7 +36,7 @@ do
3636
3737### Parse an array
3838
39−Parse `n` 32-bit signed integers.
39+Parse an array of `n` 32-bit signed integers.
4040
4141```purescript
4242do
@@ -51,6 +51,7 @@ way that's compatible with the
5151function from the Haskell
5252[__binary__](https://hackage.haskell.org/package/binary)
5353library.
54+
5455We give this as an example, rather than supporting it in the library, because
5556it depends on
5657[`Data.TextDecoding.decodeUtf8`](https://pursuit.purescript.org/packages/purescript-text-encoding/docs/Data.TextDecoding#v:decodeUtf8).
@@ -58,12 +59,14 @@ it depends on
5859```purescript
5960do
6061 result <- Text.Parsing.Parser.runParserT dataview $ do
61− -- Parse a big-endian 64-big length prefix
62+ -- Parse 32 bits of the big-endian 64-bit length prefix.
6263 _ <- anyUint32be
6364 length <- anyUint32be
6465 stringview <- takeN $ UInt.toInt length
6566 stringarray <- liftEffect $ mkTypedArray stringview
66− pure $ Data.TextDecoding.decodeUtf8 stringarray
67+ case Data.TextDecoding.decodeUtf8 stringarray of
68+ Left err -> Data.Parsing.Parser.fail $ show err
69+ Right s -> pure s
6770
6871where
6972 mkTypedArray :: Data.ArrayBuffer.Types.DataView -> Effect Data.ArrayBuffer.Types.Uint8Array