------------------------------------------------------------------------------ -- -- -- GNAT LIBRARY COMPONENTS -- -- -- -- G N A T . B I G _ E N D I A N _ I N T E R F A C E S -- -- -- -- B o d y -- -- -- -- $Revision: 1.0 $ -- -- -- -- Copyright (C) 1999 Michael Roe -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 2, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- -- for more details. You should have received a copy of the GNU General -- -- Public License distributed with GNAT; see file COPYING. If not, write -- -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, -- -- MA 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from this -- -- unit, or you link this unit with other files to produce an executable, -- -- this unit does not by itself cause the resulting executable to be -- -- covered by the GNU General Public License. This exception does not -- -- however invalidate any other reasons why the executable file might be -- -- covered by the GNU Public License. -- -- -- -- GNAT is maintained by Ada Core Technologies Inc (http://www.gnat.com). -- -- -- ------------------------------------------------------------------------------ with System; use type System.Bit_Order; with Ada.Unchecked_Conversion; package body GNAT.Big_Endian_Interfaces is function Unchecked_To_Unsigned_16 is new Ada.Unchecked_Conversion (Octets_2, Unsigned_16); function Unchecked_To_Unsigned_32 is new Ada.Unchecked_Conversion (Octets_4, Unsigned_32); function Unchecked_To_Unsigned_64 is new Ada.Unchecked_Conversion (Octets_8, Unsigned_64); function Unchecked_To_Octets_2 is new Ada.Unchecked_Conversion (Unsigned_16, Octets_2); function Unchecked_To_Octets_4 is new Ada.Unchecked_Conversion (Unsigned_32, Octets_4); function Unchecked_To_Octets_8 is new Ada.Unchecked_Conversion (Unsigned_64, Octets_8); --------------------- -- To_Unsigned_16 -- --------------------- function To_Unsigned_16 (X : Octets_2) return Interfaces.Unsigned_16 is begin if System.Default_Bit_Order = System.High_Order_First then return Unchecked_To_Unsigned_16 (X); else return Unchecked_To_Unsigned_16 ((X (1), X (0))); end if; end To_Unsigned_16; --------------------- -- To_Unsigned_32 -- --------------------- function To_Unsigned_32 (X : Octets_4) return Interfaces.Unsigned_32 is begin if System.Default_Bit_Order = System.High_Order_First then return Unchecked_To_Unsigned_32 (X); else return Unchecked_To_Unsigned_32 ((X (3), X (2), X (1), X (0))); end if; end To_Unsigned_32; --------------------- -- To_Unsigned_64 -- --------------------- function To_Unsigned_64 (X : Octets_8) return Interfaces.Unsigned_64 is begin if System.Default_Bit_Order = System.High_Order_First then return Unchecked_To_Unsigned_64 (X); else return Unchecked_To_Unsigned_64 ((X (7), X (6), X (5), X (4), X (3), X (2), X (1), X (0))); end if; end To_Unsigned_64; ----------------- -- To_Octets_2 -- ----------------- function To_Octets_2 (X : Unsigned_16) return Octets_2 is begin if System.Default_Bit_Order = System.High_Order_First then return Unchecked_To_Octets_2 (X); else declare Y : Octets_2 := Unchecked_To_Octets_2 (X); begin return (Y (1), Y (0)); end; end if; end To_Octets_2; ----------------- -- To_Octets_4 -- ----------------- function To_Octets_4 (X : Unsigned_32) return Octets_4 is begin if System.Default_Bit_Order = System.High_Order_First then return Unchecked_To_Octets_4 (X); else declare Y : Octets_4 := Unchecked_To_Octets_4 (X); begin return (Y (3), Y (2), Y (1), Y (0)); end; end if; end To_Octets_4; ----------------- -- To_Octets_8 -- ----------------- function To_Octets_8 (X : Unsigned_64) return Octets_8 is begin if System.Default_Bit_Order = System.High_Order_First then return Unchecked_To_Octets_8 (X); else declare Y : Octets_8 := Unchecked_To_Octets_8 (X); begin return (Y (7), Y (6), Y (5), Y (4), Y (3), Y (2), Y (1), Y (0)); end; end if; end To_Octets_8; end GNAT.Big_Endian_Interfaces;