Index: src/natools-s_expressions-atom_buffers.adb ================================================================== --- src/natools-s_expressions-atom_buffers.adb +++ src/natools-s_expressions-atom_buffers.adb @@ -216,6 +216,30 @@ procedure Soft_Reset (Buffer : in out Atom_Buffer) is begin Buffer.Used := 0; end Soft_Reset; + + overriding procedure Write + (Buffer : in out Atom_Buffer; + Item : in Ada.Streams.Stream_Element_Array) + renames Append; + + + overriding procedure Read + (Buffer : in out Atom_Buffer; + Item : out Ada.Streams.Stream_Element_Array; + Last : out Ada.Streams.Stream_Element_Offset) is + begin + if Item'Length < Buffer.Used then + Last := Item'Last; + Item := Buffer.Ref.Query.Data.all (1 .. Item'Length); + Buffer.Used := Buffer.Used - Item'Length; + else + Last := Item'First + Buffer.Used - 1; + Item (Item'First .. Last) + := Buffer.Ref.Query.Data.all (1 .. Buffer.Used); + Buffer.Used := 0; + end if; + end Read; + end Natools.S_Expressions.Atom_Buffers; Index: src/natools-s_expressions-atom_buffers.ads ================================================================== --- src/natools-s_expressions-atom_buffers.ads +++ src/natools-s_expressions-atom_buffers.ads @@ -25,13 +25,21 @@ with Natools.S_Expressions.Atom_Refs; package Natools.S_Expressions.Atom_Buffers is pragma Preelaborate (Atom_Buffers); - type Atom_Buffer is tagged limited private; + type Atom_Buffer is new Ada.Streams.Root_Stream_Type with private; pragma Preelaborable_Initialization (Atom_Buffer); + overriding procedure Write + (Buffer : in out Atom_Buffer; + Item : in Ada.Streams.Stream_Element_Array); + overriding procedure Read + (Buffer : in out Atom_Buffer; + Item : out Ada.Streams.Stream_Element_Array; + Last : out Ada.Streams.Stream_Element_Offset); + procedure Preallocate (Buffer : in out Atom_Buffer; Length : in Count); -- Preallocate enough memory to append Length octets without -- any further allocation. procedure Append (Buffer : in out Atom_Buffer; Data : in Atom); @@ -69,11 +77,11 @@ procedure Soft_Reset (Buffer : in out Atom_Buffer); -- Clear buffer keeping internal memory private - type Atom_Buffer is tagged limited record + type Atom_Buffer is new Ada.Streams.Root_Stream_Type with record Ref : Atom_Refs.Reference; Available, Used : Count := 0; end record; end Natools.S_Expressions.Atom_Buffers;