什么是 protobuf

Protocal Buffers(简称protobuf)是谷歌的一项技术,用于结构化的数据序列化、反序列化。
Protocol Buffers 是一种语言无关、平台无关、可扩展的序列化结构数据的方法,它可用于(数据)通信协议、数据存储等。
Protocol Buffers 是一种灵活,高效,自动化机制的结构数据序列化方法-可类比 XML,但是比 XML 更小(3 ~ 10倍)、更快(20 ~ 100倍)、更为简单。
你可以定义数据的结构,然后使用特殊生成的源代码轻松的在各种数据流中使用各种语言进行编写和读取结构数据。你甚至可以更新数据结构,而不破坏由旧数据结构编译的已部署程序
protobuf 就是一个序列化数据和反序列化数据的方法,类似的还有 XML、Json、Java 的 Serializable 等。
但protobuf的效率高于XML、Json,不过protobuf生成的是字节码,可读性相比之略差

生成代码指定

  1. protoc demo.proto --java_out=./
  2. --cpp_out :在目标目录DST_DIR中产生C++代码
  3. --java_out :在目标目录DST_DIR中产生Java代码
  4. --python_out :在目标目录 DST_DIR 中产生Python代码
  5. --go_out :在目标目录 DST_DIR 中产生Go代码
  6. --ruby_out:在目标目录 DST_DIR 中产生Ruby代码
  7. --javanano_out:在目标目录DST_DIR中生成JavaNano
  8. --objc_out:在目标目录DST_DIR中产生Object代码
  9. --csharp_out:在目标目录DST_DIR中产生Object代码
  10. --php_out:在目标目录DST_DIR中产生Object代码

protobuf安装配置

protobuf编辑器安装

下载地址:https://github.com/protocolbuffers/protobuf/releases
image.png
配置环境变量
image.png
打开cmd命令行,输入

  1. protoc
  2. protoc --version
  3. # 生成protoc代码
  4. protoc demo.proto --java_out=./

image.png
image.png

IDEA配置protobuf

1、File->Setting->Plugins
安装protobuf插件
image.png
重启之后我们可以在工具栏看到这两个选项
一个是配置全局的 protobuf
一个是生成所有的 protobuf 文件
image.png
2、配置protobufs :Configure->GenProtobuf
此处配置的是安装的protoc.exe
protoc path :我们下载的 protobuf 编辑器的位置,在 bin 目录下有一个 .exe 文件
quick gen : 对应的语言,这里选择伟大的 Java
image.png

简单-proto案例

1、引入pom依赖

  1. <!-- protobuf 支持 Java 核心包-->
  2. <dependency>
  3. <groupId>com.google.protobuf</groupId>
  4. <artifactId>protobuf-java</artifactId>
  5. <version>3.20.1</version>
  6. </dependency>
  7. <!-- proto Json 互转会用到-->
  8. <dependency>
  9. <groupId>com.google.protobuf</groupId>
  10. <artifactId>protobuf-java-util</artifactId>
  11. <version>3.20.1</version>
  12. </dependency>

2、编写 .proto 文件

新建一个 demo.proto

  1. //使用 proto3 语法 ,未指定则使用proto2
  2. syntax = "proto3";
  3. //生成 proto 文件所在包路径
  4. package com.qingfeng.proto;
  5. //生成 proto 文件所在包路径
  6. option java_package = "com.qingfeng.proto";
  7. //生成 proto 文件名
  8. option java_outer_classname="DemoProto";
  9. message Demo{
  10. //自身属性
  11. int32 id = 1;
  12. string code = 2;
  13. string name = 3;
  14. }

image.png

3、生成 proto 对象

选中我们新建的.proto 文件,右键,选择框中的选项就可以生成了,将生成之后的文件拷贝到java目录下面。
image.png

4、新建测试类

  1. package com.qingfeng.test;
  2. import com.google.protobuf.InvalidProtocolBufferException;
  3. import com.google.protobuf.util.JsonFormat;
  4. import com.qingfeng.proto.DemoProto;
  5. import java.util.Arrays;
  6. /**
  7. * @author Administrator
  8. * @version 1.0.0
  9. * @ProjectName com.qingfeng-client
  10. * @Description TODO
  11. * @createTime 2022年05月01日 18:10:00
  12. */
  13. public class DemoTest {
  14. public static void main(String[] args) {
  15. //初始化数据
  16. DemoProto.Demo.Builder demo = DemoProto.Demo.newBuilder();
  17. demo.setId(1)
  18. .setCode("001")
  19. .setName("张三")
  20. .build();
  21. //序列化
  22. DemoProto.Demo build = demo.build();
  23. //转换成字节数组
  24. byte[] s = build.toByteArray();
  25. System.out.println("protobuf数据bytes[]:" + Arrays.toString(s));
  26. System.out.println("protobuf序列化大小: " + s.length);
  27. DemoProto.Demo demo1 = null;
  28. String jsonObject = null;
  29. try {
  30. //反序列化
  31. demo1 = DemoProto.Demo.parseFrom(s);
  32. //转 json
  33. jsonObject = JsonFormat.printer().print(demo1);
  34. } catch (InvalidProtocolBufferException e) {
  35. e.printStackTrace();
  36. }
  37. System.out.println("Json格式化结果:\n" + jsonObject);
  38. System.out.println("Json格式化数据大小: " + jsonObject.getBytes().length);
  39. }
  40. }

protobuf 与 Java 数据类型对应

1、字段规则

required : 字段只能也必须出现 1 次,多用于必填项,必须赋值的字符

  1. required int32 id = 1

optional : 字段可出现 0 次或多次,可有可无的字段,可以使用[default = xxx]配置默认值

  1. optional string name = 1 [default = "张三"]

repeated : 字段可出现任意多次(包括 0),多用于 Java List 属性

  1. //list String
  2. repeated string strList = 5;
  3. //list 对象
  4. repeated Role roleList = 6;

2、字段类型

protobuf 类型 java 类型
double double
float float
int32 int
int64 long
bool boolean
string String

系统默认值
string默认为空字符串
bool默认为false
数值默认为0
enum默认为第一个元素

3、复杂类型

Java String、Integer List 在 protobuf 的定义

  1. //创建一个 User 对象
  2. message User{
  3. //list Int
  4. repeated int32 intList = 1;
  5. //list String
  6. repeated string strList = 5;
  7. }

Java 对象 List 在 protobuf 的定义

  1. //创建一个 User 对象
  2. message User{
  3. //list 对象
  4. repeated Role roleList = 6;
  5. }

Java String、Integer Map 在 protobuf 的定义

  1. //创建一个 User 对象
  2. message User{
  3. // 定义简单的 Map string
  4. map<string, int32> intMap = 7;
  5. // 定义复杂的 Map 对象
  6. map<string, string> stringMap = 8;
  7. }

Java 对象 Map 在 protobuf 的定义

  1. //创建一个 User 对象
  2. message User{
  3. // 定义复杂的 Map 对象
  4. map<string, MapVauleObject> mapObject = 8;
  5. }
  6. // 定义 Map 的 value 对象
  7. message MapVauleObject {
  8. string code = 1;
  9. string name = 2;
  10. }

Java 实体类中嵌套实体 在 protobuf 的定义

  1. //创建一个 User 对象
  2. message User{
  3. // 对象
  4. NickName nickName = 4;
  5. }
  6. // 定义一个新的Name对象
  7. message NickName {
  8. string nickName = 1;
  9. }

复杂-Proto案例

