/// <summary> /// This method gets the buffer and returns an instance of class /// corresponding to the type of the PDU which was in the buffer; the /// fields of the returned PDU are set to the data from the buffer. /// </summary> public static SmppPdu Create(Stream buffer) { // Read the length and id from the buffer SmppReader reader = new SmppReader(buffer); int length = reader.ReadInt32(); int id = reader.ReadInt32(); // If we don't have the entire message yet, then throw an exception. if (buffer.Length < length) { throw new IncompletePduException(); } // Create a new PDU SmppPdu pdu = PduFactory.CreatePdu(id); if (pdu != null) { // Reset back to the length buffer.Seek(-8, SeekOrigin.Current); // Stream the whole thing in pdu.Deserialize(reader); return(pdu); } // Not found in our list of supported PDUs throw new UnknownPduException(id); }
/// <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); } }
/// <summary> /// This method implements the ISupportSmppByteStream.GetFromStream /// method so that the PDU can serialize itself from the data stream. /// </summary> /// <param name="reader">StreamReader</param> public override void GetFromStream(SmppReader reader) { reader.ReadObject(mid_); reader.ReadObject(finalDate_); reader.ReadObject(msgState_); errCode_ = reader.ReadInt32(); }
/// <summary> /// This method retrieves the C-Octet string from the byte stream /// </summary> /// <param name="reader">Byte stream</param> public void GetFromStream(SmppReader reader) { addr_.GetFromStream(reader); status_ = reader.ReadInt32(); }
/// <summary> /// This method retrieves the integer from the byte stream /// </summary> /// <param name="reader">Byte stream</param> public void GetFromStream(SmppReader reader) { data_ = reader.ReadInt32(); ValidateData(); }