lib/struct.js
function StructType (arg, data) {
    if (!(this instanceof StructType)) {
      return new StructType(arg, data)
    }
    debug('creating new struct instance')
    var store
    if (Buffer.isBuffer(arg)) {
      debug('using passed-in Buffer instance to back the struct', arg)
      assert(arg.length >= StructType.size, 'Buffer instance must be at least ' +
          StructType.size + ' bytes to back this struct type')
      store = arg
      arg = data
    } else {
      debug('creating new Buffer instance to back the struct (size: %d)', StructType.size)
      store = new Buffer(StructType.size)
    }

    // set the backing Buffer store
    store.type = StructType
    this['ref.buffer'] = store

    if (arg) {
      for (var key in arg) {
        // hopefully hit the struct setters
        this[key] = arg[key]
      }
    }
    StructType._instanceCreated = true
  }
function StructType (arg, data) {
    if (!(this instanceof StructType)) {
      return new StructType(arg, data)
    }
    debug('creating new struct instance')
    var store
    if (Buffer.isBuffer(arg)) {
      debug('using passed-in Buffer instance to back the struct', arg)
      assert(arg.length >= StructType.size, 'Buffer instance must be at least ' +
          StructType.size + ' bytes to back this struct type')
      store = arg
      arg = data
    } else {
      debug('creating new Buffer instance to back the struct (size: %d)', StructType.size)
      store = new Buffer(StructType.size)
    }

    // set the backing Buffer store
    store.type = StructType
    this['ref.buffer'] = store

    if (arg) {
      for (var key in arg) {
        // hopefully hit the struct setters
        this[key] = arg[key]
      }
    }
    StructType._instanceCreated = true
  }
function StructType ( arg , data ) { if ( ! ( this instanceof StructType ) ) { return new StructType ( arg , data ) } debug ( 'creating new struct instance' ) var store if ( Buffer . isBuffer ( arg ) ) { debug ( 'using passed-in Buffer instance to back the struct' , arg ) assert ( arg . length >= StructType . size , 'Buffer instance must be at least ' + StructType . size + ' bytes to back this struct type' ) store = arg arg = data } else { debug ( 'creating new Buffer instance to back the struct (size: %d)' , StructType . size ) store = new Buffer ( StructType . size ) } // set the backing Buffer store store . type = StructType this [ 'ref.buffer' ] = store if ( arg ) { for ( var key in arg ) { // hopefully hit the struct setters this [ key ] = arg [ key ] } } StructType . _instanceCreated = true }
This is the "constructor" of the Struct type that gets returned.

Invoke it with `new` to create a new Buffer instance backing the struct.
Pass it an existing Buffer instance to use that as the backing buffer.
Pass in an Object containing the struct fields to auto-populate the
struct with the data.
This is the constructor of the Struct type that gets returned .