From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-65-14.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!reader01.eternal-september.org!aioe.org!2bOJBbN/dOuClNqbvu11SQ.user.46.165.242.91.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Sockets, Streams, and Element_Arrays: Much confusion Date: Sat, 31 Dec 2022 21:16:18 +0100 Organization: Aioe.org NNTP Server Message-ID: References: <6183be57-2796-0ab7-739f-a5b557083ee6@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: gioia.aioe.org; logging-data="10908"; posting-host="2bOJBbN/dOuClNqbvu11SQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org"; User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 X-Notice: Filtered by postfilter v. 0.9.2 Content-Language: en-US Xref: reader01.eternal-september.org comp.lang.ada:64755 List-Id: On 2022-12-31 20:36, Mark Gardner wrote: > On 31/12/2022 19:39, Simon Wright wrote: >> Message'Write the record into the memory stream; >> transmit the written contents as one datagram. > > I'm guessing with Memory_Stream'Write(Socket_Stream, Buffer);? No, you create a memory stream object. Then you write your packet into it: My_Message'Write (My_Memory_Stream'Access); Once written you use the accumulated stream contents to write it into the socket. An implementation of a memory-resident stream is very simple. E.g. see: http://www.dmitry-kazakov.de/ada/strings_edit.htm#Strings_Edit.Streams My advise would be not to do this. It is wasting resources and complicated being indirect when 'Write and 'Read are compiler-generated. If you implement 'Write and 'Read yourself, then why not calling these implementations directly. It just does not make sense to me. I always wonder why people always overdesign communication stuff. Build messages directly in a Stream_Element_Array. Use system-independent ways to encode packet data. E.g. chained codes for integers. Mantissa + exponent for real numbers. If you have Booleans and enumerations it is a good idea to pack them into one or two octets to shorten the packets. All this is very straightforward and easy to implement. You can also consider using some standard data representation format, e.g. ASN.1. An Ada ASN.1 implementation is here: http://www.dmitry-kazakov.de/ada/components.htm#ASN.1 You describe your message in ASN.1 as an Ada tagged type derived from building blocks. Then you can encode and decode it directly from Stream_Element_Array. I would not recommend that either. ASN.1 is quite overblown. Happy New Year! -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de