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=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,cd9fd73b6a96d80d X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-10-20 11:28:22 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.stueberl.de!teaser.fr!enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: "Beard, Frank Randolph CIV" Newsgroups: comp.lang.ada Subject: RE: Byte Swapping Constrained Data Types Date: Mon, 20 Oct 2003 14:25:10 -0400 Organization: Cuivre, Argent, Or Message-ID: NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Trace: melchior.cuivre.fr.eu.org 1066674379 47707 80.67.180.195 (20 Oct 2003 18:26:19 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Mon, 20 Oct 2003 18:26:19 +0000 (UTC) To: "Brian Barker" , Return-Path: X-MimeOLE: Produced By Microsoft Exchange V6.0.6375.0 content-class: urn:content-classes:message X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Byte Swapping Constrained Data Types Thread-Index: AcOXLGBrcySGfHGBRKOzVuI5kbvNjQACA3SA X-OriginalArrivalTime: 20 Oct 2003 18:25:10.0798 (UTC) FILETIME=[7F1B0AE0:01C39737] X-Virus-Scanned: by amavisd-new-20030616-p5 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Gateway to the comp.lang.ada Usenet newsgroup List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: archiver1.google.com comp.lang.ada:1222 Date: 2003-10-20T14:25:10-04:00 As soon as you reference the Terminal variable, range checking occurs. You are going to have to swap the bytes before you reference it. For instance: procedure Some_Routine is type Intermediate_Type is mod 2**32; procedure Swap is new Endian.Generic_Swap(Intermediate_Type); function To_Terminal is Ada.Unchecked_Conversion(Intermediate_Type, Terminal); begin --+ Copying your raw network data into the intermediate. --+ Swap. Swap(My_Intermediate); --+ Convert it. My_Terminal :=3D To_Terminal(My_Intermediate); We had a case similar to yours but we used a rep clause instead. Ours about 72 bits of data into a record structure. We used the rep clause to lay it out from the data stream. The Swap is more flexible, because we had different rep clauses depending on what system we were running. Frank -----Original Message----- From: Brian Barker [mailto:bbarker@ball.com] Sent: Monday, October 20, 2003 12:52 To: comp.lang.ada@ada-france.org Subject: Byte Swapping Constrained Data Types ObjectAda for Windows 7.2.2 Native =20 This is more of an Ada specific question if someone could help me. =20 I have declared an enumerated type like so: =20 type Terminal is ( Null_Terminal, Primary, Secondary, Console ); =20 for Terminal use ( Null_Terminal =3D> 0, Primary =3D> 1, Secondary =3D> 2, Console =3D> 3); =20 for Terminal'Size use 32; =20 =20 I also have created a procedure based off of a generic byte-swap routine: =20 procedure Swap is new Endian.Generic_Swap(Terminal); =20 I receive a record over TCP/IP and it is in Big Endian format, so I must byte swap it. I have already copied the raw network data into my structure that contains the Terminal type. When I try to byte swap it I receive a constraint error, because the big endian value of Terminal is out of range. =20 Swap(My_Record.Sending_Terminal); -- <- Sending_Terminal is of type Terminal =20 I want to keep the generic swap, because I have so many abstract data types. I just want to get around this constraint range check when I try to pass the value into the swap routine. Does anyone have a better suggestion? _______________________________________________ comp.lang.ada mailing list comp.lang.ada@ada-france.org http://www.ada-france.org/mailman/listinfo/comp.lang.ada