gRPC 对应Java类型
来源:互联网 发布:fopen提高权限 linux 编辑:程序博客网 时间:2024/05/21 11:06
官方指南
如下链接为Protocol Buffers官方指南,请参阅: https://developers.google.com/protocol-buffers/docs/proto3
.proto定义示例
1234567891011121314151617181920212223242526
syntax = "proto3";option java_multiple_files = true;// 此处cn.enncloud为程序包名,规则详见“详细说明[1]”package cn.enncloud;// 此处使用service标签定义服务service NewsService {// 此处使用rpc标签定义方法 rpc add (News) returns (NewsResponse) { } rpc save (News) returns (NewsResponse) { } rpc delete (News) returns (NewsResponse) { } rpc list (News) returns (NewsResponse) { }}// 此处使用message标签定义方法的入参和出参message NewsResponse { News news = 1 [deprecated = true]; repeated News newslist = 2;}message News { int32 id = 1; string requestTitle = 2;}
详细说明:
- [1]package后面接的cn.enncloud是程序包名,可以自定义;
- proto文件名必须小写开头,每个单词都要以小写字母开头,单词之间以下划线分割,例如xxx_yyy_service.proto。对应的servcie要定义为XxxYyyService,必须严格驼峰,不能连续大写;
- 一个proto文件内只能定义一个service,多个 service 需要多个 proto 文件,service和message必须在同一个 proto 文件中;
- message定义的对象命名规范为首字母大写,如此定义是gPRC的规范;
- proto 文件须放置在项目中的如下目录${Project}/src/main/proto/
类型对应关系表
注:由于proto本身的限制,建议真正使用BeanCopyUtils时不要建议使用标准类型与包装类型直接转换;例如:int->integer
示例[2]
12345
message Simple { string msg = 1; // repeated string 对字节数组 repeated string results = 2;}
.proto Type Notes C++ Type Java Type Python Type[2] Go Type Ruby Type C# Type PHP Type double doubledoublefloatfloat64Floatdoublefloatfloat floatfloatfloatfloat32Floatfloatfloatint32Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint32 instead.int32intintint32Fixnum or Bignum (as required)intintegerint64Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint64 instead.int64longint/long[3]int64Bignumlonginteger/string[5]uint32Uses variable-length encoding.uint32int[1]int/long[3]uint32Fixnum or Bignum (as required)uintintegeruint64Uses variable-length encoding.uint64long[1]int/long[3]uint64Bignumulonginteger/string[5]sint32Uses variable-length encoding. Signed int value. These more efficiently encode negative numbers than regular int32s.int32intintint32Fixnum or Bignum (as required)intintegersint64Uses variable-length encoding. Signed int value. These more efficiently encode negative numbers than regular int64s.int64longint/long[3]int64Bignumlonginteger/string[5]fixed32Always four bytes. More efficient than uint32 if values are often greater than 228.uint32int[1]intuint32Fixnum or Bignum (as required)uintintegerfixed64Always eight bytes. More efficient than uint64 if values are often greater than 256.uint64long[1]int/long[3]uint64Bignumulonginteger/string[5]sfixed32Always four bytes.int32intintint32Fixnum or Bignum (as required)intintegersfixed64Always eight bytes.int64longint/long[3]int64Bignumlonginteger/string[5]bool boolbooleanboolboolTrueClass/FalseClassboolbooleanstringA string must always contain UTF-8 encoded or 7-bit ASCII text.stringStringstr/unicode[4]stringString (UTF-8)stringstringbytesMay contain any arbitrary sequence of bytes.stringByteStringstr[]byteString (ASCII-8BIT)ByteStringstring
扩展实现示例
枚举
123456789
enum Corpus { UNIVERSAL = 0; WEB = 1; IMAGES = 2; LOCAL = 3; NEWS = 4; PRODUCTS = 5; VIDEO = 6;}
对象列表List
12345678910
message SearchResponse { // 此处就是定义对象的List repeated Result results = 1;}message Result { string url = 1; string title = 2; repeated SearchResponse searchResponse = 3;}
Map
123456
message MeetingResponse { string id = 1; string error = 2; // 此处定义了Map对象 map<string, string> projects = 3;}
由于ProtoBuffer不支持Object类型,因此建议如果有需求map<string, string>的方式
阅读全文
0 0
- gRPC 对应Java类型
- flash 与 java 类型对应
- MySQL和java类型对应
- hibernate、java、数据库对应类型
- orale数据类型对应java类型
- hibernate、java、数据库对应类型
- tinyint对应java什么类型
- hibernate、java、数据库对应类型
- Java对应sql类型(oralce)
- Oracle数据类型对应Java类型
- java数据类型对应数据库类型
- Oracle数据类型对应Java类型
- Java类型和本地类型对应
- JDBC类型与JAVA类型对应关系
- 数据库类型和java类型对应关系
- java类型与mysql类型对应表
- Java类型和本地类型对应
- mysql 字段类型对应 java属性类型
- App反编译工具
- 描述一下JVM加载class文件的原理机制?
- 1068. Sum Time limit
- nodejs安装mysql包
- 最近遇到的问题
- gRPC 对应Java类型
- Mysql 函数快速查询
- 8.2计数排序
- 面试旧敌之红黑树(直白介绍深入理解)
- hadoop mr程序出现The constructor Job(Configuration, String) is deprecated
- AS开发中设置
- FreeIPA LDAP HA安装
- #HDU 2444 The Accomodation of Students
- GCC 编译详解