繁体   English   中英

使用Protobuf-net自定义类型序列化

[英]Custom typ serialization with Protobuf-net

是否可以将protobuf-net与自定义类型序列化一起使用?

这是我所拥有的一个伪例子

  //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
  {
  }

我需要将所有“ ActorRef”类型序列化为相同的类型,我只需要存储“ Path”并忽略其余的即可。 我还需要能够在此处拦截/解决“ ActorRef”的反序列化。 因此,当反序列化程序找到序列化的“路径”时,我需要它来调用我的自定义处理程序并以这种方式解析ActorRef。

差不多,ActorRef及其子类型的自定义序列化和反序列化。 例如

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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