Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ProtoBuf - Azure Service Fabric

Tags:

I am looking at replacing the default serializer for RPC in ASF. This involves implementing a few interfaces, one of which is passed between services communicating via RPC

 public interface IServiceRemotingResponseMessageBody
  {
    void Set(object response);

    object Get(Type paramType);
  }

As the implementation needs to be serializable, the obvious ProtoBuf implementation is something like

    [ProtoContract]
    public class ProtoBufRemotingResponseBody : IServiceRemotingResponseMessageBody
    {
        [ProtoMember(1)]
        public object Value { get; set; }

        public void Set(object response)
        {
            Value = response;
        }

        public object Get(Type paramType)
        {
            return Value;
        }
    }

Unfortunately this fails miserably with

No serializer defined for type: System.Object

Is there a workaround here? System.Object has no contract, but the OOTB DataContract serializer can, as can MessagePack here, but these are not schematized which creates versioning headaches when using reliable collections. I have tried using a common base type, but Value can be IEnumerable<T> or T etc.

Can anyone help? Thanks, KH

like image 658
KnowHoper Avatar asked Jan 15 '18 02:01

KnowHoper


1 Answers

At the moment, protobuf-net does not have good support for object, except via some messy hacks. The simplest to try (just to see if it works for your scenario) is to find the "dynamic types" flag on that proto-member attribute and set it to true. This library-specific hack burns some type metadata into to data to allow it to work with unknown types, but it is far from perfect.

The "better" fix here would involve me finding the time to implement the "any" feature (added to the Google library relatively recently, around the time of proto3 IIRC). This works broadly similarly, but would be implemented in a cross-library way.

like image 83
Marc Gravell Avatar answered Sep 23 '22 13:09

Marc Gravell