2

字符串怎么承载 int32 信息?

 2 years ago
source link: https://www.v2ex.com/t/802322
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

V2EX  ›  程序员

字符串怎么承载 int32 信息?

  JustLookBy · 3 小时 1 分钟前 · 820 次点击

需求:js 传输的 json 字符串里面有坐标数组,坐标数值都小于 4,096 。 尽可能压缩传输体积。

目前想法是 把 x,y 坐标直接 (x<<16)|y 聚集成一个 int32 值,刚好 4 个字节对应 utf8 4 个字节,然而有很多字符都没对应的,所以无法一一转化.

用的是 websocket 传输,虽然支持 arrayBuffer 类型,但是我的数据都是字符串格式的,还有其他信息要一起。

大佬们有什么方案吗?把坐标压缩到字符串里面节省空间


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK