/// <summary> Parses the smpp buffer to a DeliverSm object </summary> /// <param name="defaultEncoding"></param> /// <param name="buf"></param> /// <param name="offset"></param> /// <returns> DeliverSm </returns> public static DeliverSm Create(DataCodings defaultEncoding, SmppBuffer buf, ref int offset) { DeliverSm deliverSm = new DeliverSm(defaultEncoding); try { int start_offset = offset; buf.ExtractHeader(deliverSm, ref offset); deliverSm.ServiceType = buf.ExtractCString(ref offset); deliverSm.SourceTon = buf.ExtractByte(ref offset); deliverSm.SourceNpi = buf.ExtractByte(ref offset); deliverSm.SourceAddr = buf.ExtractCString(ref offset); deliverSm.DestTon = buf.ExtractByte(ref offset); deliverSm.DestNpi = buf.ExtractByte(ref offset); deliverSm.DestAddr = buf.ExtractCString(ref offset); deliverSm.EsmClass = buf.ExtractByte(ref offset); deliverSm.ProtocolId = buf.ExtractByte(ref offset); deliverSm.PriorityFlag = buf.ExtractByte(ref offset); deliverSm.ScheduleDeliveryTime = buf.ExtractCString(ref offset); deliverSm.ValidityPeriod = buf.ExtractCString(ref offset); deliverSm.RegisteredDelivery = buf.ExtractByte(ref offset); deliverSm.ReplaceIfPresent = buf.ExtractByte(ref offset); deliverSm.DataCoding = (DataCodings) buf.ExtractByte(ref offset); deliverSm.DefaultMessageId = buf.ExtractByte(ref offset); deliverSm.ShortMessageLength = buf.ExtractByte(ref offset); if (deliverSm.ShortMessageLength > 0) { deliverSm.UserDataBuffer = new SmppBuffer(defaultEncoding, buf.ExtractByteArray(ref offset, deliverSm.ShortMessageLength)); } while (offset - start_offset < deliverSm.Length) { deliverSm.Optional.Add(buf.ExtractTLV(ref offset)); } if (deliverSm.ShortMessageLength == 0) { if (deliverSm.Optional != null && deliverSm.Optional.Count > 0) { TLV tlv_payload = deliverSm.Optional[OptionalTags.MessagePayload]; if (tlv_payload != null) { deliverSm.UserDataBuffer = new SmppBuffer(defaultEncoding, tlv_payload.Value); } TLV tlv_globalSeq = deliverSm.Optional[OptionalTags.SarMsgRefNum]; if (tlv_globalSeq != null) { deliverSm.MessageReferenceNumber = SmppBuffer.BytesToShort(tlv_globalSeq.Value, 0); } TLV tlv_pocketsNumber = deliverSm.Optional[OptionalTags.SarTotalSegments]; if (tlv_pocketsNumber != null) { deliverSm.TotalSegments = tlv_pocketsNumber.Value[0]; } TLV tlv_localSeq = deliverSm.Optional[OptionalTags.SarSegmentSeqnum]; if (tlv_localSeq != null) { deliverSm.SeqmentNumber = tlv_localSeq.Value[0]; } } } if (deliverSm.UserDataBuffer != null && deliverSm.UserDataBuffer.Length > 0) { bool hasUDHI = deliverSm.MessageFeature == GSMSpecificFeatures.UDHI || deliverSm.MessageFeature == GSMSpecificFeatures.UDHIandReplyPath; deliverSm.UserData = UserData.Create(deliverSm.UserDataBuffer, hasUDHI); if (deliverSm.UserData.Headers.Count > 0) { UserDataHeader udh = deliverSm.UserData.Headers[InformationElementIdentifiers.ConcatenatedShortMessages8bit]; if (udh != null) { deliverSm.MessageReferenceNumber = udh.Data[0]; deliverSm.TotalSegments = udh.Data[1]; deliverSm.SeqmentNumber = udh.Data[2]; } udh = deliverSm.UserData.Headers[InformationElementIdentifiers.ConcatenatedShortMessage16bit]; if (udh != null) { deliverSm.MessageReferenceNumber = SmppBuffer.BytesToShort(udh.Data, 0); deliverSm.TotalSegments = udh.Data[2]; deliverSm.SeqmentNumber = udh.Data[3]; } } } else { deliverSm.UserData = UserData.Create(); } } catch { deliverSm = null; } return deliverSm; }
/// <summary> Called to create a SubmitMulti object </summary> /// <param name="defaultEncoding"></param> /// <param name="buf"></param> /// <param name="offset"></param> /// <returns> SubmitMulti </returns> public static SubmitMultiSm Create(DataCodings defaultEncoding, SmppBuffer buf, ref int offset) { SubmitMultiSm submitMulti = new SubmitMultiSm(defaultEncoding); try { int start_offset = offset; buf.ExtractHeader(submitMulti, ref offset); submitMulti.ServiceType = buf.ExtractCString(ref offset); submitMulti.SourceTon = buf.ExtractByte(ref offset); submitMulti.SourceNpi = buf.ExtractByte(ref offset); submitMulti.SourceAddr = buf.ExtractCString(ref offset); submitMulti.DestinationAddresses = buf.ExtractDestinationAddresses(ref offset); submitMulti.EsmClass = buf.ExtractByte(ref offset); submitMulti.ProtocolId = buf.ExtractByte(ref offset); submitMulti.PriorityFlag = buf.ExtractByte(ref offset); submitMulti.ScheduleDeliveryTime = buf.ExtractCString(ref offset); submitMulti.ValidityPeriod = buf.ExtractCString(ref offset); submitMulti.RegisteredDelivery = buf.ExtractByte(ref offset); submitMulti.ReplaceIfPresent = buf.ExtractByte(ref offset); submitMulti.DataCoding = (DataCodings) buf.ExtractByte(ref offset); submitMulti.DefaultMsgId = buf.ExtractByte(ref offset); submitMulti.ShortMessageLength = buf.ExtractByte(ref offset); if (submitMulti.ShortMessageLength > 0) { submitMulti.UserDataBuffer = new SmppBuffer(defaultEncoding, buf.ExtractByteArray(ref offset, submitMulti.ShortMessageLength)); } while (offset - start_offset < submitMulti.Length) { submitMulti.Optional.Add(buf.ExtractTLV(ref offset)); } } catch { submitMulti = null; } return submitMulti; }