public byte[] marshall() throws Exception {
    out = new ByteArrayOutputStream();
    out.reset();
    out.write(PduUtilities.makeByteArrayFromInt(getCmd_len(), 4));
    out.write(PduUtilities.makeByteArrayFromInt(getCmd_id(), 4));
    out.write(PduUtilities.makeByteArrayFromInt(getCmd_status(), 4));
    out.write(PduUtilities.makeByteArrayFromInt(getSeq_no(), 4));

    out.write(PduUtilities.stringToNullTerminatedByteArray(service_type));
    out.write(PduUtilities.makeByteArrayFromInt(source_addr_ton, 1));
    out.write(PduUtilities.makeByteArrayFromInt(source_addr_npi, 1));
    out.write(PduUtilities.stringToNullTerminatedByteArray(source_addr));
    out.write(PduUtilities.makeByteArrayFromInt(dest_addr_ton, 1));
    out.write(PduUtilities.makeByteArrayFromInt(dest_addr_npi, 1));
    out.write(PduUtilities.stringToNullTerminatedByteArray(destination_addr));
    out.write(PduUtilities.makeByteArrayFromInt(esm_class, 1));
    out.write(PduUtilities.makeByteArrayFromInt(registered_delivery_flag, 1));
    out.write(PduUtilities.makeByteArrayFromInt(data_coding, 1));

    for (Iterator<Tlv> it = optionalsByTag.values().iterator(); it.hasNext(); ) {
      Tlv opt = it.next();
      out.write(PduUtilities.makeByteArrayFromInt(opt.getTag(), 2));
      out.write(PduUtilities.makeByteArrayFromInt(opt.getLen(), 2));
      out.write(opt.getValue());
    }

    byte[] response = out.toByteArray();
    int l = response.length;
    response = PduUtilities.setPduLength(response, l);
    return response;
  }
 public void setOptionnal(Tlv opt) {
   optionalsByTag.put(new Short(opt.getTag()), opt);
 }