新增user.proto文件

  1. // Generated by the protocol buffer compiler. DO NOT EDIT!
  2. // source: User.proto
  3. package com.qingfeng.proto;
  4. public final class UserProto {
  5. private UserProto() {}
  6. public static void registerAllExtensions(
  7. com.google.protobuf.ExtensionRegistryLite registry) {
  8. }
  9. public static void registerAllExtensions(
  10. com.google.protobuf.ExtensionRegistry registry) {
  11. registerAllExtensions(
  12. (com.google.protobuf.ExtensionRegistryLite) registry);
  13. }
  14. public interface UserOrBuilder extends
  15. // @@protoc_insertion_point(interface_extends:com.qingfeng.proto.User)
  16. com.google.protobuf.MessageOrBuilder {
  17. /**
  18. * <pre>
  19. *自身属性
  20. * </pre>
  21. *
  22. * <code>int32 id = 1;</code>
  23. * @return The id.
  24. */
  25. int getId();
  26. /**
  27. * <code>string code = 2;</code>
  28. * @return The code.
  29. */
  30. java.lang.String getCode();
  31. /**
  32. * <code>string code = 2;</code>
  33. * @return The bytes for code.
  34. */
  35. com.google.protobuf.ByteString
  36. getCodeBytes();
  37. /**
  38. * <code>string name = 3;</code>
  39. * @return The name.
  40. */
  41. java.lang.String getName();
  42. /**
  43. * <code>string name = 3;</code>
  44. * @return The bytes for name.
  45. */
  46. com.google.protobuf.ByteString
  47. getNameBytes();
  48. /**
  49. * <pre>
  50. * 对象
  51. * </pre>
  52. *
  53. * <code>.com.qingfeng.proto.NickName nickName = 4;</code>
  54. * @return Whether the nickName field is set.
  55. */
  56. boolean hasNickName();
  57. /**
  58. * <pre>
  59. * 对象
  60. * </pre>
  61. *
  62. * <code>.com.qingfeng.proto.NickName nickName = 4;</code>
  63. * @return The nickName.
  64. */
  65. com.qingfeng.proto.UserProto.NickName getNickName();
  66. /**
  67. * <pre>
  68. * 对象
  69. * </pre>
  70. *
  71. * <code>.com.qingfeng.proto.NickName nickName = 4;</code>
  72. */
  73. com.qingfeng.proto.UserProto.NickNameOrBuilder getNickNameOrBuilder();
  74. /**
  75. * <pre>
  76. *list 引用类型
  77. * </pre>
  78. *
  79. * <code>repeated string strList = 5;</code>
  80. * @return A list containing the strList.
  81. */
  82. java.util.List<java.lang.String>
  83. getStrListList();
  84. /**
  85. * <pre>
  86. *list 引用类型
  87. * </pre>
  88. *
  89. * <code>repeated string strList = 5;</code>
  90. * @return The count of strList.
  91. */
  92. int getStrListCount();
  93. /**
  94. * <pre>
  95. *list 引用类型
  96. * </pre>
  97. *
  98. * <code>repeated string strList = 5;</code>
  99. * @param index The index of the element to return.
  100. * @return The strList at the given index.
  101. */
  102. java.lang.String getStrList(int index);
  103. /**
  104. * <pre>
  105. *list 引用类型
  106. * </pre>
  107. *
  108. * <code>repeated string strList = 5;</code>
  109. * @param index The index of the value to return.
  110. * @return The bytes of the strList at the given index.
  111. */
  112. com.google.protobuf.ByteString
  113. getStrListBytes(int index);
  114. /**
  115. * <pre>
  116. * 定义简单的 Map string
  117. * </pre>
  118. *
  119. * <code>map&lt;string, string&gt; map = 6;</code>
  120. */
  121. int getMapCount();
  122. /**
  123. * <pre>
  124. * 定义简单的 Map string
  125. * </pre>
  126. *
  127. * <code>map&lt;string, string&gt; map = 6;</code>
  128. */
  129. boolean containsMap(
  130. java.lang.String key);
  131. /**
  132. * Use {@link #getMapMap()} instead.
  133. */
  134. @java.lang.Deprecated
  135. java.util.Map<java.lang.String, java.lang.String>
  136. getMap();
  137. /**
  138. * <pre>
  139. * 定义简单的 Map string
  140. * </pre>
  141. *
  142. * <code>map&lt;string, string&gt; map = 6;</code>
  143. */
  144. java.util.Map<java.lang.String, java.lang.String>
  145. getMapMap();
  146. /**
  147. * <pre>
  148. * 定义简单的 Map string
  149. * </pre>
  150. *
  151. * <code>map&lt;string, string&gt; map = 6;</code>
  152. */
  153. /* nullable */
  154. java.lang.String getMapOrDefault(
  155. java.lang.String key,
  156. /* nullable */
  157. java.lang.String defaultValue);
  158. /**
  159. * <pre>
  160. * 定义简单的 Map string
  161. * </pre>
  162. *
  163. * <code>map&lt;string, string&gt; map = 6;</code>
  164. */
  165. java.lang.String getMapOrThrow(
  166. java.lang.String key);
  167. /**
  168. * <pre>
  169. * 定义复杂的 Map 对象
  170. * </pre>
  171. *
  172. * <code>map&lt;string, .com.qingfeng.proto.MapVauleObject&gt; mapObject = 7;</code>
  173. */
  174. int getMapObjectCount();
  175. /**
  176. * <pre>
  177. * 定义复杂的 Map 对象
  178. * </pre>
  179. *
  180. * <code>map&lt;string, .com.qingfeng.proto.MapVauleObject&gt; mapObject = 7;</code>
  181. */
  182. boolean containsMapObject(
  183. java.lang.String key);
  184. /**
  185. * Use {@link #getMapObjectMap()} instead.
  186. */
  187. @java.lang.Deprecated
  188. java.util.Map<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject>
  189. getMapObject();
  190. /**
  191. * <pre>
  192. * 定义复杂的 Map 对象
  193. * </pre>
  194. *
  195. * <code>map&lt;string, .com.qingfeng.proto.MapVauleObject&gt; mapObject = 7;</code>
  196. */
  197. java.util.Map<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject>
  198. getMapObjectMap();
  199. /**
  200. * <pre>
  201. * 定义复杂的 Map 对象
  202. * </pre>
  203. *
  204. * <code>map&lt;string, .com.qingfeng.proto.MapVauleObject&gt; mapObject = 7;</code>
  205. */
  206. /* nullable */
  207. com.qingfeng.proto.UserProto.MapVauleObject getMapObjectOrDefault(
  208. java.lang.String key,
  209. /* nullable */
  210. com.qingfeng.proto.UserProto.MapVauleObject defaultValue);
  211. /**
  212. * <pre>
  213. * 定义复杂的 Map 对象
  214. * </pre>
  215. *
  216. * <code>map&lt;string, .com.qingfeng.proto.MapVauleObject&gt; mapObject = 7;</code>
  217. */
  218. com.qingfeng.proto.UserProto.MapVauleObject getMapObjectOrThrow(
  219. java.lang.String key);
  220. }
  221. /**
  222. * <pre>
  223. *创建一个 User 对象
  224. * </pre>
  225. *
  226. * Protobuf type {@code com.qingfeng.proto.User}
  227. */
  228. public static final class User extends
  229. com.google.protobuf.GeneratedMessageV3 implements
  230. // @@protoc_insertion_point(message_implements:com.qingfeng.proto.User)
  231. UserOrBuilder {
  232. private static final long serialVersionUID = 0L;
  233. // Use User.newBuilder() to construct.
  234. private User(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
  235. super(builder);
  236. }
  237. private User() {
  238. code_ = "";
  239. name_ = "";
  240. strList_ = com.google.protobuf.LazyStringArrayList.EMPTY;
  241. }
  242. @java.lang.Override
  243. @SuppressWarnings({"unused"})
  244. protected java.lang.Object newInstance(
  245. UnusedPrivateParameter unused) {
  246. return new User();
  247. }
  248. @java.lang.Override
  249. public final com.google.protobuf.UnknownFieldSet
  250. getUnknownFields() {
  251. return this.unknownFields;
  252. }
  253. private User(
  254. com.google.protobuf.CodedInputStream input,
  255. com.google.protobuf.ExtensionRegistryLite extensionRegistry)
  256. throws com.google.protobuf.InvalidProtocolBufferException {
  257. this();
  258. if (extensionRegistry == null) {
  259. throw new java.lang.NullPointerException();
  260. }
  261. int mutable_bitField0_ = 0;
  262. com.google.protobuf.UnknownFieldSet.Builder unknownFields =
  263. com.google.protobuf.UnknownFieldSet.newBuilder();
  264. try {
  265. boolean done = false;
  266. while (!done) {
  267. int tag = input.readTag();
  268. switch (tag) {
  269. case 0:
  270. done = true;
  271. break;
  272. case 8: {
  273. id_ = input.readInt32();
  274. break;
  275. }
  276. case 18: {
  277. java.lang.String s = input.readStringRequireUtf8();
  278. code_ = s;
  279. break;
  280. }
  281. case 26: {
  282. java.lang.String s = input.readStringRequireUtf8();
  283. name_ = s;
  284. break;
  285. }
  286. case 34: {
  287. com.qingfeng.proto.UserProto.NickName.Builder subBuilder = null;
  288. if (nickName_ != null) {
  289. subBuilder = nickName_.toBuilder();
  290. }
  291. nickName_ = input.readMessage(com.qingfeng.proto.UserProto.NickName.parser(), extensionRegistry);
  292. if (subBuilder != null) {
  293. subBuilder.mergeFrom(nickName_);
  294. nickName_ = subBuilder.buildPartial();
  295. }
  296. break;
  297. }
  298. case 42: {
  299. java.lang.String s = input.readStringRequireUtf8();
  300. if (!((mutable_bitField0_ & 0x00000001) != 0)) {
  301. strList_ = new com.google.protobuf.LazyStringArrayList();
  302. mutable_bitField0_ |= 0x00000001;
  303. }
  304. strList_.add(s);
  305. break;
  306. }
  307. case 50: {
  308. if (!((mutable_bitField0_ & 0x00000002) != 0)) {
  309. map_ = com.google.protobuf.MapField.newMapField(
  310. MapDefaultEntryHolder.defaultEntry);
  311. mutable_bitField0_ |= 0x00000002;
  312. }
  313. com.google.protobuf.MapEntry<java.lang.String, java.lang.String>
  314. map__ = input.readMessage(
  315. MapDefaultEntryHolder.defaultEntry.getParserForType(), extensionRegistry);
  316. map_.getMutableMap().put(
  317. map__.getKey(), map__.getValue());
  318. break;
  319. }
  320. case 58: {
  321. if (!((mutable_bitField0_ & 0x00000004) != 0)) {
  322. mapObject_ = com.google.protobuf.MapField.newMapField(
  323. MapObjectDefaultEntryHolder.defaultEntry);
  324. mutable_bitField0_ |= 0x00000004;
  325. }
  326. com.google.protobuf.MapEntry<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject>
  327. mapObject__ = input.readMessage(
  328. MapObjectDefaultEntryHolder.defaultEntry.getParserForType(), extensionRegistry);
  329. mapObject_.getMutableMap().put(
  330. mapObject__.getKey(), mapObject__.getValue());
  331. break;
  332. }
  333. default: {
  334. if (!parseUnknownField(
  335. input, unknownFields, extensionRegistry, tag)) {
  336. done = true;
  337. }
  338. break;
  339. }
  340. }
  341. }
  342. } catch (com.google.protobuf.InvalidProtocolBufferException e) {
  343. throw e.setUnfinishedMessage(this);
  344. } catch (com.google.protobuf.UninitializedMessageException e) {
  345. throw e.asInvalidProtocolBufferException().setUnfinishedMessage(this);
  346. } catch (java.io.IOException e) {
  347. throw new com.google.protobuf.InvalidProtocolBufferException(
  348. e).setUnfinishedMessage(this);
  349. } finally {
  350. if (((mutable_bitField0_ & 0x00000001) != 0)) {
  351. strList_ = strList_.getUnmodifiableView();
  352. }
  353. this.unknownFields = unknownFields.build();
  354. makeExtensionsImmutable();
  355. }
  356. }
  357. public static final com.google.protobuf.Descriptors.Descriptor
  358. getDescriptor() {
  359. return com.qingfeng.proto.UserProto.internal_static_com_qingfeng_proto_User_descriptor;
  360. }
  361. @SuppressWarnings({"rawtypes"})
  362. @java.lang.Override
  363. protected com.google.protobuf.MapField internalGetMapField(
  364. int number) {
  365. switch (number) {
  366. case 6:
  367. return internalGetMap();
  368. case 7:
  369. return internalGetMapObject();
  370. default:
  371. throw new RuntimeException(
  372. "Invalid map field number: " + number);
  373. }
  374. }
  375. @java.lang.Override
  376. protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
  377. internalGetFieldAccessorTable() {
  378. return com.qingfeng.proto.UserProto.internal_static_com_qingfeng_proto_User_fieldAccessorTable
  379. .ensureFieldAccessorsInitialized(
  380. com.qingfeng.proto.UserProto.User.class, com.qingfeng.proto.UserProto.User.Builder.class);
  381. }
  382. public static final int ID_FIELD_NUMBER = 1;
  383. private int id_;
  384. /**
  385. * <pre>
  386. *自身属性
  387. * </pre>
  388. *
  389. * <code>int32 id = 1;</code>
  390. * @return The id.
  391. */
  392. @java.lang.Override
  393. public int getId() {
  394. return id_;
  395. }
  396. public static final int CODE_FIELD_NUMBER = 2;
  397. private volatile java.lang.Object code_;
  398. /**
  399. * <code>string code = 2;</code>
  400. * @return The code.
  401. */
  402. @java.lang.Override
  403. public java.lang.String getCode() {
  404. java.lang.Object ref = code_;
  405. if (ref instanceof java.lang.String) {
  406. return (java.lang.String) ref;
  407. } else {
  408. com.google.protobuf.ByteString bs =
  409. (com.google.protobuf.ByteString) ref;
  410. java.lang.String s = bs.toStringUtf8();
  411. code_ = s;
  412. return s;
  413. }
  414. }
  415. /**
  416. * <code>string code = 2;</code>
  417. * @return The bytes for code.
  418. */
  419. @java.lang.Override
  420. public com.google.protobuf.ByteString
  421. getCodeBytes() {
  422. java.lang.Object ref = code_;
  423. if (ref instanceof java.lang.String) {
  424. com.google.protobuf.ByteString b =
  425. com.google.protobuf.ByteString.copyFromUtf8(
  426. (java.lang.String) ref);
  427. code_ = b;
  428. return b;
  429. } else {
  430. return (com.google.protobuf.ByteString) ref;
  431. }
  432. }
  433. public static final int NAME_FIELD_NUMBER = 3;
  434. private volatile java.lang.Object name_;
  435. /**
  436. * <code>string name = 3;</code>
  437. * @return The name.
  438. */
  439. @java.lang.Override
  440. public java.lang.String getName() {
  441. java.lang.Object ref = name_;
  442. if (ref instanceof java.lang.String) {
  443. return (java.lang.String) ref;
  444. } else {
  445. com.google.protobuf.ByteString bs =
  446. (com.google.protobuf.ByteString) ref;
  447. java.lang.String s = bs.toStringUtf8();
  448. name_ = s;
  449. return s;
  450. }
  451. }
  452. /**
  453. * <code>string name = 3;</code>
  454. * @return The bytes for name.
  455. */
  456. @java.lang.Override
  457. public com.google.protobuf.ByteString
  458. getNameBytes() {
  459. java.lang.Object ref = name_;
  460. if (ref instanceof java.lang.String) {
  461. com.google.protobuf.ByteString b =
  462. com.google.protobuf.ByteString.copyFromUtf8(
  463. (java.lang.String) ref);
  464. name_ = b;
  465. return b;
  466. } else {
  467. return (com.google.protobuf.ByteString) ref;
  468. }
  469. }
  470. public static final int NICKNAME_FIELD_NUMBER = 4;
  471. private com.qingfeng.proto.UserProto.NickName nickName_;
  472. /**
  473. * <pre>
  474. * 对象
  475. * </pre>
  476. *
  477. * <code>.com.qingfeng.proto.NickName nickName = 4;</code>
  478. * @return Whether the nickName field is set.
  479. */
  480. @java.lang.Override
  481. public boolean hasNickName() {
  482. return nickName_ != null;
  483. }
  484. /**
  485. * <pre>
  486. * 对象
  487. * </pre>
  488. *
  489. * <code>.com.qingfeng.proto.NickName nickName = 4;</code>
  490. * @return The nickName.
  491. */
  492. @java.lang.Override
  493. public com.qingfeng.proto.UserProto.NickName getNickName() {
  494. return nickName_ == null ? com.qingfeng.proto.UserProto.NickName.getDefaultInstance() : nickName_;
  495. }
  496. /**
  497. * <pre>
  498. * 对象
  499. * </pre>
  500. *
  501. * <code>.com.qingfeng.proto.NickName nickName = 4;</code>
  502. */
  503. @java.lang.Override
  504. public com.qingfeng.proto.UserProto.NickNameOrBuilder getNickNameOrBuilder() {
  505. return getNickName();
  506. }
  507. public static final int STRLIST_FIELD_NUMBER = 5;
  508. private com.google.protobuf.LazyStringList strList_;
  509. /**
  510. * <pre>
  511. *list 引用类型
  512. * </pre>
  513. *
  514. * <code>repeated string strList = 5;</code>
  515. * @return A list containing the strList.
  516. */
  517. public com.google.protobuf.ProtocolStringList
  518. getStrListList() {
  519. return strList_;
  520. }
  521. /**
  522. * <pre>
  523. *list 引用类型
  524. * </pre>
  525. *
  526. * <code>repeated string strList = 5;</code>
  527. * @return The count of strList.
  528. */
  529. public int getStrListCount() {
  530. return strList_.size();
  531. }
  532. /**
  533. * <pre>
  534. *list 引用类型
  535. * </pre>
  536. *
  537. * <code>repeated string strList = 5;</code>
  538. * @param index The index of the element to return.
  539. * @return The strList at the given index.
  540. */
  541. public java.lang.String getStrList(int index) {
  542. return strList_.get(index);
  543. }
  544. /**
  545. * <pre>
  546. *list 引用类型
  547. * </pre>
  548. *
  549. * <code>repeated string strList = 5;</code>
  550. * @param index The index of the value to return.
  551. * @return The bytes of the strList at the given index.
  552. */
  553. public com.google.protobuf.ByteString
  554. getStrListBytes(int index) {
  555. return strList_.getByteString(index);
  556. }
  557. public static final int MAP_FIELD_NUMBER = 6;
  558. private static final class MapDefaultEntryHolder {
  559. static final com.google.protobuf.MapEntry<
  560. java.lang.String, java.lang.String> defaultEntry =
  561. com.google.protobuf.MapEntry
  562. .<java.lang.String, java.lang.String>newDefaultInstance(
  563. com.qingfeng.proto.UserProto.internal_static_com_qingfeng_proto_User_MapEntry_descriptor,
  564. com.google.protobuf.WireFormat.FieldType.STRING,
  565. "",
  566. com.google.protobuf.WireFormat.FieldType.STRING,
  567. "");
  568. }
  569. private com.google.protobuf.MapField<
  570. java.lang.String, java.lang.String> map_;
  571. private com.google.protobuf.MapField<java.lang.String, java.lang.String>
  572. internalGetMap() {
  573. if (map_ == null) {
  574. return com.google.protobuf.MapField.emptyMapField(
  575. MapDefaultEntryHolder.defaultEntry);
  576. }
  577. return map_;
  578. }
  579. public int getMapCount() {
  580. return internalGetMap().getMap().size();
  581. }
  582. /**
  583. * <pre>
  584. * 定义简单的 Map string
  585. * </pre>
  586. *
  587. * <code>map&lt;string, string&gt; map = 6;</code>
  588. */
  589. @java.lang.Override
  590. public boolean containsMap(
  591. java.lang.String key) {
  592. if (key == null) { throw new NullPointerException("map key"); }
  593. return internalGetMap().getMap().containsKey(key);
  594. }
  595. /**
  596. * Use {@link #getMapMap()} instead.
  597. */
  598. @java.lang.Override
  599. @java.lang.Deprecated
  600. public java.util.Map<java.lang.String, java.lang.String> getMap() {
  601. return getMapMap();
  602. }
  603. /**
  604. * <pre>
  605. * 定义简单的 Map string
  606. * </pre>
  607. *
  608. * <code>map&lt;string, string&gt; map = 6;</code>
  609. */
  610. @java.lang.Override
  611. public java.util.Map<java.lang.String, java.lang.String> getMapMap() {
  612. return internalGetMap().getMap();
  613. }
  614. /**
  615. * <pre>
  616. * 定义简单的 Map string
  617. * </pre>
  618. *
  619. * <code>map&lt;string, string&gt; map = 6;</code>
  620. */
  621. @java.lang.Override
  622. public java.lang.String getMapOrDefault(
  623. java.lang.String key,
  624. java.lang.String defaultValue) {
  625. if (key == null) { throw new NullPointerException("map key"); }
  626. java.util.Map<java.lang.String, java.lang.String> map =
  627. internalGetMap().getMap();
  628. return map.containsKey(key) ? map.get(key) : defaultValue;
  629. }
  630. /**
  631. * <pre>
  632. * 定义简单的 Map string
  633. * </pre>
  634. *
  635. * <code>map&lt;string, string&gt; map = 6;</code>
  636. */
  637. @java.lang.Override
  638. public java.lang.String getMapOrThrow(
  639. java.lang.String key) {
  640. if (key == null) { throw new NullPointerException("map key"); }
  641. java.util.Map<java.lang.String, java.lang.String> map =
  642. internalGetMap().getMap();
  643. if (!map.containsKey(key)) {
  644. throw new java.lang.IllegalArgumentException();
  645. }
  646. return map.get(key);
  647. }
  648. public static final int MAPOBJECT_FIELD_NUMBER = 7;
  649. private static final class MapObjectDefaultEntryHolder {
  650. static final com.google.protobuf.MapEntry<
  651. java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject> defaultEntry =
  652. com.google.protobuf.MapEntry
  653. .<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject>newDefaultInstance(
  654. com.qingfeng.proto.UserProto.internal_static_com_qingfeng_proto_User_MapObjectEntry_descriptor,
  655. com.google.protobuf.WireFormat.FieldType.STRING,
  656. "",
  657. com.google.protobuf.WireFormat.FieldType.MESSAGE,
  658. com.qingfeng.proto.UserProto.MapVauleObject.getDefaultInstance());
  659. }
  660. private com.google.protobuf.MapField<
  661. java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject> mapObject_;
  662. private com.google.protobuf.MapField<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject>
  663. internalGetMapObject() {
  664. if (mapObject_ == null) {
  665. return com.google.protobuf.MapField.emptyMapField(
  666. MapObjectDefaultEntryHolder.defaultEntry);
  667. }
  668. return mapObject_;
  669. }
  670. public int getMapObjectCount() {
  671. return internalGetMapObject().getMap().size();
  672. }
  673. /**
  674. * <pre>
  675. * 定义复杂的 Map 对象
  676. * </pre>
  677. *
  678. * <code>map&lt;string, .com.qingfeng.proto.MapVauleObject&gt; mapObject = 7;</code>
  679. */
  680. @java.lang.Override
  681. public boolean containsMapObject(
  682. java.lang.String key) {
  683. if (key == null) { throw new NullPointerException("map key"); }
  684. return internalGetMapObject().getMap().containsKey(key);
  685. }
  686. /**
  687. * Use {@link #getMapObjectMap()} instead.
  688. */
  689. @java.lang.Override
  690. @java.lang.Deprecated
  691. public java.util.Map<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject> getMapObject() {
  692. return getMapObjectMap();
  693. }
  694. /**
  695. * <pre>
  696. * 定义复杂的 Map 对象
  697. * </pre>
  698. *
  699. * <code>map&lt;string, .com.qingfeng.proto.MapVauleObject&gt; mapObject = 7;</code>
  700. */
  701. @java.lang.Override
  702. public java.util.Map<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject> getMapObjectMap() {
  703. return internalGetMapObject().getMap();
  704. }
  705. /**
  706. * <pre>
  707. * 定义复杂的 Map 对象
  708. * </pre>
  709. *
  710. * <code>map&lt;string, .com.qingfeng.proto.MapVauleObject&gt; mapObject = 7;</code>
  711. */
  712. @java.lang.Override
  713. public com.qingfeng.proto.UserProto.MapVauleObject getMapObjectOrDefault(
  714. java.lang.String key,
  715. com.qingfeng.proto.UserProto.MapVauleObject defaultValue) {
  716. if (key == null) { throw new NullPointerException("map key"); }
  717. java.util.Map<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject> map =
  718. internalGetMapObject().getMap();
  719. return map.containsKey(key) ? map.get(key) : defaultValue;
  720. }
  721. /**
  722. * <pre>
  723. * 定义复杂的 Map 对象
  724. * </pre>
  725. *
  726. * <code>map&lt;string, .com.qingfeng.proto.MapVauleObject&gt; mapObject = 7;</code>
  727. */
  728. @java.lang.Override
  729. public com.qingfeng.proto.UserProto.MapVauleObject getMapObjectOrThrow(
  730. java.lang.String key) {
  731. if (key == null) { throw new NullPointerException("map key"); }
  732. java.util.Map<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject> map =
  733. internalGetMapObject().getMap();
  734. if (!map.containsKey(key)) {
  735. throw new java.lang.IllegalArgumentException();
  736. }
  737. return map.get(key);
  738. }
  739. private byte memoizedIsInitialized = -1;
  740. @java.lang.Override
  741. public final boolean isInitialized() {
  742. byte isInitialized = memoizedIsInitialized;
  743. if (isInitialized == 1) return true;
  744. if (isInitialized == 0) return false;
  745. memoizedIsInitialized = 1;
  746. return true;
  747. }
  748. @java.lang.Override
  749. public void writeTo(com.google.protobuf.CodedOutputStream output)
  750. throws java.io.IOException {
  751. if (id_ != 0) {
  752. output.writeInt32(1, id_);
  753. }
  754. if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(code_)) {
  755. com.google.protobuf.GeneratedMessageV3.writeString(output, 2, code_);
  756. }
  757. if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) {
  758. com.google.protobuf.GeneratedMessageV3.writeString(output, 3, name_);
  759. }
  760. if (nickName_ != null) {
  761. output.writeMessage(4, getNickName());
  762. }
  763. for (int i = 0; i < strList_.size(); i++) {
  764. com.google.protobuf.GeneratedMessageV3.writeString(output, 5, strList_.getRaw(i));
  765. }
  766. com.google.protobuf.GeneratedMessageV3
  767. .serializeStringMapTo(
  768. output,
  769. internalGetMap(),
  770. MapDefaultEntryHolder.defaultEntry,
  771. 6);
  772. com.google.protobuf.GeneratedMessageV3
  773. .serializeStringMapTo(
  774. output,
  775. internalGetMapObject(),
  776. MapObjectDefaultEntryHolder.defaultEntry,
  777. 7);
  778. unknownFields.writeTo(output);
  779. }
  780. @java.lang.Override
  781. public int getSerializedSize() {
  782. int size = memoizedSize;
  783. if (size != -1) return size;
  784. size = 0;
  785. if (id_ != 0) {
  786. size += com.google.protobuf.CodedOutputStream
  787. .computeInt32Size(1, id_);
  788. }
  789. if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(code_)) {
  790. size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, code_);
  791. }
  792. if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) {
  793. size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, name_);
  794. }
  795. if (nickName_ != null) {
  796. size += com.google.protobuf.CodedOutputStream
  797. .computeMessageSize(4, getNickName());
  798. }
  799. {
  800. int dataSize = 0;
  801. for (int i = 0; i < strList_.size(); i++) {
  802. dataSize += computeStringSizeNoTag(strList_.getRaw(i));
  803. }
  804. size += dataSize;
  805. size += 1 * getStrListList().size();
  806. }
  807. for (java.util.Map.Entry<java.lang.String, java.lang.String> entry
  808. : internalGetMap().getMap().entrySet()) {
  809. com.google.protobuf.MapEntry<java.lang.String, java.lang.String>
  810. map__ = MapDefaultEntryHolder.defaultEntry.newBuilderForType()
  811. .setKey(entry.getKey())
  812. .setValue(entry.getValue())
  813. .build();
  814. size += com.google.protobuf.CodedOutputStream
  815. .computeMessageSize(6, map__);
  816. }
  817. for (java.util.Map.Entry<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject> entry
  818. : internalGetMapObject().getMap().entrySet()) {
  819. com.google.protobuf.MapEntry<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject>
  820. mapObject__ = MapObjectDefaultEntryHolder.defaultEntry.newBuilderForType()
  821. .setKey(entry.getKey())
  822. .setValue(entry.getValue())
  823. .build();
  824. size += com.google.protobuf.CodedOutputStream
  825. .computeMessageSize(7, mapObject__);
  826. }
  827. size += unknownFields.getSerializedSize();
  828. memoizedSize = size;
  829. return size;
  830. }
  831. @java.lang.Override
  832. public boolean equals(final java.lang.Object obj) {
  833. if (obj == this) {
  834. return true;
  835. }
  836. if (!(obj instanceof com.qingfeng.proto.UserProto.User)) {
  837. return super.equals(obj);
  838. }
  839. com.qingfeng.proto.UserProto.User other = (com.qingfeng.proto.UserProto.User) obj;
  840. if (getId()
  841. != other.getId()) return false;
  842. if (!getCode()
  843. .equals(other.getCode())) return false;
  844. if (!getName()
  845. .equals(other.getName())) return false;
  846. if (hasNickName() != other.hasNickName()) return false;
  847. if (hasNickName()) {
  848. if (!getNickName()
  849. .equals(other.getNickName())) return false;
  850. }
  851. if (!getStrListList()
  852. .equals(other.getStrListList())) return false;
  853. if (!internalGetMap().equals(
  854. other.internalGetMap())) return false;
  855. if (!internalGetMapObject().equals(
  856. other.internalGetMapObject())) return false;
  857. if (!unknownFields.equals(other.unknownFields)) return false;
  858. return true;
  859. }
  860. @java.lang.Override
  861. public int hashCode() {
  862. if (memoizedHashCode != 0) {
  863. return memoizedHashCode;
  864. }
  865. int hash = 41;
  866. hash = (19 * hash) + getDescriptor().hashCode();
  867. hash = (37 * hash) + ID_FIELD_NUMBER;
  868. hash = (53 * hash) + getId();
  869. hash = (37 * hash) + CODE_FIELD_NUMBER;
  870. hash = (53 * hash) + getCode().hashCode();
  871. hash = (37 * hash) + NAME_FIELD_NUMBER;
  872. hash = (53 * hash) + getName().hashCode();
  873. if (hasNickName()) {
  874. hash = (37 * hash) + NICKNAME_FIELD_NUMBER;
  875. hash = (53 * hash) + getNickName().hashCode();
  876. }
  877. if (getStrListCount() > 0) {
  878. hash = (37 * hash) + STRLIST_FIELD_NUMBER;
  879. hash = (53 * hash) + getStrListList().hashCode();
  880. }
  881. if (!internalGetMap().getMap().isEmpty()) {
  882. hash = (37 * hash) + MAP_FIELD_NUMBER;
  883. hash = (53 * hash) + internalGetMap().hashCode();
  884. }
  885. if (!internalGetMapObject().getMap().isEmpty()) {
  886. hash = (37 * hash) + MAPOBJECT_FIELD_NUMBER;
  887. hash = (53 * hash) + internalGetMapObject().hashCode();
  888. }
  889. hash = (29 * hash) + unknownFields.hashCode();
  890. memoizedHashCode = hash;
  891. return hash;
  892. }
  893. public static com.qingfeng.proto.UserProto.User parseFrom(
  894. java.nio.ByteBuffer data)
  895. throws com.google.protobuf.InvalidProtocolBufferException {
  896. return PARSER.parseFrom(data);
  897. }
  898. public static com.qingfeng.proto.UserProto.User parseFrom(
  899. java.nio.ByteBuffer data,
  900. com.google.protobuf.ExtensionRegistryLite extensionRegistry)
  901. throws com.google.protobuf.InvalidProtocolBufferException {
  902. return PARSER.parseFrom(data, extensionRegistry);
  903. }
  904. public static com.qingfeng.proto.UserProto.User parseFrom(
  905. com.google.protobuf.ByteString data)
  906. throws com.google.protobuf.InvalidProtocolBufferException {
  907. return PARSER.parseFrom(data);
  908. }
  909. public static com.qingfeng.proto.UserProto.User parseFrom(
  910. com.google.protobuf.ByteString data,
  911. com.google.protobuf.ExtensionRegistryLite extensionRegistry)
  912. throws com.google.protobuf.InvalidProtocolBufferException {
  913. return PARSER.parseFrom(data, extensionRegistry);
  914. }
  915. public static com.qingfeng.proto.UserProto.User parseFrom(byte[] data)
  916. throws com.google.protobuf.InvalidProtocolBufferException {
  917. return PARSER.parseFrom(data);
  918. }
  919. public static com.qingfeng.proto.UserProto.User parseFrom(
  920. byte[] data,
  921. com.google.protobuf.ExtensionRegistryLite extensionRegistry)
  922. throws com.google.protobuf.InvalidProtocolBufferException {
  923. return PARSER.parseFrom(data, extensionRegistry);
  924. }
  925. public static com.qingfeng.proto.UserProto.User parseFrom(java.io.InputStream input)
  926. throws java.io.IOException {
  927. return com.google.protobuf.GeneratedMessageV3
  928. .parseWithIOException(PARSER, input);
  929. }
  930. public static com.qingfeng.proto.UserProto.User parseFrom(
  931. java.io.InputStream input,
  932. com.google.protobuf.ExtensionRegistryLite extensionRegistry)
  933. throws java.io.IOException {
  934. return com.google.protobuf.GeneratedMessageV3
  935. .parseWithIOException(PARSER, input, extensionRegistry);
  936. }
  937. public static com.qingfeng.proto.UserProto.User parseDelimitedFrom(java.io.InputStream input)
  938. throws java.io.IOException {
  939. return com.google.protobuf.GeneratedMessageV3
  940. .parseDelimitedWithIOException(PARSER, input);
  941. }
  942. public static com.qingfeng.proto.UserProto.User parseDelimitedFrom(
  943. java.io.InputStream input,
  944. com.google.protobuf.ExtensionRegistryLite extensionRegistry)
  945. throws java.io.IOException {
  946. return com.google.protobuf.GeneratedMessageV3
  947. .parseDelimitedWithIOException(PARSER, input, extensionRegistry);
  948. }
  949. public static com.qingfeng.proto.UserProto.User parseFrom(
  950. com.google.protobuf.CodedInputStream input)
  951. throws java.io.IOException {
  952. return com.google.protobuf.GeneratedMessageV3
  953. .parseWithIOException(PARSER, input);
  954. }
  955. public static com.qingfeng.proto.UserProto.User parseFrom(
  956. com.google.protobuf.CodedInputStream input,
  957. com.google.protobuf.ExtensionRegistryLite extensionRegistry)
  958. throws java.io.IOException {
  959. return com.google.protobuf.GeneratedMessageV3
  960. .parseWithIOException(PARSER, input, extensionRegistry);
  961. }
  962. @java.lang.Override
  963. public Builder newBuilderForType() { return newBuilder(); }
  964. public static Builder newBuilder() {
  965. return DEFAULT_INSTANCE.toBuilder();
  966. }
  967. public static Builder newBuilder(com.qingfeng.proto.UserProto.User prototype) {
  968. return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
  969. }
  970. @java.lang.Override
  971. public Builder toBuilder() {
  972. return this == DEFAULT_INSTANCE
  973. ? new Builder() : new Builder().mergeFrom(this);
  974. }
  975. @java.lang.Override
  976. protected Builder newBuilderForType(
  977. com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
  978. Builder builder = new Builder(parent);
  979. return builder;
  980. }
  981. /**
  982. * <pre>
  983. *创建一个 User 对象
  984. * </pre>
  985. *
  986. * Protobuf type {@code com.qingfeng.proto.User}
  987. */
  988. public static final class Builder extends
  989. com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
  990. // @@protoc_insertion_point(builder_implements:com.qingfeng.proto.User)
  991. com.qingfeng.proto.UserProto.UserOrBuilder {
  992. public static final com.google.protobuf.Descriptors.Descriptor
  993. getDescriptor() {
  994. return com.qingfeng.proto.UserProto.internal_static_com_qingfeng_proto_User_descriptor;
  995. }
  996. @SuppressWarnings({"rawtypes"})
  997. protected com.google.protobuf.MapField internalGetMapField(
  998. int number) {
  999. switch (number) {
  1000. case 6:
  1001. return internalGetMap();
  1002. case 7:
  1003. return internalGetMapObject();
  1004. default:
  1005. throw new RuntimeException(
  1006. "Invalid map field number: " + number);
  1007. }
  1008. }
  1009. @SuppressWarnings({"rawtypes"})
  1010. protected com.google.protobuf.MapField internalGetMutableMapField(
  1011. int number) {
  1012. switch (number) {
  1013. case 6:
  1014. return internalGetMutableMap();
  1015. case 7:
  1016. return internalGetMutableMapObject();
  1017. default:
  1018. throw new RuntimeException(
  1019. "Invalid map field number: " + number);
  1020. }
  1021. }
  1022. @java.lang.Override
  1023. protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
  1024. internalGetFieldAccessorTable() {
  1025. return com.qingfeng.proto.UserProto.internal_static_com_qingfeng_proto_User_fieldAccessorTable
  1026. .ensureFieldAccessorsInitialized(
  1027. com.qingfeng.proto.UserProto.User.class, com.qingfeng.proto.UserProto.User.Builder.class);
  1028. }
  1029. // Construct using com.qingfeng.proto.UserProto.User.newBuilder()
  1030. private Builder() {
  1031. maybeForceBuilderInitialization();
  1032. }
  1033. private Builder(
  1034. com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
  1035. super(parent);
  1036. maybeForceBuilderInitialization();
  1037. }
  1038. private void maybeForceBuilderInitialization() {
  1039. if (com.google.protobuf.GeneratedMessageV3
  1040. .alwaysUseFieldBuilders) {
  1041. }
  1042. }
  1043. @java.lang.Override
  1044. public Builder clear() {
  1045. super.clear();
  1046. id_ = 0;
  1047. code_ = "";
  1048. name_ = "";
  1049. if (nickNameBuilder_ == null) {
  1050. nickName_ = null;
  1051. } else {
  1052. nickName_ = null;
  1053. nickNameBuilder_ = null;
  1054. }
  1055. strList_ = com.google.protobuf.LazyStringArrayList.EMPTY;
  1056. bitField0_ = (bitField0_ & ~0x00000001);
  1057. internalGetMutableMap().clear();
  1058. internalGetMutableMapObject().clear();
  1059. return this;
  1060. }
  1061. @java.lang.Override
  1062. public com.google.protobuf.Descriptors.Descriptor
  1063. getDescriptorForType() {
  1064. return com.qingfeng.proto.UserProto.internal_static_com_qingfeng_proto_User_descriptor;
  1065. }
  1066. @java.lang.Override
  1067. public com.qingfeng.proto.UserProto.User getDefaultInstanceForType() {
  1068. return com.qingfeng.proto.UserProto.User.getDefaultInstance();
  1069. }
  1070. @java.lang.Override
  1071. public com.qingfeng.proto.UserProto.User build() {
  1072. com.qingfeng.proto.UserProto.User result = buildPartial();
  1073. if (!result.isInitialized()) {
  1074. throw newUninitializedMessageException(result);
  1075. }
  1076. return result;
  1077. }
  1078. @java.lang.Override
  1079. public com.qingfeng.proto.UserProto.User buildPartial() {
  1080. com.qingfeng.proto.UserProto.User result = new com.qingfeng.proto.UserProto.User(this);
  1081. int from_bitField0_ = bitField0_;
  1082. result.id_ = id_;
  1083. result.code_ = code_;
  1084. result.name_ = name_;
  1085. if (nickNameBuilder_ == null) {
  1086. result.nickName_ = nickName_;
  1087. } else {
  1088. result.nickName_ = nickNameBuilder_.build();
  1089. }
  1090. if (((bitField0_ & 0x00000001) != 0)) {
  1091. strList_ = strList_.getUnmodifiableView();
  1092. bitField0_ = (bitField0_ & ~0x00000001);
  1093. }
  1094. result.strList_ = strList_;
  1095. result.map_ = internalGetMap();
  1096. result.map_.makeImmutable();
  1097. result.mapObject_ = internalGetMapObject();
  1098. result.mapObject_.makeImmutable();
  1099. onBuilt();
  1100. return result;
  1101. }
  1102. @java.lang.Override
  1103. public Builder clone() {
  1104. return super.clone();
  1105. }
  1106. @java.lang.Override
  1107. public Builder setField(
  1108. com.google.protobuf.Descriptors.FieldDescriptor field,
  1109. java.lang.Object value) {
  1110. return super.setField(field, value);
  1111. }
  1112. @java.lang.Override
  1113. public Builder clearField(
  1114. com.google.protobuf.Descriptors.FieldDescriptor field) {
  1115. return super.clearField(field);
  1116. }
  1117. @java.lang.Override
  1118. public Builder clearOneof(
  1119. com.google.protobuf.Descriptors.OneofDescriptor oneof) {
  1120. return super.clearOneof(oneof);
  1121. }
  1122. @java.lang.Override
  1123. public Builder setRepeatedField(
  1124. com.google.protobuf.Descriptors.FieldDescriptor field,
  1125. int index, java.lang.Object value) {
  1126. return super.setRepeatedField(field, index, value);
  1127. }
  1128. @java.lang.Override
  1129. public Builder addRepeatedField(
  1130. com.google.protobuf.Descriptors.FieldDescriptor field,
  1131. java.lang.Object value) {
  1132. return super.addRepeatedField(field, value);
  1133. }
  1134. @java.lang.Override
  1135. public Builder mergeFrom(com.google.protobuf.Message other) {
  1136. if (other instanceof com.qingfeng.proto.UserProto.User) {
  1137. return mergeFrom((com.qingfeng.proto.UserProto.User)other);
  1138. } else {
  1139. super.mergeFrom(other);
  1140. return this;
  1141. }
  1142. }
  1143. public Builder mergeFrom(com.qingfeng.proto.UserProto.User other) {
  1144. if (other == com.qingfeng.proto.UserProto.User.getDefaultInstance()) return this;
  1145. if (other.getId() != 0) {
  1146. setId(other.getId());
  1147. }
  1148. if (!other.getCode().isEmpty()) {
  1149. code_ = other.code_;
  1150. onChanged();
  1151. }
  1152. if (!other.getName().isEmpty()) {
  1153. name_ = other.name_;
  1154. onChanged();
  1155. }
  1156. if (other.hasNickName()) {
  1157. mergeNickName(other.getNickName());
  1158. }
  1159. if (!other.strList_.isEmpty()) {
  1160. if (strList_.isEmpty()) {
  1161. strList_ = other.strList_;
  1162. bitField0_ = (bitField0_ & ~0x00000001);
  1163. } else {
  1164. ensureStrListIsMutable();
  1165. strList_.addAll(other.strList_);
  1166. }
  1167. onChanged();
  1168. }
  1169. internalGetMutableMap().mergeFrom(
  1170. other.internalGetMap());
  1171. internalGetMutableMapObject().mergeFrom(
  1172. other.internalGetMapObject());
  1173. this.mergeUnknownFields(other.unknownFields);
  1174. onChanged();
  1175. return this;
  1176. }
  1177. @java.lang.Override
  1178. public final boolean isInitialized() {
  1179. return true;
  1180. }
  1181. @java.lang.Override
  1182. public Builder mergeFrom(
  1183. com.google.protobuf.CodedInputStream input,
  1184. com.google.protobuf.ExtensionRegistryLite extensionRegistry)
  1185. throws java.io.IOException {
  1186. com.qingfeng.proto.UserProto.User parsedMessage = null;
  1187. try {
  1188. parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
  1189. } catch (com.google.protobuf.InvalidProtocolBufferException e) {
  1190. parsedMessage = (com.qingfeng.proto.UserProto.User) e.getUnfinishedMessage();
  1191. throw e.unwrapIOException();
  1192. } finally {
  1193. if (parsedMessage != null) {
  1194. mergeFrom(parsedMessage);
  1195. }
  1196. }
  1197. return this;
  1198. }
  1199. private int bitField0_;
  1200. private int id_ ;
  1201. /**
  1202. * <pre>
  1203. *自身属性
  1204. * </pre>
  1205. *
  1206. * <code>int32 id = 1;</code>
  1207. * @return The id.
  1208. */
  1209. @java.lang.Override
  1210. public int getId() {
  1211. return id_;
  1212. }
  1213. /**
  1214. * <pre>
  1215. *自身属性
  1216. * </pre>
  1217. *
  1218. * <code>int32 id = 1;</code>
  1219. * @param value The id to set.
  1220. * @return This builder for chaining.
  1221. */
  1222. public Builder setId(int value) {
  1223. id_ = value;
  1224. onChanged();
  1225. return this;
  1226. }
  1227. /**
  1228. * <pre>
  1229. *自身属性
  1230. * </pre>
  1231. *
  1232. * <code>int32 id = 1;</code>
  1233. * @return This builder for chaining.
  1234. */
  1235. public Builder clearId() {
  1236. id_ = 0;
  1237. onChanged();
  1238. return this;
  1239. }
  1240. private java.lang.Object code_ = "";
  1241. /**
  1242. * <code>string code = 2;</code>
  1243. * @return The code.
  1244. */
  1245. public java.lang.String getCode() {
  1246. java.lang.Object ref = code_;
  1247. if (!(ref instanceof java.lang.String)) {
  1248. com.google.protobuf.ByteString bs =
  1249. (com.google.protobuf.ByteString) ref;
  1250. java.lang.String s = bs.toStringUtf8();
  1251. code_ = s;
  1252. return s;
  1253. } else {
  1254. return (java.lang.String) ref;
  1255. }
  1256. }
  1257. /**
  1258. * <code>string code = 2;</code>
  1259. * @return The bytes for code.
  1260. */
  1261. public com.google.protobuf.ByteString
  1262. getCodeBytes() {
  1263. java.lang.Object ref = code_;
  1264. if (ref instanceof String) {
  1265. com.google.protobuf.ByteString b =
  1266. com.google.protobuf.ByteString.copyFromUtf8(
  1267. (java.lang.String) ref);
  1268. code_ = b;
  1269. return b;
  1270. } else {
  1271. return (com.google.protobuf.ByteString) ref;
  1272. }
  1273. }
  1274. /**
  1275. * <code>string code = 2;</code>
  1276. * @param value The code to set.
  1277. * @return This builder for chaining.
  1278. */
  1279. public Builder setCode(
  1280. java.lang.String value) {
  1281. if (value == null) {
  1282. throw new NullPointerException();
  1283. }
  1284. code_ = value;
  1285. onChanged();
  1286. return this;
  1287. }
  1288. /**
  1289. * <code>string code = 2;</code>
  1290. * @return This builder for chaining.
  1291. */
  1292. public Builder clearCode() {
  1293. code_ = getDefaultInstance().getCode();
  1294. onChanged();
  1295. return this;
  1296. }
  1297. /**
  1298. * <code>string code = 2;</code>
  1299. * @param value The bytes for code to set.
  1300. * @return This builder for chaining.
  1301. */
  1302. public Builder setCodeBytes(
  1303. com.google.protobuf.ByteString value) {
  1304. if (value == null) {
  1305. throw new NullPointerException();
  1306. }
  1307. checkByteStringIsUtf8(value);
  1308. code_ = value;
  1309. onChanged();
  1310. return this;
  1311. }
  1312. private java.lang.Object name_ = "";
  1313. /**
  1314. * <code>string name = 3;</code>
  1315. * @return The name.
  1316. */
  1317. public java.lang.String getName() {
  1318. java.lang.Object ref = name_;
  1319. if (!(ref instanceof java.lang.String)) {
  1320. com.google.protobuf.ByteString bs =
  1321. (com.google.protobuf.ByteString) ref;
  1322. java.lang.String s = bs.toStringUtf8();
  1323. name_ = s;
  1324. return s;
  1325. } else {
  1326. return (java.lang.String) ref;
  1327. }
  1328. }
  1329. /**
  1330. * <code>string name = 3;</code>
  1331. * @return The bytes for name.
  1332. */
  1333. public com.google.protobuf.ByteString
  1334. getNameBytes() {
  1335. java.lang.Object ref = name_;
  1336. if (ref instanceof String) {
  1337. com.google.protobuf.ByteString b =
  1338. com.google.protobuf.ByteString.copyFromUtf8(
  1339. (java.lang.String) ref);
  1340. name_ = b;
  1341. return b;
  1342. } else {
  1343. return (com.google.protobuf.ByteString) ref;
  1344. }
  1345. }
  1346. /**
  1347. * <code>string name = 3;</code>
  1348. * @param value The name to set.
  1349. * @return This builder for chaining.
  1350. */
  1351. public Builder setName(
  1352. java.lang.String value) {
  1353. if (value == null) {
  1354. throw new NullPointerException();
  1355. }
  1356. name_ = value;
  1357. onChanged();
  1358. return this;
  1359. }
  1360. /**
  1361. * <code>string name = 3;</code>
  1362. * @return This builder for chaining.
  1363. */
  1364. public Builder clearName() {
  1365. name_ = getDefaultInstance().getName();
  1366. onChanged();
  1367. return this;
  1368. }
  1369. /**
  1370. * <code>string name = 3;</code>
  1371. * @param value The bytes for name to set.
  1372. * @return This builder for chaining.
  1373. */
  1374. public Builder setNameBytes(
  1375. com.google.protobuf.ByteString value) {
  1376. if (value == null) {
  1377. throw new NullPointerException();
  1378. }
  1379. checkByteStringIsUtf8(value);
  1380. name_ = value;
  1381. onChanged();
  1382. return this;
  1383. }
  1384. private com.qingfeng.proto.UserProto.NickName nickName_;
  1385. private com.google.protobuf.SingleFieldBuilderV3<
  1386. com.qingfeng.proto.UserProto.NickName, com.qingfeng.proto.UserProto.NickName.Builder, com.qingfeng.proto.UserProto.NickNameOrBuilder> nickNameBuilder_;
  1387. /**
  1388. * <pre>
  1389. * 对象
  1390. * </pre>
  1391. *
  1392. * <code>.com.qingfeng.proto.NickName nickName = 4;</code>
  1393. * @return Whether the nickName field is set.
  1394. */
  1395. public boolean hasNickName() {
  1396. return nickNameBuilder_ != null || nickName_ != null;
  1397. }
  1398. /**
  1399. * <pre>
  1400. * 对象
  1401. * </pre>
  1402. *
  1403. * <code>.com.qingfeng.proto.NickName nickName = 4;</code>
  1404. * @return The nickName.
  1405. */
  1406. public com.qingfeng.proto.UserProto.NickName getNickName() {
  1407. if (nickNameBuilder_ == null) {
  1408. return nickName_ == null ? com.qingfeng.proto.UserProto.NickName.getDefaultInstance() : nickName_;
  1409. } else {
  1410. return nickNameBuilder_.getMessage();
  1411. }
  1412. }
  1413. /**
  1414. * <pre>
  1415. * 对象
  1416. * </pre>
  1417. *
  1418. * <code>.com.qingfeng.proto.NickName nickName = 4;</code>
  1419. */
  1420. public Builder setNickName(com.qingfeng.proto.UserProto.NickName value) {
  1421. if (nickNameBuilder_ == null) {
  1422. if (value == null) {
  1423. throw new NullPointerException();
  1424. }
  1425. nickName_ = value;
  1426. onChanged();
  1427. } else {
  1428. nickNameBuilder_.setMessage(value);
  1429. }
  1430. return this;
  1431. }
  1432. /**
  1433. * <pre>
  1434. * 对象
  1435. * </pre>
  1436. *
  1437. * <code>.com.qingfeng.proto.NickName nickName = 4;</code>
  1438. */
  1439. public Builder setNickName(
  1440. com.qingfeng.proto.UserProto.NickName.Builder builderForValue) {
  1441. if (nickNameBuilder_ == null) {
  1442. nickName_ = builderForValue.build();
  1443. onChanged();
  1444. } else {
  1445. nickNameBuilder_.setMessage(builderForValue.build());
  1446. }
  1447. return this;
  1448. }
  1449. /**
  1450. * <pre>
  1451. * 对象
  1452. * </pre>
  1453. *
  1454. * <code>.com.qingfeng.proto.NickName nickName = 4;</code>
  1455. */
  1456. public Builder mergeNickName(com.qingfeng.proto.UserProto.NickName value) {
  1457. if (nickNameBuilder_ == null) {
  1458. if (nickName_ != null) {
  1459. nickName_ =
  1460. com.qingfeng.proto.UserProto.NickName.newBuilder(nickName_).mergeFrom(value).buildPartial();
  1461. } else {
  1462. nickName_ = value;
  1463. }
  1464. onChanged();
  1465. } else {
  1466. nickNameBuilder_.mergeFrom(value);
  1467. }
  1468. return this;
  1469. }
  1470. /**
  1471. * <pre>
  1472. * 对象
  1473. * </pre>
  1474. *
  1475. * <code>.com.qingfeng.proto.NickName nickName = 4;</code>
  1476. */
  1477. public Builder clearNickName() {
  1478. if (nickNameBuilder_ == null) {
  1479. nickName_ = null;
  1480. onChanged();
  1481. } else {
  1482. nickName_ = null;
  1483. nickNameBuilder_ = null;
  1484. }
  1485. return this;
  1486. }
  1487. /**
  1488. * <pre>
  1489. * 对象
  1490. * </pre>
  1491. *
  1492. * <code>.com.qingfeng.proto.NickName nickName = 4;</code>
  1493. */
  1494. public com.qingfeng.proto.UserProto.NickName.Builder getNickNameBuilder() {
  1495. onChanged();
  1496. return getNickNameFieldBuilder().getBuilder();
  1497. }
  1498. /**
  1499. * <pre>
  1500. * 对象
  1501. * </pre>
  1502. *
  1503. * <code>.com.qingfeng.proto.NickName nickName = 4;</code>
  1504. */
  1505. public com.qingfeng.proto.UserProto.NickNameOrBuilder getNickNameOrBuilder() {
  1506. if (nickNameBuilder_ != null) {
  1507. return nickNameBuilder_.getMessageOrBuilder();
  1508. } else {
  1509. return nickName_ == null ?
  1510. com.qingfeng.proto.UserProto.NickName.getDefaultInstance() : nickName_;
  1511. }
  1512. }
  1513. /**
  1514. * <pre>
  1515. * 对象
  1516. * </pre>
  1517. *
  1518. * <code>.com.qingfeng.proto.NickName nickName = 4;</code>
  1519. */
  1520. private com.google.protobuf.SingleFieldBuilderV3<
  1521. com.qingfeng.proto.UserProto.NickName, com.qingfeng.proto.UserProto.NickName.Builder, com.qingfeng.proto.UserProto.NickNameOrBuilder>
  1522. getNickNameFieldBuilder() {
  1523. if (nickNameBuilder_ == null) {
  1524. nickNameBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
  1525. com.qingfeng.proto.UserProto.NickName, com.qingfeng.proto.UserProto.NickName.Builder, com.qingfeng.proto.UserProto.NickNameOrBuilder>(
  1526. getNickName(),
  1527. getParentForChildren(),
  1528. isClean());
  1529. nickName_ = null;
  1530. }
  1531. return nickNameBuilder_;
  1532. }
  1533. private com.google.protobuf.LazyStringList strList_ = com.google.protobuf.LazyStringArrayList.EMPTY;
  1534. private void ensureStrListIsMutable() {
  1535. if (!((bitField0_ & 0x00000001) != 0)) {
  1536. strList_ = new com.google.protobuf.LazyStringArrayList(strList_);
  1537. bitField0_ |= 0x00000001;
  1538. }
  1539. }
  1540. /**
  1541. * <pre>
  1542. *list 引用类型
  1543. * </pre>
  1544. *
  1545. * <code>repeated string strList = 5;</code>
  1546. * @return A list containing the strList.
  1547. */
  1548. public com.google.protobuf.ProtocolStringList
  1549. getStrListList() {
  1550. return strList_.getUnmodifiableView();
  1551. }
  1552. /**
  1553. * <pre>
  1554. *list 引用类型
  1555. * </pre>
  1556. *
  1557. * <code>repeated string strList = 5;</code>
  1558. * @return The count of strList.
  1559. */
  1560. public int getStrListCount() {
  1561. return strList_.size();
  1562. }
  1563. /**
  1564. * <pre>
  1565. *list 引用类型
  1566. * </pre>
  1567. *
  1568. * <code>repeated string strList = 5;</code>
  1569. * @param index The index of the element to return.
  1570. * @return The strList at the given index.
  1571. */
  1572. public java.lang.String getStrList(int index) {
  1573. return strList_.get(index);
  1574. }
  1575. /**
  1576. * <pre>
  1577. *list 引用类型
  1578. * </pre>
  1579. *
  1580. * <code>repeated string strList = 5;</code>
  1581. * @param index The index of the value to return.
  1582. * @return The bytes of the strList at the given index.
  1583. */
  1584. public com.google.protobuf.ByteString
  1585. getStrListBytes(int index) {
  1586. return strList_.getByteString(index);
  1587. }
  1588. /**
  1589. * <pre>
  1590. *list 引用类型
  1591. * </pre>
  1592. *
  1593. * <code>repeated string strList = 5;</code>
  1594. * @param index The index to set the value at.
  1595. * @param value The strList to set.
  1596. * @return This builder for chaining.
  1597. */
  1598. public Builder setStrList(
  1599. int index, java.lang.String value) {
  1600. if (value == null) {
  1601. throw new NullPointerException();
  1602. }
  1603. ensureStrListIsMutable();
  1604. strList_.set(index, value);
  1605. onChanged();
  1606. return this;
  1607. }
  1608. /**
  1609. * <pre>
  1610. *list 引用类型
  1611. * </pre>
  1612. *
  1613. * <code>repeated string strList = 5;</code>
  1614. * @param value The strList to add.
  1615. * @return This builder for chaining.
  1616. */
  1617. public Builder addStrList(
  1618. java.lang.String value) {
  1619. if (value == null) {
  1620. throw new NullPointerException();
  1621. }
  1622. ensureStrListIsMutable();
  1623. strList_.add(value);
  1624. onChanged();
  1625. return this;
  1626. }
  1627. /**
  1628. * <pre>
  1629. *list 引用类型
  1630. * </pre>
  1631. *
  1632. * <code>repeated string strList = 5;</code>
  1633. * @param values The strList to add.
  1634. * @return This builder for chaining.
  1635. */
  1636. public Builder addAllStrList(
  1637. java.lang.Iterable<java.lang.String> values) {
  1638. ensureStrListIsMutable();
  1639. com.google.protobuf.AbstractMessageLite.Builder.addAll(
  1640. values, strList_);
  1641. onChanged();
  1642. return this;
  1643. }
  1644. /**
  1645. * <pre>
  1646. *list 引用类型
  1647. * </pre>
  1648. *
  1649. * <code>repeated string strList = 5;</code>
  1650. * @return This builder for chaining.
  1651. */
  1652. public Builder clearStrList() {
  1653. strList_ = com.google.protobuf.LazyStringArrayList.EMPTY;
  1654. bitField0_ = (bitField0_ & ~0x00000001);
  1655. onChanged();
  1656. return this;
  1657. }
  1658. /**
  1659. * <pre>
  1660. *list 引用类型
  1661. * </pre>
  1662. *
  1663. * <code>repeated string strList = 5;</code>
  1664. * @param value The bytes of the strList to add.
  1665. * @return This builder for chaining.
  1666. */
  1667. public Builder addStrListBytes(
  1668. com.google.protobuf.ByteString value) {
  1669. if (value == null) {
  1670. throw new NullPointerException();
  1671. }
  1672. checkByteStringIsUtf8(value);
  1673. ensureStrListIsMutable();
  1674. strList_.add(value);
  1675. onChanged();
  1676. return this;
  1677. }
  1678. private com.google.protobuf.MapField<
  1679. java.lang.String, java.lang.String> map_;
  1680. private com.google.protobuf.MapField<java.lang.String, java.lang.String>
  1681. internalGetMap() {
  1682. if (map_ == null) {
  1683. return com.google.protobuf.MapField.emptyMapField(
  1684. MapDefaultEntryHolder.defaultEntry);
  1685. }
  1686. return map_;
  1687. }
  1688. private com.google.protobuf.MapField<java.lang.String, java.lang.String>
  1689. internalGetMutableMap() {
  1690. onChanged();;
  1691. if (map_ == null) {
  1692. map_ = com.google.protobuf.MapField.newMapField(
  1693. MapDefaultEntryHolder.defaultEntry);
  1694. }
  1695. if (!map_.isMutable()) {
  1696. map_ = map_.copy();
  1697. }
  1698. return map_;
  1699. }
  1700. public int getMapCount() {
  1701. return internalGetMap().getMap().size();
  1702. }
  1703. /**
  1704. * <pre>
  1705. * 定义简单的 Map string
  1706. * </pre>
  1707. *
  1708. * <code>map&lt;string, string&gt; map = 6;</code>
  1709. */
  1710. @java.lang.Override
  1711. public boolean containsMap(
  1712. java.lang.String key) {
  1713. if (key == null) { throw new NullPointerException("map key"); }
  1714. return internalGetMap().getMap().containsKey(key);
  1715. }
  1716. /**
  1717. * Use {@link #getMapMap()} instead.
  1718. */
  1719. @java.lang.Override
  1720. @java.lang.Deprecated
  1721. public java.util.Map<java.lang.String, java.lang.String> getMap() {
  1722. return getMapMap();
  1723. }
  1724. /**
  1725. * <pre>
  1726. * 定义简单的 Map string
  1727. * </pre>
  1728. *
  1729. * <code>map&lt;string, string&gt; map = 6;</code>
  1730. */
  1731. @java.lang.Override
  1732. public java.util.Map<java.lang.String, java.lang.String> getMapMap() {
  1733. return internalGetMap().getMap();
  1734. }
  1735. /**
  1736. * <pre>
  1737. * 定义简单的 Map string
  1738. * </pre>
  1739. *
  1740. * <code>map&lt;string, string&gt; map = 6;</code>
  1741. */
  1742. @java.lang.Override
  1743. public java.lang.String getMapOrDefault(
  1744. java.lang.String key,
  1745. java.lang.String defaultValue) {
  1746. if (key == null) { throw new NullPointerException("map key"); }
  1747. java.util.Map<java.lang.String, java.lang.String> map =
  1748. internalGetMap().getMap();
  1749. return map.containsKey(key) ? map.get(key) : defaultValue;
  1750. }
  1751. /**
  1752. * <pre>
  1753. * 定义简单的 Map string
  1754. * </pre>
  1755. *
  1756. * <code>map&lt;string, string&gt; map = 6;</code>
  1757. */
  1758. @java.lang.Override
  1759. public java.lang.String getMapOrThrow(
  1760. java.lang.String key) {
  1761. if (key == null) { throw new NullPointerException("map key"); }
  1762. java.util.Map<java.lang.String, java.lang.String> map =
  1763. internalGetMap().getMap();
  1764. if (!map.containsKey(key)) {
  1765. throw new java.lang.IllegalArgumentException();
  1766. }
  1767. return map.get(key);
  1768. }
  1769. public Builder clearMap() {
  1770. internalGetMutableMap().getMutableMap()
  1771. .clear();
  1772. return this;
  1773. }
  1774. /**
  1775. * <pre>
  1776. * 定义简单的 Map string
  1777. * </pre>
  1778. *
  1779. * <code>map&lt;string, string&gt; map = 6;</code>
  1780. */
  1781. public Builder removeMap(
  1782. java.lang.String key) {
  1783. if (key == null) { throw new NullPointerException("map key"); }
  1784. internalGetMutableMap().getMutableMap()
  1785. .remove(key);
  1786. return this;
  1787. }
  1788. /**
  1789. * Use alternate mutation accessors instead.
  1790. */
  1791. @java.lang.Deprecated
  1792. public java.util.Map<java.lang.String, java.lang.String>
  1793. getMutableMap() {
  1794. return internalGetMutableMap().getMutableMap();
  1795. }
  1796. /**
  1797. * <pre>
  1798. * 定义简单的 Map string
  1799. * </pre>
  1800. *
  1801. * <code>map&lt;string, string&gt; map = 6;</code>
  1802. */
  1803. public Builder putMap(
  1804. java.lang.String key,
  1805. java.lang.String value) {
  1806. if (key == null) { throw new NullPointerException("map key"); }
  1807. if (value == null) {
  1808. throw new NullPointerException("map value");
  1809. }
  1810. internalGetMutableMap().getMutableMap()
  1811. .put(key, value);
  1812. return this;
  1813. }
  1814. /**
  1815. * <pre>
  1816. * 定义简单的 Map string
  1817. * </pre>
  1818. *
  1819. * <code>map&lt;string, string&gt; map = 6;</code>
  1820. */
  1821. public Builder putAllMap(
  1822. java.util.Map<java.lang.String, java.lang.String> values) {
  1823. internalGetMutableMap().getMutableMap()
  1824. .putAll(values);
  1825. return this;
  1826. }
  1827. private com.google.protobuf.MapField<
  1828. java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject> mapObject_;
  1829. private com.google.protobuf.MapField<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject>
  1830. internalGetMapObject() {
  1831. if (mapObject_ == null) {
  1832. return com.google.protobuf.MapField.emptyMapField(
  1833. MapObjectDefaultEntryHolder.defaultEntry);
  1834. }
  1835. return mapObject_;
  1836. }
  1837. private com.google.protobuf.MapField<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject>
  1838. internalGetMutableMapObject() {
  1839. onChanged();;
  1840. if (mapObject_ == null) {
  1841. mapObject_ = com.google.protobuf.MapField.newMapField(
  1842. MapObjectDefaultEntryHolder.defaultEntry);
  1843. }
  1844. if (!mapObject_.isMutable()) {
  1845. mapObject_ = mapObject_.copy();
  1846. }
  1847. return mapObject_;
  1848. }
  1849. public int getMapObjectCount() {
  1850. return internalGetMapObject().getMap().size();
  1851. }
  1852. /**
  1853. * <pre>
  1854. * 定义复杂的 Map 对象
  1855. * </pre>
  1856. *
  1857. * <code>map&lt;string, .com.qingfeng.proto.MapVauleObject&gt; mapObject = 7;</code>
  1858. */
  1859. @java.lang.Override
  1860. public boolean containsMapObject(
  1861. java.lang.String key) {
  1862. if (key == null) { throw new NullPointerException("map key"); }
  1863. return internalGetMapObject().getMap().containsKey(key);
  1864. }
  1865. /**
  1866. * Use {@link #getMapObjectMap()} instead.
  1867. */
  1868. @java.lang.Override
  1869. @java.lang.Deprecated
  1870. public java.util.Map<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject> getMapObject() {
  1871. return getMapObjectMap();
  1872. }
  1873. /**
  1874. * <pre>
  1875. * 定义复杂的 Map 对象
  1876. * </pre>
  1877. *
  1878. * <code>map&lt;string, .com.qingfeng.proto.MapVauleObject&gt; mapObject = 7;</code>
  1879. */
  1880. @java.lang.Override
  1881. public java.util.Map<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject> getMapObjectMap() {
  1882. return internalGetMapObject().getMap();
  1883. }
  1884. /**
  1885. * <pre>
  1886. * 定义复杂的 Map 对象
  1887. * </pre>
  1888. *
  1889. * <code>map&lt;string, .com.qingfeng.proto.MapVauleObject&gt; mapObject = 7;</code>
  1890. */
  1891. @java.lang.Override
  1892. public com.qingfeng.proto.UserProto.MapVauleObject getMapObjectOrDefault(
  1893. java.lang.String key,
  1894. com.qingfeng.proto.UserProto.MapVauleObject defaultValue) {
  1895. if (key == null) { throw new NullPointerException("map key"); }
  1896. java.util.Map<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject> map =
  1897. internalGetMapObject().getMap();
  1898. return map.containsKey(key) ? map.get(key) : defaultValue;
  1899. }
  1900. /**
  1901. * <pre>
  1902. * 定义复杂的 Map 对象
  1903. * </pre>
  1904. *
  1905. * <code>map&lt;string, .com.qingfeng.proto.MapVauleObject&gt; mapObject = 7;</code>
  1906. */
  1907. @java.lang.Override
  1908. public com.qingfeng.proto.UserProto.MapVauleObject getMapObjectOrThrow(
  1909. java.lang.String key) {
  1910. if (key == null) { throw new NullPointerException("map key"); }
  1911. java.util.Map<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject> map =
  1912. internalGetMapObject().getMap();
  1913. if (!map.containsKey(key)) {
  1914. throw new java.lang.IllegalArgumentException();
  1915. }
  1916. return map.get(key);
  1917. }
  1918. public Builder clearMapObject() {
  1919. internalGetMutableMapObject().getMutableMap()
  1920. .clear();
  1921. return this;
  1922. }
  1923. /**
  1924. * <pre>
  1925. * 定义复杂的 Map 对象
  1926. * </pre>
  1927. *
  1928. * <code>map&lt;string, .com.qingfeng.proto.MapVauleObject&gt; mapObject = 7;</code>
  1929. */
  1930. public Builder removeMapObject(
  1931. java.lang.String key) {
  1932. if (key == null) { throw new NullPointerException("map key"); }
  1933. internalGetMutableMapObject().getMutableMap()
  1934. .remove(key);
  1935. return this;
  1936. }
  1937. /**
  1938. * Use alternate mutation accessors instead.
  1939. */
  1940. @java.lang.Deprecated
  1941. public java.util.Map<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject>
  1942. getMutableMapObject() {
  1943. return internalGetMutableMapObject().getMutableMap();
  1944. }
  1945. /**
  1946. * <pre>
  1947. * 定义复杂的 Map 对象
  1948. * </pre>
  1949. *
  1950. * <code>map&lt;string, .com.qingfeng.proto.MapVauleObject&gt; mapObject = 7;</code>
  1951. */
  1952. public Builder putMapObject(
  1953. java.lang.String key,
  1954. com.qingfeng.proto.UserProto.MapVauleObject value) {
  1955. if (key == null) { throw new NullPointerException("map key"); }
  1956. if (value == null) {
  1957. throw new NullPointerException("map value");
  1958. }
  1959. internalGetMutableMapObject().getMutableMap()
  1960. .put(key, value);
  1961. return this;
  1962. }
  1963. /**
  1964. * <pre>
  1965. * 定义复杂的 Map 对象
  1966. * </pre>
  1967. *
  1968. * <code>map&lt;string, .com.qingfeng.proto.MapVauleObject&gt; mapObject = 7;</code>
  1969. */
  1970. public Builder putAllMapObject(
  1971. java.util.Map<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject> values) {
  1972. internalGetMutableMapObject().getMutableMap()
  1973. .putAll(values);
  1974. return this;
  1975. }
  1976. @java.lang.Override
  1977. public final Builder setUnknownFields(
  1978. final com.google.protobuf.UnknownFieldSet unknownFields) {
  1979. return super.setUnknownFields(unknownFields);
  1980. }
  1981. @java.lang.Override
  1982. public final Builder mergeUnknownFields(
  1983. final com.google.protobuf.UnknownFieldSet unknownFields) {
  1984. return super.mergeUnknownFields(unknownFields);
  1985. }
  1986. // @@protoc_insertion_point(builder_scope:com.qingfeng.proto.User)
  1987. }
  1988. // @@protoc_insertion_point(class_scope:com.qingfeng.proto.User)
  1989. private static final com.qingfeng.proto.UserProto.User DEFAULT_INSTANCE;
  1990. static {
  1991. DEFAULT_INSTANCE = new com.qingfeng.proto.UserProto.User();
  1992. }
  1993. public static com.qingfeng.proto.UserProto.User getDefaultInstance() {
  1994. return DEFAULT_INSTANCE;
  1995. }
  1996. private static final com.google.protobuf.Parser<User>
  1997. PARSER = new com.google.protobuf.AbstractParser<User>() {
  1998. @java.lang.Override
  1999. public User parsePartialFrom(
  2000. com.google.protobuf.CodedInputStream input,
  2001. com.google.protobuf.ExtensionRegistryLite extensionRegistry)
  2002. throws com.google.protobuf.InvalidProtocolBufferException {
  2003. return new User(input, extensionRegistry);
  2004. }
  2005. };
  2006. public static com.google.protobuf.Parser<User> parser() {
  2007. return PARSER;
  2008. }
  2009. @java.lang.Override
  2010. public com.google.protobuf.Parser<User> getParserForType() {
  2011. return PARSER;
  2012. }
  2013. @java.lang.Override
  2014. public com.qingfeng.proto.UserProto.User getDefaultInstanceForType() {
  2015. return DEFAULT_INSTANCE;
  2016. }
  2017. }
  2018. public interface NickNameOrBuilder extends
  2019. // @@protoc_insertion_point(interface_extends:com.qingfeng.proto.NickName)
  2020. com.google.protobuf.MessageOrBuilder {
  2021. /**
  2022. * <code>string nickName = 1;</code>
  2023. * @return The nickName.
  2024. */
  2025. java.lang.String getNickName();
  2026. /**
  2027. * <code>string nickName = 1;</code>
  2028. * @return The bytes for nickName.
  2029. */
  2030. com.google.protobuf.ByteString
  2031. getNickNameBytes();
  2032. }
  2033. /**
  2034. * <pre>
  2035. * 定义一个新的Name对象
  2036. * </pre>
  2037. *
  2038. * Protobuf type {@code com.qingfeng.proto.NickName}
  2039. */
  2040. public static final class NickName extends
  2041. com.google.protobuf.GeneratedMessageV3 implements
  2042. // @@protoc_insertion_point(message_implements:com.qingfeng.proto.NickName)
  2043. NickNameOrBuilder {
  2044. private static final long serialVersionUID = 0L;
  2045. // Use NickName.newBuilder() to construct.
  2046. private NickName(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
  2047. super(builder);
  2048. }
  2049. private NickName() {
  2050. nickName_ = "";
  2051. }
  2052. @java.lang.Override
  2053. @SuppressWarnings({"unused"})
  2054. protected java.lang.Object newInstance(
  2055. UnusedPrivateParameter unused) {
  2056. return new NickName();
  2057. }
  2058. @java.lang.Override
  2059. public final com.google.protobuf.UnknownFieldSet
  2060. getUnknownFields() {
  2061. return this.unknownFields;
  2062. }
  2063. private NickName(
  2064. com.google.protobuf.CodedInputStream input,
  2065. com.google.protobuf.ExtensionRegistryLite extensionRegistry)
  2066. throws com.google.protobuf.InvalidProtocolBufferException {
  2067. this();
  2068. if (extensionRegistry == null) {
  2069. throw new java.lang.NullPointerException();
  2070. }
  2071. com.google.protobuf.UnknownFieldSet.Builder unknownFields =
  2072. com.google.protobuf.UnknownFieldSet.newBuilder();
  2073. try {
  2074. boolean done = false;
  2075. while (!done) {
  2076. int tag = input.readTag();
  2077. switch (tag) {
  2078. case 0:
  2079. done = true;
  2080. break;
  2081. case 10: {
  2082. java.lang.String s = input.readStringRequireUtf8();
  2083. nickName_ = s;
  2084. break;
  2085. }
  2086. default: {
  2087. if (!parseUnknownField(
  2088. input, unknownFields, extensionRegistry, tag)) {
  2089. done = true;
  2090. }
  2091. break;
  2092. }
  2093. }
  2094. }
  2095. } catch (com.google.protobuf.InvalidProtocolBufferException e) {
  2096. throw e.setUnfinishedMessage(this);
  2097. } catch (com.google.protobuf.UninitializedMessageException e) {
  2098. throw e.asInvalidProtocolBufferException().setUnfinishedMessage(this);
  2099. } catch (java.io.IOException e) {
  2100. throw new com.google.protobuf.InvalidProtocolBufferException(
  2101. e).setUnfinishedMessage(this);
  2102. } finally {
  2103. this.unknownFields = unknownFields.build();
  2104. makeExtensionsImmutable();
  2105. }
  2106. }
  2107. public static final com.google.protobuf.Descriptors.Descriptor
  2108. getDescriptor() {
  2109. return com.qingfeng.proto.UserProto.internal_static_com_qingfeng_proto_NickName_descriptor;
  2110. }
  2111. @java.lang.Override
  2112. protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
  2113. internalGetFieldAccessorTable() {
  2114. return com.qingfeng.proto.UserProto.internal_static_com_qingfeng_proto_NickName_fieldAccessorTable
  2115. .ensureFieldAccessorsInitialized(
  2116. com.qingfeng.proto.UserProto.NickName.class, com.qingfeng.proto.UserProto.NickName.Builder.class);
  2117. }
  2118. public static final int NICKNAME_FIELD_NUMBER = 1;
  2119. private volatile java.lang.Object nickName_;
  2120. /**
  2121. * <code>string nickName = 1;</code>
  2122. * @return The nickName.
  2123. */
  2124. @java.lang.Override
  2125. public java.lang.String getNickName() {
  2126. java.lang.Object ref = nickName_;
  2127. if (ref instanceof java.lang.String) {
  2128. return (java.lang.String) ref;
  2129. } else {
  2130. com.google.protobuf.ByteString bs =
  2131. (com.google.protobuf.ByteString) ref;
  2132. java.lang.String s = bs.toStringUtf8();
  2133. nickName_ = s;
  2134. return s;
  2135. }
  2136. }
  2137. /**
  2138. * <code>string nickName = 1;</code>
  2139. * @return The bytes for nickName.
  2140. */
  2141. @java.lang.Override
  2142. public com.google.protobuf.ByteString
  2143. getNickNameBytes() {
  2144. java.lang.Object ref = nickName_;
  2145. if (ref instanceof java.lang.String) {
  2146. com.google.protobuf.ByteString b =
  2147. com.google.protobuf.ByteString.copyFromUtf8(
  2148. (java.lang.String) ref);
  2149. nickName_ = b;
  2150. return b;
  2151. } else {
  2152. return (com.google.protobuf.ByteString) ref;
  2153. }
  2154. }
  2155. private byte memoizedIsInitialized = -1;
  2156. @java.lang.Override
  2157. public final boolean isInitialized() {
  2158. byte isInitialized = memoizedIsInitialized;
  2159. if (isInitialized == 1) return true;
  2160. if (isInitialized == 0) return false;
  2161. memoizedIsInitialized = 1;
  2162. return true;
  2163. }
  2164. @java.lang.Override
  2165. public void writeTo(com.google.protobuf.CodedOutputStream output)
  2166. throws java.io.IOException {
  2167. if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(nickName_)) {
  2168. com.google.protobuf.GeneratedMessageV3.writeString(output, 1, nickName_);
  2169. }
  2170. unknownFields.writeTo(output);
  2171. }
  2172. @java.lang.Override
  2173. public int getSerializedSize() {
  2174. int size = memoizedSize;
  2175. if (size != -1) return size;
  2176. size = 0;
  2177. if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(nickName_)) {
  2178. size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, nickName_);
  2179. }
  2180. size += unknownFields.getSerializedSize();
  2181. memoizedSize = size;
  2182. return size;
  2183. }
  2184. @java.lang.Override
  2185. public boolean equals(final java.lang.Object obj) {
  2186. if (obj == this) {
  2187. return true;
  2188. }
  2189. if (!(obj instanceof com.qingfeng.proto.UserProto.NickName)) {
  2190. return super.equals(obj);
  2191. }
  2192. com.qingfeng.proto.UserProto.NickName other = (com.qingfeng.proto.UserProto.NickName) obj;
  2193. if (!getNickName()
  2194. .equals(other.getNickName())) return false;
  2195. if (!unknownFields.equals(other.unknownFields)) return false;
  2196. return true;
  2197. }
  2198. @java.lang.Override
  2199. public int hashCode() {
  2200. if (memoizedHashCode != 0) {
  2201. return memoizedHashCode;
  2202. }
  2203. int hash = 41;
  2204. hash = (19 * hash) + getDescriptor().hashCode();
  2205. hash = (37 * hash) + NICKNAME_FIELD_NUMBER;
  2206. hash = (53 * hash) + getNickName().hashCode();
  2207. hash = (29 * hash) + unknownFields.hashCode();
  2208. memoizedHashCode = hash;
  2209. return hash;
  2210. }
  2211. public static com.qingfeng.proto.UserProto.NickName parseFrom(
  2212. java.nio.ByteBuffer data)
  2213. throws com.google.protobuf.InvalidProtocolBufferException {
  2214. return PARSER.parseFrom(data);
  2215. }
  2216. public static com.qingfeng.proto.UserProto.NickName parseFrom(
  2217. java.nio.ByteBuffer data,
  2218. com.google.protobuf.ExtensionRegistryLite extensionRegistry)
  2219. throws com.google.protobuf.InvalidProtocolBufferException {
  2220. return PARSER.parseFrom(data, extensionRegistry);
  2221. }
  2222. public static com.qingfeng.proto.UserProto.NickName parseFrom(
  2223. com.google.protobuf.ByteString data)
  2224. throws com.google.protobuf.InvalidProtocolBufferException {
  2225. return PARSER.parseFrom(data);
  2226. }
  2227. public static com.qingfeng.proto.UserProto.NickName parseFrom(
  2228. com.google.protobuf.ByteString data,
  2229. com.google.protobuf.ExtensionRegistryLite extensionRegistry)
  2230. throws com.google.protobuf.InvalidProtocolBufferException {
  2231. return PARSER.parseFrom(data, extensionRegistry);
  2232. }
  2233. public static com.qingfeng.proto.UserProto.NickName parseFrom(byte[] data)
  2234. throws com.google.protobuf.InvalidProtocolBufferException {
  2235. return PARSER.parseFrom(data);
  2236. }
  2237. public static com.qingfeng.proto.UserProto.NickName parseFrom(
  2238. byte[] data,
  2239. com.google.protobuf.ExtensionRegistryLite extensionRegistry)
  2240. throws com.google.protobuf.InvalidProtocolBufferException {
  2241. return PARSER.parseFrom(data, extensionRegistry);
  2242. }
  2243. public static com.qingfeng.proto.UserProto.NickName parseFrom(java.io.InputStream input)
  2244. throws java.io.IOException {
  2245. return com.google.protobuf.GeneratedMessageV3
  2246. .parseWithIOException(PARSER, input);
  2247. }
  2248. public static com.qingfeng.proto.UserProto.NickName parseFrom(
  2249. java.io.InputStream input,
  2250. com.google.protobuf.ExtensionRegistryLite extensionRegistry)
  2251. throws java.io.IOException {
  2252. return com.google.protobuf.GeneratedMessageV3
  2253. .parseWithIOException(PARSER, input, extensionRegistry);
  2254. }
  2255. public static com.qingfeng.proto.UserProto.NickName parseDelimitedFrom(java.io.InputStream input)
  2256. throws java.io.IOException {
  2257. return com.google.protobuf.GeneratedMessageV3
  2258. .parseDelimitedWithIOException(PARSER, input);
  2259. }
  2260. public static com.qingfeng.proto.UserProto.NickName parseDelimitedFrom(
  2261. java.io.InputStream input,
  2262. com.google.protobuf.ExtensionRegistryLite extensionRegistry)
  2263. throws java.io.IOException {
  2264. return com.google.protobuf.GeneratedMessageV3
  2265. .parseDelimitedWithIOException(PARSER, input, extensionRegistry);
  2266. }
  2267. public static com.qingfeng.proto.UserProto.NickName parseFrom(
  2268. com.google.protobuf.CodedInputStream input)
  2269. throws java.io.IOException {
  2270. return com.google.protobuf.GeneratedMessageV3
  2271. .parseWithIOException(PARSER, input);
  2272. }
  2273. public static com.qingfeng.proto.UserProto.NickName parseFrom(
  2274. com.google.protobuf.CodedInputStream input,
  2275. com.google.protobuf.ExtensionRegistryLite extensionRegistry)
  2276. throws java.io.IOException {
  2277. return com.google.protobuf.GeneratedMessageV3
  2278. .parseWithIOException(PARSER, input, extensionRegistry);
  2279. }
  2280. @java.lang.Override
  2281. public Builder newBuilderForType() { return newBuilder(); }
  2282. public static Builder newBuilder() {
  2283. return DEFAULT_INSTANCE.toBuilder();
  2284. }
  2285. public static Builder newBuilder(com.qingfeng.proto.UserProto.NickName prototype) {
  2286. return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
  2287. }
  2288. @java.lang.Override
  2289. public Builder toBuilder() {
  2290. return this == DEFAULT_INSTANCE
  2291. ? new Builder() : new Builder().mergeFrom(this);
  2292. }
  2293. @java.lang.Override
  2294. protected Builder newBuilderForType(
  2295. com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
  2296. Builder builder = new Builder(parent);
  2297. return builder;
  2298. }
  2299. /**
  2300. * <pre>
  2301. * 定义一个新的Name对象
  2302. * </pre>
  2303. *
  2304. * Protobuf type {@code com.qingfeng.proto.NickName}
  2305. */
  2306. public static final class Builder extends
  2307. com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
  2308. // @@protoc_insertion_point(builder_implements:com.qingfeng.proto.NickName)
  2309. com.qingfeng.proto.UserProto.NickNameOrBuilder {
  2310. public static final com.google.protobuf.Descriptors.Descriptor
  2311. getDescriptor() {
  2312. return com.qingfeng.proto.UserProto.internal_static_com_qingfeng_proto_NickName_descriptor;
  2313. }
  2314. @java.lang.Override
  2315. protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
  2316. internalGetFieldAccessorTable() {
  2317. return com.qingfeng.proto.UserProto.internal_static_com_qingfeng_proto_NickName_fieldAccessorTable
  2318. .ensureFieldAccessorsInitialized(
  2319. com.qingfeng.proto.UserProto.NickName.class, com.qingfeng.proto.UserProto.NickName.Builder.class);
  2320. }
  2321. // Construct using com.qingfeng.proto.UserProto.NickName.newBuilder()
  2322. private Builder() {
  2323. maybeForceBuilderInitialization();
  2324. }
  2325. private Builder(
  2326. com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
  2327. super(parent);
  2328. maybeForceBuilderInitialization();
  2329. }
  2330. private void maybeForceBuilderInitialization() {
  2331. if (com.google.protobuf.GeneratedMessageV3
  2332. .alwaysUseFieldBuilders) {
  2333. }
  2334. }
  2335. @java.lang.Override
  2336. public Builder clear() {
  2337. super.clear();
  2338. nickName_ = "";
  2339. return this;
  2340. }
  2341. @java.lang.Override
  2342. public com.google.protobuf.Descriptors.Descriptor
  2343. getDescriptorForType() {
  2344. return com.qingfeng.proto.UserProto.internal_static_com_qingfeng_proto_NickName_descriptor;
  2345. }
  2346. @java.lang.Override
  2347. public com.qingfeng.proto.UserProto.NickName getDefaultInstanceForType() {
  2348. return com.qingfeng.proto.UserProto.NickName.getDefaultInstance();
  2349. }
  2350. @java.lang.Override
  2351. public com.qingfeng.proto.UserProto.NickName build() {
  2352. com.qingfeng.proto.UserProto.NickName result = buildPartial();
  2353. if (!result.isInitialized()) {
  2354. throw newUninitializedMessageException(result);
  2355. }
  2356. return result;
  2357. }
  2358. @java.lang.Override
  2359. public com.qingfeng.proto.UserProto.NickName buildPartial() {
  2360. com.qingfeng.proto.UserProto.NickName result = new com.qingfeng.proto.UserProto.NickName(this);
  2361. result.nickName_ = nickName_;
  2362. onBuilt();
  2363. return result;
  2364. }
  2365. @java.lang.Override
  2366. public Builder clone() {
  2367. return super.clone();
  2368. }
  2369. @java.lang.Override
  2370. public Builder setField(
  2371. com.google.protobuf.Descriptors.FieldDescriptor field,
  2372. java.lang.Object value) {
  2373. return super.setField(field, value);
  2374. }
  2375. @java.lang.Override
  2376. public Builder clearField(
  2377. com.google.protobuf.Descriptors.FieldDescriptor field) {
  2378. return super.clearField(field);
  2379. }
  2380. @java.lang.Override
  2381. public Builder clearOneof(
  2382. com.google.protobuf.Descriptors.OneofDescriptor oneof) {
  2383. return super.clearOneof(oneof);
  2384. }
  2385. @java.lang.Override
  2386. public Builder setRepeatedField(
  2387. com.google.protobuf.Descriptors.FieldDescriptor field,
  2388. int index, java.lang.Object value) {
  2389. return super.setRepeatedField(field, index, value);
  2390. }
  2391. @java.lang.Override
  2392. public Builder addRepeatedField(
  2393. com.google.protobuf.Descriptors.FieldDescriptor field,
  2394. java.lang.Object value) {
  2395. return super.addRepeatedField(field, value);
  2396. }
  2397. @java.lang.Override
  2398. public Builder mergeFrom(com.google.protobuf.Message other) {
  2399. if (other instanceof com.qingfeng.proto.UserProto.NickName) {
  2400. return mergeFrom((com.qingfeng.proto.UserProto.NickName)other);
  2401. } else {
  2402. super.mergeFrom(other);
  2403. return this;
  2404. }
  2405. }
  2406. public Builder mergeFrom(com.qingfeng.proto.UserProto.NickName other) {
  2407. if (other == com.qingfeng.proto.UserProto.NickName.getDefaultInstance()) return this;
  2408. if (!other.getNickName().isEmpty()) {
  2409. nickName_ = other.nickName_;
  2410. onChanged();
  2411. }
  2412. this.mergeUnknownFields(other.unknownFields);
  2413. onChanged();
  2414. return this;
  2415. }
  2416. @java.lang.Override
  2417. public final boolean isInitialized() {
  2418. return true;
  2419. }
  2420. @java.lang.Override
  2421. public Builder mergeFrom(
  2422. com.google.protobuf.CodedInputStream input,
  2423. com.google.protobuf.ExtensionRegistryLite extensionRegistry)
  2424. throws java.io.IOException {
  2425. com.qingfeng.proto.UserProto.NickName parsedMessage = null;
  2426. try {
  2427. parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
  2428. } catch (com.google.protobuf.InvalidProtocolBufferException e) {
  2429. parsedMessage = (com.qingfeng.proto.UserProto.NickName) e.getUnfinishedMessage();
  2430. throw e.unwrapIOException();
  2431. } finally {
  2432. if (parsedMessage != null) {
  2433. mergeFrom(parsedMessage);
  2434. }
  2435. }
  2436. return this;
  2437. }
  2438. private java.lang.Object nickName_ = "";
  2439. /**
  2440. * <code>string nickName = 1;</code>
  2441. * @return The nickName.
  2442. */
  2443. public java.lang.String getNickName() {
  2444. java.lang.Object ref = nickName_;
  2445. if (!(ref instanceof java.lang.String)) {
  2446. com.google.protobuf.ByteString bs =
  2447. (com.google.protobuf.ByteString) ref;
  2448. java.lang.String s = bs.toStringUtf8();
  2449. nickName_ = s;
  2450. return s;
  2451. } else {
  2452. return (java.lang.String) ref;
  2453. }
  2454. }
  2455. /**
  2456. * <code>string nickName = 1;</code>
  2457. * @return The bytes for nickName.
  2458. */
  2459. public com.google.protobuf.ByteString
  2460. getNickNameBytes() {
  2461. java.lang.Object ref = nickName_;
  2462. if (ref instanceof String) {
  2463. com.google.protobuf.ByteString b =
  2464. com.google.protobuf.ByteString.copyFromUtf8(
  2465. (java.lang.String) ref);
  2466. nickName_ = b;
  2467. return b;
  2468. } else {
  2469. return (com.google.protobuf.ByteString) ref;
  2470. }
  2471. }
  2472. /**
  2473. * <code>string nickName = 1;</code>
  2474. * @param value The nickName to set.
  2475. * @return This builder for chaining.
  2476. */
  2477. public Builder setNickName(
  2478. java.lang.String value) {
  2479. if (value == null) {
  2480. throw new NullPointerException();
  2481. }
  2482. nickName_ = value;
  2483. onChanged();
  2484. return this;
  2485. }
  2486. /**
  2487. * <code>string nickName = 1;</code>
  2488. * @return This builder for chaining.
  2489. */
  2490. public Builder clearNickName() {
  2491. nickName_ = getDefaultInstance().getNickName();
  2492. onChanged();
  2493. return this;
  2494. }
  2495. /**
  2496. * <code>string nickName = 1;</code>
  2497. * @param value The bytes for nickName to set.
  2498. * @return This builder for chaining.
  2499. */
  2500. public Builder setNickNameBytes(
  2501. com.google.protobuf.ByteString value) {
  2502. if (value == null) {
  2503. throw new NullPointerException();
  2504. }
  2505. checkByteStringIsUtf8(value);
  2506. nickName_ = value;
  2507. onChanged();
  2508. return this;
  2509. }
  2510. @java.lang.Override
  2511. public final Builder setUnknownFields(
  2512. final com.google.protobuf.UnknownFieldSet unknownFields) {
  2513. return super.setUnknownFields(unknownFields);
  2514. }
  2515. @java.lang.Override
  2516. public final Builder mergeUnknownFields(
  2517. final com.google.protobuf.UnknownFieldSet unknownFields) {
  2518. return super.mergeUnknownFields(unknownFields);
  2519. }
  2520. // @@protoc_insertion_point(builder_scope:com.qingfeng.proto.NickName)
  2521. }
  2522. // @@protoc_insertion_point(class_scope:com.qingfeng.proto.NickName)
  2523. private static final com.qingfeng.proto.UserProto.NickName DEFAULT_INSTANCE;
  2524. static {
  2525. DEFAULT_INSTANCE = new com.qingfeng.proto.UserProto.NickName();
  2526. }
  2527. public static com.qingfeng.proto.UserProto.NickName getDefaultInstance() {
  2528. return DEFAULT_INSTANCE;
  2529. }
  2530. private static final com.google.protobuf.Parser<NickName>
  2531. PARSER = new com.google.protobuf.AbstractParser<NickName>() {
  2532. @java.lang.Override
  2533. public NickName parsePartialFrom(
  2534. com.google.protobuf.CodedInputStream input,
  2535. com.google.protobuf.ExtensionRegistryLite extensionRegistry)
  2536. throws com.google.protobuf.InvalidProtocolBufferException {
  2537. return new NickName(input, extensionRegistry);
  2538. }
  2539. };
  2540. public static com.google.protobuf.Parser<NickName> parser() {
  2541. return PARSER;
  2542. }
  2543. @java.lang.Override
  2544. public com.google.protobuf.Parser<NickName> getParserForType() {
  2545. return PARSER;
  2546. }
  2547. @java.lang.Override
  2548. public com.qingfeng.proto.UserProto.NickName getDefaultInstanceForType() {
  2549. return DEFAULT_INSTANCE;
  2550. }
  2551. }
  2552. public interface MapVauleObjectOrBuilder extends
  2553. // @@protoc_insertion_point(interface_extends:com.qingfeng.proto.MapVauleObject)
  2554. com.google.protobuf.MessageOrBuilder {
  2555. /**
  2556. * <code>string code = 1;</code>
  2557. * @return The code.
  2558. */
  2559. java.lang.String getCode();
  2560. /**
  2561. * <code>string code = 1;</code>
  2562. * @return The bytes for code.
  2563. */
  2564. com.google.protobuf.ByteString
  2565. getCodeBytes();
  2566. /**
  2567. * <code>string name = 2;</code>
  2568. * @return The name.
  2569. */
  2570. java.lang.String getName();
  2571. /**
  2572. * <code>string name = 2;</code>
  2573. * @return The bytes for name.
  2574. */
  2575. com.google.protobuf.ByteString
  2576. getNameBytes();
  2577. }
  2578. /**
  2579. * <pre>
  2580. * 定义 Map 的 value 对象
  2581. * </pre>
  2582. *
  2583. * Protobuf type {@code com.qingfeng.proto.MapVauleObject}
  2584. */
  2585. public static final class MapVauleObject extends
  2586. com.google.protobuf.GeneratedMessageV3 implements
  2587. // @@protoc_insertion_point(message_implements:com.qingfeng.proto.MapVauleObject)
  2588. MapVauleObjectOrBuilder {
  2589. private static final long serialVersionUID = 0L;
  2590. // Use MapVauleObject.newBuilder() to construct.
  2591. private MapVauleObject(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
  2592. super(builder);
  2593. }
  2594. private MapVauleObject() {
  2595. code_ = "";
  2596. name_ = "";
  2597. }
  2598. @java.lang.Override
  2599. @SuppressWarnings({"unused"})
  2600. protected java.lang.Object newInstance(
  2601. UnusedPrivateParameter unused) {
  2602. return new MapVauleObject();
  2603. }
  2604. @java.lang.Override
  2605. public final com.google.protobuf.UnknownFieldSet
  2606. getUnknownFields() {
  2607. return this.unknownFields;
  2608. }
  2609. private MapVauleObject(
  2610. com.google.protobuf.CodedInputStream input,
  2611. com.google.protobuf.ExtensionRegistryLite extensionRegistry)
  2612. throws com.google.protobuf.InvalidProtocolBufferException {
  2613. this();
  2614. if (extensionRegistry == null) {
  2615. throw new java.lang.NullPointerException();
  2616. }
  2617. com.google.protobuf.UnknownFieldSet.Builder unknownFields =
  2618. com.google.protobuf.UnknownFieldSet.newBuilder();
  2619. try {
  2620. boolean done = false;
  2621. while (!done) {
  2622. int tag = input.readTag();
  2623. switch (tag) {
  2624. case 0:
  2625. done = true;
  2626. break;
  2627. case 10: {
  2628. java.lang.String s = input.readStringRequireUtf8();
  2629. code_ = s;
  2630. break;
  2631. }
  2632. case 18: {
  2633. java.lang.String s = input.readStringRequireUtf8();
  2634. name_ = s;
  2635. break;
  2636. }
  2637. default: {
  2638. if (!parseUnknownField(
  2639. input, unknownFields, extensionRegistry, tag)) {
  2640. done = true;
  2641. }
  2642. break;
  2643. }
  2644. }
  2645. }
  2646. } catch (com.google.protobuf.InvalidProtocolBufferException e) {
  2647. throw e.setUnfinishedMessage(this);
  2648. } catch (com.google.protobuf.UninitializedMessageException e) {
  2649. throw e.asInvalidProtocolBufferException().setUnfinishedMessage(this);
  2650. } catch (java.io.IOException e) {
  2651. throw new com.google.protobuf.InvalidProtocolBufferException(
  2652. e).setUnfinishedMessage(this);
  2653. } finally {
  2654. this.unknownFields = unknownFields.build();
  2655. makeExtensionsImmutable();
  2656. }
  2657. }
  2658. public static final com.google.protobuf.Descriptors.Descriptor
  2659. getDescriptor() {
  2660. return com.qingfeng.proto.UserProto.internal_static_com_qingfeng_proto_MapVauleObject_descriptor;
  2661. }
  2662. @java.lang.Override
  2663. protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
  2664. internalGetFieldAccessorTable() {
  2665. return com.qingfeng.proto.UserProto.internal_static_com_qingfeng_proto_MapVauleObject_fieldAccessorTable
  2666. .ensureFieldAccessorsInitialized(
  2667. com.qingfeng.proto.UserProto.MapVauleObject.class, com.qingfeng.proto.UserProto.MapVauleObject.Builder.class);
  2668. }
  2669. public static final int CODE_FIELD_NUMBER = 1;
  2670. private volatile java.lang.Object code_;
  2671. /**
  2672. * <code>string code = 1;</code>
  2673. * @return The code.
  2674. */
  2675. @java.lang.Override
  2676. public java.lang.String getCode() {
  2677. java.lang.Object ref = code_;
  2678. if (ref instanceof java.lang.String) {
  2679. return (java.lang.String) ref;
  2680. } else {
  2681. com.google.protobuf.ByteString bs =
  2682. (com.google.protobuf.ByteString) ref;
  2683. java.lang.String s = bs.toStringUtf8();
  2684. code_ = s;
  2685. return s;
  2686. }
  2687. }
  2688. /**
  2689. * <code>string code = 1;</code>
  2690. * @return The bytes for code.
  2691. */
  2692. @java.lang.Override
  2693. public com.google.protobuf.ByteString
  2694. getCodeBytes() {
  2695. java.lang.Object ref = code_;
  2696. if (ref instanceof java.lang.String) {
  2697. com.google.protobuf.ByteString b =
  2698. com.google.protobuf.ByteString.copyFromUtf8(
  2699. (java.lang.String) ref);
  2700. code_ = b;
  2701. return b;
  2702. } else {
  2703. return (com.google.protobuf.ByteString) ref;
  2704. }
  2705. }
  2706. public static final int NAME_FIELD_NUMBER = 2;
  2707. private volatile java.lang.Object name_;
  2708. /**
  2709. * <code>string name = 2;</code>
  2710. * @return The name.
  2711. */
  2712. @java.lang.Override
  2713. public java.lang.String getName() {
  2714. java.lang.Object ref = name_;
  2715. if (ref instanceof java.lang.String) {
  2716. return (java.lang.String) ref;
  2717. } else {
  2718. com.google.protobuf.ByteString bs =
  2719. (com.google.protobuf.ByteString) ref;
  2720. java.lang.String s = bs.toStringUtf8();
  2721. name_ = s;
  2722. return s;
  2723. }
  2724. }
  2725. /**
  2726. * <code>string name = 2;</code>
  2727. * @return The bytes for name.
  2728. */
  2729. @java.lang.Override
  2730. public com.google.protobuf.ByteString
  2731. getNameBytes() {
  2732. java.lang.Object ref = name_;
  2733. if (ref instanceof java.lang.String) {
  2734. com.google.protobuf.ByteString b =
  2735. com.google.protobuf.ByteString.copyFromUtf8(
  2736. (java.lang.String) ref);
  2737. name_ = b;
  2738. return b;
  2739. } else {
  2740. return (com.google.protobuf.ByteString) ref;
  2741. }
  2742. }
  2743. private byte memoizedIsInitialized = -1;
  2744. @java.lang.Override
  2745. public final boolean isInitialized() {
  2746. byte isInitialized = memoizedIsInitialized;
  2747. if (isInitialized == 1) return true;
  2748. if (isInitialized == 0) return false;
  2749. memoizedIsInitialized = 1;
  2750. return true;
  2751. }
  2752. @java.lang.Override
  2753. public void writeTo(com.google.protobuf.CodedOutputStream output)
  2754. throws java.io.IOException {
  2755. if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(code_)) {
  2756. com.google.protobuf.GeneratedMessageV3.writeString(output, 1, code_);
  2757. }
  2758. if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) {
  2759. com.google.protobuf.GeneratedMessageV3.writeString(output, 2, name_);
  2760. }
  2761. unknownFields.writeTo(output);
  2762. }
  2763. @java.lang.Override
  2764. public int getSerializedSize() {
  2765. int size = memoizedSize;
  2766. if (size != -1) return size;
  2767. size = 0;
  2768. if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(code_)) {
  2769. size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, code_);
  2770. }
  2771. if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) {
  2772. size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, name_);
  2773. }
  2774. size += unknownFields.getSerializedSize();
  2775. memoizedSize = size;
  2776. return size;
  2777. }
  2778. @java.lang.Override
  2779. public boolean equals(final java.lang.Object obj) {
  2780. if (obj == this) {
  2781. return true;
  2782. }
  2783. if (!(obj instanceof com.qingfeng.proto.UserProto.MapVauleObject)) {
  2784. return super.equals(obj);
  2785. }
  2786. com.qingfeng.proto.UserProto.MapVauleObject other = (com.qingfeng.proto.UserProto.MapVauleObject) obj;
  2787. if (!getCode()
  2788. .equals(other.getCode())) return false;
  2789. if (!getName()
  2790. .equals(other.getName())) return false;
  2791. if (!unknownFields.equals(other.unknownFields)) return false;
  2792. return true;
  2793. }
  2794. @java.lang.Override
  2795. public int hashCode() {
  2796. if (memoizedHashCode != 0) {
  2797. return memoizedHashCode;
  2798. }
  2799. int hash = 41;
  2800. hash = (19 * hash) + getDescriptor().hashCode();
  2801. hash = (37 * hash) + CODE_FIELD_NUMBER;
  2802. hash = (53 * hash) + getCode().hashCode();
  2803. hash = (37 * hash) + NAME_FIELD_NUMBER;
  2804. hash = (53 * hash) + getName().hashCode();
  2805. hash = (29 * hash) + unknownFields.hashCode();
  2806. memoizedHashCode = hash;
  2807. return hash;
  2808. }
  2809. public static com.qingfeng.proto.UserProto.MapVauleObject parseFrom(
  2810. java.nio.ByteBuffer data)
  2811. throws com.google.protobuf.InvalidProtocolBufferException {
  2812. return PARSER.parseFrom(data);
  2813. }
  2814. public static com.qingfeng.proto.UserProto.MapVauleObject parseFrom(
  2815. java.nio.ByteBuffer data,
  2816. com.google.protobuf.ExtensionRegistryLite extensionRegistry)
  2817. throws com.google.protobuf.InvalidProtocolBufferException {
  2818. return PARSER.parseFrom(data, extensionRegistry);
  2819. }
  2820. public static com.qingfeng.proto.UserProto.MapVauleObject parseFrom(
  2821. com.google.protobuf.ByteString data)
  2822. throws com.google.protobuf.InvalidProtocolBufferException {
  2823. return PARSER.parseFrom(data);
  2824. }
  2825. public static com.qingfeng.proto.UserProto.MapVauleObject parseFrom(
  2826. com.google.protobuf.ByteString data,
  2827. com.google.protobuf.ExtensionRegistryLite extensionRegistry)
  2828. throws com.google.protobuf.InvalidProtocolBufferException {
  2829. return PARSER.parseFrom(data, extensionRegistry);
  2830. }
  2831. public static com.qingfeng.proto.UserProto.MapVauleObject parseFrom(byte[] data)
  2832. throws com.google.protobuf.InvalidProtocolBufferException {
  2833. return PARSER.parseFrom(data);
  2834. }
  2835. public static com.qingfeng.proto.UserProto.MapVauleObject parseFrom(
  2836. byte[] data,
  2837. com.google.protobuf.ExtensionRegistryLite extensionRegistry)
  2838. throws com.google.protobuf.InvalidProtocolBufferException {
  2839. return PARSER.parseFrom(data, extensionRegistry);
  2840. }
  2841. public static com.qingfeng.proto.UserProto.MapVauleObject parseFrom(java.io.InputStream input)
  2842. throws java.io.IOException {
  2843. return com.google.protobuf.GeneratedMessageV3
  2844. .parseWithIOException(PARSER, input);
  2845. }
  2846. public static com.qingfeng.proto.UserProto.MapVauleObject parseFrom(
  2847. java.io.InputStream input,
  2848. com.google.protobuf.ExtensionRegistryLite extensionRegistry)
  2849. throws java.io.IOException {
  2850. return com.google.protobuf.GeneratedMessageV3
  2851. .parseWithIOException(PARSER, input, extensionRegistry);
  2852. }
  2853. public static com.qingfeng.proto.UserProto.MapVauleObject parseDelimitedFrom(java.io.InputStream input)
  2854. throws java.io.IOException {
  2855. return com.google.protobuf.GeneratedMessageV3
  2856. .parseDelimitedWithIOException(PARSER, input);
  2857. }
  2858. public static com.qingfeng.proto.UserProto.MapVauleObject parseDelimitedFrom(
  2859. java.io.InputStream input,
  2860. com.google.protobuf.ExtensionRegistryLite extensionRegistry)
  2861. throws java.io.IOException {
  2862. return com.google.protobuf.GeneratedMessageV3
  2863. .parseDelimitedWithIOException(PARSER, input, extensionRegistry);
  2864. }
  2865. public static com.qingfeng.proto.UserProto.MapVauleObject parseFrom(
  2866. com.google.protobuf.CodedInputStream input)
  2867. throws java.io.IOException {
  2868. return com.google.protobuf.GeneratedMessageV3
  2869. .parseWithIOException(PARSER, input);
  2870. }
  2871. public static com.qingfeng.proto.UserProto.MapVauleObject parseFrom(
  2872. com.google.protobuf.CodedInputStream input,
  2873. com.google.protobuf.ExtensionRegistryLite extensionRegistry)
  2874. throws java.io.IOException {
  2875. return com.google.protobuf.GeneratedMessageV3
  2876. .parseWithIOException(PARSER, input, extensionRegistry);
  2877. }
  2878. @java.lang.Override
  2879. public Builder newBuilderForType() { return newBuilder(); }
  2880. public static Builder newBuilder() {
  2881. return DEFAULT_INSTANCE.toBuilder();
  2882. }
  2883. public static Builder newBuilder(com.qingfeng.proto.UserProto.MapVauleObject prototype) {
  2884. return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
  2885. }
  2886. @java.lang.Override
  2887. public Builder toBuilder() {
  2888. return this == DEFAULT_INSTANCE
  2889. ? new Builder() : new Builder().mergeFrom(this);
  2890. }
  2891. @java.lang.Override
  2892. protected Builder newBuilderForType(
  2893. com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
  2894. Builder builder = new Builder(parent);
  2895. return builder;
  2896. }
  2897. /**
  2898. * <pre>
  2899. * 定义 Map 的 value 对象
  2900. * </pre>
  2901. *
  2902. * Protobuf type {@code com.qingfeng.proto.MapVauleObject}
  2903. */
  2904. public static final class Builder extends
  2905. com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
  2906. // @@protoc_insertion_point(builder_implements:com.qingfeng.proto.MapVauleObject)
  2907. com.qingfeng.proto.UserProto.MapVauleObjectOrBuilder {
  2908. public static final com.google.protobuf.Descriptors.Descriptor
  2909. getDescriptor() {
  2910. return com.qingfeng.proto.UserProto.internal_static_com_qingfeng_proto_MapVauleObject_descriptor;
  2911. }
  2912. @java.lang.Override
  2913. protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
  2914. internalGetFieldAccessorTable() {
  2915. return com.qingfeng.proto.UserProto.internal_static_com_qingfeng_proto_MapVauleObject_fieldAccessorTable
  2916. .ensureFieldAccessorsInitialized(
  2917. com.qingfeng.proto.UserProto.MapVauleObject.class, com.qingfeng.proto.UserProto.MapVauleObject.Builder.class);
  2918. }
  2919. // Construct using com.qingfeng.proto.UserProto.MapVauleObject.newBuilder()
  2920. private Builder() {
  2921. maybeForceBuilderInitialization();
  2922. }
  2923. private Builder(
  2924. com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
  2925. super(parent);
  2926. maybeForceBuilderInitialization();
  2927. }
  2928. private void maybeForceBuilderInitialization() {
  2929. if (com.google.protobuf.GeneratedMessageV3
  2930. .alwaysUseFieldBuilders) {
  2931. }
  2932. }
  2933. @java.lang.Override
  2934. public Builder clear() {
  2935. super.clear();
  2936. code_ = "";
  2937. name_ = "";
  2938. return this;
  2939. }
  2940. @java.lang.Override
  2941. public com.google.protobuf.Descriptors.Descriptor
  2942. getDescriptorForType() {
  2943. return com.qingfeng.proto.UserProto.internal_static_com_qingfeng_proto_MapVauleObject_descriptor;
  2944. }
  2945. @java.lang.Override
  2946. public com.qingfeng.proto.UserProto.MapVauleObject getDefaultInstanceForType() {
  2947. return com.qingfeng.proto.UserProto.MapVauleObject.getDefaultInstance();
  2948. }
  2949. @java.lang.Override
  2950. public com.qingfeng.proto.UserProto.MapVauleObject build() {
  2951. com.qingfeng.proto.UserProto.MapVauleObject result = buildPartial();
  2952. if (!result.isInitialized()) {
  2953. throw newUninitializedMessageException(result);
  2954. }
  2955. return result;
  2956. }
  2957. @java.lang.Override
  2958. public com.qingfeng.proto.UserProto.MapVauleObject buildPartial() {
  2959. com.qingfeng.proto.UserProto.MapVauleObject result = new com.qingfeng.proto.UserProto.MapVauleObject(this);
  2960. result.code_ = code_;
  2961. result.name_ = name_;
  2962. onBuilt();
  2963. return result;
  2964. }
  2965. @java.lang.Override
  2966. public Builder clone() {
  2967. return super.clone();
  2968. }
  2969. @java.lang.Override
  2970. public Builder setField(
  2971. com.google.protobuf.Descriptors.FieldDescriptor field,
  2972. java.lang.Object value) {
  2973. return super.setField(field, value);
  2974. }
  2975. @java.lang.Override
  2976. public Builder clearField(
  2977. com.google.protobuf.Descriptors.FieldDescriptor field) {
  2978. return super.clearField(field);
  2979. }
  2980. @java.lang.Override
  2981. public Builder clearOneof(
  2982. com.google.protobuf.Descriptors.OneofDescriptor oneof) {
  2983. return super.clearOneof(oneof);
  2984. }
  2985. @java.lang.Override
  2986. public Builder setRepeatedField(
  2987. com.google.protobuf.Descriptors.FieldDescriptor field,
  2988. int index, java.lang.Object value) {
  2989. return super.setRepeatedField(field, index, value);
  2990. }
  2991. @java.lang.Override
  2992. public Builder addRepeatedField(
  2993. com.google.protobuf.Descriptors.FieldDescriptor field,
  2994. java.lang.Object value) {
  2995. return super.addRepeatedField(field, value);
  2996. }
  2997. @java.lang.Override
  2998. public Builder mergeFrom(com.google.protobuf.Message other) {
  2999. if (other instanceof com.qingfeng.proto.UserProto.MapVauleObject) {
  3000. return mergeFrom((com.qingfeng.proto.UserProto.MapVauleObject)other);
  3001. } else {
  3002. super.mergeFrom(other);
  3003. return this;
  3004. }
  3005. }
  3006. public Builder mergeFrom(com.qingfeng.proto.UserProto.MapVauleObject other) {
  3007. if (other == com.qingfeng.proto.UserProto.MapVauleObject.getDefaultInstance()) return this;
  3008. if (!other.getCode().isEmpty()) {
  3009. code_ = other.code_;
  3010. onChanged();
  3011. }
  3012. if (!other.getName().isEmpty()) {
  3013. name_ = other.name_;
  3014. onChanged();
  3015. }
  3016. this.mergeUnknownFields(other.unknownFields);
  3017. onChanged();
  3018. return this;
  3019. }
  3020. @java.lang.Override
  3021. public final boolean isInitialized() {
  3022. return true;
  3023. }
  3024. @java.lang.Override
  3025. public Builder mergeFrom(
  3026. com.google.protobuf.CodedInputStream input,
  3027. com.google.protobuf.ExtensionRegistryLite extensionRegistry)
  3028. throws java.io.IOException {
  3029. com.qingfeng.proto.UserProto.MapVauleObject parsedMessage = null;
  3030. try {
  3031. parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
  3032. } catch (com.google.protobuf.InvalidProtocolBufferException e) {
  3033. parsedMessage = (com.qingfeng.proto.UserProto.MapVauleObject) e.getUnfinishedMessage();
  3034. throw e.unwrapIOException();
  3035. } finally {
  3036. if (parsedMessage != null) {
  3037. mergeFrom(parsedMessage);
  3038. }
  3039. }
  3040. return this;
  3041. }
  3042. private java.lang.Object code_ = "";
  3043. /**
  3044. * <code>string code = 1;</code>
  3045. * @return The code.
  3046. */
  3047. public java.lang.String getCode() {
  3048. java.lang.Object ref = code_;
  3049. if (!(ref instanceof java.lang.String)) {
  3050. com.google.protobuf.ByteString bs =
  3051. (com.google.protobuf.ByteString) ref;
  3052. java.lang.String s = bs.toStringUtf8();
  3053. code_ = s;
  3054. return s;
  3055. } else {
  3056. return (java.lang.String) ref;
  3057. }
  3058. }
  3059. /**
  3060. * <code>string code = 1;</code>
  3061. * @return The bytes for code.
  3062. */
  3063. public com.google.protobuf.ByteString
  3064. getCodeBytes() {
  3065. java.lang.Object ref = code_;
  3066. if (ref instanceof String) {
  3067. com.google.protobuf.ByteString b =
  3068. com.google.protobuf.ByteString.copyFromUtf8(
  3069. (java.lang.String) ref);
  3070. code_ = b;
  3071. return b;
  3072. } else {
  3073. return (com.google.protobuf.ByteString) ref;
  3074. }
  3075. }
  3076. /**
  3077. * <code>string code = 1;</code>
  3078. * @param value The code to set.
  3079. * @return This builder for chaining.
  3080. */
  3081. public Builder setCode(
  3082. java.lang.String value) {
  3083. if (value == null) {
  3084. throw new NullPointerException();
  3085. }
  3086. code_ = value;
  3087. onChanged();
  3088. return this;
  3089. }
  3090. /**
  3091. * <code>string code = 1;</code>
  3092. * @return This builder for chaining.
  3093. */
  3094. public Builder clearCode() {
  3095. code_ = getDefaultInstance().getCode();
  3096. onChanged();
  3097. return this;
  3098. }
  3099. /**
  3100. * <code>string code = 1;</code>
  3101. * @param value The bytes for code to set.
  3102. * @return This builder for chaining.
  3103. */
  3104. public Builder setCodeBytes(
  3105. com.google.protobuf.ByteString value) {
  3106. if (value == null) {
  3107. throw new NullPointerException();
  3108. }
  3109. checkByteStringIsUtf8(value);
  3110. code_ = value;
  3111. onChanged();
  3112. return this;
  3113. }
  3114. private java.lang.Object name_ = "";
  3115. /**
  3116. * <code>string name = 2;</code>
  3117. * @return The name.
  3118. */
  3119. public java.lang.String getName() {
  3120. java.lang.Object ref = name_;
  3121. if (!(ref instanceof java.lang.String)) {
  3122. com.google.protobuf.ByteString bs =
  3123. (com.google.protobuf.ByteString) ref;
  3124. java.lang.String s = bs.toStringUtf8();
  3125. name_ = s;
  3126. return s;
  3127. } else {
  3128. return (java.lang.String) ref;
  3129. }
  3130. }
  3131. /**
  3132. * <code>string name = 2;</code>
  3133. * @return The bytes for name.
  3134. */
  3135. public com.google.protobuf.ByteString
  3136. getNameBytes() {
  3137. java.lang.Object ref = name_;
  3138. if (ref instanceof String) {
  3139. com.google.protobuf.ByteString b =
  3140. com.google.protobuf.ByteString.copyFromUtf8(
  3141. (java.lang.String) ref);
  3142. name_ = b;
  3143. return b;
  3144. } else {
  3145. return (com.google.protobuf.ByteString) ref;
  3146. }
  3147. }
  3148. /**
  3149. * <code>string name = 2;</code>
  3150. * @param value The name to set.
  3151. * @return This builder for chaining.
  3152. */
  3153. public Builder setName(
  3154. java.lang.String value) {
  3155. if (value == null) {
  3156. throw new NullPointerException();
  3157. }
  3158. name_ = value;
  3159. onChanged();
  3160. return this;
  3161. }
  3162. /**
  3163. * <code>string name = 2;</code>
  3164. * @return This builder for chaining.
  3165. */
  3166. public Builder clearName() {
  3167. name_ = getDefaultInstance().getName();
  3168. onChanged();
  3169. return this;
  3170. }
  3171. /**
  3172. * <code>string name = 2;</code>
  3173. * @param value The bytes for name to set.
  3174. * @return This builder for chaining.
  3175. */
  3176. public Builder setNameBytes(
  3177. com.google.protobuf.ByteString value) {
  3178. if (value == null) {
  3179. throw new NullPointerException();
  3180. }
  3181. checkByteStringIsUtf8(value);
  3182. name_ = value;
  3183. onChanged();
  3184. return this;
  3185. }
  3186. @java.lang.Override
  3187. public final Builder setUnknownFields(
  3188. final com.google.protobuf.UnknownFieldSet unknownFields) {
  3189. return super.setUnknownFields(unknownFields);
  3190. }
  3191. @java.lang.Override
  3192. public final Builder mergeUnknownFields(
  3193. final com.google.protobuf.UnknownFieldSet unknownFields) {
  3194. return super.mergeUnknownFields(unknownFields);
  3195. }
  3196. // @@protoc_insertion_point(builder_scope:com.qingfeng.proto.MapVauleObject)
  3197. }
  3198. // @@protoc_insertion_point(class_scope:com.qingfeng.proto.MapVauleObject)
  3199. private static final com.qingfeng.proto.UserProto.MapVauleObject DEFAULT_INSTANCE;
  3200. static {
  3201. DEFAULT_INSTANCE = new com.qingfeng.proto.UserProto.MapVauleObject();
  3202. }
  3203. public static com.qingfeng.proto.UserProto.MapVauleObject getDefaultInstance() {
  3204. return DEFAULT_INSTANCE;
  3205. }
  3206. private static final com.google.protobuf.Parser<MapVauleObject>
  3207. PARSER = new com.google.protobuf.AbstractParser<MapVauleObject>() {
  3208. @java.lang.Override
  3209. public MapVauleObject parsePartialFrom(
  3210. com.google.protobuf.CodedInputStream input,
  3211. com.google.protobuf.ExtensionRegistryLite extensionRegistry)
  3212. throws com.google.protobuf.InvalidProtocolBufferException {
  3213. return new MapVauleObject(input, extensionRegistry);
  3214. }
  3215. };
  3216. public static com.google.protobuf.Parser<MapVauleObject> parser() {
  3217. return PARSER;
  3218. }
  3219. @java.lang.Override
  3220. public com.google.protobuf.Parser<MapVauleObject> getParserForType() {
  3221. return PARSER;
  3222. }
  3223. @java.lang.Override
  3224. public com.qingfeng.proto.UserProto.MapVauleObject getDefaultInstanceForType() {
  3225. return DEFAULT_INSTANCE;
  3226. }
  3227. }
  3228. private static final com.google.protobuf.Descriptors.Descriptor
  3229. internal_static_com_qingfeng_proto_User_descriptor;
  3230. private static final
  3231. com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
  3232. internal_static_com_qingfeng_proto_User_fieldAccessorTable;
  3233. private static final com.google.protobuf.Descriptors.Descriptor
  3234. internal_static_com_qingfeng_proto_User_MapEntry_descriptor;
  3235. private static final
  3236. com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
  3237. internal_static_com_qingfeng_proto_User_MapEntry_fieldAccessorTable;
  3238. private static final com.google.protobuf.Descriptors.Descriptor
  3239. internal_static_com_qingfeng_proto_User_MapObjectEntry_descriptor;
  3240. private static final
  3241. com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
  3242. internal_static_com_qingfeng_proto_User_MapObjectEntry_fieldAccessorTable;
  3243. private static final com.google.protobuf.Descriptors.Descriptor
  3244. internal_static_com_qingfeng_proto_NickName_descriptor;
  3245. private static final
  3246. com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
  3247. internal_static_com_qingfeng_proto_NickName_fieldAccessorTable;
  3248. private static final com.google.protobuf.Descriptors.Descriptor
  3249. internal_static_com_qingfeng_proto_MapVauleObject_descriptor;
  3250. private static final
  3251. com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
  3252. internal_static_com_qingfeng_proto_MapVauleObject_fieldAccessorTable;
  3253. public static com.google.protobuf.Descriptors.FileDescriptor
  3254. getDescriptor() {
  3255. return descriptor;
  3256. }
  3257. private static com.google.protobuf.Descriptors.FileDescriptor
  3258. descriptor;
  3259. static {
  3260. java.lang.String[] descriptorData = {
  3261. "\n\nUser.proto\022\022com.qingfeng.proto\"\335\002\n\004Use" +
  3262. "r\022\n\n\002id\030\001 \001(\005\022\014\n\004code\030\002 \001(\t\022\014\n\004name\030\003 \001(" +
  3263. "\t\022.\n\010nickName\030\004 \001(\0132\034.com.qingfeng.proto" +
  3264. ".NickName\022\017\n\007strList\030\005 \003(\t\022.\n\003map\030\006 \003(\0132" +
  3265. "!.com.qingfeng.proto.User.MapEntry\022:\n\tma" +
  3266. "pObject\030\007 \003(\0132\'.com.qingfeng.proto.User." +
  3267. "MapObjectEntry\032*\n\010MapEntry\022\013\n\003key\030\001 \001(\t\022" +
  3268. "\r\n\005value\030\002 \001(\t:\0028\001\032T\n\016MapObjectEntry\022\013\n\003" +
  3269. "key\030\001 \001(\t\0221\n\005value\030\002 \001(\0132\".com.qingfeng." +
  3270. "proto.MapVauleObject:\0028\001\"\034\n\010NickName\022\020\n\010" +
  3271. "nickName\030\001 \001(\t\",\n\016MapVauleObject\022\014\n\004code" +
  3272. "\030\001 \001(\t\022\014\n\004name\030\002 \001(\tB\037\n\022com.qingfeng.pro" +
  3273. "toB\tUserProtob\006proto3"
  3274. };
  3275. descriptor = com.google.protobuf.Descriptors.FileDescriptor
  3276. .internalBuildGeneratedFileFrom(descriptorData,
  3277. new com.google.protobuf.Descriptors.FileDescriptor[] {
  3278. });
  3279. internal_static_com_qingfeng_proto_User_descriptor =
  3280. getDescriptor().getMessageTypes().get(0);
  3281. internal_static_com_qingfeng_proto_User_fieldAccessorTable = new
  3282. com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
  3283. internal_static_com_qingfeng_proto_User_descriptor,
  3284. new java.lang.String[] { "Id", "Code", "Name", "NickName", "StrList", "Map", "MapObject", });
  3285. internal_static_com_qingfeng_proto_User_MapEntry_descriptor =
  3286. internal_static_com_qingfeng_proto_User_descriptor.getNestedTypes().get(0);
  3287. internal_static_com_qingfeng_proto_User_MapEntry_fieldAccessorTable = new
  3288. com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
  3289. internal_static_com_qingfeng_proto_User_MapEntry_descriptor,
  3290. new java.lang.String[] { "Key", "Value", });
  3291. internal_static_com_qingfeng_proto_User_MapObjectEntry_descriptor =
  3292. internal_static_com_qingfeng_proto_User_descriptor.getNestedTypes().get(1);
  3293. internal_static_com_qingfeng_proto_User_MapObjectEntry_fieldAccessorTable = new
  3294. com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
  3295. internal_static_com_qingfeng_proto_User_MapObjectEntry_descriptor,
  3296. new java.lang.String[] { "Key", "Value", });
  3297. internal_static_com_qingfeng_proto_NickName_descriptor =
  3298. getDescriptor().getMessageTypes().get(1);
  3299. internal_static_com_qingfeng_proto_NickName_fieldAccessorTable = new
  3300. com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
  3301. internal_static_com_qingfeng_proto_NickName_descriptor,
  3302. new java.lang.String[] { "NickName", });
  3303. internal_static_com_qingfeng_proto_MapVauleObject_descriptor =
  3304. getDescriptor().getMessageTypes().get(2);
  3305. internal_static_com_qingfeng_proto_MapVauleObject_fieldAccessorTable = new
  3306. com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
  3307. internal_static_com_qingfeng_proto_MapVauleObject_descriptor,
  3308. new java.lang.String[] { "Code", "Name", });
  3309. }
  3310. // @@protoc_insertion_point(outer_class_scope)
  3311. }

