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-26 02:25:45 PST From: "Dr. Michael Paus" Newsgroups: comp.lang.ada Subject: Re: Last stream problem: byte order Date: Tue, 26 Mar 2002 11:25:42 +0100 Organization: =?iso-8859-1?Q?Ingenieurb=FCro?= Dr. Paus Message-ID: <3CA04CA6.338B37D7@ib-paus.com> References: NNTP-Posting-Host: p508304c7.dip0.t-ipconnect.de Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: news.online.de 1017138344 2922 80.131.4.199 (26 Mar 2002 10:25:44 GMT) X-Complaints-To: abuse@online.de NNTP-Posting-Date: 26 Mar 2002 10:25:44 GMT X-Mailer: Mozilla 4.78 [de] (Win98; U) X-Accept-Language: de Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!lnsnews.lns.cornell.edu!newsstand.cit.cornell.edu!news.stealth.net!news.stealth.net!news.uni-stuttgart.de!news.belwue.de!news.uni-ulm.de!rz.uni-karlsruhe.de!schlund.de!news.online.de!not-for-mail Xref: archiver1.google.com comp.lang.ada:21680 Date: 2002-03-26T10:25:44+00:00 List-Id: Erik Sigra schrieb: > > 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? The easiest way to solve this problem once an forever is to manipulate the file s-stratt.adb from the GNAT library. It handles all the stream stuff for primitive types like integers, floats etc. If you just introduce a procedure which swaps the bytes for each type you can achieve the effect you want. I did that a long time ago, so my implementation is currently outdated but if you like I could send you a copy. If you also check the byte order of your system at runtime (there is a system constant in Ada which you can check) you can even achieve the effect that all stream data is always written in network byte order independent of the platform your program is running on. This makes it easy, e.g. to exchange data with a Java application which writes its data to a DataOutputStream. Michael