简体   繁体   中英

Custom typ serialization with Protobuf-net

Is it possible to use protobuf-net with custom type serialization?

Here is a pseudo example of what I have

  //some user defined type
  public class SomeMessage 
  {
       public ActorRef ActorRef {get;set;}
  }

  //classes in my framework
  public abstract ActorRef
  {
       public string Path {get;set;}
  }

  public class FooActorRef : ActorRef
  {
  }

  public class BarActorRef : ActorRef
  {
  }

I need to serialize all of the "ActorRef" types as the same type, I just need to store the "Path" and ignore the rest. I also need to be able to intercept/resolve the deserialization of the "ActorRef" here. So when the deserializer finds a serialized "path" I need it to call my custom handler and resolve the ActorRef this way.

So pretty much, custom serialization and deserialization of the ActorRef and it's subtypes. eg

  //I want something like this to be called upon deserialization..
  public ActorRef DeserializeActorRef(SerializerSpecificData x)
  { 
          var path = x.Path;
          return myContext.ResolveActorRef(path);
  }

我使用“代理人”解决了这个问题,这正是我在这里需要的。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM