From: Simon Wright <simon@pushface.org>
Subject: Re: Sending Variable Length Messages with GNAT.Sockets
Date: Wed, 11 May 2005 22:05:54 +0100
Date: 2005-05-11T22:05:54+01:00 [thread overview]
Message-ID: <m2ll6ljwwd.fsf@grendel.local> (raw)
In-Reply-To: c2fa8$4282067b$499550c$1011@ALLTEL.NET
"Marc A. Criley" <mcNOSPAM@mckae.com> writes:
> 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.
Our project has lots of Ada (our bit) and lots of C (the other
bits). The interfaces are defined using only 32-bit quantities (after
a packed 20-byte header which initially caused us a pile of grief,
especially since we wanted to be interoperable between PC and
PowerPC).
On our side there's quite a lot of generated code to cope with mapping
Booleans to packed arrays of bits, driven by UML tags in the models,
but once the data is in the 32-bit form we do indeed use Streams.
I suppose we could have achieved the same end by writing our own
'Read, 'Write, but that might have been a bridge too far; and this way
at least the main code generator isn't intertwingled with the network
i/o part. I can't remember whether that argument occurred to me at the
time!
next prev parent reply other threads:[~2005-05-11 21:05 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
2005-05-11 17:14 ` tmoran
2005-05-11 21:05 ` Simon Wright [this message]
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