var Struct = require('structjs')

var Entry = module.exports = new Struct({
  tag:      Struct.String(4),
  checkSum: Struct.Uint32,
  offset:   Struct.Uint32,
  length:   Struct.Uint32
})

var Directory = module.exports = new Struct({
  scalerType:    Struct.Int32,
  numTables:     Struct.Uint16,
  searchRange:   Struct.Uint16.with({
    $packing: function() {
      var searchRange, next = 1
      while ((next = next * 2) <= this.numTables) {
        searchRange = next
      }
      return searchRange * 16
    }
  }),
  entrySelector: Struct.Uint16.with({
    $packing: function() {
      return Math.log(this.searchRange / 16) / Math.LN2
    }
  }),
  rangeShift:    Struct.Uint16.with({
    $packing: function() {
      return this.numTables * 16 - this.searchRange
    }
  }),
  entries:       Struct.Hash(Entry, 'tag', Struct.Ref('numTables'))
})
@@ -367,145 +367,45 @@
     
-var searchRange, next = 1%0A      while ((next = next * 2) %3C= this.numTables) %7B%0A        searchRange = next%0A      %7D%0A      return searchRange
+return easySearchable(this.numTables)
  * 1
@@ -509,29 +509,38 @@
 log(
-this.searchRange / 16
+easySearchable(this.numTables)
 ) / 
@@ -631,23 +631,49 @@
 %7B%0A      
-return 
+var searchRange = easySearchable(
 this.num
@@ -682,21 +682,50 @@
 bles
+)
  * 16
- - this.
+%0A      return this.numTables * 16 - 
 sear
@@ -814,8 +814,153 @@
 es'))%0A%7D)
+%0A%0Afunction easySearchable(numTables) %7B%0A  var result, next = 1%0A  while ((next = next * 2) %3C= numTables) %7B%0A    result = next%0A  %7D%0A  return result%0A%7D%0A

fix directory serialization