GWT 是否有效地序列化 java.lang.Longs?

发布于 2024-09-25 07:21:24 字数 224 浏览 2 评论 0原文

我通过 GWT RPC 机制在客户端和服务器之间来回发送对象 ID。 id 以长整型(8 字节)形式从数据存储区中出来。我认为我所有的 id 都只需要 4 个字节,但是可能发生一些随机的事情,给我一个 5 字节(或其他)值。

GWT 是否会聪明地将这些值打包在某种可变长度编码中,从而平均节省空间?我可以指定它在某个地方这样做吗?或者我应该编写自己的代码将长整型复制为整数并注意那些特殊情况?

谢谢~

I'm sending object IDs back and forth from client to server through the GWT RPC mechanism. The ids are coming out of the datastore as Longs (8 bytes). I think all of my ids will only need 4 bytes, but something random could happen that gives me a 5-byte (or whatever) value.

Is GWT going to be smart about packing these values in some variable-length encoding that will save space on average? Can I specify that it do so somewhere? Or should I write my own code to copy the Longs to ints and watch out for those exceptional situations?

Thanks~

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

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

发布评论

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

评论(2

时光匆匆的小流年 2024-10-02 07:21:24

GWT 文档中所述。

long:JavaScript没有64位整型,因此long需要特别考虑。在 GWT 1.5 之前,long 类型只是简单地映射到 64 位 JavaScript 浮点值的整数范围,从而使 long 变量的实际范围小于完整的 64 位。从 GWT 1.5 开始,长原语被模拟为一对 32 位整数,并在整个 64 位范围内可靠地工作。模拟溢出以匹配预期行为。有一些注意事项。由于底层模拟,大量使用长操作会对性能产生影响。此外,长原语不能在 JSNI 代码中使用,因为它们不是本机 JavaScript 数字类型。

如果你的 id 可以容纳在一个整数中,那么你的情况可能会更好。否则,如果您使用 DTO,请将 ids 设为双精度,这实际上存在于 Javascript 中。

As stated in the 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.

If your ids can fit in an Integer, you could be better off with that. Otherwise, if you're using a DTO, make the ids a double, which actually exists in Javascript.

止于盛夏 2024-10-02 07:21:24

GWT 对负载为 256 字节或更大的响应使用 gzip 压缩。如果您的响应中有很多零字节,那么这应该很有效。

来自RemoteServiceServlet.shouldCompressResponse

确定是否响应
给定的 servlet 请求应该或应该
不是 GZIP 压缩的。这个方法是
仅在以下情况下调用
请求者接受 GZIP 编码。

此实现当前返回
true 如果响应字符串是
估计字节长度长于
256 字节。子类可以重写
这个逻辑。

因此,服务器首先检查请求者(通常是浏览器)是否接受 GZIP 编码。在内部,java.util。使用 zip.GZIPOutputStream - 请参阅 RPCServerUtils。在客户端,浏览器的工作是解压缩 gzip 压缩的有效负载 - 因为这是在本机代码中完成的,应该相当快。

GWT uses gzip compression for responses with a payload of 256 bytes or greater. That should work well if you have a lot of zero bytes in your response.

From RemoteServiceServlet.shouldCompressResponse:

Determines whether the response to a
given servlet request should or should
not be GZIP compressed. This method is
only called in cases where the
requester accepts GZIP encoding.

This implementation currently returns
true if the response string's
estimated byte length is longer than
256 bytes. Subclasses can override
this logic.

So, the server first checks if the requester (the browser, usually) accepts GZIP encoding. Internally, java.util.zip.GZIPOutputStream is used - see RPCServerUtils. On the client side, it's the browser's job to decompress the gzipped payload - since this is done in native code, it should be fairly quick.

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