This module provides helpers for working with Bytes.Encode.Encoders.
Before the release of [elm/bytes], many packages would use List Int
to represent bytes. byteValues aids interaciton between those packages
and Bytes.
import Bytes.Encode exposing (Encoder)
import Bytes.Extra
import MD5
myEncoder : String -> Encoder
myEncoder string =
Bytes.Encode.sequence
[ Bytes.Encode.unsignedInt8 (String.length string)
, Bytes.Encode.string string
, Bytes.Encode.Extra.byteValues (MD5.bytes string)
]
Bytes.Extra.toByteValues (Bytes.Encode.encode (myEncoder "hello world"))
--> [ 11 -- Length of "hello world"
--> , 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64 -- "hello world" in bytes
--> , 0x5e , 0xb6 , 0x3b , 0xbb, 0xe0 , 0x1e , 0xee , 0xd0 -- |
--> , 0x93 , 0xcb , 0x22 , 0xbb, 0x8f , 0x5a , 0xcd , 0xc3 -- |- MD5 of "hello world"
--> ]One notable use of 24-bit integers is in 24-bit color, a.k.a. "True color".
Encode a 24-bit signed integer
Encode a 24-bit unsigned integer
Create an encoder for a list. This does not encode the length of the list.