我通过 GWT RPC 机制在客户端和服务器之间来回发送对象 ID。 id 以 Longs(8 字节)的形式从数据存储中出来。我认为我所有的 id 只需要 4 个字节,但可能会发生一些随机事件,给我一个 5 字节(或其他)的值。
GWT 是否会聪明地将这些值打包成某种可变长度编码,这样平均可以节省空间?我可以在某处指定它这样做吗?或者我应该编写自己的代码将多头复制到整数并注意那些特殊情况?
谢谢~
最佳答案
如 GWT documentation 中所述.
long: JavaScript has no 64-bit integral type, so long needs special consideration. Prior to GWT 1.5, the long type was was simply mapped to the integral range of a 64-bit JavaScript floating-point value, giving long variables an actual range less than the full 64 bits. As of GWT 1.5, long primitives are emulated as a pair of 32-bit integers, and work reliably over the entire 64-bit range. Overflow is emulated to match the expected behavior. There are a couple of caveats. Heavy use of long operations will have a performance impact due to the underlying emulation. Additionally, long primitives cannot be used in JSNI code because they are not a native JavaScript numeric type.
如果您的 id 可以放入整数,那么您可能会更好。否则,如果您使用的是 DTO,请将 id 设为 double ,这实际上存在于 Javascript 中。
关于serialization - GWT 能有效地序列化 java.lang.Longs 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3808209/