internal static byte[] EncodeString(string str) { if (str == null) { str = ""; } return(SMPPEncodingUtil.GetBytesFromString(str)); }
protected override IEnumerable <SendSmPDU> GetPDUs(DataCoding defaultEncoding) { SubmitSm sm = CreateSubmitSm(); sm.SourceAddress.Address = vSourceAddress; sm.DestinationAddress.Address = vDestinatinoAddress; // Urgh, typo :( sm.DataCoding = defaultEncoding; if (!string.IsNullOrEmpty(UserMessageReference)) { var msgIdBytes = SMPPEncodingUtil.GetBytesFromCString(UserMessageReference); sm.Tlv.Add(new Lib.Protocol.Tlv.Tlv(Lib.Protocol.Tlv.Tag.user_message_reference, (ushort)msgIdBytes.Length, msgIdBytes)); } if (vRegisterDeliveryNotification) { sm.RegisteredDelivery = RegisteredDelivery.DeliveryReceipt; } vMaxMessageLength = GetMaxMessageLength(defaultEncoding, false); byte[] bytes = SMPPEncodingUtil.GetBytesFromString(vText, defaultEncoding); string uni = Encoding.Unicode.GetString(bytes); string ascii = Encoding.ASCII.GetString(bytes); string utf8 = Encoding.UTF8.GetString(bytes); // Unicode encoding return 2 items for 1 char // We check vText Length first if (vText.Length > vMaxMessageLength && bytes.Length > vMaxMessageLength) // Split into multiple! { var SegID = new Random().Next(1000, 9999); // create random SegmentID vMaxMessageLength = GetMaxMessageLength(defaultEncoding, true); var messages = Split(vText, vMaxMessageLength); var totalSegments = messages.Count; // get the number of (how many) parts var udh = new Udh(SegID, totalSegments, 0); // ID, Total, part for (int i = 0; i < totalSegments; i++) { udh.MessageSequence = i + 1; // seq+1 , - parts of the message sm.SetMessageText(messages[i], defaultEncoding, udh); // send parts of the message + all other UDH settings yield return(sm); } } else { sm.SetMessageBytes(bytes); yield return(sm); } }
public virtual void SetMessageText(string message, DataCoding dataCoding, Udh udh) { ByteBuffer buffer = new ByteBuffer(160); if (udh != null) { buffer.Append(udh.GetBytes()); } buffer.Append(SMPPEncodingUtil.GetBytesFromString(message, dataCoding)); SetMessageBytes(buffer.ToBytes()); if (udh != null) { EsmClass = EsmClass | EsmClass.UdhiIndicator; } DataCoding = dataCoding; }