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.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: border1.nntp.dca3.giganews.com!backlog4.nntp.dca3.giganews.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Binary and XML serialization of types Date: Fri, 24 Jan 2014 17:13:59 +0000 Organization: A noiseless patient Spider Message-ID: References: <20a36d96-850e-4020-8dfa-777eb9c944f4@googlegroups.com> <9e27abb7-e944-4bd4-a10c-600fe4da7872@googlegroups.com> <56a5aeb6-8704-457c-a24f-b664746afe72@googlegroups.com> <52e227f4$0$6553$9b4e6d93@newsspool4.arcor-online.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx05.eternal-september.org; posting-host="f4c34a0d1a0b50d7528d4047756bbea8"; logging-data="6017"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/0ScgvmjP8Bb5HUbknC4DZoc703dstN/I=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (darwin) Cancel-Lock: sha1:7jAa/4bEaY9wkfl17X9TguIgaY8= sha1:fgRxtib0b+7MRBWHhvlLY8jcfXI= X-Original-Bytes: 3009 Xref: number.nntp.dca.giganews.com comp.lang.ada:184549 Date: 2014-01-24T17:13:59+00:00 List-Id: Georg Bauhaus writes: > On 23.01.14 20:58, hanslad@gmail.com wrote: >> Thanks Adam, >> >> Ok,that makes sense. >> One more question: Am I on the right path here, or is there a better >> way to do binary encoding into streams? I want this to perform as >> fast as possible. > > If speed is paramount and the setup permits the same representation > of data at either end of the line, then using the Read and Write > procedures for Stream_Element_Array is likely to be unbeatable > (Streams.Stream_IO). > This suggests conversion of objects of type Guid into objects of > type Stream_Element_Array with the help of an 'Address clause or > through an instance of Unchecked_Conversion. (And some careful > commenting might be a good idea.) As long as there's no awkward implementation detail in there .. for example, GNAT's Ada.Containers.Vectors has type Vector is new Controlled with record Elements : Elements_Access; Last : Extended_Index := No_Index; Busy : Natural := 0; Lock : Natural := 0; end record; but procedure Write (Stream : not null access Root_Stream_Type'Class; Container : Vector) is begin Count_Type'Base'Write (Stream, Length (Container)); for J in Index_Type'First .. Container.Last loop Element_Type'Write (Stream, Container.Elements.EA (J)); end loop; end Write; Also, see the loop at the end of Write; Element_Type might have its own complicated structure. I'd say that the fact you're probably going to send the streamed data over the wire means that speed won't be paramount. On the other hand, you might want to minimise the number of OS interactions ...