public int decode(InputStream iStream, boolean explicit) throws IOException {
    int codeLength = 0;
    int subCodeLength = 0;
    int choiceDecodeLength = 0;
    BerIdentifier berIdentifier = new BerIdentifier();
    boolean decodedIdentifier = false;

    if (explicit) {
      codeLength += id.decodeAndCheck(iStream);
    }

    BerLength length = new BerLength();
    codeLength += length.decode(iStream);

    if (subCodeLength < length.val) {
      if (decodedIdentifier == false) {
        subCodeLength += berIdentifier.decode(iStream);
        decodedIdentifier = true;
      }
      if (berIdentifier.equals(BerInteger.identifier)) {
        invokeID = new BerInteger();
        subCodeLength += invokeID.decode(iStream, false);
        decodedIdentifier = false;
      } else {
        throw new IOException("Identifier does not macht required sequence element identifer.");
      }
    }
    if (subCodeLength < length.val) {
      if (decodedIdentifier == false) {
        subCodeLength += berIdentifier.decode(iStream);
        decodedIdentifier = true;
      }
      confirmedServiceRequest = new ConfirmedServiceRequest();
      choiceDecodeLength = confirmedServiceRequest.decode(iStream, berIdentifier);
      if (choiceDecodeLength != 0) {
        decodedIdentifier = false;
        subCodeLength += choiceDecodeLength;
      }
    }
    if (subCodeLength != length.val) {
      throw new IOException("Decoded sequence has wrong length tag");
    }
    codeLength += subCodeLength;

    return codeLength;
  }
  public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException {

    int codeLength;

    if (code != null) {
      codeLength = code.length;
      for (int i = code.length - 1; i >= 0; i--) {
        berOStream.write(code[i]);
      }
    } else {
      codeLength = 0;
      codeLength += confirmedServiceRequest.encode(berOStream, true);

      codeLength += invokeID.encode(berOStream, true);

      codeLength += BerLength.encodeLength(berOStream, codeLength);
    }

    if (explicit) {
      codeLength += id.encode(berOStream);
    }

    return codeLength;
  }