From ... Path: supernews.google.com!sn-xit-02!supernews.com!isdnet!newsfeeds.belnet.be!news.belnet.be!news.tele.dk!129.240.148.23!uio.no!Norway.EU.net!127.0.0.1!nobody From: Erik Naggum Newsgroups: comp.lang.lisp Subject: Re: hetrogenous binary streams Date: 15 Dec 2000 02:50:09 +0000 Organization: Naggum Software; vox: +47 800 35477; gsm: +47 93 256 360; fax: +47 93 270 868; http://naggum.no; http://naggum.net Lines: 48 Message-ID: <3185837409763528@naggum.net> References: <91bm27$m44$1@nnrp1.deja.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: oslo-nntp.eunet.no 976850222 21452 195.0.192.66 (15 Dec 2000 03:17:02 GMT) X-Complaints-To: newsmaster@eunet.no NNTP-Posting-Date: 15 Dec 2000 03:17:02 GMT mail-copies-to: never User-Agent: Gnus/5.0803 (Gnus v5.8.3) Emacs/20.7 Xref: supernews.google.com comp.lang.lisp:5281 * David Morse | I have a binary stream with entries that can be ints, doubles, unsigned | longs, chars, whatever. Do you know beforehand exactly what bit patterns the stream will contain, or do you have special encoding of the data types that lets you read them independent of high-level type expectations? | I'm trying to read them from lisp, but all I see is read-byte and | read-char, that don't do what I want at all. The Lisp reader is built from read-char, and it can build any object. You can write a reader for your own format that can build any object, too, using read-byte if the stream is binary. This is not always trivial, but it can certainly be done. | I think I want read-double, read-int, etc. But there don't seem to be | such functions. No, because binary formats are not defined by the language. Such formats are either much more complex than textual representation or they are as machine-dependent as a raw memory dump, which they much too often actually are. You may be able to dump data to be loaded back into the same build of the same program on the same machine with the same version compiler and same version libraries and everything else being the same, but otherwise, it is highly risky business to load binary data. Therefore, such complexification as you find in ASN.1 BER and tagged data formats from .fasl (fast load) files in Lisp systems are necessary. | Okay, so how do I do it? :) You don't write binary data to begin with. :) If you really have no choice about the data you're reading, you need to interpret the bit patterns yourself and build Lisp objects from them. This is not as impossible as it sounds, but some Lisps have functions that help you do this. E.g., Allegro CL 6.0 has functions that both hack up floating-point types into several shorts (16-bit integers) and reassemble them, for use in binary data formats. Do (apropos :shorts) to find them. You build integers from bytes the easy way, but you may also specify bytes that are bigger than the trivial 8 bits. A Lisp "byte" is as large as you want it. Specify the :element-type when you open the stream. #:Erik -- The United States of America, soon a Bush league world power. Yeee-haw!