14 lines
360 B
Ruby
14 lines
360 B
Ruby
class SearchingForSyncState < StatePattern::State
|
|
def handle_byte_stream(bytes)
|
|
idx = 0;
|
|
# spool unwanted bytes
|
|
while (idx < bytes.length && bytes[idx] != Synchronizer::SYNC_PATTERN[0]) do idx = idx+1 end
|
|
|
|
#p "Found pattern at idx = #{idx}"
|
|
transition_to(ConfirmingSyncPatternState)
|
|
|
|
# return
|
|
return bytes[idx..-1] || ""
|
|
end
|
|
end
|