当前位置: 首页 > news >正文

怎样登录柳州建设网站网络推广平台哪家公司最好

怎样登录柳州建设网站,网络推广平台哪家公司最好,网页设计与制作 培训,简述网站建设基本流程答案一、.proto文件字段概述 grpc的接口传输参数都是根据.proto文件约定的字段格式进行传输的grpc提供了多种类型字段#xff1b;主要包括标量值类型#xff08;基础类型#xff09;、日期时间、可为null类型、字节、列表、字典、Any类型#xff08;任意类型#xff09;、One…一、.proto文件字段概述 grpc的接口传输参数都是根据.proto文件约定的字段格式进行传输的grpc提供了多种类型字段主要包括标量值类型基础类型、日期时间、可为null类型、字节、列表、字典、Any类型任意类型、Oneof等字段严格规范是一种强类型文件协议 二、案例介绍 标量值类型日期时间可为null类型字节列表字典Any类型Oneof一种语言特性可以通过该特性进行对象切换处理使用 oneof 指定可能返回 A对象或B对象 的响应消息 三、服务端定义 定义通用消息实体根据不同的类型创建对应的案例实体特殊的字段需要导入指定的包才能使用定义引用字段的各个服务接口内部实现逻辑及打印展示相应的字段结果 // 1.提供公共的实体proto文件 // 2.服务引用对应的proto文件// 通用消息文件datamessages.proto syntax proto3;option csharp_namespace GrpcProject;package grpc.serviceing;// 基础类型实体 message BaseConfig{string name 1;double position 2;float distance 3 ;int32 age 4;int64 timeSpanId 5;uint32 uAge 6;uint64 uTimeSpanId 7;sint32 sAge 8;sint64 sTimeSpanId 9;bool flag 10; }// 日期类型实体 需要导入 日期namespace import google/protobuf/duration.proto; import google/protobuf/timestamp.proto;message DateConfig{int64 id 1;google.protobuf.Timestamp dateTimestamp 2;google.protobuf.Duration dateDuration 3; }// 字节类型 message ByteConfig{int64 id 1;bytes positionBytes 2; }// 可为null类型 需要导入 null的namespace import google/protobuf/wrappers.proto;message NullConfig{int64 id 1;google.protobuf.BoolValue nullBool 2;google.protobuf.DoubleValue nullDoubule 3;google.protobuf.FloatValue nullFloat 4;google.protobuf.Int32Value nullInt 5;google.protobuf.Int64Value nullLong 6;google.protobuf.UInt32Value nullUInt 7;google.protobuf.StringValue nullString 8;google.protobuf.BytesValue nullBytes 9; }// 集合类型 message ListConfig{int64 id 1;// 数组repeated string names 2;repeated ListDetailConfig details 3;// 字典mapint32,string attributes 4;mapint32,ListDetailConfig dicDetail 5; }message ListDetailConfig{string name 1;int32 height 2; }// 任意类型 需要导入对应的包 import google/protobuf/any.proto; message AnyConfig{int32 id 1;google.protobuf.Any anyObject 2; }// Oneof类型 编译器在生成消息类时处理 oneof 关键字。 使用 oneof 指定可能返回 A 或 B 或 C 的响应消息 message OneofConfig{oneof result{A oA 1;B oB 2;C oC 3;} }message A{int32 id 1; }message B{int32 id 1; }message C{int32 id 1; }// 接口服务定义protofield.proto文件syntax proto3;import google/protobuf/empty.proto; import Protos/datamessages.proto;option csharp_namespace GrpcProject;package grpc.serviceing;service FieldRpc{// 基础字段处理rpc BaseConfigService(BaseConfig) returns (google.protobuf.Empty);// 日期字段处理rpc DateConfigService(DateConfig) returns (google.protobuf.Empty);// 字节处理rpc ByteConfigService(ByteConfig) returns (google.protobuf.Empty);// null字段处理rpc NullConfigService(NullConfig) returns (google.protobuf.Empty);// 集合类型字段处理rpc ListConfigService(ListConfig) returns (google.protobuf.Empty);// 任意类型字段处理rpc AnyConfigService(AnyConfig) returns (google.protobuf.Empty);// Oneof类型字段处理rpc OneofConfigService(OneofConfig) returns (google.protobuf.Empty); } // 服务实现类/// summary/// 字段处理服务/// /summarypublic class ProtoFieldService : FieldRpc.FieldRpcBase{// 基础配置public override async TaskEmpty BaseConfigService(BaseConfig request, ServerCallContext context){await Console.Out.WriteLineAsync(\r\n--------------------------基础配置--------------------------\r\n);// 打印字段信息var properties request.GetType().GetProperties();foreach (var property in properties){var value property.GetValue(request);await Console.Out.WriteLineAsync(${property.Name}{value});}return new Empty();}// 日期配置public override async TaskEmpty DateConfigService(DateConfig request, ServerCallContext context){await Console.Out.WriteLineAsync(\r\n--------------------------日期配置--------------------------\r\n);// timspanvar duration request.DateDuration.ToTimeSpan();await Console.Out.WriteLineAsync(${nameof(duration)}{duration.TotalSeconds});// datetimevar time request.DateTimestamp.ToDateTime();await Console.Out.WriteLineAsync(${nameof(time)}{time:yyyy-MM-dd HH:mm:ss});return new Empty();}// 字节public override async TaskEmpty ByteConfigService(ByteConfig request, ServerCallContext context){await Console.Out.WriteLineAsync(\r\n--------------------------字节配置--------------------------\r\n);var bytes request.PositionBytes.ToByteArray();var message Encoding.UTF8.GetString(bytes, 0, bytes.Length);await Console.Out.WriteLineAsync(${nameof(message)}{message});return new Empty();}// null配置public override async TaskEmpty NullConfigService(NullConfig request, ServerCallContext context){await Console.Out.WriteLineAsync(\r\n--------------------------null配置--------------------------\r\n);// 打印字段信息var properties request.GetType().GetProperties();foreach (var property in properties){var value property.GetValue(request);var printValue value null ? 返回null值 : value;await Console.Out.WriteLineAsync(${property.Name}{printValue});}return new Empty();}// 集合public override async TaskEmpty ListConfigService(ListConfig request, ServerCallContext context){await Console.Out.WriteLineAsync(\r\n--------------------------集合配置--------------------------\r\n);var id request.Id;await Console.Out.WriteLineAsync($主键标识{id}\r\n);// 转换数组arrayawait Console.Out.WriteLineAsync($打印names信息);var names request.Names.ToArray();foreach (var name in names){await Console.Out.WriteLineAsync(name);}// 转换listawait Console.Out.WriteLineAsync($\r\n打印detailList信息);var detailList request.Details.ToList();foreach (var item in detailList){await Console.Out.WriteLineAsync($ListDetailConfig{nameof(item.Name)} {item.Name}{nameof(item.Height)} {item.Height}。);}// 字典await Console.Out.WriteLineAsync($\r\n打印一般字典信息);var dicAttributes request.Attributes.ToDictionary(t t.Key, t t.Value);foreach (var attr in dicAttributes){await Console.Out.WriteLineAsync($key{attr.Key}value{attr.Value}。);}await Console.Out.WriteLineAsync($\r\n打印对象字典信息);foreach (var item in request.DicDetail){await Console.Out.WriteLineAsync($key{item.Key}value{item.Value.Name} | {item.Value.Height}。);}return new Empty();}// Anypublic override async TaskEmpty AnyConfigService(AnyConfig request, ServerCallContext context){await Console.Out.WriteLineAsync(\r\n--------------------------Any配置--------------------------\r\n);var anyObject request.AnyObject;// 检查是否是A对象if (anyObject.Is(A.Descriptor)){var a anyObject.UnpackA();if (a is not null){await Console.Out.WriteLineAsync($A对象{a.Id});}}else if (anyObject.Is(B.Descriptor)){var b anyObject.UnpackB();if (b is not null){await Console.Out.WriteLineAsync($B对象{b.Id});}}else if (anyObject.Is(C.Descriptor)){var c anyObject.UnpackC();if (c is not null){await Console.Out.WriteLineAsync($C对象{c.Id});}}else{await Console.Out.WriteLineAsync(Any未解析到任何对象);}return new Empty();}// oneofpublic override async TaskEmpty OneofConfigService(OneofConfig request, ServerCallContext context){await Console.Out.WriteLineAsync(\r\n--------------------------Oneof配置--------------------------\r\n);// 检测对应的对象是否有值switch (request.ResultCase){case OneofConfig.ResultOneofCase.None:await Console.Out.WriteLineAsync(未检测到任何对象);break;case OneofConfig.ResultOneofCase.OA:await Console.Out.WriteLineAsync($对象OA存在值{request.OA.Id});break;case OneofConfig.ResultOneofCase.OB:await Console.Out.WriteLineAsync($对象OB存在值{request.OB.Id});break;case OneofConfig.ResultOneofCase.OC:await Console.Out.WriteLineAsync($对象OC存在值{request.OC.Id});break;default:break;}return new Empty();}} 三、客户端定义 引用proto文件配置为客户端类型根据编译生成的函数进行传参调用创建WPF测试客户端各个服务接口创建对应的按钮进行调用执行过程中服务端控制台会打印对应的消息 // 基础private async void BtnBaseconfig_Click(object sender, RoutedEventArgs e){await WpfFieldClient.Show(1);MessageBox();}// 日期private async void BtnDateconfig_Click(object sender, RoutedEventArgs e){await WpfFieldClient.Show(2);MessageBox();}// 字节private async void BtnByteconfig_Click(object sender, RoutedEventArgs e){await WpfFieldClient.Show(3);MessageBox();}// nullprivate async void BtnNullconfig_Click(object sender, RoutedEventArgs e){await WpfFieldClient.Show(4);MessageBox();}// listprivate async void BtnListconfig_Click(object sender, RoutedEventArgs e){await WpfFieldClient.Show(5);MessageBox();}// anyprivate async void BtnAnyconfig_Click(object sender, RoutedEventArgs e){await WpfFieldClient.Show(6);MessageBox();}// Oneofprivate async void BtnOneofconfig_Click(object sender, RoutedEventArgs e){await WpfFieldClient.Show(7);MessageBox();} 调用的类库 public class WpfFieldClient{/// summary/// 根据参数选择不同的方法执行/// /summary/// param namek/parampublic static async Task Show(int k){var channel GrpcChannel.ForAddress(https://localhost:7188);var client new GrpcProject.FieldRpc.FieldRpcClient(channel);// 基础BaseConfig config new BaseConfig();config.Name 张三;config.Position 2.33D;config.Distance 5.48F;config.Age 10;config.TimeSpanId 6538590027736100;config.SAge 1921;config.STimeSpanId 6538590027736130;config.Flag true;// 日期DateConfig dateConfig new DateConfig();dateConfig.Id 179;dateConfig.DateDuration Duration.FromTimeSpan(TimeSpan.FromSeconds(5));// 注意这里的时间是utc时间dateConfig.DateTimestamp Timestamp.FromDateTime(DateTime.UtcNow);// 字节ByteConfig byteConfig new ByteConfig();byteConfig.Id 9854564654654;byteConfig.PositionBytes ByteString.CopyFrom(Encoding.UTF8.GetBytes(庄这人的南的很));// nullNullConfig nullConfig new NullConfig();nullConfig.Id 1854564654654;nullConfig.NullBool true;nullConfig.NullFloat null;nullConfig.NullUInt null;nullConfig.NullInt 15;nullConfig.NullLong 112345451234787;// ListConfigListConfig listConfig new ListConfig();var attributes new Dictionaryint, string{[1] one,[2] two,[3] three,[4] four,[5] five};listConfig.Id 123456456;listConfig.Attributes.Add(attributes);var dicDetail new Dictionaryint, ListDetailConfig{[1] new ListDetailConfig { Height 1, Name one },[2] new ListDetailConfig { Height 2, Name two },[3] new ListDetailConfig { Height 3, Name three },[4] new ListDetailConfig { Height 4, Name four },[5] new ListDetailConfig { Height 5, Name five }};listConfig.DicDetail.Add(dicDetail);listConfig.Details.Add(new ListDetailConfig { Height 8, Name Eight });var detailConfigs new ListListDetailConfig{new ListDetailConfig { Height9,Namenine},new ListDetailConfig{ Height10,Nameten}};listConfig.Details.Add(detailConfigs);// AnyAnyConfig anyConfig new AnyConfig();anyConfig.Id 42564134;anyConfig.AnyObject Any.Pack(new B { Id 15 });// OneofOneofConfig oneofConfig new OneofConfig();oneofConfig.OA new A { Id 1 };//oneofConfig.OC new C { Id 2 };var emptyResult k switch{1 await client.BaseConfigServiceAsync(config),2 await client.DateConfigServiceAsync(dateConfig),3 await client.ByteConfigServiceAsync(byteConfig),4 await client.NullConfigServiceAsync(nullConfig),5 await client.ListConfigServiceAsync(listConfig),6 await client.AnyConfigServiceAsync(anyConfig),7 await client.OneofConfigServiceAsync(oneofConfig),_ new Empty()};}} 五、执行结果 服务端 客户端 六、源码地址 链接https://pan.baidu.com/s/150TKY2Kgln3l_uKAsztyzw  提取码hkb9
http://www.pierceye.com/news/331784/

