That is a great example, thanks Markus! I hope to have some time next
week to look at your example in more detail, but one thing I already
noticed is that you don't explicitly deal with endianness. Have you
verified that all your clients use the same (in this case presumably
little endian) encoding?
I am currently thinking back and forth how closely to expose the
various browser apis surrounding binary data especially with regards
to endianness. Do we want to expose both typed arrays and data views?
Or should the elm api be based solely on dataviews and require the
user to always specify the endianness?
Several file formats either specify the endianness in the file and
some insane ones even switch endinaness for certain blocks (psd for
example but I think also jpeg because the exif block can be in a
different endianness than the rest of the file). So maybe the actual
functions of a binary decoder/encoder will have to explicitly state
the endianness.
I am brainstorming while I write this - I think a binary
decoder/encoder might be based on typed array using uint8 only
internally, and on the elm side we expose a number of functions with
specified endianness.
```elm
type alias Cursor = { arrayBuffer : ArrayBuffer, position : Int }
-- Decoders:
uint16Little : Cursor -> (Int, Cursor)
uint16Big: Cursor -> (Int, Cursor)
float32Little : Cursor -> (Float, Cursor)
float32Big : Cursor -> (Float, Cursor)
float64Little : Cursor -> (Float, Cursor)
float64Big : Cursor -> (Float, Cursor)
type alias DecoderFn a = (Cursor -> (a, Cursor))
array : DecoderFn a -> Int -> Cursor -> (Array a, Cursor)
combine : (a -> b -> c) -> DecoderFn a -> DecoderFn b -> Cursor -> (c, Cursor)
-- we may want to have map and andThen too or instead of combine
```
Do you think you will also have the use case where you have data that
is more complex than just lists of numbers? Do you think an api along
these lines would make sense?
--
Daniel Bachler
http://www.danielbachler.de
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Elm Discuss" group.
> To unsubscribe from this topic, visit
>
https://groups.google.com/d/topic/elm-discuss/fVFXqEHpxAQ/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
>
elm-discuss...@googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.