I was looking for a toImmutable() method on the Buf object so I could pass it to an Actor. If there is one, please tell me and update the docs to refer to it in the intro to "Buf".
SlimerDudeTue 6 Mar 2012
Um... sys::StrBuf#toStr? As an immutable StrBuf is just a Str, right!?
Still, as it's a pointer into a block of bytes, it doesn't make sense to me to make it immutable - b'cos then the pointer becomes fixed!
Can you not send over whatever your Buf is backed by? e.g. the file, map or byte block?
dobesvTue 6 Mar 2012
I mean a binary Buf that holds bytes/octets, not a Str. Something like Java's byte[].
I'm not sure how to get access to the bytes the Buf is backed by - if you create a Buf using Buf.make() it allocates the buffer internally and I don't see any method to access the internal buffer.
brianTue 6 Mar 2012
No there is no current immutable version of Buf. I've considered adding it, but don't want to add a bunch of extra checks to byte access since at that level the overhead becomes meaninful.
If it is small I will often use Buf.toBase64 as a Str.
If passing Bufs back and forth to Actors, I'm usually careful and just optimize to pass the Buf itself using Unsafe.
dobesvTue 6 Mar 2012
OK, thanks.
dobesvTue 6 Mar 2012
Is there any way to wrap a byte[] received from Java into a Buf instance for use in Fantom?
brianTue 6 Mar 2012
Is there any way to wrap a byte[] received from Java into a Buf instance for use in Fantom?
Not very easily, I'll add a hook to Interop or to ByteArray for that
dobesv Tue 6 Mar 2012
I was looking for a toImmutable() method on the Buf object so I could pass it to an Actor. If there is one, please tell me and update the docs to refer to it in the intro to "Buf".
SlimerDude Tue 6 Mar 2012
Um... sys::StrBuf#toStr? As an immutable StrBuf is just a Str, right!?
SlimerDude Tue 6 Mar 2012
Oh, so there's a
sys::Buf
also!Still, as it's a pointer into a block of bytes, it doesn't make sense to me to make it immutable - b'cos then the pointer becomes fixed!
Can you not send over whatever your Buf is backed by? e.g. the file, map or byte block?
dobesv Tue 6 Mar 2012
I mean a binary Buf that holds bytes/octets, not a Str. Something like Java's byte[].
I'm not sure how to get access to the bytes the Buf is backed by - if you create a Buf using Buf.make() it allocates the buffer internally and I don't see any method to access the internal buffer.
brian Tue 6 Mar 2012
No there is no current immutable version of Buf. I've considered adding it, but don't want to add a bunch of extra checks to byte access since at that level the overhead becomes meaninful.
If it is small I will often use Buf.toBase64 as a Str.
If passing Bufs back and forth to Actors, I'm usually careful and just optimize to pass the Buf itself using Unsafe.
dobesv Tue 6 Mar 2012
OK, thanks.
dobesv Tue 6 Mar 2012
Is there any way to wrap a byte[] received from Java into a Buf instance for use in Fantom?
brian Tue 6 Mar 2012
Not very easily, I'll add a hook to Interop or to ByteArray for that
dobesv Wed 7 Mar 2012
OK thanks!