From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: * X-Spam-Status: No, score=1.3 required=5.0 tests=BAYES_00,INVALID_MSGID, MSGID_RANDY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a883dc07df0d6bb1 X-Google-Attributes: gid103376,public From: Ted Dennison Subject: Re: Decoding an octet stream Date: 1999/12/02 Message-ID: <8265dq$ecp$1@nnrp1.deja.com>#1/1 X-Deja-AN: 555678587 References: <877lj2q36g.fsf@deneb.cygnus.argh.org> <81u247$kc3$1@hobbes2.crc.com> <821rc5$bim$1@nnrp1.deja.com> <822o4d$ehh$1@birch.prod.itd.earthlink.net> <8233fm$ngf$1@nntp3.atl.mindspring.net> <87bt8a2uvr.fsf@deneb.cygnus.argh.org> X-Http-Proxy: 1.0 x35.deja.com:80 (Squid/1.1.22) for client 204.48.27.130 Organization: Deja.com - Before you buy. X-Article-Creation-Date: Thu Dec 02 16:06:43 1999 GMT X-MyDeja-Info: XMYDJUIDtedennison Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.6 [en] (WinNT; I) Date: 1999-12-02T00:00:00+00:00 List-Id: In article <87bt8a2uvr.fsf@deneb.cygnus.argh.org>, " "@deneb.cygnus.argh.org (Florian Weimer) wrote: > swhalen@netcom.com writes: > Perhaps I may ask again: Is it reasonable to assume that > Storage_Element'Size equals 8 (although the standard doesn't > require this, of course)? And, looking at David's code, does I don't. My code figures it out by doing the following: Bytes_Per_Element : constant := (Ada.Streams.Stream_Element'Size + 7) / 8; It only really comes up when you need to convert between stream elements and bytes for some reason though. I suppose if you are writing your own 'Write routine using Unchecked_Conversion instead of other 'Write's it also would be an issue. Then you would need to do something like this ("Instance" is the type you are converting): Bytes_Per_Element : constant := (Ada.Streams.Stream_Element'Size + 7) / 8; Bytes_Per_Instance : constant Natural := (Instance'Size + 7) / 8; Elements_Per_Instance : constant Ada.Streams.Stream_Element_Offset := Ada.Streams.Stream_Element_Offset( (Bytes_Per_Instance + (Bytes_Per_Element - 1)) / Bytes_Per_Element); subtype Instance_Array is Ada.Streams.Stream_Element_Array (1 .. Elements_Per_Instance); function From_Instance is new Unchecked_Conversion (Source => Instance, Target => Instance_Array); function To_Instance is new Unchecked_Conversion (Source => Instance_Array, Target => Instance); Otherwise you will be working entirely in stream_element_array's anyway. -- T.E.D. Sent via Deja.com http://www.deja.com/ Before you buy.