From: "Eric G. Miller" <egm2@jps-nospam.net>
Subject: Re: Last stream problem: byte order
Date: Tue, 26 Mar 2002 04:32:43 GMT
Date: 2002-03-26T04:32:43+00:00 [thread overview]
Message-ID: <pan.2002.03.25.20.33.30.870308.29435@jps-nospam.net> (raw)
In-Reply-To: mailman.1017085322.10332.comp.lang.ada@ada.eu.org
In <mailman.1017085322.10332.comp.lang.ada@ada.eu.org>, 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 ...
next prev parent reply other threads:[~2002-03-26 4:32 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-03-25 19:45 Last stream problem: byte order Erik Sigra
2002-03-25 22:28 ` Jeffrey Carter
2002-03-25 22:36 ` Stephen Leake
2002-03-26 4:32 ` Eric G. Miller [this message]
2002-03-26 10:25 ` Dr. Michael Paus
2002-03-26 17:53 ` Pascal Obry
2002-03-26 18:25 ` Dr. Michael Paus
2002-03-26 19:25 ` Pascal Obry
2002-03-27 15:37 ` Erik Sigra
2002-03-27 18:12 ` Dr. Michael Paus
2002-03-28 2:24 ` Eric G. Miller
2002-03-28 18:34 ` Stephen Leake
2002-03-28 18:38 ` Simon Wright
2002-03-29 2:08 ` Eric G. Miller
2002-03-29 6:52 ` Simon Wright
2002-03-29 7:06 ` Simon Wright
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox