3

I would like to use ServiceStack on the server side, and I would like to use protobuf-net as the serialization system used by ServiceStack. However, some of the clients will not be using the ServiceStack client libraries. They will be using protobuf-net directly.

In reading the widely linked ServiceStack protocol buffers howto (http://stevenhollidge.blogspot.in/2012/04/servicestack-rest-with-protobuf.html), it indicates using [DataContract] and [DataMember(Order=i)] attributes on the classes and properties respectively. However, when I read the protobuf-net documentation it indicates attributes are [ProtoContract] and [ProtoMember(i)] instead.

If I want my DTOs to work with both native protbuf-net and ServiceStack's protobuf-net wrapper do I need to add both attributes to every class and property, or will one or the other be sufficient?

davidpricedev
  • 1,957
  • 2
  • 17
  • 30

1 Answers1

2

ProtoBuf requires a mapping from Properties to numerical indexes, both of the options you've specified are equivalent ways to do this:

[DataContract]
public class Dto
{
    [DataMember(Order=i)]
    public string PropertyName { get; set; }
}

[ProtoContract]
public class Dto
{
    [ProtoMember(i)]
    public string PropertyName { get; set; }
}
Community
  • 1
  • 1
mythz
  • 138,929
  • 27
  • 237
  • 382