字符串的压缩算法

发布于 2024-11-09 07:04:54 字数 119 浏览 3 评论 0原文

我必须使用连接的对象属性生成 QRCodes。这些字符串可能很长,这就是为什么我想知道要使用哪种压缩算法,因为我知道我的字符串长度在 25 到 100 多个字符之间,

提前感谢,

Jerec

I have to generate QRCodes using concatenated object properties. These strings might be long, that's why I'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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暗恋未遂 2024-11-16 07:04:54

我假设由于您将在存储字符串之前使用压缩,因此任何客户端都无法读取这些 QR 码,因此它必须是您编写的应用程序(b/c 您正在存储具有未知编码的字符,客户端将无法解码)。

让您的应用程序创建一个 URI (例如一个 < 一个href="http://www.google.com/url?sa=t&source=web&cd=1&ved=0CDIQFjAA&url=http://en.wikipedia.org/wiki/Globally _unique_identifier&ei=1hLcTcuWOqrb0QGutpH9Dw&usg=AFQjCNG8ACp9GO_beQ2Nw1FXitJ3UuWqQQ&sig2=wouzRgiawqrQRS1FfVd44A" rel="nofollow">GUID 或 URL)以及当您的应用程序解码该 URI 它会查找您想要存储在二维码中的所有值(未压缩)。然后您的应用程序就可以以任何它想要的方式查找格式。

例如,假设您的持久存储是一个 xml 文件,但它可以是任何内容:

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

在 QR 代码上编码:“http://mydomain.com/790C9704-8C61-435F-991D-CDBB5767AA3D”,然后可以查找值。

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.

心安伴我暖 2024-11-16 07:04:54

用于编码 QR 码的算法取决于您编码的数据类型。请参阅http://www.swetake.com/qr/qr1_en.html

例如,如果您知道每个 id 始终具有相同的位数,因此可以将它们串在一起而不使用标点符号,则可以将它们编码为纯数字,并且每三个字符使用 10 位。

如果您需要某种分隔符,如果您在“0-9A-Z $%*+-./:”中使用某些内容,您将保留字母数字并在 11 位中获得 2 个字符。

如果您给它任意数据(请注意,这包括任何小写字母:上面的列表不包括小写字母),您将使用每个字符 8 位。

因此仅数字最终会小 60%。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文