summaryrefslogtreecommitdiffstats
path: root/K2LABI/Common/FlowDecoder/FlowDecoder.h
blob: 6f8be6483618e67297f14296ad6a3848d151f307 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef __FLOW_DECODER_H__
#define __FLOW_DECODER_H__

#include "IFlowDecoder.h"


class CFlowDecoder : public IFlowDecoder
{
public:
    CFlowDecoder();
    virtual ~CFlowDecoder() {}

    // Gets called to submit a new package to buffer
    void            DecodeFlow(BYTE* pBuffer, unsigned long nLen);
    virtual void    Reset();

protected:
    void            InitializeBuffer(BYTE* pBuffer, unsigned long nLen);
    unsigned long   GetNumberOfBytesInBuffer() const;
    unsigned long   GetNumberOfMemoryChunks() const;
    bool            GetMemoryChunk(unsigned long nNum, BYTE*& pReadPointer, unsigned long& nBytesAvailable) const;
    bool            AddBytesToBuffer(BYTE* pBuffer, unsigned long nLen);
    bool            CopyFromBuffer(BYTE* pTarget, unsigned long len) const;
    bool            RemoveBytesFromBuffer(unsigned long len);

protected:
    enum eStateRetVal
    {
        E_STATE_NEEDS_MORE_DATA,
        E_STATE_GOT_WRONG_DATA,
        E_STATE_OK,
        E_STATE_UNDEFINED
    };

    bool m_nSynchronized;

    virtual eStateRetVal ReceiveHeader() = 0;
    virtual eStateRetVal ReceivePacket() = 0;

private:
    enum eDecoderState
    {
        E_WAITING_FOR_HEADER,
        E_WAITING_FOR_PACKET_DATA,
    };

    unsigned long   m_nBytesInBuffer;
    BYTE*           m_pCurrentReadPointer;
    BYTE*           m_pBufferStart;
    BYTE*           m_pBufferEnd;
    eDecoderState   m_DecoderState;
};

#endif // __FLOW_DECODER_H__