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 autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,2e66fe8b30e3ee2c,start X-Google-Attributes: gid103376,public From: Marin David Condic Subject: S'Write and How To Count Bytes Date: 2000/09/30 Message-ID: <39D6891A.7DC448B6@acm.org>#1/1 X-Deja-AN: 676045068 Content-Transfer-Encoding: 7bit Organization: Quadrus Corporation X-Accept-Language: en X-Server-Date: 1 Oct 2000 00:44:47 GMT Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 2000-10-01T00:44:47+00:00 List-Id: Suppose I have a type something like this: type My_Record is record A_String : Unbounded_String := Null_Unbounded_String ; end record ; In theory, I should be able to create an object that is derived from Ada.Streams.Root_Stream_Type which has a Read and Write procedure that will allow me to create a call such as: My_Record'Write (Ptr, A_Record) ; where Ptr is a pointer to my derived Root_Stream_Type object. Now here's where it gets fun: The object derived from Root_Stream_Type is going to contain some version of a Stream_Element_Array. Possibly dynamically allocated. The Write procedure that I create for the Root_Stream_Type is going to get automagically called with a Stream_Element_Array parameter, from which you could determine the size, allocate what you need for a buffer and attach it to the Root_Stream_Type. That buffer can then be sent somewhere or used in some other manner. The problem is this: What if you want the record to contain the number of bytes that it converts to so that the number ends up in the stream? You can't easily determine how many bytes there will be in the record nor can you determine what the 'Write is really going to produce. You could possibly retain the size information in your Root_Stream_Type after the conversion, but by then its too late. You already converted it and if you had a "Count" field in the record, its value is probably dead wrong. You could convert it to the stream once, interrogate the Root_Stream_Type you built to determine the number of bytes in it, then include that byte count in your record and convert it all over again. That seems a little inefficient. Is there any good way of determining in advance how many bytes you are going to get when converting an object to a stream? 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 ======================================================================