Hopefully a pretty quick question....

GIven the following:

my Buf $b .= new([72, 105, 0, 32, 97, 103, 97, 105, 110, 0]);
say $b.decode;

I would expect this to print 'Hi'.
Instead it prints 'Hi again'.

https://docs.raku.org/type/Buf#(Blob)_method_decode

The decode documentation for Buf only states that 'Applies an encoding to
turn the blob into a Str <https://docs.raku.org/type/Str>; the encoding
will be UTF-8 by default.'


The zero (0) in that Buf should imply an end of string yet decode seems to
want to decode the number of elements instead.

Furthermore, If I 'say $b.decode.chars;' it counts the initial null as part
of Str.
In my mind, that means Str doesn't really mean string.

So the question, how does one ACTUALLY decode what's in a buffer to a
string where it adheres to the semantics of NULL termination for strings
cleanly.

Another question might be, should decode() follow null terminating
semantics instead of number of elements in a given Buf.

Thanks,
Paul
-- 
__________________

:(){ :|:& };:

Reply via email to