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!news3.google.com!news.glorb.com!easynet-monga!easynet.net!peer.news.zetnet.net!194.159.246.34.MISMATCH!peer-uk.news.demon.net!kibo.news.demon.net!mutlu.news.demon.net!news.demon.co.uk!demon!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Sending Variable Length Messages with GNAT.Sockets Date: Wed, 11 May 2005 22:05:54 +0100 Organization: Pushface Message-ID: 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> NNTP-Posting-Host: pogner.demon.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: news.demon.co.uk 1115845555 9105 62.49.19.209 (11 May 2005 21:05:55 GMT) X-Complaints-To: abuse@demon.net NNTP-Posting-Date: Wed, 11 May 2005 21:05:55 +0000 (UTC) Cancel-Lock: sha1:IrmSTj+t+exYGBEWh7hYZQQc4q8= User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (darwin) Xref: g2news1.google.com comp.lang.ada:11000 Date: 2005-05-11T22:05:54+01:00 List-Id: "Marc A. Criley" 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!