新建UserTest测试类

package com.qingfeng.test;

import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.MessageOrBuilder;
import com.google.protobuf.TextFormat;
import com.qingfeng.proto.UserProto;

import java.util.Arrays;

/**
 * @author Administrator
 * @version 1.0.0
 * @ProjectName com.qingfeng-client
 * @Description TODO
 * @createTime 2022年05月01日 18:44:00
 */
public class UserTest {

    public static void main(String[] args) {

        //初始化数据
        UserProto.User.Builder user = UserProto.User.newBuilder();
        user.setId(1)
                .setCode("001")
                .setName("张三")
                .build();

        //内部对象
        UserProto.NickName.Builder nickName = UserProto.NickName.newBuilder();
        user.setNickName(nickName.setNickName("昵称").build());

        //简单 list
        user.addStrList("01");
        user.addStrList("02");

        //简单 map
        user.putMap("key1", "value1");
        user.putMap("key2", "value2");

        //object map
        UserProto.MapVauleObject.Builder objectMap1 = UserProto.MapVauleObject.newBuilder();
        user.putMapObject("objectMap1", objectMap1.setCode("code1").setName("name1").build());

        UserProto.MapVauleObject.Builder objectMap2 = UserProto.MapVauleObject.newBuilder();
        user.putMapObject("objectMap2", objectMap2.setCode("code2").setName("name2").build());


        //序列化
        UserProto.User build = user.build();
        //转换成字节数组
        byte[] s = build.toByteArray();
        System.out.println("protobuf数据bytes[]:" + Arrays.toString(s));
        System.out.println("protobuf序列化大小: " + s.length);


        UserProto.User user1 = null;
        String jsonObject = null;
        try {
            //反序列化
            user1 = UserProto.User.parseFrom(s);
            System.out.println("反序列化:\n" + user1.toString());
            System.out.println("中文反序列化:\n" + printToUnicodeString(user1));

        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
//        System.out.println("***********************************************");
//        //中文反序列化时会转成八进制,可采用 TextFormat.printToUnicodeString 进行转换
//        System.out.println("直接反序列化:\n" + printToUnicodeString(user1));
    }

    /**
     * 处理反序列化时中文出现的八进制问题(属性值为中文时可能会出现这样的八进制\346\223\215\344\275\234\345\221\230)
     * 可直接使用 protobuf 自带的 TextFormat.printToUnicodeString(message) 方法,但是这个方法过时了,直接从这个方法内部拿出来使用就可以了
     *
     * @param message 转换的 protobuf 对象
     * @return string
     */
    public static String printToUnicodeString(MessageOrBuilder message) {
        return TextFormat.printer().escapingNonAscii(false).printToString(message);
    }

}

protobuf 和 JSON 互相转换

使用这个转换必须要使用 protobuf 的 java util jar 包

