Closed RoyalIcing closed 4 days ago
This will also mean removing the Orb.I32.String
module with its functions. Which is great as I’d prefer to have the amount of included boilerplate code to a minimum.
Orb.I32.String
has been removed.
Orb.Str
has been added, which is a Custom Type for (i32 i32)
. The first i32
is the string’s memory address, and the second is its length in bytes.
Orb conveniently converts strings like
"abc"
into an integer “pointer”, and automatically adds an(data)
entry initialized in memory at that pointer offset.These strings are modelled after C’s strings. They are nul-terminated, which means you must measure their length at runtime by looping over every character until you hit
\0
.This means the zero byte is not possible to encode, which is important for some protocols to include.
I think the general consensus (citations needed) is that people consider C’s nul-terminators a mistake. Better to have an explicit length stored somehow. This is faster as you don’t have to iterate over the string to know its length, and likely safer as you can’t change a string’s length by merely flipping a byte to/from
0x0
. It also lets you extract many “slices” from the string by advancing the start offset and shortening the length.Proposed options:
_str
and_len
suffixes.Memory.Range
. The downside is you’d need some lightweight inlined macros to extract the offset and length. And it might be a “weird” Orb-only convention. I’d prefer a solution that is elegant and obvious.Further things to consider
string
in the WebAssembly Component Model. I don’t fully understand how this is represented yet.