Hi,
I’m doing my first experiments with elm and elm/bytes
. I’m creating encoders/decoders and looking for an easy way to give them input data while I’m learning and testing.
Decoders (and a Bytes
encoder) accept a Bytes
type, but this type seems to be (justifiably) opaque. Is there a way to create a Bytes
type directly? Is there another approach to experimenting with encoders/decoders?
For example, if I’m naively encoding an Int
:
type alias IntThing =
{ -- more fields later
data : Int
}
toIntThingEncoder : IntThing -> Encoder
toIntThingEncoder thing =
Encode.unsignedInt8 thing.data
I can easily experiment with it using something like:
toIntThingEncoder { data = 3 }
If, however, if I’m using a Bytes
type:
type alias ByteThing =
{ -- more fields later
data : Bytes
}
toByteThingEncoder : ByteThing -> Encoder
toByteThingEncoder thing =
Encode.bytes thing.data
I’m not sure of an easy way to get data to feed into the encoder:
encode (toByteThingEncoder ?)
Any insight would be much appreciated.
Thanks!