#ifndef _QUEUE_H_
  #define _QUEUE_H_

    #include "main.h"
    #include "utilits.h"
    #include "utils.h"
   
    #include <stddef.h> // size_t
    #include <stdint.h> // uint16_t
    
    typedef struct _QUEUE_ENTRY_
    {
        uint16_t cbytes;   // количество байт в элементе очереди
    } 
    QUEUE_ENTRY;

    typedef struct _QUEUE_
    { 
        char * pString;
        size_t nStringLen;
        //-----------------------
        size_t count;                  // count of elements in the queue
        size_t bytes_available;        // free bytes in the buffer
        size_t size;                   // the size of buffer of the queue
        
        QUEUE_ENTRY * LastWrite;       // The previous write pointer 
        QUEUE_ENTRY * pQueueHead;      // The pointer to the start of the buffer
        QUEUE_ENTRY * pWritePointer;   // write-pointer (head of the queue)
        QUEUE_ENTRY * pReadPointer;    // read-pointer (tail of the queue)
        
    } QUEUE;

    #define MAX_QUEUE_SIZE 4096
        
    BOOL queue_create( BYTE * memoryblock, size_t size, QUEUE * pQueue );
    BOOL queue_clear( QUEUE * pQueue );
    BOOL queue_getcount( QUEUE * pQueue, size_t * pSize );
    BOOL queue_cat( QUEUE * pQueue, const BYTE * pData, size_t bytes);
    BOOL queue_add( QUEUE * pQueue, const BYTE * pData, size_t bytes);
    BOOL queue_get( QUEUE * pQueue, BYTE * pReturnData, size_t cbMaxSize, size_t * pLength );
    BOOL queue_get_topitemsize( QUEUE * pQueue, size_t * pSize );
    
  // unused:  
  //BOOL queue_getsize( QUEUE * pQueue, unsigned int * pCount );   // alternate "__queue_size(pQueue)" macros
  //BOOL queue_bytes_available( QUEUE * pQueue, size_t * pBytes ); // alternate "__queue_bytesavailable(pQueue)" macros  
  //BOOL queue_peeklastbyte( QUEUE * pQueue, BYTE * pReturnByte );
  //BOOL queue_peekbyte( QUEUE * pQueue, BYTE * pReturnByte, int Number );
#endif

