/// <summary> /// This method retrieves a PDU from a byte stream. /// </summary> /// <param name="stm">Byte stream</param> public void Deserialize(SmppReader stm) { state_ = PduStatus.invalid; try { // Get the header from the buffer length_ = stm.ReadInt32(); int id = stm.ReadInt32(); status_ = stm.ReadInt32(); sequenceNumber_ = stm.ReadInt32(); if (id != this.CommandId) { throw new UnexpectedPduException(id); } state_ = PduStatus.validHeader; // Now read the body of the PDU if (length_ > REQUIRED_SIZE) { this.GetFromStream(stm); state_ |= PduStatus.validBody; // Read any optional parameters that are present. while (!((SmppByteStream)stm.Stream).EOS) { TlvParameter tlv = new TlvParameter(); try { tlv.GetFromStream(stm); TlvParameter tlvExisting = GetOptionalElement(tlv.Tag); if (tlvExisting == null) { AddOptionalElements(tlv); } else { if (tlvExisting.Tag == tlv.Tag) { tlvExisting.Data = tlv.Data; } else { throw new TlvException("Read bad Tlv stream!"); } } } catch (ArgumentOutOfRangeException) { } } } } catch (InvalidOperationException e) { throw new IncompletePduException(this, e); } catch (PduException e) { e.PDU = this; throw e; } catch (System.Exception e) { throw new PduException(this, e); } }