/* #line 139 "./ragel/tsip_parser_header_Subscription_State.rl" */

        public static TSIP_HeaderSubscriptionState Parse(String data)
        {
            int cs  = 0;
            int p   = 0;
            int pe  = data.Length;
            int eof = pe;
            TSIP_HeaderSubscriptionState hdr_Subscription_State = new TSIP_HeaderSubscriptionState();

            int tag_start = 0;


/* #line 524 "../Headers/TSIP_HeaderSubscriptionState.cs" */
            {
                cs = tsip_machine_parser_header_Subscription_State_start;
            }

/* #line 151 "./ragel/tsip_parser_header_Subscription_State.rl" */

/* #line 531 "../Headers/TSIP_HeaderSubscriptionState.cs" */
            {
                sbyte _klen;
                short _trans;
                sbyte _acts;
                sbyte _nacts;
                short _keys;

                if (p == pe)
                {
                    goto _test_eof;
                }
                if (cs == 0)
                {
                    goto _out;
                }
_resume:
                _keys  = _tsip_machine_parser_header_Subscription_State_key_offsets[cs];
                _trans = (short)_tsip_machine_parser_header_Subscription_State_index_offsets[cs];

                _klen = _tsip_machine_parser_header_Subscription_State_single_lengths[cs];
                if (_klen > 0)
                {
                    short _lower = _keys;
                    short _mid;
                    short _upper = (short)(_keys + _klen - 1);
                    while (true)
                    {
                        if (_upper < _lower)
                        {
                            break;
                        }

                        _mid = (short)(_lower + ((_upper - _lower) >> 1));
                        if (data[p] < _tsip_machine_parser_header_Subscription_State_trans_keys[_mid])
                        {
                            _upper = (short)(_mid - 1);
                        }
                        else if (data[p] > _tsip_machine_parser_header_Subscription_State_trans_keys[_mid])
                        {
                            _lower = (short)(_mid + 1);
                        }
                        else
                        {
                            _trans += (short)(_mid - _keys);
                            goto _match;
                        }
                    }
                    _keys  += (short)_klen;
                    _trans += (short)_klen;
                }

                _klen = _tsip_machine_parser_header_Subscription_State_range_lengths[cs];
                if (_klen > 0)
                {
                    short _lower = _keys;
                    short _mid;
                    short _upper = (short)(_keys + (_klen << 1) - 2);
                    while (true)
                    {
                        if (_upper < _lower)
                        {
                            break;
                        }

                        _mid = (short)(_lower + (((_upper - _lower) >> 1) & ~1));
                        if (data[p] < _tsip_machine_parser_header_Subscription_State_trans_keys[_mid])
                        {
                            _upper = (short)(_mid - 2);
                        }
                        else if (data[p] > _tsip_machine_parser_header_Subscription_State_trans_keys[_mid + 1])
                        {
                            _lower = (short)(_mid + 2);
                        }
                        else
                        {
                            _trans += (short)((_mid - _keys) >> 1);
                            goto _match;
                        }
                    }
                    _trans += (short)_klen;
                }

_match:
                _trans = (short)_tsip_machine_parser_header_Subscription_State_indicies[_trans];
                cs     = _tsip_machine_parser_header_Subscription_State_trans_targs[_trans];

                if (_tsip_machine_parser_header_Subscription_State_trans_actions[_trans] == 0)
                {
                    goto _again;
                }

                _acts  = _tsip_machine_parser_header_Subscription_State_trans_actions[_trans];
                _nacts = _tsip_machine_parser_header_Subscription_State_actions[_acts++];
                while (_nacts-- > 0)
                {
                    switch (_tsip_machine_parser_header_Subscription_State_actions[_acts++])
                    {
                    case 0:
/* #line 31 "./ragel/tsip_parser_header_Subscription_State.rl" */
                    {
                        tag_start = p;
                    }
                    break;

                    case 1:
/* #line 35 "./ragel/tsip_parser_header_Subscription_State.rl" */
                    {
                        hdr_Subscription_State.State = TSK_RagelState.Parser.GetString(data, p, tag_start);
                    }
                    break;

                    case 2:
/* #line 39 "./ragel/tsip_parser_header_Subscription_State.rl" */
                    {
                        hdr_Subscription_State.Reason = TSK_RagelState.Parser.GetString(data, p, tag_start);
                    }
                    break;

                    case 3:
/* #line 43 "./ragel/tsip_parser_header_Subscription_State.rl" */
                    {
                        hdr_Subscription_State.Expires = TSK_RagelState.Parser.GetInt32(data, p, tag_start);
                    }
                    break;

                    case 4:
/* #line 47 "./ragel/tsip_parser_header_Subscription_State.rl" */
                    {
                        hdr_Subscription_State.RetryAfter = TSK_RagelState.Parser.GetInt32(data, p, tag_start);
                    }
                    break;

                    case 5:
/* #line 51 "./ragel/tsip_parser_header_Subscription_State.rl" */
                    {
                        hdr_Subscription_State.Params = TSK_RagelState.Parser.AddParam(data, p, tag_start, hdr_Subscription_State.Params);
                    }
                    break;

                    case 6:
/* #line 55 "./ragel/tsip_parser_header_Subscription_State.rl" */
                    {
                    }
                    break;

/* #line 646 "../Headers/TSIP_HeaderSubscriptionState.cs" */
                    default: break;
                    }
                }

_again:
                if (cs == 0)
                {
                    goto _out;
                }
                if (++p != pe)
                {
                    goto _resume;
                }
                _test_eof : {}
                _out      : {}
            }

/* #line 152 "./ragel/tsip_parser_header_Subscription_State.rl" */

            if (cs <
/* #line 663 "../Headers/TSIP_HeaderSubscriptionState.cs" */
                136
/* #line 153 "./ragel/tsip_parser_header_Subscription_State.rl" */
                )
            {
                TSK_Debug.Error("Failed to parse SIP 'Subscription-State' header.");
                hdr_Subscription_State.Dispose();
                hdr_Subscription_State = null;
            }

            return(hdr_Subscription_State);
        }
        /* #line 139 "./ragel/tsip_parser_header_Subscription_State.rl" */
        public static TSIP_HeaderSubscriptionState Parse(String data)
        {
            int cs = 0;
            int p = 0;
            int pe = data.Length;
            int eof = pe;
            TSIP_HeaderSubscriptionState hdr_Subscription_State = new TSIP_HeaderSubscriptionState();

            int tag_start = 0;

            /* #line 524 "../Headers/TSIP_HeaderSubscriptionState.cs" */
            {
            cs = tsip_machine_parser_header_Subscription_State_start;
            }

            /* #line 151 "./ragel/tsip_parser_header_Subscription_State.rl" */

            /* #line 531 "../Headers/TSIP_HeaderSubscriptionState.cs" */
            {
            sbyte _klen;
            short _trans;
            sbyte _acts;
            sbyte _nacts;
            short _keys;

            if ( p == pe )
            goto _test_eof;
            if ( cs == 0 )
            goto _out;
            _resume:
            _keys = _tsip_machine_parser_header_Subscription_State_key_offsets[cs];
            _trans = (short)_tsip_machine_parser_header_Subscription_State_index_offsets[cs];

            _klen = _tsip_machine_parser_header_Subscription_State_single_lengths[cs];
            if ( _klen > 0 ) {
            short _lower = _keys;
            short _mid;
            short _upper = (short) (_keys + _klen - 1);
            while (true) {
            if ( _upper < _lower )
                break;

            _mid = (short) (_lower + ((_upper-_lower) >> 1));
            if ( data[p] < _tsip_machine_parser_header_Subscription_State_trans_keys[_mid] )
                _upper = (short) (_mid - 1);
            else if ( data[p] > _tsip_machine_parser_header_Subscription_State_trans_keys[_mid] )
                _lower = (short) (_mid + 1);
            else {
                _trans += (short) (_mid - _keys);
                goto _match;
            }
            }
            _keys += (short) _klen;
            _trans += (short) _klen;
            }

            _klen = _tsip_machine_parser_header_Subscription_State_range_lengths[cs];
            if ( _klen > 0 ) {
            short _lower = _keys;
            short _mid;
            short _upper = (short) (_keys + (_klen<<1) - 2);
            while (true) {
            if ( _upper < _lower )
                break;

            _mid = (short) (_lower + (((_upper-_lower) >> 1) & ~1));
            if ( data[p] < _tsip_machine_parser_header_Subscription_State_trans_keys[_mid] )
                _upper = (short) (_mid - 2);
            else if ( data[p] > _tsip_machine_parser_header_Subscription_State_trans_keys[_mid+1] )
                _lower = (short) (_mid + 2);
            else {
                _trans += (short)((_mid - _keys)>>1);
                goto _match;
            }
            }
            _trans += (short) _klen;
            }

            _match:
            _trans = (short)_tsip_machine_parser_header_Subscription_State_indicies[_trans];
            cs = _tsip_machine_parser_header_Subscription_State_trans_targs[_trans];

            if ( _tsip_machine_parser_header_Subscription_State_trans_actions[_trans] == 0 )
            goto _again;

            _acts = _tsip_machine_parser_header_Subscription_State_trans_actions[_trans];
            _nacts = _tsip_machine_parser_header_Subscription_State_actions[_acts++];
            while ( _nacts-- > 0 )
            {
            switch ( _tsip_machine_parser_header_Subscription_State_actions[_acts++] )
            {
            case 0:
            /* #line 31 "./ragel/tsip_parser_header_Subscription_State.rl" */
            {
            tag_start = p;
            }
            break;
            case 1:
            /* #line 35 "./ragel/tsip_parser_header_Subscription_State.rl" */
            {
            hdr_Subscription_State.State = TSK_RagelState.Parser.GetString(data, p, tag_start);
            }
            break;
            case 2:
            /* #line 39 "./ragel/tsip_parser_header_Subscription_State.rl" */
            {
            hdr_Subscription_State.Reason = TSK_RagelState.Parser.GetString(data, p, tag_start);
            }
            break;
            case 3:
            /* #line 43 "./ragel/tsip_parser_header_Subscription_State.rl" */
            {
            hdr_Subscription_State.Expires = TSK_RagelState.Parser.GetInt32(data, p, tag_start);
            }
            break;
            case 4:
            /* #line 47 "./ragel/tsip_parser_header_Subscription_State.rl" */
            {
            hdr_Subscription_State.RetryAfter = TSK_RagelState.Parser.GetInt32(data, p, tag_start);
            }
            break;
            case 5:
            /* #line 51 "./ragel/tsip_parser_header_Subscription_State.rl" */
            {
            hdr_Subscription_State.Params = TSK_RagelState.Parser.AddParam(data, p, tag_start, hdr_Subscription_State.Params);
            }
            break;
            case 6:
            /* #line 55 "./ragel/tsip_parser_header_Subscription_State.rl" */
            {
            }
            break;
            /* #line 646 "../Headers/TSIP_HeaderSubscriptionState.cs" */
            default: break;
            }
            }

            _again:
            if ( cs == 0 )
            goto _out;
            if ( ++p != pe )
            goto _resume;
            _test_eof: {}
            _out: {}
            }

            /* #line 152 "./ragel/tsip_parser_header_Subscription_State.rl" */

            if( cs <
            /* #line 663 "../Headers/TSIP_HeaderSubscriptionState.cs" */
            136
            /* #line 153 "./ragel/tsip_parser_header_Subscription_State.rl" */
             ){
                TSK_Debug.Error("Failed to parse SIP 'Subscription-State' header.");
                hdr_Subscription_State.Dispose();
                hdr_Subscription_State = null;
            }

            return hdr_Subscription_State;
        }