1 / 9

Protocol Buffers

Protocol Buffers. Portable binary serialization, the Google way. What problem?. For high volume work, no ideal serializer: Xml/data-contracts: (relatively) expensive to process; large due to repeated tags Soap: as xml, but more BinaryFormatter (/NDCS): proprietary closed [non-]standard

Télécharger la présentation

Protocol Buffers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Protocol Buffers Portable binary serialization, the Google way

  2. What problem? For high volume work, no ideal serializer: • Xml/data-contracts: (relatively) expensive to process; large due to repeated tags • Soap: as xml, but more • BinaryFormatter (/NDCS): proprietary closed [non-]standard • Bespoke: lots of work; lots of potential for error

  3. What is protobuf? Protocol Buffers defines two things: • A compact binary serialization format (pb) • A text-based descriptor language (.proto) Implementation specific: • Runtime serialization library / code • .proto parser / code generator protobuf-net is one of 3 in-progress efforts for .NET

  4. What is a .proto? Yet another descriptor language... message Test1 { required int32 a = 1; } message Test3 { optional Test1 c = 3; } service SearchService { rpc Search (SearchRequest) returns (SearchResponse); }

  5. So why bother? • Compact: • no string field names (contrast: XmlSerializer; DataContractSerializer) • uses variable-length encoding where sensible • minimal framing overhead • Portable: • cross-platform (contrast: BinaryFormatter) • extensible (roundtrip-safe) • (protobuf-net works with .NET 2.0; .NET 3.0; CF 2.0; CF 3.0; Silverlight 2.0; Mono) • Fast: • efficient to parse Optimised for common scenarios, but doesn’t support every complex worst-case scenario.

  6. Look familiar? Closely related to data/service-contracts [DataContract] public class Test1 { [DataMember(Name="a", Order=1, IsRequired=true)] public int A {get;set;} } [DataContract] public class Test3 { [DataMember(Name="c", Order=3, IsRequired=false)] public Test1 C {get;set;} } [ServiceContract] public interface ISearchService { [OperationContract] SearchResponse Search(SearchRequest request); }

  7. Demo

  8. Where can we use it? • Communications • Remoting • WCF • Sockets / http (proto-rpc?) • Persistance • File system • Database BLOB • SQL/CLR?

  9. Existing data? • Works with common frameworks: • WCF • LINQ-based data-contracts • XmlType / XmlElement • Can be used to replace, or in parallel with, standard serializers: • ISerializable • IXmlSerializable • Custom attributes for full control • Can also be specified at the class (rather than member) for use with partial classes

More Related