comp.lang.ada
 help / color / mirror / Atom feed
From: Marin David Condic <mcondic.nospam@acm.org>
Subject: Re: S'Write and How To Count Bytes
Date: 2000/10/02
Date: 2000-10-02T13:16:38+00:00	[thread overview]
Message-ID: <39D88ACE.92DF8897@acm.org> (raw)
In-Reply-To: hXTB5.64979$Ao1.5807473@newsrump.sjc.telocity.net

"David C. Hoos, Sr." wrote:

> If your record contains an unbounded string, I would in the My_Record'Write
> procedure convert the unbounded string to a Standard.String, and write its
> length to the stream with Natural'Write, followed by a call to String'Write.
> This will put the length of the string on the stream, followed by the
> string itself.
>
> Then, the My_Record'Read procedure would read the length from the stream,
> using Natural'Read, use that length to declare a string of the proper size
> (in a declare block), then read the string with String'Read.
> Finally, you would convert the string to the unbounded string component in
> your My_Record'Read's out parameter of type My_Record.

Well, there are a couple of questions here. One if which is "How does 'Write"
normally handle an Unbounded_String or any other private type for that matter?"
The ARM says they are defined for any non-limited type (ARM 13.13.2{36}) but I
could easily see a private type (or any type) containing Access variables - no
mention of that. It mentions Elementary types, Array types, Record types, but
not Access types. (Or is Access an Elementary type? If so, its still a special
case) Obviously, transmitting Access variables is *not* a good idea. (What if I
store an unbounded string using Stream_IO? Is it going to come back properly, or
will I have just stored a now-useless access variable that used to point to the
string?)

The other question is: "What if you extended the type and still wanted to handle
the general case with dispatching => T'Class'Write?" That's really what I want
to do - not so much a specific case of Unbounded_Strings. In other words, I need
to somehow get the number of bytes I'm transmitting into the stream and I can't
count on the listener at the other end to be using Ada or anything else. (The
device expects one of several messages with varying lengths - it needs the
number of bytes as the first datum to correctly read all the data for the
message before attempting to process it.) I believe I can use the 'Read and
'Write attributes to correctly get the individual data pieces into the stream,
but I need to know how many bytes that is going to be before putting it in the
stream. So far as I can tell, there is no way to do this except convert it to a
stream, count the bytes that turned into, insert the byte count in the record,
then convert it to a stream again. Awfully wasteful!

Maybe for Ada0x, there should be an attribute T'Stream_Size and/or
T'Class'Stream_Size. Not sure that this would not simply have to degenerate to
converting everything and counting it in the background though.

Thanks for the help.

MDC
--
======================================================================
Marin David Condic - Quadrus Corporation - http://www.quadruscorp.com/
Send Replies To: m c o n d i c @ q u a d r u s c o r p . c o m
Visit my web site at:  http://www.mcondic.com/

    "Giving money and power to Government is like giving whiskey
    and car keys to teenage boys."

        --   P. J. O'Rourke
======================================================================






  reply	other threads:[~2000-10-02  0:00 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-09-30  0:00 S'Write and How To Count Bytes Marin David Condic
2000-10-01  0:00 ` David C. Hoos, Sr.
2000-10-02  0:00   ` Marin David Condic [this message]
2000-10-02  0:00     ` Ted Dennison
2000-10-02  0:00       ` tmoran
2000-10-02  0:00         ` Marin David Condic
2000-10-02  0:00         ` tmoran
2000-10-02  0:00           ` Marin David Condic
2000-10-11  0:00             ` Nick Roberts
2000-10-11  0:00               ` Marin David Condic
2000-10-02  0:00           ` Ted Dennison
2000-10-03  0:00       ` Robert A Duff
2000-10-06  0:00         ` Randy Brukardt
2000-10-07  0:11           ` Ted Dennison
2000-10-06  0:00             ` Randy Brukardt
2000-10-07  0:00             ` Marin David Condic
2000-10-08  0:00               ` Jean-Pierre Rosen
2000-10-09  0:00                 ` Randy Brukardt
2000-10-11  0:00                 ` Marin David Condic
2000-10-02  0:00   ` Dr. Joachim Schr�er
2000-10-02  0:00     ` Marin David Condic
2000-10-06  0:00       ` Charles Hixson
2000-10-02  0:00 ` David C. Hoos, Sr.
2000-10-02  6:58 ` tmoran
2000-10-02  0:00   ` Marin David Condic
  -- strict thread matches above, loose matches on Subject: below --
2000-10-02  0:00 tmoran
2000-10-03  5:21 ` Marin David Condic
2000-10-03  0:00 Mario Amado Alves
2000-10-03  0:00 ` Marin David Condic
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox