[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
displaced arrays
Date: Thu, 3 Sep 1992 17:26-0400
From: Barry Margolin <barmar@think.com>
Be careful doing this, as it exposes the byte order of the machine. If
you're using this for network communication, you can have portability
problems.
On the other hand, if this code only needs to run in Genera, there are
some existing macro packages that provide this functionality. They are
called DEFSTORAGE, and there's a version in the SYS package and another
(incompatible) one in LMFS. They let you use a syntax similar to
DEFSTRUCT to describe the layout of objects in byte arrays and define
accessors for them.
You can also use the RPC implementation to layout storage. In fact
Symbolics code uses the RPC support stuff to implement their image
(TIFF,GIF, etc) readers and writers.
For example here is a lmfs::defstorage declaration for a dbase header:
(lmfs:defstorage (dbase-header)
(vdbase-file lmfs:fixnum-bytes 1)
(update-date lmfs:fixnum-bytes 3) ;YYMMDD in binary?
(num-records lmfs:fixnum)
(header-size lmfs:fixnum-bytes 2) ;bytes
(record-size lmfs:fixnum-bytes 2) ;bytes
(reserved lmfs:fixnum-bytes 3)
(reserved-network lmfs:char 13)
(reserved-2 lmfs:fixnum-bytes 4)
#+ignore
(field-descriptions lmfs:array (lmfs:*) field-description)
#+ignore
(dbase-header-end lmfs:fixnum-bytes 1) ;(0DH)
#+ignore
(data-records lmfs:array (lmfs:*) data-record))
An here is an RPC example for a gif header::
;;This uses the stuff from >rel-8>embedding>rpc>octect-structure.lisp:
(rpc:define-octet-structure (gif-screen-descriptor :access-type :unsigned-8)
(width rpc:integer-16)
(height rpc:integer-16)
(* (* rpc:cardinal-8
(pixel-size-1 (load-byte 0 3))
(color-resolution-1 (load-byte 4 3))
(color-map-p (rpc:boolean-bit 7))))
(background-pixel rpc:cardinal-8)
(* (rpc:padding rpc:cardinal-8 1)))
Regards from another Bit Hacker,
Albert Boulanger
aboulanger@bbn.com