protobuf网继承和放大器;场数 [英] protobuf-net Inheritance & Field Numbers

查看:217
本文介绍了protobuf网继承和放大器;场数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图构建一个序列化系统为我们的应用程序,它必须能够处理继承。为了进一步使问题复杂化的应用程序是可扩展的类型可能都不太可能在编译时已知的。

I am trying to construct a serialisation system for our application that must be able to handle inheritance. To further complicate matters the application is extensible so types might are very unlikely to be known at compile time.

我已经通过 previous计算器这个问题得到了回答,并且帮助我得到一个很长的路要走我的目标,但我已经打了一个绊脚石这可能是更多的是缺乏了解比任何真正的问题!

I have read through a previous stackoverflow question that was answered and that helped me get a long way to my goal but I have hit a stumbling block that is probably more of a lack of understanding than any real issue!

所以这是code,我有当前...

So this is the code that I have currently...

public interface IBaseFrame
{

}

public class BasicDataFrame : IBaseFrame
{

}

public class AnotherFrame : BasicDataFrame
{

}

。 。 。

. . . .

RuntimeTypeModel model = TypeModel.Create();
MetaType baseType = model.Add(typeof(IBaseFrame), true);
MetaType basicFrameType = model.Add(typeof(BasicDataFrame),true);

baseType.AddSubType(7, typeof(BasicDataFrame));
model.Add(typeof(AnotherFrame), true);

basicFrameType.AddSubType(8, typeof(AnotherFrame));

现在这个code正常工作(据我可以告诉!),所有在世界上好的......我关心的是其中的值7和8被用在code以上的 fieldNumber 的的AddSubType方法的参数。

Now this code works correctly (as far as I can tell!) and all is good in the world... My concern is where the values 7 and 8 are used in the code above for the fieldNumber argument of the AddSubType method.

由于插件列举我登记他们的帧类型与SerialisationManager,我将它们添加到模型的的 fieldNumber 的(我开始是在任意大量的,所以我不要一个递增计数器T担心扩展基类的未来)。

As the plugins are enumerated I am registering their frame types with the SerialisationManager and I add them to the model with an incrementing counter for the fieldNumber (I start it at an arbitrarily large number so I don't have to worry about extending the base classes in the future).

我很担心,如果插件列举以不同的顺序,或新的添加(或删除),则自动生成的 fieldNumber 的将是针对不同的子类型的不同之处在于将随后导致与使用者之间的共用的日志文件的问题(谁可能有不同的插件,因此,亚型)或甚至文件时插件可能已被删除在同一系统上

I am worried that if the plugins are enumerated in a different order or new ones are added (or removed) then the auto generated fieldNumber is going to be different for the different sub types that will then cause issues with sharing log files between users (who may have different plugins and therefore subtypes) or even files on the same system when a plugin may have been removed.

有没有用这种继承的自动处理和不引入兼容性问题在未来或任何狡猾的方式,当插件更改或做我需要拿出一个机制,当这些的 fieldNumbers 的可保证保留contant在所有设备?

Is there any cunning way of dealing with this kind of inheritance automatically and without introducing compatibility issues in the future or when plugins change or do I need to come up with a mechanism where these fieldNumbers can be guaranteed to remain contant across all installations?

任何帮助或建议,可以给将大大AP preciated!

Any help or advice that can be given would be greatly appreciated!

推荐答案

没有魔法在这里;数字是基本上合同的一部分,并且如果要反序列化你存储的数据previously重要的是它们可以被可靠地再现。如果数据不能在编译时已知的,也许配置或类型的一些外部注册表以场数可能有帮助。你的担心是正确的。

No magic here; the numbers are essentially part of the contract, and it is important that they can be reliably reproduced if you want to deserialize data you stored previously. If the data can't be known at compile-time, maybe configuration or some external registry of types to field numbers may help. Your concerns are accurate.

这篇关于protobuf网继承和放大器;场数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