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-07 04:46:04 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newspeer.clara.net!news.clara.net!newspeer.highwayone.net!newsfeed1.telenordia.se!algonet!pepsi.tninet.se!not-for-mail From: Mats Karlssohn Newsgroups: comp.lang.ada Subject: Re: records containing variable length arrays [long] Date: Thu, 07 Jun 2001 13:44:57 +0200 Organization: MIDA Systemutveckling AB Message-ID: <3B1F6939.88D49233@mida.se> References: <3B1E8BB9.42BF95D2@mida.se> <3B1EB781.11B6923D@boeing.com> NNTP-Posting-Host: sdu147-248.ppp.algonet.se Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: cubacola.tninet.se 991914199 14845 195.163.248.147 (7 Jun 2001 11:43:19 GMT) X-Complaints-To: abuse@algo.net NNTP-Posting-Date: 7 Jun 2001 11:43:19 GMT X-Mailer: Mozilla 4.77 [en] (WinNT; U) X-Accept-Language: en Xref: archiver1.google.com comp.lang.ada:8304 Date: 2001-06-07T11:43:19+00:00 List-Id: Jeffrey Carter wrote: > > Mats Karlssohn wrote: %< > The basic concept for what you're trying to do is a discriminated record > type: > > type Bounded_String (Max_Length : Positive) is record > Current_Length : Natural := 0; > Value : String (1 .. Max_Length) := (others => '*'); > end record; Yes, that's right. > > -- the other big problem is to get the correct representation > > for Message use > > record %< > > Status at 4 range 0..15; > > Response_Length at 4 range 0.. 7; This is a typo... "Response_Length at 5 range 0..7;" is the correct representation statement, this also means that all the following components move up one byte. %< > However, you have additional problems, such as overlaying your lengths, > which would be your discriminants, with Status. I presume that you > receive your message as a simple Buffer. In that case you might be able > to work something along these lines Yes, I receive a C pointer (converted to System.Address) and an integer Length from a buffer manager for the shared memory where thit beast lives. I forgot to mention that I really only neet to read this data structure, I will NOT need to assign to it. > type Message (Response_Length : Byte; Output_Length : Byte) is record > Magic : Word; > Operation : Word; > Response_Data : Buffer (1 .. Response_Length); > Output_Data : Buffer (1 .. Output_Length); > CRC : Word; > end record; > > I have specified the Buffers starting at one because Ada does not allow > an expression containing a discriminant. That's OK but not ideal... I can handle that in the access functions. The spec. says that it is indexed from 0 but I'll just have to take care of it. The problem comes when Output_Length becomes 0, a value which it can legally have. In that case the Output_Data buffer is 0 bytes long and hence disapears from the message. This is kind of an almost error, not the normal use, but still, allowed. Any suggestions on that one ? > for Message use record > Magic at 0 range 0..15; > Operation at 2 range 0..15; > Response_Length at 4 range 0.. 7; > Output_Length at 5 range 0.. 7; > end record; > pragma Pack (Message); Hmmm... yes, I think I see. I think that I havn't done my homework, I really didn't think of trying to include the discriminants in the representation. > We will have to ensure that the compiler will lay out the Buffers and > CRC properly, but that seems the most likely result. Ahh... this seems doable, I'll look into it some more this evening. %< > Your only issue now is to reconstruct Status from the 2 discriminants. > This is reasonably simple and left as an exercise for the reader. And not an issue since I mistyped.... TNX 1e6 -- 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