gleam
gleam copied to clipboard
utf16 serialization segment flag forgotten
let name = "marimota"
let padded_name =
bit_array.slice(
bit_array.append(<<name:utf16>>, bit_array_copy(<<0, 0>>, 22)),
0,
44,
)
produces erlang
Name@1 = <<"marimota"/utf8>>,
Padded_name = begin
_pipe = gleam_stdlib:bit_array_slice(
gleam@bit_array:append(<<Name@1/binary>>, binary:copy(<<0, 0>>, 22)),
0,
44
)
added extra context just in case
Thank you.
What should the generated code look like instead?
<<Name@1/binary-utf16>> or similar also erlang doesn't automatically convert them, since on gleam we use strings rather than binaries, a good solution would be the compiler backend to do the conversion by calling unicode:characters_to_binary(Data, InEncoding, OutEncoding) similarly might want to fetch the right implementation on javascript side or at least error
Thanks for the clarification!
I think we should error in this case, like Erlang does.
erlang errors after trying to serialize it from utf8, to preserve that behavior can just emit the utf-16 and let erlang error