         @_buffer[i] = fill
       @_write @_buffer.slice 0, size
 
+  buffer: (shiftable...) ->
+    callback = @_reset(shiftable)
+    read = 0
+    while @pattern
+      if read is @_buffer.length
+        buffer = new Buffer buffer.length * 2
+        @_buffer.copy(buffer)
+        @_buffer = buffer
+      read += @write(@_buffer, read, @_buffer.length - read)
+    callback.call @self, @_buffer.slice 0, read
+
   serialize: (shiftable...) ->
-    if typeof shiftable[shiftable.length - 1] == 'function'
-      callback = shiftable.pop()
-
-    nameOrPattern = shiftable.shift()
-    packet        = @packets[nameOrPattern] or {}
-    pattern       = packet.pattern or parsePattern(nameOrPattern)
-    callback    or= packet.callback or noop
-
-    if not packet.pattern
-      for part in pattern
-        if part.transforms
-          part.transforms.reverse()
-
-    @pattern      = pattern
-    @callback     = callback
-    @patternIndex = 0
-    @outgoing     = shiftable
-
-    for value, i in @outgoing
-      @outgoing[i] = @pipeline(pattern[i], value)
-
-    @nextField()
-    @nextValue()
-
+    @callback = @_reset(shiftable)
     # Implementing pause requires callbacks.
     if @streaming
       while @pattern
         read = @write(@_buffer, 0, @_buffer.length)
         @_write @_buffer.slice 0, read
+
+  _reset: (shiftable) ->
+    if typeof shiftable[shiftable.length - 1] == 'function'
+      callback = shiftable.pop()
+
+    nameOrPattern = shiftable.shift()
+    packet        = @packets[nameOrPattern] or {}
+    pattern       = packet.pattern or parsePattern(nameOrPattern)
+    callback    or= packet.callback or noop
+
+    if not packet.pattern
+      for part in pattern
+        if part.transforms
+          part.transforms.reverse()
+
+    @pattern      = pattern
+    @callback     = noop
+    @patternIndex = 0
+    @outgoing     = shiftable
+
+    for value, i in @outgoing
+      @outgoing[i] = @pipeline(pattern[i], value)
+
+    @nextField()
+    @nextValue()
+
+    callback
 
   _write: (slice) ->
     if @_decoder

    @callback = null
    @fields = []

  pipeline: (pattern, value) ->
    # Run the piplines for parsing.
    if pattern.transforms

ieee754 = require "./ieee754"
stream = require "stream"

# Convert an array of bytes into an hex string, two characters for each byte. #
# FIXME Why less than 10 when we're doing hex?
hex = (bytes) ->
  h = bytes.map (b) -> if b < 10 then "0" + b.toString(16) else b.toString(16)
  h.join("")

# Default callback, when no callback is provided.