         <!--  proto 与 Json 互转会用到-->
        <dependency>
            <groupId>com.google.protobuf</groupId>
            <artifactId>protobuf-java-util</artifactId>
            <version>3.15.3</version>
        </dependency>

protobuf 转 Json

String json = JsonFormat.printer().print(sourceMessage);

Json 转 protobuf

JsonFormat.parser().ignoringUnknownFields().merge(json, targetBuilder);
return targetBuilder.build();

protobuf 和 JSON 互转工具类

package com.qingfeng.utils;

import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.Message;
import com.google.protobuf.util.JsonFormat;

/**
 * @ProjectName ProtoJsonUtil
 * @author Administrator
 * @version 1.0.0
 * @Description
 * <ul> 注意:
 *  <li>该实现无法处理含有Any类型字段的Message</li>
 *  <li>enum类型数据会转化为enum的字符串名</li>
 *  <li>bytes会转化为utf8编码的字符串</li>
 * </ul> 以上这段暂未进行测试
 * @createTime 2022/5/1 0001 18:50
 */
public class ProtoJsonUtil {
    /**
     * proto 对象转 JSON
     * 使用方法: //反序列化之后
     *             UserProto.User user1 = UserProto.User.parseFrom(user);
     *             //转 json
     *             String jsonObject = ProtoJsonUtil.toJson(user1);
     * @param sourceMessage proto 对象
     * @return 返回 JSON 数据
     * @throws InvalidProtocolBufferException
     */
    public static String toJson(Message sourceMessage) throws InvalidProtocolBufferException {
        if (sourceMessage != null) {
            String json = JsonFormat.printer().includingDefaultValueFields().print(sourceMessage);
            return json;
        }
        return null;
    }

