From: Mats Karlssohn <mats@mida.se>
Subject: Re: records containing variable length arrays [long]
Date: Thu, 07 Jun 2001 13:44:57 +0200
Date: 2001-06-07T11:43:19+00:00 [thread overview]
Message-ID: <3B1F6939.88D49233@mida.se> (raw)
In-Reply-To: 3B1EB781.11B6923D@boeing.com
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
next prev parent reply other threads:[~2001-06-07 11:44 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-06-06 19:59 records containing variable length arrays [long] Mats Karlssohn
2001-06-06 23:06 ` Jeffrey Carter
2001-06-07 11:44 ` Mats Karlssohn [this message]
2001-06-08 2:10 ` Jeffrey Carter
2001-06-07 21:38 ` Stephen Leake
2001-06-08 12:32 ` Mats Karlssohn
2001-06-08 16:42 ` Jeffrey Carter
2001-06-08 22:28 ` Jeffrey Carter
2001-06-19 11:43 ` Mats Karlssohn
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox