From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,5ae752c88e0dde5e X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,UTF8 Path: g2news1.google.com!news3.google.com!feeder.news-service.com!tudelft.nl!txtfeed1.tudelft.nl!zen.net.uk!dedekind.zen.co.uk!aioe.org!not-for-mail From: =?utf-8?Q?Yannick_Duch=C3=AAne_=28Hibou57?= =?utf-8?Q?=29?= Newsgroups: comp.lang.ada Subject: Re: Using representation clauses in networking software Date: Sun, 15 Aug 2010 15:44:34 +0200 Organization: Ada At Home Message-ID: References: <8739ugqfeb.fsf@mid.deneb.enyo.de> NNTP-Posting-Host: lii8bauySSx0YHeDgKSgMg.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Content-Transfer-Encoding: Quoted-Printable X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.2 User-Agent: Opera Mail/10.61 (Win32) Xref: g2news1.google.com comp.lang.ada:13335 Date: 2010-08-15T15:44:34+02:00 List-Id: Hello Florian Le Sun, 15 Aug 2010 13:33:32 +0200, Florian Weimer a = = =C3=A9crit: > 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 conversi= on = when sending something outside. This is done this way to be more efficie= nt = 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 derive= d = from T1 is to be stored in file or retrieved from a device using the si= ze = of X bits. Both are the same in some sense, except T2 has a representati= on = clause. When you do =E2=80=9CT1 (Object_Of_Type_T1)=E2=80=9D 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 bi= ts = 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 whi= ch = 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 packa= ge = 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 ).