comp.lang.ada
 help / color / mirror / Atom feed
From: Ted Dennison <dennison@telepath.com>
Subject: Re: S'Write and How To Count Bytes
Date: 2000/10/02
Date: 2000-10-02T00:00:00+00:00	[thread overview]
Message-ID: <8raa11$nmg$1@nnrp1.deja.com> (raw)
In-Reply-To: 39D88ACE.92DF8897@acm.org

In article <39D88ACE.92DF8897@acm.org>,
  Marin David Condic <mcondic.nospam@acm.org> wrote:
> 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

If they are non-composite types, they get their bit pattern written out.
If they are compositie types, 'Write gets called for each component.
This can be kinda nasty when you've got a big array and 'Write for that
stream is not entirely trivial.

> 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

The value of the access type (not what it points to) gets written. This
is almost certianly *not* what you want. In that case the author of the
private type needs to make their own 'Write for that type which does
something more sensible (eg: 'Write on Object.all).

> 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?)

I'm not sure if implementors are required to make 'Write on unbounded
strings (or bounded ones for that matter) do anything sensible. I don't
see anything in the LRM about it, so I'd guess not. You should probably
convert them to strings and do a String'Write (or 'Output).

>
> 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!

I had a similar need. What I did is made my custom stream require an
"Open" and "Close" (primitives on the stream type) around a series of
writes. This isn't that heinous; Ada.Streams.Text_IO has a similar
restriction. Open leaves a 4 byte (I guess 2 would probably suffice)
space at the front of the buffer for a count. Close calculates the
number of bytes between the count bytes and the end of the stream data,
and puts that value into the count bytes.


> 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.
The problem with this is that since users can make their own 'Write
attribute routines, there is no way to calculate this short of actually
performing the writes. You might as well just do it yourself.

--
T.E.D.

http://www.telepath.com/~dennison/Ted/TED.html


Sent via Deja.com http://www.deja.com/
Before you buy.




  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   ` Dr. Joachim Schr�er
2000-10-02  0:00     ` Marin David Condic
2000-10-06  0:00       ` Charles Hixson
2000-10-02  0:00   ` Marin David Condic
2000-10-02  0:00     ` Ted Dennison [this message]
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           ` Ted Dennison
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-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 ` 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