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!BLmi2Wt9MIz6qXtlQu2iWw.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: Sun, 1 Jan 2023 10:48:16 +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="37247"; posting-host="BLmi2Wt9MIz6qXtlQu2iWw.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:64761 List-Id: On 2023-01-01 00:41, Simon Wright wrote: > "Dmitry A. Kazakov" writes: > >> 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. > > It has to depend on the design criteria. > > If you need something now, and it's not performance critical, and you > have control over both ends of the channel, why not go for a > low-brain-power solution? Because it is still much simpler (and safer) than record layouts. > On the other hand, when faced with e.g. SNTP, why not use Ada's > facilities (e.g. [1]) to describe the network packet and use unchecked > conversion to convert to/from the corresponding stream element array to > be sent/received? Well decoding NTP query from Stream_Element_Array takes 2 statements (extracting two big-endian 32-bit numbers). You can check the implementation here: http://www.dmitry-kazakov.de/ada/components.htm#17.17 which is under-zero brained (:-)) compared to dealing with definition of record layout and bit orders you suggest. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de