How about extra/pack?
You can do something like:
B{ 4 0 0 0 6 0 0 0 8 0 0 0 3 0 0 0 0 0 0 0 0 }
"iiicq" unpack-le .
{ 4 6 8 3 0 }
I just added a new way to read packed bytes from a stream directly:
B{ 4 0 0 0 6 0 0 0 8 0 0 0 } binary <byte-reader> [
"iii" read-packed-le
] with-input-stream
-> { 4 6 8 }
It throw an error if the stream is exhausted:
B{ 4 0 0 0 6 0 0 0 } binary <byte-reader> [
"iii" read-packed-le
] with-input-stream
Exception:
packed-read-fail instance
"str" "iii"
"bytes" B{ 4 0 0 0 6 0 0 0 }
You can also do it by byte-length instead of using the strings:
read-u16 read-s32 read-c-string
The above would read an unsigned 16 bit number, a signed 32, and a C-
string that was null-terminated.
Doug
On Jan 15, 2009, at 4:26 PM, Adam wrote:
> I'm looking for what William describes for a project here at work.
>
> On Thu, Jan 15, 2009 at 1:23 PM, Slava Pestov <[email protected]>
> wrote:
>> On Thu, Jan 15, 2009 at 3:17 PM, William Tanksley, Jr
>> <[email protected]> wrote:
>>> Does Factor have a read-delimited-record facility for binary data?
>>> Naturally, you'd have to set up the reader with the information
>>> about
>>> how to break the stream into records.
>>
>> There's a read-until word, which might be what he wants.
>>
>>> ...On the other hand, if he's reading lines, I don't see any reason
>>> not to use an explicit encoding. Perhaps he's worried about staying
>>> 8-bit clean, and thinks the ASCII encoding will error out if the
>>> high
>>> bit is set... Will it?
>>
>> The ASCII encoding throws an error if the high-bit is set on an octet
>> read from the stream, because ASCII is only defined for octets in the
>> range 0..127.
>>
>> Slava
>>
>> ------------------------------------------------------------------------------
>> This SF.net email is sponsored by:
>> SourcForge Community
>> SourceForge wants to tell your story.
>> http://p.sf.net/sfu/sf-spreadtheword
>> _______________________________________________
>> Factor-talk mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/factor-talk
>>
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by:
> SourcForge Community
> SourceForge wants to tell your story.
> http://p.sf.net/sfu/sf-spreadtheword
> _______________________________________________
> Factor-talk mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/factor-talk
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk