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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: border1.nntp.dca3.giganews.com!backlog3.nntp.dca3.giganews.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!goblin2!goblin.stu.neva.ru!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Binary and XML serialization of types Date: Fri, 31 Jan 2014 11:49:10 +0100 Organization: cbb software GmbH Message-ID: <18q1ats1rko50$.zp43ryd37uis.dlg@40tude.net> References: <20a36d96-850e-4020-8dfa-777eb9c944f4@googlegroups.com> <9e27abb7-e944-4bd4-a10c-600fe4da7872@googlegroups.com> <56a5aeb6-8704-457c-a24f-b664746afe72@googlegroups.com> <13pvagjpwejni$.1e8ll5btxg1f5$.dlg@40tude.net> <5bf8c737-b99d-4069-885f-03fe82f06cc6@googlegroups.com> <14k7gbu5ws82b.3pn20kh5ci50.dlg@40tude.net> <1txs6yifzioke$.30cghpl6qq1j$.dlg@40tude.net> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: I5Na6+WsEzT8WoegI0VZTA.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 X-Original-Bytes: 3078 Xref: number.nntp.dca.giganews.com comp.lang.ada:184624 Date: 2014-01-31T11:49:10+01:00 List-Id: On Fri, 31 Jan 2014 01:51:37 -0800 (PST), hanslad@gmail.com wrote: > One question: You have implemented the litle endian Unsigned_16 Get like this: > > procedure Get > ( Data : in out Stream_Element_Array; > Pointer : in out Stream_Element_Offset; > Value : out Unsigned_16 > ) is > begin > if ( Pointer < Data'First > or else > ( Pointer > Data'Last > and then > Pointer > Data'Last + 1 > ) ) > then > Raise_Exception > ( Layout_Error'Identity, > "Pointer is out of bounds" > ); > elsif Pointer + 1 > Data'Last then > Raise_Exception (End_Error'Identity, "End of data"); > end if; > Value := > ( Shift_Left (Unsigned_16 (Data (Pointer + 1)), 8) > or Unsigned_16 (Data (Pointer)) > ); > Pointer := Pointer + 2; > end Get; > > Is it assumed that the system is little endian. How will this work on a big endian system? The number is built up from stream elements using arithmetic operations. These operation should work regardless the endianness of the host machine. P.S. I cannot find a reference in RM which states the semantics of Shift_Left. I presume that it is such that Shift_Left (2#0001#, 1) = 2#0010# independently on the machine endianness. P.P.S. Conversion from Stream_Element to Unsigned_16 must also be independent on the machine endianness. The bit-endianness of Stream_Element must be handled by the hardware, e.g. by the Ethernet controller, when it stores received octets into the host machine memory. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de