相关文章:

  • 响应式网站制作公司org域名购买
  • 石家庄网站建设德信互联科技有限公司爬取漫画数据做网站
  • 国内免费iphone网站百度自然排名优化
  • 自己做网站主机做网站和推广
  • wordpress 淘宝嘉兴做网站优化
  • h5 网站开发流程asp个人网站建设
  • 网站建设 正邦企业邮箱怎么认证
  • 建设流网站项目成都住建局官网首页
  • 网站简历文字如何空行产品如何推广市场
  • 吕梁网站设计腾讯营销平台
  • 如何查看网站流量公众号申请网站
  • 阐述企业搭建网站的重要性免费做效果图的网站有哪些
  • 快速网站搭建南宁广告公司网站建设
  • 做数学题网站专业做网站建设 昆山
  • 建筑网站上海网页设计图片素材网
  • 延边网站开发depawo做汽车网站销售怎么入手
  • 商城网站开发技术南京好的网站制作公司
  • 嘉兴网站建设嘉兴网站推广网站网络营销方案
  • 镇江建工建设集团网站建设银行网站怎么基本转个人
  • 自己建的网站打开的特别慢盐城网站建设效果
  • 专业建站报价wordpress这软件怎么搜索
  • 德国网站建设电工培训内容
  • 织梦手机wap网站标签调用外贸网站建设公司如何
  • 在那里能找到网站泰安公司网站开发
  • 大兴区企业网站建设我们网站的优势
  • 呼伦贝尔市建设局网站关键词如何排名在首页
  • 网站带后台模板网站的建设宗旨
  • 深圳网站建设php专门查企业的网站
  • 做问卷调查的网站有啥世界比分榜
  • 网站301定向深圳电梯广告制作公司网站