Page 1 of 1

Validate or Determine encoding API

Posted: Tue Oct 15, 2019 6:14 am
by wojtek
Hi,

I think it would be very nice and relatively easy to do feature, if library could determine the best encoding for given text message, or at least give a possibility to validate compatibility of message with given encoding.

With latest beta, incompatible characters are replaced by '?' instead of throwing exception. It's a good step, but it caused a bug in our system.

We would like to define allowed encodings, give InetLab a message and let library choose the most efficient encoding which includes every character from message in its charset.

We've implemented such functionality in our system (with help of your BasicCharsetMap class), but I think it's rather responsibility of SMPP library and other customers could take advantage of that.

If you think it's too much effort, as an alternative InetLab could provide a method to check if a message can be safely sent using chosen encoding. It could let us know that a message will be derived in a different shape than we expected.

Thanks for your help

Re: Validate or Determine encoding API

Posted: Fri Oct 25, 2019 12:10 pm
by alt
Could you give me some example from your world?
Which encodings do you use in your solution? And what is corresponding data_coding for each encoding.

for GSMEncoding we could add the method _gsmEncoding.IsTextValid(text); or any other name that you can suggest.

Re: Validate or Determine encoding API

Posted: Fri Feb 14, 2020 7:24 pm
by alt
I have added extension method CanBeEncoded in the version 2.8-beta

You can use this method like:

Code: Select all

 
            string text = "Привет";

            Encoding encoding = client.EncodingMapper.GetMappedEncoding(DataCodings.Default);

            if (encoding.CanBeEncoded(text)) return DataCodings.Default;

            encoding = client.EncodingMapper.GetMappedEncoding(DataCodings.ASCII);

            if (encoding.CanBeEncoded(text)) return DataCodings.ASCII;

            return DataCodings.UCS2;