MassTransit

 

FluentProtocolBuffers

Page history last edited by drusellers 1 yr ago

Based on a suggestion from Oren (Ayende) we have started looking at Google's protocol buffers as an optimal serialization mechanism. It provides a mapping layer which will give us a  lot of flexibility around making messages easier to use and reuse accross systems. Also looking to take what we have learned from FluentNHibernate about avoiding ceremony and what not. I am proposing the following sample syntax.

 

http://code.google.com/apis/protocolbuffers/

 

Sample Example

 

 

public class OrderMapping : Proto<Order>
{
    public OrderMapping()
    {
        Field(m=>m.BusinessId).Required(); //properties are optional by default
        Field(m=>m.Description);
        Field(m=>m.LineItems); //detects the IList and uses the PB repeated
        Field(m=>m.Address);
    }
}

public class AddressMapping : Proto<Address>
{
    public AddressMapping()
    {
        Field(m=>m.Street); //by default the things are ordered in the order of registration
        Field(m=>m.State, 33);
        ExtensionSpace(200, Int.Max);
    }
}

Proto<Address> addressMap = Proto<Address>.FromFile("address.proto");
addressMap.WriteToFile(".address.proto");

Then you could also call Proto.Validate() and get a human intelligible list of errors.

Comments (0)

You don't have permission to comment on this page.