polyorb_hi-marshallers_g.adb 3.63 KB
Newer Older
1 2 3 4 5 6 7 8
------------------------------------------------------------------------------
--                                                                          --
--                          PolyORB HI COMPONENTS                           --
--                                                                          --
--             P O L Y O R B _ H I . M A R S H A L L E R S _ G              --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
--    Copyright (C) 2006-2009 Telecom ParisTech, 2010-2015 ESA & ISAE.      --
--                                                                          --
-- PolyORB-HI is free software; you can redistribute it and/or modify under --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
-- sion. PolyORB-HI is distributed in the hope that it will be useful, but  --
-- WITHOUT ANY WARRANTY; without even the implied warranty of               --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     --
--                                                                          --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception,   --
-- version 3.1, as published by the Free Software Foundation.               --
--                                                                          --
-- You should have received a copy of the GNU General Public License and    --
-- a copy of the GCC Runtime Library Exception along with this program;     --
-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
-- <http://www.gnu.org/licenses/>.                                          --
26
--                                                                          --
jhugues's avatar
jhugues committed
27 28
--              PolyORB-HI/Ada is maintained by the TASTE project           --
--                      (taste-users@lists.tuxfamily.org)                   --
29 30 31 32 33 34 35 36 37
--                                                                          --
------------------------------------------------------------------------------

with Ada.Unchecked_Conversion;
with PolyORB_HI.Streams;

package body PolyORB_HI.Marshallers_G is
   use type PolyORB_HI.Streams.Stream_Element_Offset;

yoogx's avatar
yoogx committed
38 39
   Data_Size : constant PolyORB_HI.Streams.Stream_Element_Offset
     := Data_Type'Object_Size / 8;
40

yoogx's avatar
yoogx committed
41 42
   subtype Data_Type_Stream is
     PolyORB_HI.Streams.Stream_Element_Array (1 .. Data_Size);
43 44 45 46 47 48 49 50 51 52 53 54

   function Data_Type_To_Stream is
      new Ada.Unchecked_Conversion (Data_Type, Data_Type_Stream);
   function Stream_To_Data_Type is
      new Ada.Unchecked_Conversion (Data_Type_Stream, Data_Type);

   --------------
   -- Marshall --
   --------------

   procedure Marshall
     (R :        Data_Type;
yoogx's avatar
yoogx committed
55 56 57 58
      M : in out Messages.Message_Type)
   is
      Data : constant Data_Type_Stream := Data_Type_To_Stream (R);

59
   begin
yoogx's avatar
yoogx committed
60
      Messages.Write (M, Data);
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
   end Marshall;

   ----------------
   -- Unmarshall --
   ----------------

   procedure Unmarshall
     (R :    out Data_Type;
      M : in out Messages.Message_Type)
   is
      Data : PolyORB_HI.Streams.Stream_Element_Array (1 .. Data_Size);
      Last : PolyORB_HI.Streams.Stream_Element_Offset;
   begin
      Messages.Read (M, Data, Last);

yoogx's avatar
yoogx committed
76 77
      if Last = Data_Size then --  XXX Data'Size [attribute]
         R := Stream_To_Data_Type (Data_Type_Stream (Data));
78 79 80 81
      end if;
   end Unmarshall;

end PolyORB_HI.Marshallers_G;