Getting this ERROR: "Expected class, delegate, enum, interface, or struct", and there are no missing/extra braces
===

I know this error normally means I'm missing or have an extra curly brace somewhere but mine all match up...

Can anyone tell me what this error could mean otherwise, I cannot for the life of me figure it out!

(Don't worry about the actual code, unless of course you see something blatantly wrong, I have not yet completely worked it all out)

namespace CSharp
{

    public class BitStream
    {
        static int[] masks = new int[32];
        static byte start_code_prefix={0x00,0x00,0x01};
        static byte short_video_start_marker={0x00,0x00,0x01};
        
        byte *_buffer = 0;
	    int _bufferSize = 0;
	    int _currByte = 0;
	    int	_currBit = 0;	// current read position;

	    public BitStream(byte *buffer,int size)
        {
            _buffer = buffer;
	        _bufferSize = size;
            
            for(int i=0;i<32;i++) 
            {
	            [i]masks=1;
	            if (i<31) [i]masks=[i]masks<<(31-i);
            }
        }

	    public void GetPosition(int &bytes, int &bits)
        {	    
		    bytes=_currByte; bits=_currBit; 
        }

        public int SetPosition(int bytes, int bits)
        {	    
            _currByte=bytes;
	        _currBit=bits;
	        //return QV_SUCCESS;
        }

	    public int GetNextBit();
        {	    
            if (_currByte>=_bufferSize) return -1		// no more data

	        byte data=_buffer[_currByte];

	        int bit=_currBit+24;
	        _currBit++;

	        if (_currBit==8) {
		        _currByte=_currByte+1;
		        _currBit=0;
	        }

	        if ((data&masks[bit])==0) return 0;
	        else return 1;
        }
	
	    public int GetNextBits(int numOfBits)
        {	    
            int value=0;
	        for (int i=0;i<numOfBits;i++) 
            {
		        int bit=GetNextBit();
		        if (bit<0) break;
		        else if (bit==1) value=value|masks[32+i-numOfBits];
	        }
	        return value;
        }

	    public byte *GetNextBytes(int &numOfBytes)			// byte aligned
        {	    
            ByteAlign();

	        if (_currByte>=_bufferSize) return NULL;		// no more data

	        byte *data=&_buffer[_currByte];

	        if (_currByte+numOfBytes>_bufferSize) numOfBytes=(int)(_bufferSize-_currByte);
	        _currByte=_currByte+numOfBytes;

	        return data;
        }

	    public bool NextStartCode(byte &startcode)
        {	    
            //int nBytes=sizeof(start_code_prefix)+1;
	        int nBytes=1;
	        bool found;

	        ByteAlign();

	        do 
            {
		        found=true;
		        byte *ptr=GetNextBytes(nBytes);
		        if (ptr==NULL) 
                {
			        found=false;
			        break;
		        }

		        for (int k=0;k<sizeof(start_code_prefix);k++) 
                {
			        if (*(ptr+k)!=start_code_prefix[k])
                    {
				        found=false;
				        break;
			        }
		        }

		        if (found) 
                {
			        startcode=*(ptr+sizeof(start_code_prefix));
			        _currByte=_currByte+sizeof(start_code_prefix);
			        break;
		        }

	        } while (!found);

	        return found;
        }

	    public void ByteAlign()
        {	    
            if (_currBit!=0) 
            {
		        _currByte=_currByte+1;
		        _currBit=0;
	        }
        }

	    public bool MarkerBit()
        {	    
            if (GetNextBit()!=1) return false;
	        return true;
        }

        public bool IsEOS()
        {	    
            if (_currByte>=_bufferSize) return true;		// no more data
            return false;
        }

        public static void Main()
        {
            int ParseTxPkt(byte[] *pTxPkt, byte[] **ppPayload, int &payloadLen, int &pid, int &payload_unit_start_indicator,int &continuity_counter, int64 &pcr, int64 &offset,bool peek)
            {
                int transport_error_indicator;
                int transport_priority;
                int transport_scrambling_control;
                int adaptation_field_control;
                int adaptation_field_length;
                int payloadOffset;
                bool pcr_flag;
                int ret=QV_FAILURE;
                byte *txPkt;

                BitStream *stream=NULL;  
                payloadOffset=-1;
                payloadLen=0;
                *ppPayload=NULL;
                pcr=-1;
                pcr_flag=false;

                txPkt=pTxPkt;

                stream=new BitStream(txPkt,TX_PKT_SIZE);

                if (stream->GetNextBits(8)!=Sync_Byte) {
                    delete stream;
                    return QV_FAILURE;
                }

                transport_error_indicator=stream->GetNextBit();
                payload_unit_start_indicator=stream->GetNextBit();
                transport_priority=stream->GetNextBit();
                pid=stream->GetNextBits(13);
                transport_scrambling_control=stream->GetNextBits(2);
                adaptation_field_control=stream->GetNextBits(2);
                continuity_counter=stream->GetNextBits(4);

                switch (adaptation_field_control) {
                case 0:    // reserved
                    break;
                case 2:    // no payload
                    *ppPayload=NULL;
                    payloadLen=0;
                    adaptation_field_length=stream->GetNextBits(8);
                    if (adaptation_field_length>0 && pcr<0) {
                        stream->GetNextBits(3);
                        pcr_flag=stream->GetNextBits(1);
                        stream->GetNextBits(4);
                        if (pcr_flag) {
                            pcr=stream->GetNextBits(32);
                            pcr=pcr*2+stream->GetNextBits(1);
                        }
                    }
                    ret=QV_SUCCESS;
                    break;
                case 1:    // no adaptation field
                    payloadOffset=4;
                    payloadLen=TX_PKT_SIZE-4;
                    *ppPayload=txPkt+payloadOffset;
                    ret=QV_SUCCESS;
                    break;
                case 3:    // adaptation field and payload
                    adaptation_field_length=stream->GetNextBits(8);
                    payloadOffset=4+1+adaptation_field_length;
                    payloadLen=TX_PKT_SIZE-4-(1+adaptation_field_length);
                    *ppPayload=txPkt+payloadOffset;
                    if (adaptation_field_length>0) {
                        stream->GetNextBits(3);
                        pcr_flag=stream->GetNextBits(1);
                        stream->GetNextBits(4);
                        if (pcr_flag) {
                            pcr=stream->GetNextBits(32);      
                            pcr=pcr*2+stream->GetNextBits(1);
                        }
                    }
                    ret=QV_SUCCESS;
                    break;
                }

                delete stream;
                return ret;
            }
        }
    }
}