   from_json: (json) ->
     @id = json.id
     return super(json)
+
+class PresentationContextItemAc extends PresentationContextItem
+  type: 0x21
+  name: 'presentation_context_ac'
+  decode: () ->
+    super()
+    @resultReason = @_buff[@_start + 6]
+  fixed_fields: () ->
+    new Buffer([@id, 0, @resultReason, 0])
+  to_json: () ->
+    _json = super()
+    _json.resultReason = @resultReason
+    return _json
+  from_json: (json) ->
+    @resultReason = json.resultReason
+    return super(json)
+
 
 class AbstractSyntaxItem extends Item
   type: 0x30

exports.PDUAssociateRq = PDUAssociateRq


if require.main is module
  echo_json = {
    "name": "association_rq",
    "called_aet_title": "TESTME",
    "calling_aet_title": "DCMECHO",
    "application_context": "1.2.840.10008.3.1.1.1"
    "presentation_context": [
      "id": 1,
      "abstract_syntax": "1.2.840.10008.1.1",
      "transfer_syntax": ["1.2.840.10008.1.2"]]
    "user_information":
      "maximum_length": 16384
      "implementation_class_uid": "1.2.40.0.13.1.1"
      "asynchronous_operations_window":
        "maximum_number_operations_invoked": 0
        "maximum_number_operations_performed": 0
      "implementation_version_name": "dcm4che-2.0"
  }

  _pdu = new PDUAssociateRq(echo_json)
  console.log "pdu ==>", _pdu
  console.log "PDU JSON:", JSON.stringify(_pdu.to_json(), null, 4)
  _enc = new PDUEncoder()
  _enc.on 'data', (buff) ->
    console.log "BUFFER:", buff
    _dec = new PDUDecoder()
    _dec.on 'data', (pdu) ->
      console.log "encoded/decoded pdu", JSON.stringify(pdu.to_json(), null, 4)
    _dec.write buff
    _dec.end()
  _enc.write _pdu

###
if require.main is module and false
  net = require "net"
  server = net.createServer {}, (conn) ->
    log.info "connection"
    conn.on 'end', () ->
      log.info "connection end"
    conn.pipe new PDUDecoder()
  server.listen 11112, () ->
    log.info "server bound to port 11112"
###
    @calling_aet_title = json.calling_aet_title
    return super(json)

class PDUAssociateAc extends PDUAssociateRq

class Item extends PDU
  _json_name: false

