【C# protobuf自动更新cs文件】教程文章相关的互联网学习教程文章

c# – 使用Protobuf-Net序列化运行时消息协议【代码】

可以说我有一些数据1: {1: 0.02: 13: "2"4: true }但在编译时我不知道合同.但是,在运行时,我可以加载一个数据描述符,告诉我我有多少字段以及每个字段中的每种类型.即new Type[]{typeof(double),typeof(int),typeof(string),typeof(bool)};问:在运行时,如何在给定数据描述的情况下从协议文件中读取(和写入)消息? 我目前的想法是:在运行时创建一个类型(emit)给定数据描述然后使用protocol-buf序列化/反序列化.然后通过反射/动态访...

c# – Protobuf-net无法仅使用getter序列化属性 – 无法对属性应用更改【代码】

我使用protobuf-net来序列化一个对象,我得到了异常: 无法对属性TestProject.TestMessage.ClientId应用更改 使用stacktrace:at ProtoBuf.Serializers.PropertyDecorator.SanityCheck(TypeModel model, PropertyInfo property, IProtoSerializer tail, Boolean& writeValue, Boolean nonPublic, Boolean allowInternal) at ProtoBuf.Serializers.PropertyDecorator..ctor(TypeModel model, Type forType, PropertyInfo property, I...

c# – ProtoBuf-net AsReference需要Activator.CreateInstance中的公共构造函数吗?【代码】

在我的两个类看起来像这样(最小)using System; using System.Collections.Generic; using System.Collections; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; using System.IO; using ProtoBuf;namespace Sandbox {public partial class Form1 : Form{public Form1(){Family family = new Family();Child child1 = new Child(1);Child child2 = new Child(2);Parent parent = new Parent(new L...

C#Protobuf-net:小数字字典:零不能正常往返【代码】

我发现了protobuf-net中十进制零序列化/反序列化的一个奇怪的错误,想知道是否有人为此找到了一个好的解决方法,或者这实际上是一个功能. 鉴于上面的字典,如果我在linqpad中运行:void Main() {{Dictionary<string, decimal> dict = new Dictionary<string, decimal>();dict.Add("one", 0.0000000m);DumpStreamed(dict);}{Dictionary<string, decimal> dict = new Dictionary<string, decimal>();dict.Add("one", 0m);DumpStreamed(d...

c# – Netty protobuf和google csharp原型用法【代码】

我想与Java服务器应用程序通信C#客户端应用程序. Java使用带有protobuf管道enconder的Ne??tty框架. 我的原型文件: 导入“google / protobuf / csharp_options.proto”;option (google.protobuf.csharp_file_options).namespace = "ChatClient.LoginProtocol"; option (google.protobuf.csharp_file_options).umbrella_classname = "LoginProtocol";option optimize_for = SPEED;message Credential {required string email = 1...

c# – 通过WCF实现protobuf-net与DataContractSerializer的性能【代码】

我测试了protobuf序列化,似乎对于一定数量的对象,它比常规的datacontract序列化慢.使用DataContractSerializer传输大小更大但在序列化和反序列化期间使用DataContractSerializer更快 你认为这是正常的还是我犯了错误?[DataContract] public partial class Toto {[DataMember]public string NomToto { get; set; }[DataMember]public string PrenomToto { get; set; } } 这是我的datacontract课程,这与protobuf相同[ProtoContract]...

c# – 如何使用Protobuf.net更改类型中成员的ProtoMember索引?【代码】

我有这样的类型:[ProtoContract] class Person {[ProtoMember(1)]public string Name {get;set:}[ProtoMember(2)]public int Id {get;set;} }后来我意识到我需要另一个属性Age所以添加它像:[ProtoContract] class Person {[ProtoMember(1)]public string Name {get;set:}[ProtoMember(3)]public int Age {get;set;}[ProtoMember(2)]public int Id {get;set;} }但由于我还处于开发阶段,我想将Age ProtoMember索引从3更改为2,并适当...

c# – 检测到Protobuf-net可能的递归:序列化子项和父项【代码】

我是序列化的新手,甚至是protobuf的新手.这是我的问题,我有这些课程:[ProtoContract] class Controle {[ProtoMember(1, AsReference=true)]public HashSet<Controle> ControlesInternes { get; set; }[ProtoMember(2)]public string TypeControle { get; set; }[ProtoMember(3)]public Dictionary<string, string> Attributs { get; set; }[ProtoMember(4)]public int Ligne { get; set; }[ProtoMember(5)]public string InnerTex...

c# – protobuf-net无法反序列化我的课程【代码】

我想序列化一个’Player’类,并通过我的网络流发送给客户端. 球员类[ProtoMember(1)]public int flag;[ProtoMember(2)]public Int16 id;[ProtoMember(3)]public MyVector3 CharPos;[ProtoMember(7)]public bool spawned;MyVector3(由于protobuf不支持Vector3的序列化这一事实)[ProtoContract] public class MyVector3 {[ProtoMember(4)]public float X { get; set; }[ProtoMember(5)]public float Y { get; set; }[ProtoMember(6)]...

使用protobuf-net生成C#时保留proto注释【代码】

我们使用protobuf-net来处理C#应用程序中的协议缓冲区需求.由于我们将.proto文件与其他非托管应用程序共享,因此我们从.proto文件生成代码(不使用代码优先的protobuf-net方法).为了尽可能保持DRY,我们在.proto文件中保留了很多接口文档.我们通过protogen.exe生成C#代码,由项目构建目标调用. 现在,有没有办法(自动)将这些注释转移到已编译的C#代码中? 基本上,给出一个像这样的.proto:// This message is used to request a resourc...

c# – 如何使用protobuf-net扩展?【代码】

我创建了一个.proto文件,并且ProtoBufTool成功创建了.cs文件.我是csharp的新手,我正在尝试设置扩展字段.但不知道怎么做?有没有人有任何使用protobuf-net使用扩展的例子. 我的.proto文件:package messages; message DMsg {optional int32 msgtype = 1;extensions 100 to max; } extend DMsg { optional string fltColumns = 101; }这是创建的类://---------------------------------------------------------------------------...

c# – protobuf-net:检测到可能的递归【代码】

我尝试序列化对象图(不是很深)时遇到异常.有意义的部分是这样的:[ERROR] FATAL UNHANDLED EXCEPTION: ProtoBuf.ProtoException: Possiblerecursion d etected (offset: 5 level(s)): red atProtoBuf.ProtoWriter.CheckRecursionStackAndPush (object) <0x00127> atProtoBuf.ProtoWriter.StartSubItem (object,ProtoBuf.ProtoWriter,bool)<0x0002f>该图表示文件/目录结构,我的模型(简化)如下所示:[ProtoContract] [ProtoInclude(...

c# – 如何在使用protobuf-net继承时选择字段编号?【代码】

我正在使用protobuf-net来序列化许多类型,其中一些类型是从基类型继承而来的.我知道Protocol Buffers规范不支持继承,并且protobuf-net中的支持基本上是一种解决方法,因为这样. 我正在配置自定义RuntimeTypeModel,并使用Add和AddSubType方法,而不是使用protobuf-net属性.我不太了解的是我应该如何确定传递给AddSubType方法的字段编号使用哪些数字(也就是在ProtoInclude属性中使用的数字). This SO question和其他几个类似的人并没有...

c# – 对于哪些场景,protobuf-net不合适?

我们一直在使用BinarySerialization和我们的C#app,但是需要序列化的类的大小和复杂性导致了sloooooow(de)序列化和大文件. 我们怀疑我们应该编写自己的自定义序列化程序;但是protobuf-net声称比标准.Net二进制序列化具有显着的速度和大小优势,并且可能比大量的定制序列化器更容易添加到我们的应用程序中. 在花费大量时间和精力试图让它为我们工作之前,我很想知道是否有任何交易破坏者.我们正在使用通过接口定义的属性,抽象子类的通用...

c# – 用protobuf-net进行质量过滤【代码】

我用protobuf-net序列化了一个对象列表. 从理论上讲,.bin文件可以包含数百万个对象. 假设对象属于包含以下内容的类:public string EventName;我必须进行查询并创建一个包含与查询匹配的对象的列表.使用LINQ从序列化文件中提取匹配对象的正确方法是什么?解决方法:protobuf格式是项目的线性序列;任何索引等你只能单独申请.然而,IEnumerable< T>可用;你可能会发现:var item = Serializer.DeserializeItems<YourType>(source).First...