33

Recently (January 2015) Microsoft open-sourced Bond, their framework for working with schematized data. In many aspects it is similar to Google's Protocol Buffers.

What are the biggest differences between the two? What are pros and cons, that is, in which situations I would like to use one, but not the other? Of course, I'm not talking about obvious things like consistency with other projects or already existing APIs, but rather the features of both libraries. To give an example, Bond has bonded<T> which, if I remember correctly, doesn't have a counterpart in Protocol Buffers.

ZunTzu
  • 7,244
  • 3
  • 31
  • 39
dtldarek
  • 949
  • 1
  • 13
  • 17
  • Covered [pretty well already](http://microsoft.github.io/bond/why_bond.html). – Hans Passant Jan 11 '15 at 18:03
  • @HansPassant Thanks for pointing that out (I don't know how I could miss that page). On the other hand I think it would be great to hear also from some else than the creators of the framework. – dtldarek Jan 12 '15 at 09:37
  • @HansPassant no it is not provide performance bench mark clearly – sorosh_sabz Jun 04 '21 at 13:39

1 Answers1

44

In general, Bond has better type system and supports multiple protocols.

In particular, pros are:

  • Bond supports generics
  • Bond has different types to represent collections: vector<T>, map<T>, list<T>
  • Bond supports type-safe lazy deserialization (bonded<T>)
  • Bond supports multiple formats (fast binary, compact binary, XML, JSON) + marshaling and transcoding

Cons:

  • Bond doesn't support different types for fixed and variable integer encoding. In Bond, the way how integers are encoded is determined by the output format (fast or compact), but in Protocol Buffers, there are integer types that always have fixed size: fixed32 and fixed64.
  • Bond doesn't support union types (oneof in Protocol Buffers)

I did some tests, and it appears that size of simple messages in Bond and ProtoBuf binary formats are about the same. I compared serialization and deserialization time using Bond and C# ProtoBuf library: in my case Bond performed a bit better, you can find my source code on GitHub

To sum up, I think it's better to use Bond when you work with some complex types of data or when you need to represent the same data in different formats: e.g. store as binaries, but expose as JSON etc.

takemyoxygen
  • 4,294
  • 22
  • 19