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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,dcfafdc50abb8ce4 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-06-08 05:36:02 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news.algonet.se!algonet!pepsi.tninet.se!not-for-mail From: Mats Karlssohn Newsgroups: comp.lang.ada Subject: Re: records containing variable length arrays [long] Date: Fri, 08 Jun 2001 14:32:55 +0200 Organization: MIDA Systemutveckling AB Message-ID: <3B20C5F7.94DC72A1@mida.se> References: <3B1E8BB9.42BF95D2@mida.se> NNTP-Posting-Host: du232-156.ppp.algonet.se Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: zingo.tninet.se 992003472 17906 195.100.156.232 (8 Jun 2001 12:31:12 GMT) X-Complaints-To: abuse@algo.net NNTP-Posting-Date: 8 Jun 2001 12:31:12 GMT X-Mailer: Mozilla 4.77 [en] (WinNT; U) X-Accept-Language: en Xref: archiver1.google.com comp.lang.ada:8395 Date: 2001-06-08T12:31:12+00:00 List-Id: I will try to address two posts with the same reply here... Jeffrey Carter wrote: %< > In that case you can access it simply. We'll call what you get from C > Data_Address and Data_Length. Then you can say > > Raw_Data : constant Buffer (1 .. Data_Length); > -- or (7 .. Data_Length + 6), if you prefer > pragma Import (Ada, Raw_Data); -- Prevent any initialization of Raw_Data > for Raw_Data'Address use Data_Address; > > You can then Translate this to an appropriately constrained record type. > Since you do not need to modify it, you can make it constant, which > should avoid copying the data. > > If you want to live dangerously, you can avoid the buffer representation > and simply apply the address clause to the record object. Stephen Leake wrote: %< > Do you really need to declare the message as a single type? That is, > do you really need to pass objects of that type around? Or can you get > by with reading the message from a stream, and building a set of > internal objects that other packages access in a controlled way? Last night i came up with a partitial solution that seems promising. I realised that I will need to pass pointers to the messages around to different routines. I ended up declaring the record in the way that was discussed earlier. Then I declare an access type to the record and use an instance of System.Address_To_Access_Conversions to convert the C pointer to an Ada pointer. I'll probably wrap another layer around the buffer manager and let that glue perform the address to access conversion. Right now this seems to work but I have a layout problem in another similar (but not identical) record type. See below for a new question. Stephen Leake wrote: > The point being that there are many reasonable communications > protocols that simply cannot be expressed as an Ada record, and this > seems to be one of them. The correct approach is to encode the > protocol as a procedure that reads from a stream, not as an Ada record > type. Well, I guess that could be done, but I really do not want to copy the data around. I gets dumped into shared (actually reflected) memory by another CPU and in some cases the records can be quite big and arriving fast. Now, for the new (but related) question. Given this declaration and representation: type Message(Response_Length : Byte; Output_Length : Byte) is record Magic : Word; Operation : Word; Status : Word; Response_Data : Buffer(1..Response_Length); Output_Data : Buffer(1..Output_Length); CRC : Word; end record; for Message use record Magic at 0 range 0..15; Operation at 2 range 0..15; Status at 4 range 0..15; Response_Length at 6 range 0.. 7; Output_Length at 7 range 0.. 7; end record; pragma Pack(Message); Is there a way to explicitly put at least the CRC element into the representation clause ? My experiments haven't gotten me anywhere on this part. -- Mats Karlssohn, developer mailto:mats@mida.se Mida Systemutveckling AB http://www.mida.se Box 64, S-732 22 ARBOGA, SWEDEN Phone: +46-(0)589-89808 Fax: +46-(0)589-89809