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!newsread.com!news-xfer.newsread.com!news.glorb.com!newsfeed2.easynews.com!newsfeed1.easynews.com!easynews.com!easynews!atl-c07.usenetserver.com!pc03.usenetserver.com!ALLTEL.NET!not-for-mail Date: Wed, 11 May 2005 08:19:55 -0500 From: "Marc A. Criley" User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: 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> <1115650283.330746.109740@f14g2000cwb.googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: X-Complaints-To: abuse@usenetserver.com Organization: UseNetServer.com X-Trace: c2fa84282067ba13cf0a901011 Xref: g2news1.google.com comp.lang.ada:10993 Date: 2005-05-11T08:19:55-05:00 List-Id: 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