4.1.6. GNATCOLL.Coders

package GNATCOLL.Coders is

   type Coder_Interface is limited interface;

   type Coder_Access is access all Coder_Interface'Class;

   type Flush_Mode is
     (No_Flush,
      --  Regular way for coding, no flush

      Sync_Flush,
      --  All pending output is flushed to the output buffer and the output
      --  is aligned on a byte boundary, so that the decoder can get all
      --  input data available so far. (In particular In_Last = In_Data'Last
      --  after the call to Transcode if enough output space has been provided
      --  before the call). Flushing may degrade compression for some
      --  compression algorithms and so it should be used only when necessary.

      Full_Flush,
      --  All output is flushed as with Synch_Flush, and the coding state is
      --  reset so that decoding can restart from this point if previous
      --  compressed data has been damaged or if random access is desired.
      --  Using Full_Flush too often can seriously degrade the compression kind
      --  of coding.

      Finish);
      --  Just to tell the coder that input data is complete

   function Is_Open (Coder : Coder_Interface) return Boolean is abstract;
   --  Indicates that coder is ready to transcode data.
   --  Initialization procedure has to be implemented in the descendant with
   --  parameters appropriate to the transcoding algorithm.

   procedure Transcode
     (Coder    : in out Coder_Interface;
      In_Data  :        Stream_Element_Array;
      In_Last  :    out Stream_Element_Offset;
      Out_Data :    out Stream_Element_Array;
      Out_Last :    out Stream_Element_Offset;
      Flush    :        Flush_Mode) is abstract
     with Pre'Class => In_Data'First > Stream_Element_Offset'First
       and then Out_Data'First > Stream_Element_Offset'First;
   --  Transcodes data from In_Data to Out_Date.
   --  In_Last is the index of last element from In_Data accepted by
   --  the Coder.
   --  Out_Last is the index of the last element written to the Out_Data.
   --  To tell the Coder that incoming data is complete, pass Finish as the
   --  Flush parameter and call Transcoder with empty In_Data until Finished
   --  routine indicates end of stream.

   procedure Flush
     (Coder    : in out Coder_Interface'Class;
      Out_Data :    out Stream_Element_Array;
      Out_Last :    out Stream_Element_Offset;
      Flush    :        Flush_Mode) with Inline;
   --  Flushes the data from coder

   function Total_In
     (Coder : Coder_Interface) return Stream_Element_Count is abstract;
   --  Returns total amount of input data sent into the coder

   function Total_Out
     (Coder : Coder_Interface) return Stream_Element_Count is abstract;
   --  Returns total amount of output data taken from the coder

   function Finished (Coder : Coder_Interface) return Boolean is abstract;
   --  Indicates that incoming data stream finished and all internally
   --  processed data is out of coder.

   procedure Close (Coder : in out Coder_Interface) is abstract;
   --  Frees all internal coder memory allocations

end GNATCOLL.Coders;