开发者

Compression algorithms for Strings

I have to generate QRCodes using concatenated object properties. These strings might be long, that's why I开发者_StackOverflow中文版'd like to know which compression algorithm to use knowing that my String's length is between 25 an 100+ characters

thanks in advance,

Jerec


I am assuming that since you are going to use compression before you store the strings that these QR codes will not be readable by any client, it would have to be an application that you wrote (b/c you are storing character with an unknown encoding, the client won't be able to decode).

Instead of compressing and storing the long string in the QR code, have your application create a URI (like a GUID or a URL) and when your application decodes that URI it looks up all the values (uncompressed) that you wanted to store in the QR code. Then your app can just look up the format in any way it wants.

For example, assuming your persistant storage is an xml file, but it could be anything:

<URI = "http://mydomain.com/790C9704-8C61-435F-991D-CDBB5767AA3D">
    <MyElement>14523</MyElement>
    <MyElement>67548</MyElement>
    ...
    <MyElement>46167</MyElement>
</URI>

Encoded on QR code: "http://mydomain.com/790C9704-8C61-435F-991D-CDBB5767AA3D", values can then be looked up.


The algorithm used to encode QR codes is dependent on the type of data you encode. See http://www.swetake.com/qr/qr1_en.html.

If you know, for example, that you always have the same number of digits per id and therefor could just string them together without punctuation, you can encode them as purely numeric and you'll use 10 bits for every three characters.

If you need some kind of separator, if you use something in "0-9A-Z $%*+-./:", you'll stay alphanumeric and get 2 characters in 11 bits.

If you give it arbitrary data (note that this includes any lower case: the list above does not include lower case letters) you're going to be using 8 bits per characters.

So numeric only would end up being 60% smaller.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