 vrs = require("../lib/vrs")
 
 log = require("./logger")('pdu')
+
+# helper: total length for array of buffers
+total_length = (arr) ->
+  arr.reduce((sum, buff) ->
+    return sum + buff.length
+  , 0)
 
 ##
 # PDUDecoder

  _enc = new PDUEncoder()
  _enc.on 'data', (buff) ->
    console.log "BUFFER:", buff
  _enc.write _pdu

###

    for item in @presentation_context
      _buffers.push item.encode()
    # _buffers.push @user_information.encode()
    _var_len = total_length(_buffers)
    _header = Buffer.concat([new Buffer([0x01, 0x00]), mk_uint32(66 + _var_len),
                              # protocol version
                              mk_uint16(1),
                              # reserved
                              new Buffer([0x00, 0x00]),
                              # called & calling aet title
                              new Buffer(printf("%-16s%-16s", @called_aet_title.substr(0,16),
                                @calling_aet_title.substr(0,16)), 'binary'),
