Class: UniversalDetector::CodingStateMachine

Inherits:
Object
  • Object
show all
Defined in:
lib/CodingStateMachine.rb

Instance Method Summary collapse

Constructor Details

#initialize(sm) ⇒ CodingStateMachine

Returns a new instance of CodingStateMachine.



33
34
35
36
37
38
# File 'lib/CodingStateMachine.rb', line 33

def initialize(sm)
    @_mModel = sm
    @_mCurrentBytePos = 0
    @_mCurrentCharLen = 0
    reset()
end

Instance Method Details

#get_coding_state_machineObject



70
71
72
# File 'lib/CodingStateMachine.rb', line 70

def get_coding_state_machine
    return @_mModel['name']
end

#get_current_charlenObject



66
67
68
# File 'lib/CodingStateMachine.rb', line 66

def get_current_charlen
    return @_mCurrentCharLen
end

#next_state(c) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/CodingStateMachine.rb', line 44

def next_state(c)
    # for each byte we get its class
    # if it is first byte, we also get byte length
    byteCls = @_mModel['classTable'][c]
    
    if @_mCurrentState == :Start
        @_mCurrentBytePos = 0
        @_mCurrentCharLen = @_mModel['charLenTable'][byteCls]
    end
    # from byte's class and stateTable, we get its next state
    stateValue = {:Start => 0, :Error  => 1, :ItsMe  => 2}
    unless stateValue[@_mCurrentState]
        v = @_mCurrentState
    else
        v = stateValue[@_mCurrentState]
    end
    @_mCurrentState = @_mModel['stateTable'][v * @_mModel['classFactor'] + byteCls]
    
    @_mCurrentBytePos += 1
    return @_mCurrentState
end

#resetObject



40
41
42
# File 'lib/CodingStateMachine.rb', line 40

def reset
    @_mCurrentState = :Start
end