    /**
     * JSON 转 proto 对象
     * 使用方法:Message message = ProtoJsonUtil.toObject(UserProto.User.newBuilder(), jsonObject);
     * @param targetBuilder proto 对象 bulider
     * @param json          json 数据
     * @return 返回转换后的 proto 对象
     * @throws InvalidProtocolBufferException
     */
    public static Message toObject(Message.Builder targetBuilder, String json) throws InvalidProtocolBufferException {
        if (json != null) {
            //ignoringUnknownFields 如果 json 串中存在的属性 proto 对象中不存在,则进行忽略,否则会抛出异常
            JsonFormat.parser().ignoringUnknownFields().merge(json, targetBuilder);
            return targetBuilder.build();
        }
        return null;
    }
}

修改json转换

image.png

protobuf 与 Java 对象互转

使用了 lombok 和 Gson,需要导入依赖

<dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.6</version>
        </dependency>

创建对应 Java 实体类

1、创建User实体类

/**
 * @author Administrator
 * @version 1.0.0
 * @ProjectName com.qingfeng-client
 * @Description TODO
 * @createTime 2022年05月01日 18:53:00
 */
@Data
public class User {

    private int id;
    private String code;
    private String name;
    private NickName nickName;
    private List<String> strList;
    private Map<String,String> map;
    private Map<String,MapVauleObject> mapObject;

}

创建NickName

/**
 * @author Administrator
 * @version 1.0.0
 * @ProjectName com.qingfeng-client
 * @Description TODO
 * @createTime 2022年05月01日 18:55:00
 */
@Data
public class NickName {

