This project is read-only.
ProtoBuf - fast, portable, binary serialization

About Protocol Buffers

Protocol Buffers are a way of encoding structured data in an efficient yet extensible format. Google uses Protocol Buffers for almost all of its internal RPC protocols and file formats.

ProtoBuf.NET is an implementation of ProtoBuf serialization for .NET by Marc Gravell.


Lokad.CQRS uses ProtoBuf serialization internally for transferring and persisting message envelopes in Lokad Message Format. ProtoBuf serialization is also the recommended approach for serializing messages in Lokad.CQRS. That's because:
  • format is extremely compact and fast, better than XML Serialization, Data Contracts or Binary Formatter (performance).
  • format is evolution-friendly from the start.
  • format is cross-platform.

Usage of ProtoBuf also results in fewer messages exceeding the size limit of Azure Queues. This results in faster performance, as do not need to persist them in the BLOB storage.

Besides, it just works in the production

ProtoBuf Module

In order to switch Lokad.CQRS Message domain to ProtoBuf serialization, you just need to mention `UseProtocolBuffers`:
.Domain(d =>
{
  // let's use Protocol Buffers!
  d.UseProtocolBuffers();
  d.InCurrentAssembly();
  d.WithDefaultInterfaces();
})

That's how message definitions look like:
[ProtoContract]
public sealed class PingPongCommand : IMessage
{
  [ProtoMember(1)] public int Ball { get; private set; }
  [ProtoMember(2)] public string Game { get; private set; }

  public PingPongCommand(int ball, string game)
  {
    Ball = ball;
    Game = game;
  }

  PingPongCommand() { }
}

Note that:
  • contract attributes are currently defined in Lokad.Serialization (that's where ProtoBuf.NET is merged). We plan to detach them from the ProtoBuf and Lokad.Serialization, moving to Lokad.Shared.dll.
  • Presence of parameterless constructor is currently required by the ProtoBuf.NET
  • You can also use Data Contract and XML attributes (as allowed by ProtoBuf.NET) to mark your classes. However Data Contract extensibility at the moment does not work in ProtoBuf.NET.

See ProtoBuf.NET Getting Started for more information on defining messages.

Last edited Apr 11, 2011 at 11:06 PM by AlexandrYZ, version 2

Comments

No comments yet.