comp.lang.ada
 help / color / mirror / Atom feed
From: "Yannick Duchêne (Hibou57)" <yannick_duchene@yahoo.fr>
Subject: Re: Using representation clauses in networking software
Date: Sun, 15 Aug 2010 15:44:34 +0200
Date: 2010-08-15T15:44:34+02:00	[thread overview]
Message-ID: <op.vhhe4kqfule2fv@garhos> (raw)
In-Reply-To: 8739ugqfeb.fsf@mid.deneb.enyo.de

Hello Florian
Le Sun, 15 Aug 2010 13:33:32 +0200, Florian Weimer <fw@deneb.enyo.de> a  
écrit:
> Have there been any efforts to fix representation clauses so that they
> are suitable for expressing elements commonly found in networking
> protocols?

General case first and yours then

For representation issue, the common scheme is to use conversion when  
receiving something from the outside of the application and use conversion  
when sending something outside. This is done this way to be more efficient  
as this preserve the best representation for all internal uses.

This conversion may be implicitly defined via a type conversion between a  
type and a derived type if one has a representation clause applying. Ex. a  
type T1 is a type with its universal definition, a second type T2 derived  
 from T1 is to be stored in file or retrieved from a device using the size  
of X bits. Both are the same in some sense, except T2 has a representation  
clause. When you do “T1 (Object_Of_Type_T1)” there is an implicit  
conversion. The other way conversion is the same.

Your case now (without representation attribute, as this one does not  
exist so far)

I do not know neither any representation clause for Byte Ordering.  
However, you probably have a set of basic type like 16 bits words, 64 bits  
words or anything else. The best is to have a similar thing as the above,  
except this would be implemented explicitly. You would define a function  
From_Local_To_Network and and From_Network_To_Local (with two different  
types for Local_Type and Network_Type to avoid to erroneously mixing it).

Just to try to meet your request (something else later) : I do not know a  
way to have a method which would automatically know the bit order of its  
platform, except perhaps receiving a standard data, like 16#1234#  
(0x1234), and then check if it looks like 16#3412# or like 16#1234#. Or  
this may be a link to a tiny-tiny library which would only contains a  
simple data word, which could be checked the same way. Ex. a library which  
would contains the same 6#1234# which would be linked as an external C  
stuff and could be tested for the same way.

The other way (which does not meet you requirement) : use the ability of  
Ada to have multiple package body for the same package specification and  
define two package body for the same network<->platform conversion package  
specification. Then, use a simple configuration option to build the  
application using one or the other (you will not face thousand of cases,  
as there are not some much commonly used platform in real life).

You may write it or reuse one (pretty sure something like this already  
exist in whatever license).

Or else you may suggest it for a future Ada revision (via this newsgroup  
or else ada-auth.org ).



  reply	other threads:[~2010-08-15 13:44 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-15 11:33 Using representation clauses in networking software Florian Weimer
2010-08-15 13:44 ` Yannick Duchêne (Hibou57) [this message]
2010-08-15 14:32   ` Dmitry A. Kazakov
2010-08-15 14:44     ` Florian Weimer
2010-08-15 15:04       ` Dmitry A. Kazakov
2010-08-15 15:32         ` Florian Weimer
2010-08-15 16:10           ` Dmitry A. Kazakov
2010-08-15 16:40             ` Yannick Duchêne (Hibou57)
2010-08-15 17:58               ` Dmitry A. Kazakov
2010-08-15 19:11                 ` Shark8
2010-08-15 19:15                 ` Simon Wright
2010-08-15 20:25                   ` Maciej Sobczak
2010-08-15 21:24                     ` Simon Wright
2010-08-16  6:40                     ` Dmitry A. Kazakov
2010-09-04 20:46                     ` Florian Weimer
2010-08-15 15:39         ` Yannick Duchêne (Hibou57)
2010-08-15 15:31       ` Yannick Duchêne (Hibou57)
2010-08-15 15:30     ` Yannick Duchêne (Hibou57)
2010-08-15 16:10       ` Dmitry A. Kazakov
2010-08-16 10:57     ` Stephen Leake
2010-08-15 15:58 ` Simon Wright
2010-08-15 16:03   ` Florian Weimer
2010-08-17  3:32     ` Randy Brukardt
2010-08-16  9:12 ` anon
replies disabled

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