Google Protocol Buffers 或类似的 .net/javascript 的东西

发布于 2024-07-27 12:01:16 字数 491 浏览 3 评论 0原文

我们当前使用 Ajax 调用 .net Web 服务,然后将 Json 对象返回给客户端。 其中一些 Json 对象非常庞大(未压缩时> 500k)。 我们听说过一些关于 Google Protocol Buffers 的好消息,并且一直在进行试验。

到目前为止,我们在服务器上使用最常见的 .net 版本“protobuf-net”进行序列化的运气非常好。 我们在客户端反序列化方面运气不佳。 我们尝试使用似乎是唯一的 JavaScript 反序列化器 protobuf.js。 我们发现它不容易使用,示例或文档很少,而且它似乎不处理字符串和整数之外的数据类型。

看来此时,.net 和 Web 客户端之间的二进制数据序列化/反序列化将有一个经过验证的、定义良好的解决方案。 也许我们遗漏了一些明显的东西。

我们的要求是来自客户端的 Ajax 调用以及服务器上的 .net Web 服务方法(.asmx 或 WCF)。

如有任何意见和建议,我们将不胜感激。

We are currently using Ajax calls to a .net web service that then returns a Json object to the client. Some of these Json objects are pretty massive (> 500k uncompressed). We have heard some good things about Google Protocol Buffers and have been experimenting.

So far, we have had pretty good luck serializing on the server with what seems to be the most common .net version - "protobuf-net". We have not had much luck deserializing on the client. We tried using what seems to be the one and only javascript deserializer protobuf.js. We found that it is not easy to use, there are very few examples or documentation, and it does not seem to handle datatypes beyond strings and ints.

It would seems that at this point, there would be a proven, well defined solution for binary data serialization/deserialization between .net and a web client. Maybe we are missing something obvious.

Our requirements are Ajax calls from the client, and .net web services methods on the server (.asmx or WCF).

Any comments and suggestions are appreciated.

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

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

发布评论

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

评论(3

写给空气的情书 2024-08-03 12:01:17

如果客户端是javascript,我想你会很困难。 (正如您所说)JavaScript 的覆盖范围有限,但我不确定它会给您带来很多好处。 引用 Kenton Varda(谁真正了解protobuf):

JavaScript 的一个问题和
protobuf 是你需要很多
支持解析消息的代码。
除非你最终发送了很多
来回的东西,使得
用户下载 JS protobuf 编解码器
图书馆可能会出现净亏损。 可能是
最好使用 JSON 或 XML,因为
浏览器已经内置了
对这些的支持。

也就是说,我认为
谷歌内部的各种人都曾
玩转 javascript + 协​​议
缓冲一段时间,如果我们最终结束
任何效果足够好的东西,
我们将发布它。

所以也许未来还有希望。 现在我会坚持使用 json + deflate,或者如果您的场景允许,您也许可以使用嵌入在客户端中的 Silverlight 小程序? protobuf-net 将在 Silverlight 中工作。

If the client is javascript, I think you'll struggle. There is (as you've stated) limited javascript coverage, but I'm not sure it will gain you a lot. To quote from Kenton Varda (who really knows protobuf):

One problem with javascript and
protobuf is that you need a lot of
support code to parse the messages.
Unless you end up sending quite a lot
of stuff back and forth, making the
user download a JS protobuf codec
library may be a net loss. It may be
better to use JSON or XML because
browsers already have built-in
support for those.

That said, I think
various people inside google have been
playing with javascript + protocol
buffers for awhile and if we end up
with anything that works well enough,
we'll release it.

So maybe there is hope down the road. For now I would stick with json + deflate, or if your scenario allows it you could perhaps use a Silverlight applet embedded in the client? protobuf-net will work inside Silverlight.

佼人 2024-08-03 12:01:17

您可能会发现 JSON 实际上是最好的答案。 Justin 做了一系列JSON 与 Thrift 和 Protocol Buffers 的性能比较,并发现压缩的 JSON比protocol buffers更快,至少在Python中是这样。 这是关于该主题的早期线程

You may find JSON is in fact the best answer. Justin has done a series of performance comparisons of JSON to Thrift and Protocol Buffers and found compressed JSON to be faster than protocol buffers, at least in Python. Here's an earlier thread on the topic.

半边脸i 2024-08-03 12:01:17

如前所述,使用 javascript 的二进制协议是有问题的。 一些特别令人讨厌的方面是:

而且与 JSON 或 XML 的本机支持相比,性能不太可能更快。

As mentioned, using binary protocols from javascript is problematic. Some specifically nasty aspects are:

And performance is very unlikely to be faster, compared to native support for JSON or XML.

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