comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Sockets, Streams, and Element_Arrays: Much confusion
Date: Sun, 1 Jan 2023 10:48:16 +0100	[thread overview]
Message-ID: <torkt0$14bv$1@gioia.aioe.org> (raw)
In-Reply-To: lyk027p2eg.fsf@pushface.org

On 2023-01-01 00:41, Simon Wright wrote:
> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> 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

  reply	other threads:[~2023-01-01  9:48 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-31 12:11 Sockets, Streams, and Element_Arrays: Much confusion Mark Gardner
2022-12-31 13:11 ` Dmitry A. Kazakov
2022-12-31 13:50   ` Mark Gardner
2022-12-31 14:16     ` Dmitry A. Kazakov
2022-12-31 15:18     ` Jeffrey R.Carter
     [not found]   ` <de32dc82-ba42-4b27-a140-ddab9587219fn@googlegroups.com>
2022-12-31 22:49     ` Jeffrey R.Carter
2022-12-31 22:55     ` Dmitry A. Kazakov
2022-12-31 17:39 ` Simon Wright
2022-12-31 19:36   ` Mark Gardner
2022-12-31 20:16     ` Dmitry A. Kazakov
2022-12-31 23:41       ` Simon Wright
2023-01-01  9:48         ` Dmitry A. Kazakov [this message]
2023-01-01 16:11           ` Simon Wright
2023-01-01 16:17         ` Niklas Holsti
2023-01-05  7:55 ` Daniel Norte de Moraes
2023-01-05 10:35   ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox