使用ProtoBuf序列化类型System.Drawing.Rectangle从.NET到C

Serialize type System.Drawing.Rectangle from .Net to C++ Using protobuf

本文关键字:NET Rectangle Drawing ProtoBuf 序列化 类型 System 使用      更新时间:2023-10-16

如果我序列化(使用protobuf)c#中的矩形(system.drawing.trectangle),可以在Objective-C或C 中进行对其进行测试,因为System.Drawing.Recting.Rectangle是不是像int。

这样的常见类型

如果可能的话,在C 或Objective-C?

中获取此矩形的最佳方法是什么

我通过使用自己的类类型修复了它,我的意思是将System.Drawing.Rectangle替换为我自己的类,而不是包含相同的属性。

我的意思是,如果您要序列化和估算化,则必须使用常见类型。

System.Drawing.Rectangle类型不直接在protobuf-net中支持(自动培训代码由于几个额外的属性而不会触发),所以我假设您要么有一个替代到位,或者您正在手动配置模型 - 例如:

RuntimeTypeModel.Default.Add(typeof(Rectangle),false)
                .Add("X","Y","Width","Height");

在这种情况下,您需要做的是创建一个.proto架构,该模式匹配该。Protobuf-net实际上会在这里为您提供帮助:

var proto = RuntimeTypeModel.Default.GetSchema(typeof(Rectangle));

对我来说(即我使用的配置)生成:

message Rectangle {
   optional int32 X = 1;
   optional int32 Y = 2;
   optional int32 Width = 3;
   optional int32 Height = 4;
}

这应该可以从任何Protobuf实施中使用。