This unit is based on BBqueue.Buffers and uses markers in the buffer to track the size of each commited write grants. The size of consequent read grants will conrespond to the sizes of commited write grants.
It can be used to handle variable lenght packets:
Q : aliased Framed_Buffer (64); G : Write_Grant := Empty; G : Read_Grant := Empty; : Slice_Rec;
begin Grant (Q, WG, 8); -- Get a worst case grant of size 8 Commit (Q, WG, 4); -- Only commit 4 Grant (Q, WG, 8); -- Get a worst case grant of size 8 Commit (Q, WG, 5); -- Only commit 5 Read (W, RG); -- Returns a grant of size 4
procedure Commit (This : in out Framed_Buffer;
G : in out Write_Grant;
Size : Framed_Count := Framed_Count'Last)
Commit a writeable slice. Size can be smaller than the granted slice for partial commits. The commited slice is then available for Read.
function Empty return Read_Grant
function Empty return Write_Grant
type Framed_Buffer (Size : Buffer_Size)
is limited private;
subtype Framed_Count
is Count range Count'First .. Count'Last - Max_Frame_Header_Size;
The frame can take up to 9 bytes in addition to the allocated size. The size of what can be allocated is therefore lower than for a non-framed buffer.
procedure Grant (This : in out Framed_Buffer;
G : in out Write_Grant;
Size : Framed_Count)
Request a contiguous writeable slice of the internal buffer
Max_Frame_Header_Size : constant := 9;
procedure Read (This : in out Framed_Buffer;
G : in out Read_Grant)
Request contiguous readable slice from the internal buffer. The size of the returned Read_Grant will be based on the size of previously commited frames.
type Read_Grant is limited private;
function Read_Grant_In_Progress (This : Framed_Buffer) return Boolean
procedure Release (This : in out Framed_Buffer;
G : in out Read_Grant)
Release a readable slice. Partial releases not allowed, the full grant will be released.
function Slice (G : Read_Grant) return Slice_Rec
function Slice (G : Write_Grant) return Slice_Rec
function State (G : Read_Grant) return Result_Kind
function State (G : Write_Grant) return Result_Kind
type Write_Grant is limited private;
function Write_Grant_In_Progress (This : Framed_Buffer) return Boolean