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!XkhLYGh9FeaGRJtDGav81g.user.46.165.242.75.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Sockets, Streams, and Element_Arrays: Much confusion Date: Sat, 31 Dec 2022 23:41:11 +0000 Organization: Aioe.org NNTP Server Message-ID: References: <6183be57-2796-0ab7-739f-a5b557083ee6@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: gioia.aioe.org; logging-data="29820"; posting-host="XkhLYGh9FeaGRJtDGav81g.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org"; User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.1 (darwin) X-Notice: Filtered by postfilter v. 0.9.2 Cancel-Lock: sha1:u8CgsupZeSW6HXYiNv8Um7InFXk= Xref: reader01.eternal-september.org comp.lang.ada:64759 List-Id: "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? 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? I'd have thought that building messages directly in a stream element array would be the least desirable way to do it. [1] https://sourceforge.net/p/coldframe/adasntp/code/ci/default/tree/SNTP.impl/sntp_support.ads