xc-jp / purescript-protobuf

Google Protocol Buffers for PureScript

Home Page:http://pursuit.purescript.org/packages/purescript-protobuf/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bytes ArrayBuffer or DataView

jamesdbrock opened this issue · comments

the type of Bytes should be:

-- | The constructors are functionally interchangeable, except we usually use `BytesBuffer` when writing protobuf and
-- | `BytesView` when reading protobuf, so that when reading we don't have to make copies of slices of the ArrayBuffer.
data Bytes
  = BytesBuffer ArrayBuffer
  | BytesView DataView

-- | Read `Bytes` as a `DataView`.
viewBytes :: Bytes -> DataView
viewBytes (BytesBuffer ab) = whole ab
viewBytes (BytesView dv)  = dv

Now we have the Bytes type in arraybuffer-builder that we can use for this.

https://pursuit.purescript.org/packages/purescript-arraybuffer-builder/2.0.0/docs/Data.ArrayBuffer.Builder.Internal#t:Bytes

Hm should that type be exported outside the Internal module?

Done in v2.0.0