当前位置:网站首页>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
- 东塔攻防世界—xss绕过安全狗
- Set a plane to camera viewport
- Shopping list--
- C. Divan and bitwise operations
- Nestjs introduction and environment construction
- Revit secondary development - use panel function without opening the project
- Chapter 7 vertex processing and drawing commands of OpenGL super classic (7th Edition)
- 中文版PyCharm改为英文版PyCharm
- Pyinstaller flash back
猜你喜欢

Unity3d packaging and publishing APK process

【LeetCode】Easy | 232. Using stack to realize queue (pure C manual tearing stack)
![[typescript] cannot redeclare block range variables](/img/52/2fd3071ca9e3c5023c6b65961e2cf7.jpg)
[typescript] cannot redeclare block range variables

Virtual and pure virtual destructions

3D rotation album

Records of problems encountered in unity + hololens development

企事业单位源代码防泄露工作该如何进行

VFPBS在IIS下调用EXCEL遇到的Access is denied

Redistemplate common method summary

The fourth day of learning C language for Asian people
随机推荐
炒股用指南针开户交易安全吗?
网络变压器怎么判断好坏?网络滤波变压器坏了一般是什么症状?
Leetcode 180 Consecutive numbers (2022.06.29)
Configuration and use of controllers and routes in nestjs
Rotating frame target detection mmrotate v0.3.1 training dota data set (II)
使用码云PublicHoliday项目判断某天是否为工作日
Unity mobile end sliding screen rotation
Why can transformer break into the CV world and kill CNN?
Chapter 11 advanced data management of OpenGL super classic (version 7)
Xiaosha's lunch
How to prevent source code leakage in enterprises and institutions
Promise知识点拾遗
[note] usage model tree of the unity resource tree structure virtualizingtreeview
The fourth day of learning C language for Asian people
Set a plane to camera viewport
Bev instance prediction based on monocular camera (iccv 2021)
C # three ways to obtain web page content
9. naive Bayes
很紧张,第一天做软件测试,需要做什么?
Unity shortcut key