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

C# protobuf自动更新cs文件【代码】【图】

网上的教程大都是手动通过protoc编译, 比较难用 给当前工程添加"Google.Protobuf"和"Grpc.Tools"的引用(通过nuget), 然后添加proto文件, 编辑.csproj文件<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><TargetFramework>netcoreapp3.1</TargetFramework></PropertyGroup><ItemGroup><PackageReference Include="Google.Protobuf" Version="3.11.2" /><PackageReference Include="Grpc.Tools" Version="2.26.0"><IncludeAssets>...

c# – 从子到父的protobuf-net继承【代码】

我有一个父母班,我想要有很多平坦的孩子.这意味着一个班级将固有10个或更多不同的班级. 这就是我所拥有的. 基类:[ProtoContract] [ProtoInclude(500, typeof(Message1Send))] [ProtoInclude(501, typeof(Message2Send))] public class MessageBase {[ProtoMember(1)]public string Topic {get;set;}[ProtoMember(2)]public string Action { get; set; } }许多儿童班中的2个:[ProtoContract] public class Message1Sen...

.NetCore使用protobuf 生成C#代码(Grpc)【代码】【图】

我使用vs2019,需要安装几个nuget包 Google.protobuf Google.protobuf.Tools Grpc.AspnetCore Grpc.Net.Client 编写.proto文件 syntax ="proto3";option csharp_namespace="WeService01.Controllers"; package WeService01.Controllers;message users{ int32 ID=1; string name=2; string login_name=3; int32 roleid=4; bool is_man=5; } message getusers{ int32 ID=1; string name=2; } message getusersresponse{ int32 code=1...

client: c#+protobuf, server: golang+protobuf【代码】

前段时间看到一篇博文《可在广域网部署运行的即时通讯系统 -- GGTalk总览(附源码下载)》,他是用C#实现的即时通讯系统,功能强大,界面漂亮。 就想用golang重写服务端,把代码下载回来,发现通信框架用的是ESFramework,我没用过也不知道ESFramework的协议,重写是不行的了,只能把原作者的客户端界面扣出来,自己写一个,客户端是C#+protobuf, 服务端是golang+protobuf,动起手来才发现,功能细节实在太多了,没精力搞下去了,就...

《Dotnet9》系列-Google ProtoBuf在C#中的简单应用【代码】

时间如流水,只能流去不流回! 点赞再看,养成习惯,这是您给我创作的动力! 本文 Dotnet9 https://dotnet9.com 已收录,站长乐于分享dotnet相关技术,比如Winform、WPF、ASP.NET Core等,亦有C++桌面相关的Qt Quick和Qt Widgets等,只分享自己熟悉的、自己会的。简介 什么是 Google Protocol Buffer? 假如您在网上搜索,应该会得到类似这样的文字介绍: Google Protocol Buffer( 简称 Protobuf) 是 Google 公司内部的混合语言数据...

C#-protobuf-net-列出支持的类型【代码】

我正在开发一个自定义的ProtoBufFormatter(:MediaTypeFormatter),它能够将自己的类型动态注册到用于序列化/反序列化的RuntimeTypeModel. 为了减少对try {} catch {}块的需求,在将已经支持的类型添加到RuntimeTypeModel之前,最好先过滤掉它们.自述文件仅提供默认情况下受支持的“模糊”列表类型,而Model.GetTypes()方法仅返回手动添加到当前模型的类型列表. 自述文件:https://github.com/mgravell/protobuf-net 我正在使用protobu...

C#-Protobuf-net枚举序列化行为在版本中更改. 2.3.0【代码】

如果2.3.0之前的任何序列化对象包含枚举值并且使用带有InferTagFromNameDefault而不是ProtoMember的DataMember,则在2.3.0或更高版本中将无法正确反序列化.[DataContract] public class ClassWithEnum {[DataMember]public MyEnum Enum { get; set; } }public enum MyEnum {FirstValue,SecondValue }我上这堂课使用此代码对其进行序列化.{RuntimeTypeModel.Default.InferTagFromNameDefault = true;var v = new ClassWithEnum { Enu...

c#-如何使用protobuf-net嵌入类型信息以进行反序列化?【代码】

我希望能够以保留/嵌入类型信息的方式序列化IMessage的具体实例(类似于Json.NET中的可用信息),以便在反序列化时可以使用类型信息来实现这些信息具体实例.我很清楚下面的反序列化方法不起作用.任何有关如何更改它们以使它们起作用的指导将不胜感激.public interface IMessage {} public interface IEvent : IMessage {} [ProtoContract] public class DogBarkedEvent : IEvent {[ProtoMember(0)]public string NameOfDog { get; set...

protobuf-net:如何在C#中表示DateTime?【代码】

protogen.exe会为long类型的proto2消息字段生成此模式:private long _Count = default(long); [global::ProtoBuf.ProtoMember(1, IsRequired = false, Name=@"Count", DataFormat = global::ProtoBuf.DataFormat.TwosComplement)] [global::System.ComponentModel.DefaultValue(default(long))] public long Count {get { return _Count; }set { _Count = value; } }但由于proto2不包含日期时间类型(并且protobuf-net不支持包含go...

c#-找不到类型或名称空间名称“ ProtoBuf”【代码】

我是C#语言的新手,所以我只是不明白为什么我的构建会产生如下错误消息.The type or namespace name 'ProtoBuf' could not be found(are you missing a using directive or an assembly reference?)有趣的是,如果我以“ .NET Framework 3.5”为目标,则不会出错,但是一旦将项目设置为“ .NET Framework 2.0”,就会出现错误.代码保持不变,并且protobuf-net应该可以与.NET 2.0一起使用,因此我不确定自己缺少什么.仅供参考,导致上述错误...

C#-protobuf-net:如何在用户会话中存储【代码】

我目前能够将我创建的对象存储到HttpContext.Current.Session中,并且遇到protobuf-net.是否可以通过使用protobuf序列化对象来存储对象? 似乎protobuf希望将信息存储到Stream中,所以我(可以吗?)应该将Stream对象存储到users会话中吗?还是应该先将其从Stream转换为另一种对象类型?如果是这样,转换序列化的对象是否会违反使用protobuf的原始目的(CPU使用率,内存使用率)?有人做过吗? 我的目标是使用protobuf作为将信息存储到用户...

C#-Protobuf.NET并列出对象的已知子类型:无法添加System.String?【代码】

我正在尝试为如下所示的类编写序列化代码:public class EventMessage {public Dictionary<string, object> Headers { get; set; }public object Body { get; set; } }此类中的“对象”类型成员从很小的类型(基本上限于一种装配基本CLR类型)中保存对象.所以我想我可以简单地将这些类列出为对象类的子类型,如下所示:model.Add(typeof(object), false).AddSubType(1, typeof(X)).AddSubType(2, typeof(Y))....这样,我不必将类型信息...

C#-缺少googleapis / google / protobuf

我正在尝试从.proto文件here编译GoogleCloudSpeechToTextv1p1beta1的C#库.protobuf编译器有效,但它缺少googleapis / google / protobuf目录中的依赖项.它依赖的所有其他导入文件都存在here. 我的问题是:为什么googleapis/google directory中缺少protobuf目录?是我个人需要编译/汇编的库吗?还是Google应该提供的东西而它却丢失了?解决方法:google / protobuf目录与Google.Protobuf.Tools软件包一起提供,位于工具下(例如,有tools...

c# – protobuf-net能处理自动只读属性吗?【代码】

protobuf-net能否处理新的自动只读属性,即使用单个get和no私有集定义的自动属性?public class WithReadonlyProperty {public int ReadonlyProperty { get; }public WithReadonlyProperty(int val) {ReadonlyProperty = val;} }当我这样做RuntimeTypeModel.Default.Add(typeof (WithReadonlyProperty), false).Add(nameof(WithReadonlyProperty.ReadonlyProperty)); var test = new WithReadonlyProperty(12345); using (var outpu...

c# – Protobuf-net:无法创建抽象类的实例【代码】

根据这里找到的代码: – how to serialize / deserialize?' rel='nofollow' target='_blank'>protobuf and List – how to serialize / deserialize?我创建了一个通用的“ProtoDictionary”,其值类型为ProtoObject. 这是我的ProtoDictionary代码:public class ProtoDictionary<TKey> : Dictionary<TKey, ProtoObject> {public void Add(TKey key, string value){base.Add(key, new ProtoObject<<string>(value));}public void Ad...