    private String NickName;

}

创建MapVauleObject

/**
 * @author Administrator
 * @version 1.0.0
 * @ProjectName com.qingfeng-client
 * @Description TODO
 * @createTime 2022年05月01日 18:57:00
 */
@Data
public class MapVauleObject {

    private String code;
    private String name;

}

修改实体转换

image.png

完整的测试类

package com.qingfeng.test;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.MessageOrBuilder;
import com.google.protobuf.TextFormat;
import com.qingfeng.entity.User;
import com.qingfeng.proto.UserProto;
import com.qingfeng.utils.ProtoJsonUtil;
import org.apache.commons.beanutils.BeanUtils;

import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;

/**
 * @author Administrator
 * @version 1.0.0
 * @ProjectName com.qingfeng-client
 * @Description TODO
 * @createTime 2022年05月01日 18:44:00
 */
public class UserTest {

    public static void main(String[] args) {

        //初始化数据
        UserProto.User.Builder user = UserProto.User.newBuilder();
        user.setId(1)
                .setCode("001")
                .setName("张三")
                .build();

        //内部对象
        UserProto.NickName.Builder nickName = UserProto.NickName.newBuilder();
        user.setNickName(nickName.setNickName("昵称").build());

        //简单 list
        user.addStrList("01");
        user.addStrList("02");

        //简单 map
        user.putMap("key1", "value1");
        user.putMap("key2", "value2");

        //object map
        UserProto.MapVauleObject.Builder objectMap1 = UserProto.MapVauleObject.newBuilder();
        user.putMapObject("objectMap1", objectMap1.setCode("code1").setName("name1").build());

        UserProto.MapVauleObject.Builder objectMap2 = UserProto.MapVauleObject.newBuilder();
        user.putMapObject("objectMap2", objectMap2.setCode("code2").setName("name2").build());


        //序列化
        UserProto.User build = user.build();
        //转换成字节数组
        byte[] s = build.toByteArray();
        System.out.println("protobuf数据bytes[]:" + Arrays.toString(s));
        System.out.println("protobuf序列化大小: " + s.length);


        UserProto.User user1 = null;
        String jsonObject = null;
        try {
            //反序列化
            user1 = UserProto.User.parseFrom(s);
            System.out.println("反序列化:\n" + user1.toString());
            System.out.println("中文反序列化:\n" + printToUnicodeString(user1));

            //proto 转 json
            System.out.println("--------------------");
            jsonObject = ProtoJsonUtil.toJson(user1);
            System.out.println(jsonObject);


            // 复制 proto 对象到 Java 对象 测试,测试下来只能复制基础的属性,内部对象等不可以复制,也就是只有浅拷贝
            User user2 = new User();
            BeanUtils.copyProperties(user1, user2);
            System.out.println("复制后对象:\n " + user2.toString());


            //通过 proto Json 数据转 Java 对象
            Gson GSON = new GsonBuilder().serializeNulls().create();
            User user3 = GSON.fromJson(jsonObject, User.class);
            System.out.println("json 转换之后对象:\n " + user3.toString());

        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
//        System.out.println("***********************************************");
//        //中文反序列化时会转成八进制,可采用 TextFormat.printToUnicodeString 进行转换
//        System.out.println("直接反序列化:\n" + printToUnicodeString(user1));
    }

    /**
     * 处理反序列化时中文出现的八进制问题(属性值为中文时可能会出现这样的八进制\346\223\215\344\275\234\345\221\230)
     * 可直接使用 protobuf 自带的 TextFormat.printToUnicodeString(message) 方法,但是这个方法过时了,直接从这个方法内部拿出来使用就可以了
     *
     * @param message 转换的 protobuf 对象
     * @return string
     */
    public static String printToUnicodeString(MessageOrBuilder message) {
        return TextFormat.printer().escapingNonAscii(false).printToString(message);
    }

}