Pass elm/bytes through a port?

In general I think this should be added. Converting to anything else to pass it over a port negates any efficiency benefits of using bytes. There have been several cases where people ran into this limitation.

I’m not sure if adding to elm/json makes sense (creates a dependency to elm/bytes for elm/json).

A problem is that the elm-bytes package currently uses a DataView under the hood, which is a view on a byte array (i.e. elements are 8 bits wide). Therefore it is not obvious what should happen to a typed array with larger elements (e.g. Int32Array). Silently converting seems like a bad idea, but really any kind of conversion is bad because the whole goal of these data types is to be efficient. So either we don’t support typed arrays for the moment, or we need to be able to efficiently get them into the elm world.

We could also only support ArrayBuffer/DataView. A little against the elm spirit of finding a good general solution (that covers all low-level array types), but it would be practical.

1 Like