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,FREEMAIL_FROM, INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,2e66fe8b30e3ee2c X-Google-Attributes: gid103376,public From: "Nick Roberts" Subject: Re: S'Write and How To Count Bytes Date: 2000/10/11 Message-ID: <8s2bf1$j1v4d$1@ID-25716.news.cis.dfn.de>#1/1 X-Deja-AN: 680249095 References: <39D8EF78.27E5649F@acm.org> X-Trace: fu-berlin.de 971288866 19987597 212.188.146.106 (16 [25716]) X-MSMail-Priority: Normal X-Priority: 3 Newsgroups: comp.lang.ada X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Date: 2000-10-11T00:00:00+00:00 List-Id: I would honestly suggest you abandon the use of Ada's streams totally (except, at least, within the internals of a small package), and define your own package which formalises the entire message protocol. E.g. (inventing fictitious commands etc.): package SCSI is type Device_Type is tagged limited private; type Device_Status is (Ready, Busy, Spun_Down, Down); function Status (Device: in Device_Type) return Device_Status; procedure Reset (Device: in out Device_Type); ... type Block_List is array (Positive range <>) of Block_Number; procedure Get_Bad_Sector_Map ( Device: in out Device_Type; Map: out Block_List; Last: out Natural); ... Operation_Not_Supported: exception; private ... end SCSI; package body SCSI is ... type Byte_List is array (Positive range <>) of Unsigned_8; procedure Send_Bytes (Device: in out Device_Type; Bytes: in Byte_Array) is begin ... end; procedure Read_Bytes (Device: in out Device_Type; Bytes: out Byte_Array) is begin ... end; ... procedure Get_Bad_Sector_Map ( Device: in out Device_Type; Map: out Block_List; Last: out Natural) is Prelude: Byte_Array(1..1); Data: Byte_Array(1..4); begin Send_Bytes(Device,(1=>16#0A#)); -- fictitious code for 'GETBSMAP' Read_Bytes(Device,Prelude); -- TBD: check Prelude(1) byte Last := Map'First-1; loop Read_Bytes(Device,Data); if Data = (0,0,0,0) then return; end if; Last := Last+1; Map(Last) := ( Head_Number(Data(1)), Cylinder_Number(Integer(Data(2))*256+Integer(Data(3))), Sector_Number(Data(4))); end loop; end Get_Bad_Sector_Map; ... end SCSI; You can then allocate memory at exactly the points that make the best sense. The message protocol itself will determine how efficiently this can be done. Note how I've illustrated a solution to the unknown length problem similar to that adopted by Ada.Text_IO.Get_Line on a String. Also note how SCSI.Device_Type operations can be overridden and extended, neatly accommodating irregular devices. (Not quite so butt-ugly? ;-) -- Nick Roberts http://www.AdaOS.org ----- Original Message ----- From: "Marin David Condic" Newsgroups: comp.lang.ada Sent: Monday, October 02, 2000 9:26 PM Subject: Re: S'Write and How To Count Bytes > tmoran@bix.com wrote: > > > How about dropping the initial byte count and use an end-of-record > > indicator instead, like LF in Text_IO? > > Clearly, one could do that. You could build your whole protocol as if it > were trading lines of text. > > The bad news is that for the particular app I'm looking at, I've got an > already defined set of messages. What I am hoping to do is find a nice, > tidy way of using Ada95 to get at that message catalog and build support > tools that connect to the existing system. If the answer is really good, > I might even be able to sell the notion of changing the existing system > and eliminate some really butt-ugly code.