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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f25e636d6b770960 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-03-25 20:32:45 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!supernews.com!peer1-sjc1.usenetserver.com!usenetserver.com!hub1.nntpserver.com!newsfeed2.earthlink.net!newsfeed.earthlink.net!newsmaster1.prod.itd.earthlink.net!newsread1.prod.itd.earthlink.net.POSTED!not-for-mail From: "Eric G. Miller" Subject: Re: Last stream problem: byte order Newsgroups: comp.lang.ada Message-ID: References: User-Agent: Pan/0.11.2 (Unix) Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Comment-To: "Erik Sigra" Date: Tue, 26 Mar 2002 04:32:43 GMT NNTP-Posting-Host: 216.119.51.73 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.prod.itd.earthlink.net 1017117163 216.119.51.73 (Mon, 25 Mar 2002 20:32:43 PST) NNTP-Posting-Date: Mon, 25 Mar 2002 20:32:43 PST Organization: EarthLink Inc. -- http://www.EarthLink.net X-Received-Date: Mon, 25 Mar 2002 20:32:44 PST (newsmaster1.prod.itd.earthlink.net) Xref: archiver1.google.com comp.lang.ada:21670 Date: 2002-03-26T04:32:43+00:00 List-Id: In , Erik Sigra wrote: > Now my stream application almost works. The last remaining problem seems to > be byte order. The server is programmed in C++ with Qt and the client is > programmed in Ada with adasockets-1.0. The last thing I did was to change the > byte order in the server > ("the_stream.setByteOrder(QDataStream::LittleEndian);"). After that the > numbers came out right at the other end. > > However, this may not be a safe solution. The safe way would probably be to > always have the network communication in BigEndian format and make sure the > client always obeys this, regardless of the platform. > > So how does one set the byte order to BigEndian on the Ada side? Or is there > a different, better idea? Up to you to decide when and what order, but the following type of thing could be used by read/write routines... with Ada.Unchecked_Conversion; package Byte_Swap is type Bits8 is mod 2**8; type Two_Byte is record A : Bits8; B : Bits8; end record; for Two_Byte use record A at 0*2 range 0 .. 7; B at 0*2 range 8 .. 15; end record; function To_Two_Byte is new Ada.Unchecked_Conversion (Source => Short_Integer, Target => Two_Byte); function To_Short is new Ada.Unchecked_Conversion (Source => Two_Byte, Target => Short_Integer); -- etc ... procedure Swap (data : in out Two_Byte); -- etc ... package body Swap_Bytes is procedure Swap (data : in out Two_Byte) is tmp : Bits8; begin tmp := data.A; data.A := data.B; data.B := tmp; end Swap; -- etc ...