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: Sat, 31 Dec 2022 21:16:18 +0100	[thread overview]
Message-ID: <toq5ag$aks$1@gioia.aioe.org> (raw)
In-Reply-To: 6183be57-2796-0ab7-739f-a5b557083ee6@gmail.com

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

  reply	other threads:[~2022-12-31 20:16 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 [this message]
2022-12-31 23:41       ` Simon Wright
2023-01-01  9:48         ` Dmitry A. Kazakov
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