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.3 required=5.0 tests=BAYES_00,INVALID_MSGID, MSGID_RANDY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,2e66fe8b30e3ee2c X-Google-Attributes: gid103376,public From: Ted Dennison Subject: Re: S'Write and How To Count Bytes Date: 2000/10/02 Message-ID: <8raa11$nmg$1@nnrp1.deja.com>#1/1 X-Deja-AN: 676655578 References: <39D6891A.7DC448B6@acm.org> <39D88ACE.92DF8897@acm.org> X-Http-Proxy: 1.0 x55.deja.com:80 (Squid/1.1.22) for client 204.48.27.130 Organization: Deja.com - Before you buy. X-Article-Creation-Date: Mon Oct 02 15:36:01 2000 GMT X-MyDeja-Info: XMYDJUIDtedennison Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.7 [en] (WinNT; I) Date: 2000-10-02T00:00:00+00:00 List-Id: In article <39D88ACE.92DF8897@acm.org>, Marin David Condic 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.