comp.lang.ada
 help / color / mirror / Atom feed
From: "Marc A. Criley" <mcNOSPAM@mckae.com>
Subject: Re: Sending Variable Length Messages with GNAT.Sockets
Date: Wed, 11 May 2005 08:19:55 -0500
Date: 2005-05-11T08:19:55-05:00	[thread overview]
Message-ID: <c2fa8$4282067b$499550c$1011@ALLTEL.NET> (raw)
In-Reply-To: <m2hdhaom5b.fsf@grendel.local>

Simon Wright wrote:

> If the C side says
> 
>   struct rec {
>     char flag;
>     int count;
>   };
> 
> there will typically be 3 bytes of padding between flag & count, for 8
> bytes on the wire.
> 
> If the Ada side says
> 
>   type Rec is record
>      Flag : Interfaces.Unsigned_8;
>      Count : Interfaces.Integer_32;
>   end record;
>   pragma Convention (C, Rec);
> 
> the 'Write will output *5* bytes; but an unchecked conversion to
> Stream_Element_Array (1 .. 8) will succeed & do The Right Thing
> (endianness permitting).

This is why trying to use Ada.Streams "out-of-the-box" to communicate 
between Ada applications and those written in other languages is 
problematic at best.  You pretty much have to write your own stream I/O 
routines for each type to be transferred to get the data into an 
interoperable layout, especially for structured types like those in 
Simon's example.

I've pretty much given up on doing that, only using streams for 
intra-system Ada-to-Ada communication, and doing Unchecked_Conversions 
to Stream_Element_Array and using GNAT.Sockets for all external comms.

Marc A. Criley
www.mckae.com



  reply	other threads:[~2005-05-11 13:19 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
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 [this message]
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