BBqueue.Buffers.framed

Entities

Simple Types

Subtypes

Constants

Subprograms

Description

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);
WG  : Write_Grant := Empty;
RG  : Read_Grant := Empty;
S   : 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

Commit

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.

Parameters
This
G
Size

Empty

function Empty return Read_Grant
Return Value

Empty

function Empty return Write_Grant
Return Value

Framed_Buffer

type Framed_Buffer (Size   : Buffer_Size)
is limited private;
Record fields
Size

Framed_Count

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.

Grant

procedure Grant (This : in out Framed_Buffer;
                 G    : in out Write_Grant;
                 Size : Framed_Count)

Request a contiguous writeable slice of the internal buffer

Parameters
This
G
Size

Max_Frame_Header_Size

Max_Frame_Header_Size : constant := 9;

Read

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.

Parameters
This
G

Read_CB

generic
   with procedure Process_Read (Data : Storage_Array);
procedure Read_CB (This   : in out Framed_Buffer;
                   Result :    out Result_Kind)

Read from the buffer using a "callback". This procedure will call Process_Read () on the slice returned by Read (), if the result is Valid.

Generic formal parameters
Process_Read
Parameters
This
Result

Read_Grant

type Read_Grant is limited private;

Read_Grant_In_Progress

function Read_Grant_In_Progress (This : Framed_Buffer) return Boolean
Parameters
This
Return Value

Release

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.

Parameters
This
G

Slice

function Slice (G : Read_Grant) return Slice_Rec
Parameters
G
Return Value

Slice

function Slice (G : Write_Grant) return Slice_Rec
Parameters
G
Return Value

State

function State (G : Read_Grant) return Result_Kind
Parameters
G
Return Value

State

function State (G : Write_Grant) return Result_Kind
Parameters
G
Return Value

Write_CB

generic
   with procedure Process_Write (Data      : out Storage_Array;
                                 To_Commit : out Count);
procedure Write_CB (This   : in out Framed_Buffer;
                    Size   :        Framed_Count;
                    Result :    out Result_Kind)

Write in the buffer using a "callback". This procedure will call Process_Write () on the slice returned by Grant (), if the result is Valid. It will then call Commit with the value To_Commit returned by Process_Write ().

Generic formal parameters
Process_Write
Parameters
This
Size
Result

Write_Grant

type Write_Grant is limited private;

Write_Grant_In_Progress

function Write_Grant_In_Progress (This : Framed_Buffer) return Boolean
Parameters
This
Return Value