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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,deffccd74319c23d X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news2.google.com!proxad.net!proxad.net!skynet.be!newspost001!tjb!not-for-mail Date: Mon, 09 May 2005 13:50:51 +0200 From: Adrien Plisson User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax) X-Accept-Language: fr-fr, fr-be, fr, en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Sending Variable Length Messages with GNAT.Sockets References: <1115633512.107824.259680@g14g2000cwa.googlegroups.com> <427f3dfa$0$28058$ba620e4c@news.skynet.be> <1115637556.074009.113830@o13g2000cwo.googlegroups.com> In-Reply-To: <1115637556.074009.113830@o13g2000cwo.googlegroups.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <427f4ea9$0$24161$ba620e4c@news.skynet.be> Organization: -= Belgacom Usenet Service =- NNTP-Posting-Host: 5c1798ed.news.skynet.be X-Trace: 1115639466 news.skynet.be 24161 81.246.233.244:4487 X-Complaints-To: usenet-abuse@skynet.be Xref: g2news1.google.com comp.lang.ada:10972 Date: 2005-05-09T13:50:51+02:00 List-Id: markp wrote: > Thank you for your quick reply. Our target platforms are not Ada, so we > chose to use the write. Could you tell me some place I could look to > research how to write my own stream input/output routines? i don't know of any place where you can find examples of custom read/write. you may try http://www.adapower.com/ or other ada related example enabled website. i think the first place is understanding ARM95 13.13 and all its subsections. we also discussed it a bit in "TCP/IP Sockets with GNAT.Sockets" on comp.lang.ada last week. basically, you declare one/both of the following procedure: procedure Msg_Write( Stream : access Ada.Streams.Root_Stream_Type'Class; Message : in Msg_Type); for Msg_Type'Write use Msg_Write; procedure Msg_Read( Stream : access Ada.Streams.Root_Stream_Type'Class; Message : out Msg_Type); for Msg_Type'Read use Msg_Read; (beware of the freezing rule which can lead to the unclear messages: no more representation items for type "..." defined at line ... representation item appears too late) > I could pass > a byte count in with the message to be sent, but the stream calls seem > to only take a type, not a length. For example, in our application > code, we have a data type that can hold up an array of 512 entries, but > we might only want to send the first 32, for example. We have built > into the message header how many bytes there are, but Ada would know > nothing about that. We are used to the traditional "address, byte > count" wat of dealing with sockets when writing your own procedure to write to/read from streams, you can use any other stream attributes. as such, you can first read/write the header using standard 'Read or 'Write attribute. from this you will have the size in bytes. by carefully using the 'Size attribute, you can easily find the number of entries in your message. then, you are back to the fixed size case and can read or write just what is needed. for more complicated stuffs, you can use the Read and Write procedures of type Ada.Streams.Root_Stream_Type'Class which allows you to read/write at the "Stream_Elements" level (basically the byte level). -- rien