comp.lang.ada
 help / color / mirror / Atom feed
From: Adrien Plisson <aplisson-news@stochastique.net>
Subject: Re: Sending Variable Length Messages with GNAT.Sockets
Date: Mon, 09 May 2005 13:50:51 +0200
Date: 2005-05-09T13:50:51+02:00	[thread overview]
Message-ID: <427f4ea9$0$24161$ba620e4c@news.skynet.be> (raw)
In-Reply-To: <1115637556.074009.113830@o13g2000cwo.googlegroups.com>

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



  reply	other threads:[~2005-05-09 11:50 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-09 10:11 Sending Variable Length Messages with GNAT.Sockets markp
2005-05-09 10:39 ` Adrien Plisson
2005-05-09 11:19   ` markp
2005-05-09 11:50     ` Adrien Plisson [this message]
2005-05-09 14:30     ` John B. Matthews
2005-05-09 14:51       ` markp
2005-05-09 18:49         ` Adrien Plisson
2005-05-09 19:16         ` Simon Wright
2005-05-10 15:08           ` markp
2005-05-10 20:34           ` Simon Wright
2005-05-11 13:19             ` Marc A. Criley
2005-05-11 17:14               ` tmoran
2005-05-11 21:05               ` Simon Wright
2005-05-12 10:24                 ` Jacob Sparre Andersen
2005-05-14 11:12                   ` Simon Wright
2005-05-09 11:19   ` Jeff C
2005-05-09 11:35     ` markp
2005-05-09 11:57     ` Adrien Plisson
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox