Skip to content

Instantly share code, notes, and snippets.

@bigeasy
Created September 17, 2010 18:11
Show Gist options
  • Save bigeasy/584661 to your computer and use it in GitHub Desktop.
Save bigeasy/584661 to your computer and use it in GitHub Desktop.
write = (buffer) ->
offset = if arguments.length > 1 then arguments[1] else 0
length = if arguments.length > 2 then arguments[2] else buffer.length
OUTER: while machine != null && offset < length
pattern = machine.definition.pattern[machine.index]
if (pattern.arrayed)
INNER: loop
buffer[offset] = machine.value[machine.offset]
machine.offset += machine.increment
bytesWritten++
offset++
if machine.offset == machine.terminal
break INNER
if offset == length
break OUTER
else
INNER: loop
buffer[offset] = Math.floor(machine.value / Math.pow(256, machine.offset)) & 0xff
machine.offset += machine.increment
bytesWritten++
offset++
if machine.offset == machine.terminal
break INNER
if offset == length
break OUTER
if ++machine.index == machine.definition.pattern.length
machine.definition.callback.apply null, [ engine ]
machine = null
else
machine = mechanize machine.definition, machine.index, outgoing[machine.index]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment