最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

asp.net - Google Protocol Buffers or something similar for .netjavascript - Stack Overflow

programmeradmin1浏览0评论

We are currently using Ajax calls to a web service that then returns a Json object to the client. Some of these Json objects are pretty massive (> 500k unpressed). 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 mon 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 and a web client. Maybe we are missing something obvious.

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

Any ments and suggestions are appreciated.

We are currently using Ajax calls to a web service that then returns a Json object to the client. Some of these Json objects are pretty massive (> 500k unpressed). 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 mon 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 and a web client. Maybe we are missing something obvious.

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

Any ments and suggestions are appreciated.

Share Improve this question asked Jul 15, 2009 at 13:47 user95023user95023 911 silver badge4 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 5

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.

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

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

  • It is difficult to reliably access content as binary, from javascript -- work-arounds are typically browser-specific (see Accessing binary data from Javascript, Ajax, IE: can responseBody be read from Javascript (not VB)?)
  • Encoding/decoding standard IEEE encoded double/float values is difficult and inefficient (if not downright impossible)

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

发布评论

评论列表(0)

  1. 暂无评论