当前位置:网站首页>Stack overflow caused by C # using protobuf stack overflow
Stack overflow caused by C # using protobuf stack overflow
2022-06-30 05:25:00 【Residual charm and mortal guest】
Direct explanation :
[ProtoBuf.ProtoContract]
[ProtoBuf.ProtoInclude(11, typeof(Cat))]
[ProtoBuf.ProtoInclude(12, typeof(Dog))]
public abstract class Animal
{
[ProtoBuf.ProtoMember(1)]
public string name;
[ProtoBuf.ProtoMember(2)]
public int sex;
}
[ProtoBuf.ProtoContract]
public class Cat : Animal
{
[ProtoBuf.ProtoMember(1)]
public int value1;
}
[ProtoBuf.ProtoContract]
public class Dog : Animal
{
[ProtoBuf.ProtoMember(1)]
public int value1;
[ProtoBuf.ProtoMember(2)]
public int value2;
}
[ProtoBuf.ProtoContract]
public class Role
{
[ProtoBuf.ProtoMember(1)]
public Animal animal = new Dog();
}
Declare the above class , among Cat,Dog All inherited from Animal, And then in Role Declare a Animal class , And give the initial value new Dog()
explain Role By default animal Namely Dog
Then perform the following method :
private static void Test()
{
Role role = new Role();
role.animal = new Cat();
var buffer = ProtobufSerialize.Serialize(role);
var role2 = ProtobufSerialize.Deserialize(buffer);
}
That is change Role in animal The variable type is Cat, It can lead to Protobuf Serialization generation Stack overflow. Stack overflow problem
resolvent :
If a variable or field of a type needs to be serialized , And this field is a parent class , The initial object cannot be given
the Role The type is changed to the following way
[ProtoBuf.ProtoContract]
public class Role
{
[ProtoBuf.ProtoMember(1)]
public Animal animal;
}
边栏推荐
- Virtual and pure virtual destructions
- Bessel curve with n control points
- Rotating frame target detection mmrotate v0.3.1 training dota data set (II)
- 很紧张,第一天做软件测试,需要做什么?
- Tensorflow2 of ubantu18.04 X installation
- C # uses monopinvokecallback to directly call back C # function
- 虚析构和纯虚析构
- 剑指 Offer 18. 删除链表的节点
- 如何写论文
- How to use js to control the scroll bar of moving div
猜你喜欢

Intellj idea jars projects containing external lib to other project reference methods - jars

【LeetCode】Easy | 225. Using queue to realize stack (pure C manual tearing queue)

Unity + hololens publishing settings

Unity- the camera follows the player

mmcv常用API介绍

Unityshader learning notes - Basic Attributes

Learning about functions QAQ

中文版PyCharm改为英文版PyCharm

Summary of common loss functions in pytorch

网络变压器怎么判断好坏?网络滤波变压器坏了一般是什么症状?
随机推荐
东塔攻防世界—xss绕过安全狗
抓取手机端变体组合思路设想
Unity3d packaging and publishing APK process
Set a plane to camera viewport
Visualization of 3D geological model based on borehole data by map flapping software
mmcv常用API介绍
Revit secondary development - use panel function without opening the project
Display steerable 3D model in front of unity UI
Unity + hololens publishing settings
Promise知识点拾遗
终端便捷ssh(免密)连接
Rotation, translation and scaling of unity VR objects
Installation and getting started with pytoch
旋转框目标检测mmrotate v0.3.1入门
Unity + hololens2 performance test
uboot通过终端发送‘r‘字符读取ddr内存大小
Unity gets the resolution of the game view
Another download address for typro
Network communication problem locating steps
Unity3d position the model, rotate, drag and zoom around the model to obtain the center point of the model