Exemple #1
0
        public virtual byte[] GetBytesFromString(string cStr, DataCoding dataCoding)
        {
            if (cStr == null)
            {
                throw new ArgumentNullException("cStr");
            }
            if (cStr.Length == 0)
            {
                return(new byte[] { 0x00 });
            }
            byte[] bytes = null;
            switch (dataCoding)
            {
            case DataCoding.ASCII:
                bytes = System.Text.Encoding.ASCII.GetBytes(cStr);
                break;

            case DataCoding.Latin1:
                bytes = Latin1Encoding.GetBytes(cStr);
                break;

            case DataCoding.UCS2:
                bytes = UCS2Encoding.GetBytes(cStr);
                break;

            case DataCoding.SMSCDefault:
                bytes = SMSCDefaultEncoding.GetBytes(cStr);
                break;

            default:
                throw new SmppException(SmppErrorCode.ESME_RUNKNOWNERR, "Unsupported encoding");
            }
            return(bytes);
        }
        public virtual byte[] GetBytesFromCString(string cStr, DataCoding dataCoding, bool nullTerminated = true)
        {
            if (cStr == null)
            {
                throw new ArgumentNullException("cStr");
            }
            if (cStr.Length == 0)
            {
                return(new byte[] { 0x00 });
            }
            byte[] bytes = null;
            switch (dataCoding)
            {
            case DataCoding.ASCII:
                bytes = System.Text.Encoding.ASCII.GetBytes(cStr);
                break;

            case DataCoding.Latin1:
                bytes = Latin1Encoding.GetBytes(cStr);
                break;

            case DataCoding.UCS2:
                bytes = UCS2Encoding.GetBytes(cStr);
                break;

            case DataCoding.SMSCDefault:
                bytes = SMSCDefaultEncoding.GetBytes(cStr);
                break;

            default:
                throw new SmppException(SmppErrorCode.ESME_RUNKNOWNERR, "Unsupported encoding");
            }
            ByteBuffer buffer;

            if (nullTerminated)
            {
                buffer = new ByteBuffer(bytes, bytes.Length + 1);
                buffer.Append(new byte[] { 0x00 }); //Append a null charactor a the end
            }
            else
            {
                buffer = new ByteBuffer(bytes, bytes.Length);
            }

            return(buffer.ToBytes());
        }