什么是 protobuf
Protocal Buffers(简称protobuf)是谷歌的一项技术,用于结构化的数据序列化、反序列化。
Protocol Buffers 是一种语言无关、平台无关、可扩展的序列化结构数据的方法,它可用于(数据)通信协议、数据存储等。
Protocol Buffers 是一种灵活,高效,自动化机制的结构数据序列化方法-可类比 XML,但是比 XML 更小(3 ~ 10倍)、更快(20 ~ 100倍)、更为简单。
你可以定义数据的结构,然后使用特殊生成的源代码轻松的在各种数据流中使用各种语言进行编写和读取结构数据。你甚至可以更新数据结构,而不破坏由旧数据结构编译的已部署程序
protobuf 就是一个序列化数据和反序列化数据的方法,类似的还有 XML、Json、Java 的 Serializable 等。
但protobuf的效率高于XML、Json,不过protobuf生成的是字节码,可读性相比之略差
生成代码指定
protoc demo.proto --java_out=./
--cpp_out :在目标目录DST_DIR中产生C++代码
--java_out :在目标目录DST_DIR中产生Java代码
--python_out :在目标目录 DST_DIR 中产生Python代码
--go_out :在目标目录 DST_DIR 中产生Go代码
--ruby_out:在目标目录 DST_DIR 中产生Ruby代码
--javanano_out:在目标目录DST_DIR中生成JavaNano
--objc_out:在目标目录DST_DIR中产生Object代码
--csharp_out:在目标目录DST_DIR中产生Object代码
--php_out:在目标目录DST_DIR中产生Object代码
protobuf安装配置
protobuf编辑器安装
下载地址:https://github.com/protocolbuffers/protobuf/releases
配置环境变量
打开cmd命令行,输入
protoc
protoc --version
# 生成protoc代码
protoc demo.proto --java_out=./
IDEA配置protobuf
1、File->Setting->Plugins
安装protobuf插件
重启之后我们可以在工具栏看到这两个选项
一个是配置全局的 protobuf
一个是生成所有的 protobuf 文件
2、配置protobufs :Configure->GenProtobuf
此处配置的是安装的protoc.exe
protoc path :我们下载的 protobuf 编辑器的位置,在 bin 目录下有一个 .exe 文件
quick gen : 对应的语言,这里选择伟大的 Java
简单-proto案例
1、引入pom依赖
<!-- protobuf 支持 Java 核心包-->
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.20.1</version>
</dependency>
<!-- proto 与 Json 互转会用到-->
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java-util</artifactId>
<version>3.20.1</version>
</dependency>
2、编写 .proto 文件
新建一个 demo.proto
//使用 proto3 语法 ,未指定则使用proto2
syntax = "proto3";
//生成 proto 文件所在包路径
package com.qingfeng.proto;
//生成 proto 文件所在包路径
option java_package = "com.qingfeng.proto";
//生成 proto 文件名
option java_outer_classname="DemoProto";
message Demo{
//自身属性
int32 id = 1;
string code = 2;
string name = 3;
}
3、生成 proto 对象
选中我们新建的.proto 文件,右键,选择框中的选项就可以生成了,将生成之后的文件拷贝到java目录下面。
4、新建测试类
package com.qingfeng.test;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.util.JsonFormat;
import com.qingfeng.proto.DemoProto;
import java.util.Arrays;
/**
* @author Administrator
* @version 1.0.0
* @ProjectName com.qingfeng-client
* @Description TODO
* @createTime 2022年05月01日 18:10:00
*/
public class DemoTest {
public static void main(String[] args) {
//初始化数据
DemoProto.Demo.Builder demo = DemoProto.Demo.newBuilder();
demo.setId(1)
.setCode("001")
.setName("张三")
.build();
//序列化
DemoProto.Demo build = demo.build();
//转换成字节数组
byte[] s = build.toByteArray();
System.out.println("protobuf数据bytes[]:" + Arrays.toString(s));
System.out.println("protobuf序列化大小: " + s.length);
DemoProto.Demo demo1 = null;
String jsonObject = null;
try {
//反序列化
demo1 = DemoProto.Demo.parseFrom(s);
//转 json
jsonObject = JsonFormat.printer().print(demo1);
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
}
System.out.println("Json格式化结果:\n" + jsonObject);
System.out.println("Json格式化数据大小: " + jsonObject.getBytes().length);
}
}
protobuf 与 Java 数据类型对应
1、字段规则
required : 字段只能也必须出现 1 次,多用于必填项,必须赋值的字符
required int32 id = 1
optional : 字段可出现 0 次或多次,可有可无的字段,可以使用[default = xxx]配置默认值
optional string name = 1 [default = "张三"]
repeated : 字段可出现任意多次(包括 0),多用于 Java List 属性
//list String
repeated string strList = 5;
//list 对象
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 的定义
//创建一个 User 对象
message User{
//list Int
repeated int32 intList = 1;
//list String
repeated string strList = 5;
}
Java 对象 List 在 protobuf 的定义
//创建一个 User 对象
message User{
//list 对象
repeated Role roleList = 6;
}
Java String、Integer Map 在 protobuf 的定义
//创建一个 User 对象
message User{
// 定义简单的 Map string
map<string, int32> intMap = 7;
// 定义复杂的 Map 对象
map<string, string> stringMap = 8;
}
Java 对象 Map 在 protobuf 的定义
//创建一个 User 对象
message User{
// 定义复杂的 Map 对象
map<string, MapVauleObject> mapObject = 8;
}
// 定义 Map 的 value 对象
message MapVauleObject {
string code = 1;
string name = 2;
}
Java 实体类中嵌套实体 在 protobuf 的定义
//创建一个 User 对象
message User{
// 对象
NickName nickName = 4;
}
// 定义一个新的Name对象
message NickName {
string nickName = 1;
}
复杂-Proto案例
新增user.proto文件
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: User.proto
package com.qingfeng.proto;
public final class UserProto {
private UserProto() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistryLite registry) {
}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
registerAllExtensions(
(com.google.protobuf.ExtensionRegistryLite) registry);
}
public interface UserOrBuilder extends
// @@protoc_insertion_point(interface_extends:com.qingfeng.proto.User)
com.google.protobuf.MessageOrBuilder {
/**
* <pre>
*自身属性
* </pre>
*
* <code>int32 id = 1;</code>
* @return The id.
*/
int getId();
/**
* <code>string code = 2;</code>
* @return The code.
*/
java.lang.String getCode();
/**
* <code>string code = 2;</code>
* @return The bytes for code.
*/
com.google.protobuf.ByteString
getCodeBytes();
/**
* <code>string name = 3;</code>
* @return The name.
*/
java.lang.String getName();
/**
* <code>string name = 3;</code>
* @return The bytes for name.
*/
com.google.protobuf.ByteString
getNameBytes();
/**
* <pre>
* 对象
* </pre>
*
* <code>.com.qingfeng.proto.NickName nickName = 4;</code>
* @return Whether the nickName field is set.
*/
boolean hasNickName();
/**
* <pre>
* 对象
* </pre>
*
* <code>.com.qingfeng.proto.NickName nickName = 4;</code>
* @return The nickName.
*/
com.qingfeng.proto.UserProto.NickName getNickName();
/**
* <pre>
* 对象
* </pre>
*
* <code>.com.qingfeng.proto.NickName nickName = 4;</code>
*/
com.qingfeng.proto.UserProto.NickNameOrBuilder getNickNameOrBuilder();
/**
* <pre>
*list 引用类型
* </pre>
*
* <code>repeated string strList = 5;</code>
* @return A list containing the strList.
*/
java.util.List<java.lang.String>
getStrListList();
/**
* <pre>
*list 引用类型
* </pre>
*
* <code>repeated string strList = 5;</code>
* @return The count of strList.
*/
int getStrListCount();
/**
* <pre>
*list 引用类型
* </pre>
*
* <code>repeated string strList = 5;</code>
* @param index The index of the element to return.
* @return The strList at the given index.
*/
java.lang.String getStrList(int index);
/**
* <pre>
*list 引用类型
* </pre>
*
* <code>repeated string strList = 5;</code>
* @param index The index of the value to return.
* @return The bytes of the strList at the given index.
*/
com.google.protobuf.ByteString
getStrListBytes(int index);
/**
* <pre>
* 定义简单的 Map string
* </pre>
*
* <code>map<string, string> map = 6;</code>
*/
int getMapCount();
/**
* <pre>
* 定义简单的 Map string
* </pre>
*
* <code>map<string, string> map = 6;</code>
*/
boolean containsMap(
java.lang.String key);
/**
* Use {@link #getMapMap()} instead.
*/
@java.lang.Deprecated
java.util.Map<java.lang.String, java.lang.String>
getMap();
/**
* <pre>
* 定义简单的 Map string
* </pre>
*
* <code>map<string, string> map = 6;</code>
*/
java.util.Map<java.lang.String, java.lang.String>
getMapMap();
/**
* <pre>
* 定义简单的 Map string
* </pre>
*
* <code>map<string, string> map = 6;</code>
*/
/* nullable */
java.lang.String getMapOrDefault(
java.lang.String key,
/* nullable */
java.lang.String defaultValue);
/**
* <pre>
* 定义简单的 Map string
* </pre>
*
* <code>map<string, string> map = 6;</code>
*/
java.lang.String getMapOrThrow(
java.lang.String key);
/**
* <pre>
* 定义复杂的 Map 对象
* </pre>
*
* <code>map<string, .com.qingfeng.proto.MapVauleObject> mapObject = 7;</code>
*/
int getMapObjectCount();
/**
* <pre>
* 定义复杂的 Map 对象
* </pre>
*
* <code>map<string, .com.qingfeng.proto.MapVauleObject> mapObject = 7;</code>
*/
boolean containsMapObject(
java.lang.String key);
/**
* Use {@link #getMapObjectMap()} instead.
*/
@java.lang.Deprecated
java.util.Map<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject>
getMapObject();
/**
* <pre>
* 定义复杂的 Map 对象
* </pre>
*
* <code>map<string, .com.qingfeng.proto.MapVauleObject> mapObject = 7;</code>
*/
java.util.Map<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject>
getMapObjectMap();
/**
* <pre>
* 定义复杂的 Map 对象
* </pre>
*
* <code>map<string, .com.qingfeng.proto.MapVauleObject> mapObject = 7;</code>
*/
/* nullable */
com.qingfeng.proto.UserProto.MapVauleObject getMapObjectOrDefault(
java.lang.String key,
/* nullable */
com.qingfeng.proto.UserProto.MapVauleObject defaultValue);
/**
* <pre>
* 定义复杂的 Map 对象
* </pre>
*
* <code>map<string, .com.qingfeng.proto.MapVauleObject> mapObject = 7;</code>
*/
com.qingfeng.proto.UserProto.MapVauleObject getMapObjectOrThrow(
java.lang.String key);
}
/**
* <pre>
*创建一个 User 对象
* </pre>
*
* Protobuf type {@code com.qingfeng.proto.User}
*/
public static final class User extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:com.qingfeng.proto.User)
UserOrBuilder {
private static final long serialVersionUID = 0L;
// Use User.newBuilder() to construct.
private User(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private User() {
code_ = "";
name_ = "";
strList_ = com.google.protobuf.LazyStringArrayList.EMPTY;
}
@java.lang.Override
@SuppressWarnings({"unused"})
protected java.lang.Object newInstance(
UnusedPrivateParameter unused) {
return new User();
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private User(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
if (extensionRegistry == null) {
throw new java.lang.NullPointerException();
}
int mutable_bitField0_ = 0;
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
com.google.protobuf.UnknownFieldSet.newBuilder();
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
case 8: {
id_ = input.readInt32();
break;
}
case 18: {
java.lang.String s = input.readStringRequireUtf8();
code_ = s;
break;
}
case 26: {
java.lang.String s = input.readStringRequireUtf8();
name_ = s;
break;
}
case 34: {
com.qingfeng.proto.UserProto.NickName.Builder subBuilder = null;
if (nickName_ != null) {
subBuilder = nickName_.toBuilder();
}
nickName_ = input.readMessage(com.qingfeng.proto.UserProto.NickName.parser(), extensionRegistry);
if (subBuilder != null) {
subBuilder.mergeFrom(nickName_);
nickName_ = subBuilder.buildPartial();
}
break;
}
case 42: {
java.lang.String s = input.readStringRequireUtf8();
if (!((mutable_bitField0_ & 0x00000001) != 0)) {
strList_ = new com.google.protobuf.LazyStringArrayList();
mutable_bitField0_ |= 0x00000001;
}
strList_.add(s);
break;
}
case 50: {
if (!((mutable_bitField0_ & 0x00000002) != 0)) {
map_ = com.google.protobuf.MapField.newMapField(
MapDefaultEntryHolder.defaultEntry);
mutable_bitField0_ |= 0x00000002;
}
com.google.protobuf.MapEntry<java.lang.String, java.lang.String>
map__ = input.readMessage(
MapDefaultEntryHolder.defaultEntry.getParserForType(), extensionRegistry);
map_.getMutableMap().put(
map__.getKey(), map__.getValue());
break;
}
case 58: {
if (!((mutable_bitField0_ & 0x00000004) != 0)) {
mapObject_ = com.google.protobuf.MapField.newMapField(
MapObjectDefaultEntryHolder.defaultEntry);
mutable_bitField0_ |= 0x00000004;
}
com.google.protobuf.MapEntry<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject>
mapObject__ = input.readMessage(
MapObjectDefaultEntryHolder.defaultEntry.getParserForType(), extensionRegistry);
mapObject_.getMutableMap().put(
mapObject__.getKey(), mapObject__.getValue());
break;
}
default: {
if (!parseUnknownField(
input, unknownFields, extensionRegistry, tag)) {
done = true;
}
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(this);
} catch (com.google.protobuf.UninitializedMessageException e) {
throw e.asInvalidProtocolBufferException().setUnfinishedMessage(this);
} catch (java.io.IOException e) {
throw new com.google.protobuf.InvalidProtocolBufferException(
e).setUnfinishedMessage(this);
} finally {
if (((mutable_bitField0_ & 0x00000001) != 0)) {
strList_ = strList_.getUnmodifiableView();
}
this.unknownFields = unknownFields.build();
makeExtensionsImmutable();
}
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return com.qingfeng.proto.UserProto.internal_static_com_qingfeng_proto_User_descriptor;
}
@SuppressWarnings({"rawtypes"})
@java.lang.Override
protected com.google.protobuf.MapField internalGetMapField(
int number) {
switch (number) {
case 6:
return internalGetMap();
case 7:
return internalGetMapObject();
default:
throw new RuntimeException(
"Invalid map field number: " + number);
}
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return com.qingfeng.proto.UserProto.internal_static_com_qingfeng_proto_User_fieldAccessorTable
.ensureFieldAccessorsInitialized(
com.qingfeng.proto.UserProto.User.class, com.qingfeng.proto.UserProto.User.Builder.class);
}
public static final int ID_FIELD_NUMBER = 1;
private int id_;
/**
* <pre>
*自身属性
* </pre>
*
* <code>int32 id = 1;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
public static final int CODE_FIELD_NUMBER = 2;
private volatile java.lang.Object code_;
/**
* <code>string code = 2;</code>
* @return The code.
*/
@java.lang.Override
public java.lang.String getCode() {
java.lang.Object ref = code_;
if (ref instanceof java.lang.String) {
return (java.lang.String) ref;
} else {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
code_ = s;
return s;
}
}
/**
* <code>string code = 2;</code>
* @return The bytes for code.
*/
@java.lang.Override
public com.google.protobuf.ByteString
getCodeBytes() {
java.lang.Object ref = code_;
if (ref instanceof java.lang.String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
code_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
public static final int NAME_FIELD_NUMBER = 3;
private volatile java.lang.Object name_;
/**
* <code>string name = 3;</code>
* @return The name.
*/
@java.lang.Override
public java.lang.String getName() {
java.lang.Object ref = name_;
if (ref instanceof java.lang.String) {
return (java.lang.String) ref;
} else {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
name_ = s;
return s;
}
}
/**
* <code>string name = 3;</code>
* @return The bytes for name.
*/
@java.lang.Override
public com.google.protobuf.ByteString
getNameBytes() {
java.lang.Object ref = name_;
if (ref instanceof java.lang.String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
name_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
public static final int NICKNAME_FIELD_NUMBER = 4;
private com.qingfeng.proto.UserProto.NickName nickName_;
/**
* <pre>
* 对象
* </pre>
*
* <code>.com.qingfeng.proto.NickName nickName = 4;</code>
* @return Whether the nickName field is set.
*/
@java.lang.Override
public boolean hasNickName() {
return nickName_ != null;
}
/**
* <pre>
* 对象
* </pre>
*
* <code>.com.qingfeng.proto.NickName nickName = 4;</code>
* @return The nickName.
*/
@java.lang.Override
public com.qingfeng.proto.UserProto.NickName getNickName() {
return nickName_ == null ? com.qingfeng.proto.UserProto.NickName.getDefaultInstance() : nickName_;
}
/**
* <pre>
* 对象
* </pre>
*
* <code>.com.qingfeng.proto.NickName nickName = 4;</code>
*/
@java.lang.Override
public com.qingfeng.proto.UserProto.NickNameOrBuilder getNickNameOrBuilder() {
return getNickName();
}
public static final int STRLIST_FIELD_NUMBER = 5;
private com.google.protobuf.LazyStringList strList_;
/**
* <pre>
*list 引用类型
* </pre>
*
* <code>repeated string strList = 5;</code>
* @return A list containing the strList.
*/
public com.google.protobuf.ProtocolStringList
getStrListList() {
return strList_;
}
/**
* <pre>
*list 引用类型
* </pre>
*
* <code>repeated string strList = 5;</code>
* @return The count of strList.
*/
public int getStrListCount() {
return strList_.size();
}
/**
* <pre>
*list 引用类型
* </pre>
*
* <code>repeated string strList = 5;</code>
* @param index The index of the element to return.
* @return The strList at the given index.
*/
public java.lang.String getStrList(int index) {
return strList_.get(index);
}
/**
* <pre>
*list 引用类型
* </pre>
*
* <code>repeated string strList = 5;</code>
* @param index The index of the value to return.
* @return The bytes of the strList at the given index.
*/
public com.google.protobuf.ByteString
getStrListBytes(int index) {
return strList_.getByteString(index);
}
public static final int MAP_FIELD_NUMBER = 6;
private static final class MapDefaultEntryHolder {
static final com.google.protobuf.MapEntry<
java.lang.String, java.lang.String> defaultEntry =
com.google.protobuf.MapEntry
.<java.lang.String, java.lang.String>newDefaultInstance(
com.qingfeng.proto.UserProto.internal_static_com_qingfeng_proto_User_MapEntry_descriptor,
com.google.protobuf.WireFormat.FieldType.STRING,
"",
com.google.protobuf.WireFormat.FieldType.STRING,
"");
}
private com.google.protobuf.MapField<
java.lang.String, java.lang.String> map_;
private com.google.protobuf.MapField<java.lang.String, java.lang.String>
internalGetMap() {
if (map_ == null) {
return com.google.protobuf.MapField.emptyMapField(
MapDefaultEntryHolder.defaultEntry);
}
return map_;
}
public int getMapCount() {
return internalGetMap().getMap().size();
}
/**
* <pre>
* 定义简单的 Map string
* </pre>
*
* <code>map<string, string> map = 6;</code>
*/
@java.lang.Override
public boolean containsMap(
java.lang.String key) {
if (key == null) { throw new NullPointerException("map key"); }
return internalGetMap().getMap().containsKey(key);
}
/**
* Use {@link #getMapMap()} instead.
*/
@java.lang.Override
@java.lang.Deprecated
public java.util.Map<java.lang.String, java.lang.String> getMap() {
return getMapMap();
}
/**
* <pre>
* 定义简单的 Map string
* </pre>
*
* <code>map<string, string> map = 6;</code>
*/
@java.lang.Override
public java.util.Map<java.lang.String, java.lang.String> getMapMap() {
return internalGetMap().getMap();
}
/**
* <pre>
* 定义简单的 Map string
* </pre>
*
* <code>map<string, string> map = 6;</code>
*/
@java.lang.Override
public java.lang.String getMapOrDefault(
java.lang.String key,
java.lang.String defaultValue) {
if (key == null) { throw new NullPointerException("map key"); }
java.util.Map<java.lang.String, java.lang.String> map =
internalGetMap().getMap();
return map.containsKey(key) ? map.get(key) : defaultValue;
}
/**
* <pre>
* 定义简单的 Map string
* </pre>
*
* <code>map<string, string> map = 6;</code>
*/
@java.lang.Override
public java.lang.String getMapOrThrow(
java.lang.String key) {
if (key == null) { throw new NullPointerException("map key"); }
java.util.Map<java.lang.String, java.lang.String> map =
internalGetMap().getMap();
if (!map.containsKey(key)) {
throw new java.lang.IllegalArgumentException();
}
return map.get(key);
}
public static final int MAPOBJECT_FIELD_NUMBER = 7;
private static final class MapObjectDefaultEntryHolder {
static final com.google.protobuf.MapEntry<
java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject> defaultEntry =
com.google.protobuf.MapEntry
.<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject>newDefaultInstance(
com.qingfeng.proto.UserProto.internal_static_com_qingfeng_proto_User_MapObjectEntry_descriptor,
com.google.protobuf.WireFormat.FieldType.STRING,
"",
com.google.protobuf.WireFormat.FieldType.MESSAGE,
com.qingfeng.proto.UserProto.MapVauleObject.getDefaultInstance());
}
private com.google.protobuf.MapField<
java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject> mapObject_;
private com.google.protobuf.MapField<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject>
internalGetMapObject() {
if (mapObject_ == null) {
return com.google.protobuf.MapField.emptyMapField(
MapObjectDefaultEntryHolder.defaultEntry);
}
return mapObject_;
}
public int getMapObjectCount() {
return internalGetMapObject().getMap().size();
}
/**
* <pre>
* 定义复杂的 Map 对象
* </pre>
*
* <code>map<string, .com.qingfeng.proto.MapVauleObject> mapObject = 7;</code>
*/
@java.lang.Override
public boolean containsMapObject(
java.lang.String key) {
if (key == null) { throw new NullPointerException("map key"); }
return internalGetMapObject().getMap().containsKey(key);
}
/**
* Use {@link #getMapObjectMap()} instead.
*/
@java.lang.Override
@java.lang.Deprecated
public java.util.Map<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject> getMapObject() {
return getMapObjectMap();
}
/**
* <pre>
* 定义复杂的 Map 对象
* </pre>
*
* <code>map<string, .com.qingfeng.proto.MapVauleObject> mapObject = 7;</code>
*/
@java.lang.Override
public java.util.Map<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject> getMapObjectMap() {
return internalGetMapObject().getMap();
}
/**
* <pre>
* 定义复杂的 Map 对象
* </pre>
*
* <code>map<string, .com.qingfeng.proto.MapVauleObject> mapObject = 7;</code>
*/
@java.lang.Override
public com.qingfeng.proto.UserProto.MapVauleObject getMapObjectOrDefault(
java.lang.String key,
com.qingfeng.proto.UserProto.MapVauleObject defaultValue) {
if (key == null) { throw new NullPointerException("map key"); }
java.util.Map<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject> map =
internalGetMapObject().getMap();
return map.containsKey(key) ? map.get(key) : defaultValue;
}
/**
* <pre>
* 定义复杂的 Map 对象
* </pre>
*
* <code>map<string, .com.qingfeng.proto.MapVauleObject> mapObject = 7;</code>
*/
@java.lang.Override
public com.qingfeng.proto.UserProto.MapVauleObject getMapObjectOrThrow(
java.lang.String key) {
if (key == null) { throw new NullPointerException("map key"); }
java.util.Map<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject> map =
internalGetMapObject().getMap();
if (!map.containsKey(key)) {
throw new java.lang.IllegalArgumentException();
}
return map.get(key);
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (id_ != 0) {
output.writeInt32(1, id_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(code_)) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 2, code_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 3, name_);
}
if (nickName_ != null) {
output.writeMessage(4, getNickName());
}
for (int i = 0; i < strList_.size(); i++) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 5, strList_.getRaw(i));
}
com.google.protobuf.GeneratedMessageV3
.serializeStringMapTo(
output,
internalGetMap(),
MapDefaultEntryHolder.defaultEntry,
6);
com.google.protobuf.GeneratedMessageV3
.serializeStringMapTo(
output,
internalGetMapObject(),
MapObjectDefaultEntryHolder.defaultEntry,
7);
unknownFields.writeTo(output);
}
@java.lang.Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (id_ != 0) {
size += com.google.protobuf.CodedOutputStream
.computeInt32Size(1, id_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(code_)) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, code_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, name_);
}
if (nickName_ != null) {
size += com.google.protobuf.CodedOutputStream
.computeMessageSize(4, getNickName());
}
{
int dataSize = 0;
for (int i = 0; i < strList_.size(); i++) {
dataSize += computeStringSizeNoTag(strList_.getRaw(i));
}
size += dataSize;
size += 1 * getStrListList().size();
}
for (java.util.Map.Entry<java.lang.String, java.lang.String> entry
: internalGetMap().getMap().entrySet()) {
com.google.protobuf.MapEntry<java.lang.String, java.lang.String>
map__ = MapDefaultEntryHolder.defaultEntry.newBuilderForType()
.setKey(entry.getKey())
.setValue(entry.getValue())
.build();
size += com.google.protobuf.CodedOutputStream
.computeMessageSize(6, map__);
}
for (java.util.Map.Entry<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject> entry
: internalGetMapObject().getMap().entrySet()) {
com.google.protobuf.MapEntry<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject>
mapObject__ = MapObjectDefaultEntryHolder.defaultEntry.newBuilderForType()
.setKey(entry.getKey())
.setValue(entry.getValue())
.build();
size += com.google.protobuf.CodedOutputStream
.computeMessageSize(7, mapObject__);
}
size += unknownFields.getSerializedSize();
memoizedSize = size;
return size;
}
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof com.qingfeng.proto.UserProto.User)) {
return super.equals(obj);
}
com.qingfeng.proto.UserProto.User other = (com.qingfeng.proto.UserProto.User) obj;
if (getId()
!= other.getId()) return false;
if (!getCode()
.equals(other.getCode())) return false;
if (!getName()
.equals(other.getName())) return false;
if (hasNickName() != other.hasNickName()) return false;
if (hasNickName()) {
if (!getNickName()
.equals(other.getNickName())) return false;
}
if (!getStrListList()
.equals(other.getStrListList())) return false;
if (!internalGetMap().equals(
other.internalGetMap())) return false;
if (!internalGetMapObject().equals(
other.internalGetMapObject())) return false;
if (!unknownFields.equals(other.unknownFields)) return false;
return true;
}
@java.lang.Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + ID_FIELD_NUMBER;
hash = (53 * hash) + getId();
hash = (37 * hash) + CODE_FIELD_NUMBER;
hash = (53 * hash) + getCode().hashCode();
hash = (37 * hash) + NAME_FIELD_NUMBER;
hash = (53 * hash) + getName().hashCode();
if (hasNickName()) {
hash = (37 * hash) + NICKNAME_FIELD_NUMBER;
hash = (53 * hash) + getNickName().hashCode();
}
if (getStrListCount() > 0) {
hash = (37 * hash) + STRLIST_FIELD_NUMBER;
hash = (53 * hash) + getStrListList().hashCode();
}
if (!internalGetMap().getMap().isEmpty()) {
hash = (37 * hash) + MAP_FIELD_NUMBER;
hash = (53 * hash) + internalGetMap().hashCode();
}
if (!internalGetMapObject().getMap().isEmpty()) {
hash = (37 * hash) + MAPOBJECT_FIELD_NUMBER;
hash = (53 * hash) + internalGetMapObject().hashCode();
}
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
public static com.qingfeng.proto.UserProto.User parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static com.qingfeng.proto.UserProto.User parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static com.qingfeng.proto.UserProto.User parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static com.qingfeng.proto.UserProto.User parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static com.qingfeng.proto.UserProto.User parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static com.qingfeng.proto.UserProto.User parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static com.qingfeng.proto.UserProto.User parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static com.qingfeng.proto.UserProto.User parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static com.qingfeng.proto.UserProto.User parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static com.qingfeng.proto.UserProto.User parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static com.qingfeng.proto.UserProto.User parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static com.qingfeng.proto.UserProto.User parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
@java.lang.Override
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(com.qingfeng.proto.UserProto.User prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
@java.lang.Override
public Builder toBuilder() {
return this == DEFAULT_INSTANCE
? new Builder() : new Builder().mergeFrom(this);
}
@java.lang.Override
protected Builder newBuilderForType(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* <pre>
*创建一个 User 对象
* </pre>
*
* Protobuf type {@code com.qingfeng.proto.User}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:com.qingfeng.proto.User)
com.qingfeng.proto.UserProto.UserOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return com.qingfeng.proto.UserProto.internal_static_com_qingfeng_proto_User_descriptor;
}
@SuppressWarnings({"rawtypes"})
protected com.google.protobuf.MapField internalGetMapField(
int number) {
switch (number) {
case 6:
return internalGetMap();
case 7:
return internalGetMapObject();
default:
throw new RuntimeException(
"Invalid map field number: " + number);
}
}
@SuppressWarnings({"rawtypes"})
protected com.google.protobuf.MapField internalGetMutableMapField(
int number) {
switch (number) {
case 6:
return internalGetMutableMap();
case 7:
return internalGetMutableMapObject();
default:
throw new RuntimeException(
"Invalid map field number: " + number);
}
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return com.qingfeng.proto.UserProto.internal_static_com_qingfeng_proto_User_fieldAccessorTable
.ensureFieldAccessorsInitialized(
com.qingfeng.proto.UserProto.User.class, com.qingfeng.proto.UserProto.User.Builder.class);
}
// Construct using com.qingfeng.proto.UserProto.User.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
}
}
@java.lang.Override
public Builder clear() {
super.clear();
id_ = 0;
code_ = "";
name_ = "";
if (nickNameBuilder_ == null) {
nickName_ = null;
} else {
nickName_ = null;
nickNameBuilder_ = null;
}
strList_ = com.google.protobuf.LazyStringArrayList.EMPTY;
bitField0_ = (bitField0_ & ~0x00000001);
internalGetMutableMap().clear();
internalGetMutableMapObject().clear();
return this;
}
@java.lang.Override
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return com.qingfeng.proto.UserProto.internal_static_com_qingfeng_proto_User_descriptor;
}
@java.lang.Override
public com.qingfeng.proto.UserProto.User getDefaultInstanceForType() {
return com.qingfeng.proto.UserProto.User.getDefaultInstance();
}
@java.lang.Override
public com.qingfeng.proto.UserProto.User build() {
com.qingfeng.proto.UserProto.User result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@java.lang.Override
public com.qingfeng.proto.UserProto.User buildPartial() {
com.qingfeng.proto.UserProto.User result = new com.qingfeng.proto.UserProto.User(this);
int from_bitField0_ = bitField0_;
result.id_ = id_;
result.code_ = code_;
result.name_ = name_;
if (nickNameBuilder_ == null) {
result.nickName_ = nickName_;
} else {
result.nickName_ = nickNameBuilder_.build();
}
if (((bitField0_ & 0x00000001) != 0)) {
strList_ = strList_.getUnmodifiableView();
bitField0_ = (bitField0_ & ~0x00000001);
}
result.strList_ = strList_;
result.map_ = internalGetMap();
result.map_.makeImmutable();
result.mapObject_ = internalGetMapObject();
result.mapObject_.makeImmutable();
onBuilt();
return result;
}
@java.lang.Override
public Builder clone() {
return super.clone();
}
@java.lang.Override
public Builder setField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.setField(field, value);
}
@java.lang.Override
public Builder clearField(
com.google.protobuf.Descriptors.FieldDescriptor field) {
return super.clearField(field);
}
@java.lang.Override
public Builder clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
@java.lang.Override
public Builder setRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
int index, java.lang.Object value) {
return super.setRepeatedField(field, index, value);
}
@java.lang.Override
public Builder addRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.addRepeatedField(field, value);
}
@java.lang.Override
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof com.qingfeng.proto.UserProto.User) {
return mergeFrom((com.qingfeng.proto.UserProto.User)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(com.qingfeng.proto.UserProto.User other) {
if (other == com.qingfeng.proto.UserProto.User.getDefaultInstance()) return this;
if (other.getId() != 0) {
setId(other.getId());
}
if (!other.getCode().isEmpty()) {
code_ = other.code_;
onChanged();
}
if (!other.getName().isEmpty()) {
name_ = other.name_;
onChanged();
}
if (other.hasNickName()) {
mergeNickName(other.getNickName());
}
if (!other.strList_.isEmpty()) {
if (strList_.isEmpty()) {
strList_ = other.strList_;
bitField0_ = (bitField0_ & ~0x00000001);
} else {
ensureStrListIsMutable();
strList_.addAll(other.strList_);
}
onChanged();
}
internalGetMutableMap().mergeFrom(
other.internalGetMap());
internalGetMutableMapObject().mergeFrom(
other.internalGetMapObject());
this.mergeUnknownFields(other.unknownFields);
onChanged();
return this;
}
@java.lang.Override
public final boolean isInitialized() {
return true;
}
@java.lang.Override
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
com.qingfeng.proto.UserProto.User parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (com.qingfeng.proto.UserProto.User) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private int bitField0_;
private int id_ ;
/**
* <pre>
*自身属性
* </pre>
*
* <code>int32 id = 1;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
/**
* <pre>
*自身属性
* </pre>
*
* <code>int32 id = 1;</code>
* @param value The id to set.
* @return This builder for chaining.
*/
public Builder setId(int value) {
id_ = value;
onChanged();
return this;
}
/**
* <pre>
*自身属性
* </pre>
*
* <code>int32 id = 1;</code>
* @return This builder for chaining.
*/
public Builder clearId() {
id_ = 0;
onChanged();
return this;
}
private java.lang.Object code_ = "";
/**
* <code>string code = 2;</code>
* @return The code.
*/
public java.lang.String getCode() {
java.lang.Object ref = code_;
if (!(ref instanceof java.lang.String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
code_ = s;
return s;
} else {
return (java.lang.String) ref;
}
}
/**
* <code>string code = 2;</code>
* @return The bytes for code.
*/
public com.google.protobuf.ByteString
getCodeBytes() {
java.lang.Object ref = code_;
if (ref instanceof String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
code_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
/**
* <code>string code = 2;</code>
* @param value The code to set.
* @return This builder for chaining.
*/
public Builder setCode(
java.lang.String value) {
if (value == null) {
throw new NullPointerException();
}
code_ = value;
onChanged();
return this;
}
/**
* <code>string code = 2;</code>
* @return This builder for chaining.
*/
public Builder clearCode() {
code_ = getDefaultInstance().getCode();
onChanged();
return this;
}
/**
* <code>string code = 2;</code>
* @param value The bytes for code to set.
* @return This builder for chaining.
*/
public Builder setCodeBytes(
com.google.protobuf.ByteString value) {
if (value == null) {
throw new NullPointerException();
}
checkByteStringIsUtf8(value);
code_ = value;
onChanged();
return this;
}
private java.lang.Object name_ = "";
/**
* <code>string name = 3;</code>
* @return The name.
*/
public java.lang.String getName() {
java.lang.Object ref = name_;
if (!(ref instanceof java.lang.String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
name_ = s;
return s;
} else {
return (java.lang.String) ref;
}
}
/**
* <code>string name = 3;</code>
* @return The bytes for name.
*/
public com.google.protobuf.ByteString
getNameBytes() {
java.lang.Object ref = name_;
if (ref instanceof String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
name_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
/**
* <code>string name = 3;</code>
* @param value The name to set.
* @return This builder for chaining.
*/
public Builder setName(
java.lang.String value) {
if (value == null) {
throw new NullPointerException();
}
name_ = value;
onChanged();
return this;
}
/**
* <code>string name = 3;</code>
* @return This builder for chaining.
*/
public Builder clearName() {
name_ = getDefaultInstance().getName();
onChanged();
return this;
}
/**
* <code>string name = 3;</code>
* @param value The bytes for name to set.
* @return This builder for chaining.
*/
public Builder setNameBytes(
com.google.protobuf.ByteString value) {
if (value == null) {
throw new NullPointerException();
}
checkByteStringIsUtf8(value);
name_ = value;
onChanged();
return this;
}
private com.qingfeng.proto.UserProto.NickName nickName_;
private com.google.protobuf.SingleFieldBuilderV3<
com.qingfeng.proto.UserProto.NickName, com.qingfeng.proto.UserProto.NickName.Builder, com.qingfeng.proto.UserProto.NickNameOrBuilder> nickNameBuilder_;
/**
* <pre>
* 对象
* </pre>
*
* <code>.com.qingfeng.proto.NickName nickName = 4;</code>
* @return Whether the nickName field is set.
*/
public boolean hasNickName() {
return nickNameBuilder_ != null || nickName_ != null;
}
/**
* <pre>
* 对象
* </pre>
*
* <code>.com.qingfeng.proto.NickName nickName = 4;</code>
* @return The nickName.
*/
public com.qingfeng.proto.UserProto.NickName getNickName() {
if (nickNameBuilder_ == null) {
return nickName_ == null ? com.qingfeng.proto.UserProto.NickName.getDefaultInstance() : nickName_;
} else {
return nickNameBuilder_.getMessage();
}
}
/**
* <pre>
* 对象
* </pre>
*
* <code>.com.qingfeng.proto.NickName nickName = 4;</code>
*/
public Builder setNickName(com.qingfeng.proto.UserProto.NickName value) {
if (nickNameBuilder_ == null) {
if (value == null) {
throw new NullPointerException();
}
nickName_ = value;
onChanged();
} else {
nickNameBuilder_.setMessage(value);
}
return this;
}
/**
* <pre>
* 对象
* </pre>
*
* <code>.com.qingfeng.proto.NickName nickName = 4;</code>
*/
public Builder setNickName(
com.qingfeng.proto.UserProto.NickName.Builder builderForValue) {
if (nickNameBuilder_ == null) {
nickName_ = builderForValue.build();
onChanged();
} else {
nickNameBuilder_.setMessage(builderForValue.build());
}
return this;
}
/**
* <pre>
* 对象
* </pre>
*
* <code>.com.qingfeng.proto.NickName nickName = 4;</code>
*/
public Builder mergeNickName(com.qingfeng.proto.UserProto.NickName value) {
if (nickNameBuilder_ == null) {
if (nickName_ != null) {
nickName_ =
com.qingfeng.proto.UserProto.NickName.newBuilder(nickName_).mergeFrom(value).buildPartial();
} else {
nickName_ = value;
}
onChanged();
} else {
nickNameBuilder_.mergeFrom(value);
}
return this;
}
/**
* <pre>
* 对象
* </pre>
*
* <code>.com.qingfeng.proto.NickName nickName = 4;</code>
*/
public Builder clearNickName() {
if (nickNameBuilder_ == null) {
nickName_ = null;
onChanged();
} else {
nickName_ = null;
nickNameBuilder_ = null;
}
return this;
}
/**
* <pre>
* 对象
* </pre>
*
* <code>.com.qingfeng.proto.NickName nickName = 4;</code>
*/
public com.qingfeng.proto.UserProto.NickName.Builder getNickNameBuilder() {
onChanged();
return getNickNameFieldBuilder().getBuilder();
}
/**
* <pre>
* 对象
* </pre>
*
* <code>.com.qingfeng.proto.NickName nickName = 4;</code>
*/
public com.qingfeng.proto.UserProto.NickNameOrBuilder getNickNameOrBuilder() {
if (nickNameBuilder_ != null) {
return nickNameBuilder_.getMessageOrBuilder();
} else {
return nickName_ == null ?
com.qingfeng.proto.UserProto.NickName.getDefaultInstance() : nickName_;
}
}
/**
* <pre>
* 对象
* </pre>
*
* <code>.com.qingfeng.proto.NickName nickName = 4;</code>
*/
private com.google.protobuf.SingleFieldBuilderV3<
com.qingfeng.proto.UserProto.NickName, com.qingfeng.proto.UserProto.NickName.Builder, com.qingfeng.proto.UserProto.NickNameOrBuilder>
getNickNameFieldBuilder() {
if (nickNameBuilder_ == null) {
nickNameBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
com.qingfeng.proto.UserProto.NickName, com.qingfeng.proto.UserProto.NickName.Builder, com.qingfeng.proto.UserProto.NickNameOrBuilder>(
getNickName(),
getParentForChildren(),
isClean());
nickName_ = null;
}
return nickNameBuilder_;
}
private com.google.protobuf.LazyStringList strList_ = com.google.protobuf.LazyStringArrayList.EMPTY;
private void ensureStrListIsMutable() {
if (!((bitField0_ & 0x00000001) != 0)) {
strList_ = new com.google.protobuf.LazyStringArrayList(strList_);
bitField0_ |= 0x00000001;
}
}
/**
* <pre>
*list 引用类型
* </pre>
*
* <code>repeated string strList = 5;</code>
* @return A list containing the strList.
*/
public com.google.protobuf.ProtocolStringList
getStrListList() {
return strList_.getUnmodifiableView();
}
/**
* <pre>
*list 引用类型
* </pre>
*
* <code>repeated string strList = 5;</code>
* @return The count of strList.
*/
public int getStrListCount() {
return strList_.size();
}
/**
* <pre>
*list 引用类型
* </pre>
*
* <code>repeated string strList = 5;</code>
* @param index The index of the element to return.
* @return The strList at the given index.
*/
public java.lang.String getStrList(int index) {
return strList_.get(index);
}
/**
* <pre>
*list 引用类型
* </pre>
*
* <code>repeated string strList = 5;</code>
* @param index The index of the value to return.
* @return The bytes of the strList at the given index.
*/
public com.google.protobuf.ByteString
getStrListBytes(int index) {
return strList_.getByteString(index);
}
/**
* <pre>
*list 引用类型
* </pre>
*
* <code>repeated string strList = 5;</code>
* @param index The index to set the value at.
* @param value The strList to set.
* @return This builder for chaining.
*/
public Builder setStrList(
int index, java.lang.String value) {
if (value == null) {
throw new NullPointerException();
}
ensureStrListIsMutable();
strList_.set(index, value);
onChanged();
return this;
}
/**
* <pre>
*list 引用类型
* </pre>
*
* <code>repeated string strList = 5;</code>
* @param value The strList to add.
* @return This builder for chaining.
*/
public Builder addStrList(
java.lang.String value) {
if (value == null) {
throw new NullPointerException();
}
ensureStrListIsMutable();
strList_.add(value);
onChanged();
return this;
}
/**
* <pre>
*list 引用类型
* </pre>
*
* <code>repeated string strList = 5;</code>
* @param values The strList to add.
* @return This builder for chaining.
*/
public Builder addAllStrList(
java.lang.Iterable<java.lang.String> values) {
ensureStrListIsMutable();
com.google.protobuf.AbstractMessageLite.Builder.addAll(
values, strList_);
onChanged();
return this;
}
/**
* <pre>
*list 引用类型
* </pre>
*
* <code>repeated string strList = 5;</code>
* @return This builder for chaining.
*/
public Builder clearStrList() {
strList_ = com.google.protobuf.LazyStringArrayList.EMPTY;
bitField0_ = (bitField0_ & ~0x00000001);
onChanged();
return this;
}
/**
* <pre>
*list 引用类型
* </pre>
*
* <code>repeated string strList = 5;</code>
* @param value The bytes of the strList to add.
* @return This builder for chaining.
*/
public Builder addStrListBytes(
com.google.protobuf.ByteString value) {
if (value == null) {
throw new NullPointerException();
}
checkByteStringIsUtf8(value);
ensureStrListIsMutable();
strList_.add(value);
onChanged();
return this;
}
private com.google.protobuf.MapField<
java.lang.String, java.lang.String> map_;
private com.google.protobuf.MapField<java.lang.String, java.lang.String>
internalGetMap() {
if (map_ == null) {
return com.google.protobuf.MapField.emptyMapField(
MapDefaultEntryHolder.defaultEntry);
}
return map_;
}
private com.google.protobuf.MapField<java.lang.String, java.lang.String>
internalGetMutableMap() {
onChanged();;
if (map_ == null) {
map_ = com.google.protobuf.MapField.newMapField(
MapDefaultEntryHolder.defaultEntry);
}
if (!map_.isMutable()) {
map_ = map_.copy();
}
return map_;
}
public int getMapCount() {
return internalGetMap().getMap().size();
}
/**
* <pre>
* 定义简单的 Map string
* </pre>
*
* <code>map<string, string> map = 6;</code>
*/
@java.lang.Override
public boolean containsMap(
java.lang.String key) {
if (key == null) { throw new NullPointerException("map key"); }
return internalGetMap().getMap().containsKey(key);
}
/**
* Use {@link #getMapMap()} instead.
*/
@java.lang.Override
@java.lang.Deprecated
public java.util.Map<java.lang.String, java.lang.String> getMap() {
return getMapMap();
}
/**
* <pre>
* 定义简单的 Map string
* </pre>
*
* <code>map<string, string> map = 6;</code>
*/
@java.lang.Override
public java.util.Map<java.lang.String, java.lang.String> getMapMap() {
return internalGetMap().getMap();
}
/**
* <pre>
* 定义简单的 Map string
* </pre>
*
* <code>map<string, string> map = 6;</code>
*/
@java.lang.Override
public java.lang.String getMapOrDefault(
java.lang.String key,
java.lang.String defaultValue) {
if (key == null) { throw new NullPointerException("map key"); }
java.util.Map<java.lang.String, java.lang.String> map =
internalGetMap().getMap();
return map.containsKey(key) ? map.get(key) : defaultValue;
}
/**
* <pre>
* 定义简单的 Map string
* </pre>
*
* <code>map<string, string> map = 6;</code>
*/
@java.lang.Override
public java.lang.String getMapOrThrow(
java.lang.String key) {
if (key == null) { throw new NullPointerException("map key"); }
java.util.Map<java.lang.String, java.lang.String> map =
internalGetMap().getMap();
if (!map.containsKey(key)) {
throw new java.lang.IllegalArgumentException();
}
return map.get(key);
}
public Builder clearMap() {
internalGetMutableMap().getMutableMap()
.clear();
return this;
}
/**
* <pre>
* 定义简单的 Map string
* </pre>
*
* <code>map<string, string> map = 6;</code>
*/
public Builder removeMap(
java.lang.String key) {
if (key == null) { throw new NullPointerException("map key"); }
internalGetMutableMap().getMutableMap()
.remove(key);
return this;
}
/**
* Use alternate mutation accessors instead.
*/
@java.lang.Deprecated
public java.util.Map<java.lang.String, java.lang.String>
getMutableMap() {
return internalGetMutableMap().getMutableMap();
}
/**
* <pre>
* 定义简单的 Map string
* </pre>
*
* <code>map<string, string> map = 6;</code>
*/
public Builder putMap(
java.lang.String key,
java.lang.String value) {
if (key == null) { throw new NullPointerException("map key"); }
if (value == null) {
throw new NullPointerException("map value");
}
internalGetMutableMap().getMutableMap()
.put(key, value);
return this;
}
/**
* <pre>
* 定义简单的 Map string
* </pre>
*
* <code>map<string, string> map = 6;</code>
*/
public Builder putAllMap(
java.util.Map<java.lang.String, java.lang.String> values) {
internalGetMutableMap().getMutableMap()
.putAll(values);
return this;
}
private com.google.protobuf.MapField<
java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject> mapObject_;
private com.google.protobuf.MapField<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject>
internalGetMapObject() {
if (mapObject_ == null) {
return com.google.protobuf.MapField.emptyMapField(
MapObjectDefaultEntryHolder.defaultEntry);
}
return mapObject_;
}
private com.google.protobuf.MapField<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject>
internalGetMutableMapObject() {
onChanged();;
if (mapObject_ == null) {
mapObject_ = com.google.protobuf.MapField.newMapField(
MapObjectDefaultEntryHolder.defaultEntry);
}
if (!mapObject_.isMutable()) {
mapObject_ = mapObject_.copy();
}
return mapObject_;
}
public int getMapObjectCount() {
return internalGetMapObject().getMap().size();
}
/**
* <pre>
* 定义复杂的 Map 对象
* </pre>
*
* <code>map<string, .com.qingfeng.proto.MapVauleObject> mapObject = 7;</code>
*/
@java.lang.Override
public boolean containsMapObject(
java.lang.String key) {
if (key == null) { throw new NullPointerException("map key"); }
return internalGetMapObject().getMap().containsKey(key);
}
/**
* Use {@link #getMapObjectMap()} instead.
*/
@java.lang.Override
@java.lang.Deprecated
public java.util.Map<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject> getMapObject() {
return getMapObjectMap();
}
/**
* <pre>
* 定义复杂的 Map 对象
* </pre>
*
* <code>map<string, .com.qingfeng.proto.MapVauleObject> mapObject = 7;</code>
*/
@java.lang.Override
public java.util.Map<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject> getMapObjectMap() {
return internalGetMapObject().getMap();
}
/**
* <pre>
* 定义复杂的 Map 对象
* </pre>
*
* <code>map<string, .com.qingfeng.proto.MapVauleObject> mapObject = 7;</code>
*/
@java.lang.Override
public com.qingfeng.proto.UserProto.MapVauleObject getMapObjectOrDefault(
java.lang.String key,
com.qingfeng.proto.UserProto.MapVauleObject defaultValue) {
if (key == null) { throw new NullPointerException("map key"); }
java.util.Map<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject> map =
internalGetMapObject().getMap();
return map.containsKey(key) ? map.get(key) : defaultValue;
}
/**
* <pre>
* 定义复杂的 Map 对象
* </pre>
*
* <code>map<string, .com.qingfeng.proto.MapVauleObject> mapObject = 7;</code>
*/
@java.lang.Override
public com.qingfeng.proto.UserProto.MapVauleObject getMapObjectOrThrow(
java.lang.String key) {
if (key == null) { throw new NullPointerException("map key"); }
java.util.Map<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject> map =
internalGetMapObject().getMap();
if (!map.containsKey(key)) {
throw new java.lang.IllegalArgumentException();
}
return map.get(key);
}
public Builder clearMapObject() {
internalGetMutableMapObject().getMutableMap()
.clear();
return this;
}
/**
* <pre>
* 定义复杂的 Map 对象
* </pre>
*
* <code>map<string, .com.qingfeng.proto.MapVauleObject> mapObject = 7;</code>
*/
public Builder removeMapObject(
java.lang.String key) {
if (key == null) { throw new NullPointerException("map key"); }
internalGetMutableMapObject().getMutableMap()
.remove(key);
return this;
}
/**
* Use alternate mutation accessors instead.
*/
@java.lang.Deprecated
public java.util.Map<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject>
getMutableMapObject() {
return internalGetMutableMapObject().getMutableMap();
}
/**
* <pre>
* 定义复杂的 Map 对象
* </pre>
*
* <code>map<string, .com.qingfeng.proto.MapVauleObject> mapObject = 7;</code>
*/
public Builder putMapObject(
java.lang.String key,
com.qingfeng.proto.UserProto.MapVauleObject value) {
if (key == null) { throw new NullPointerException("map key"); }
if (value == null) {
throw new NullPointerException("map value");
}
internalGetMutableMapObject().getMutableMap()
.put(key, value);
return this;
}
/**
* <pre>
* 定义复杂的 Map 对象
* </pre>
*
* <code>map<string, .com.qingfeng.proto.MapVauleObject> mapObject = 7;</code>
*/
public Builder putAllMapObject(
java.util.Map<java.lang.String, com.qingfeng.proto.UserProto.MapVauleObject> values) {
internalGetMutableMapObject().getMutableMap()
.putAll(values);
return this;
}
@java.lang.Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@java.lang.Override
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:com.qingfeng.proto.User)
}
// @@protoc_insertion_point(class_scope:com.qingfeng.proto.User)
private static final com.qingfeng.proto.UserProto.User DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new com.qingfeng.proto.UserProto.User();
}
public static com.qingfeng.proto.UserProto.User getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<User>
PARSER = new com.google.protobuf.AbstractParser<User>() {
@java.lang.Override
public User parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new User(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<User> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<User> getParserForType() {
return PARSER;
}
@java.lang.Override
public com.qingfeng.proto.UserProto.User getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
public interface NickNameOrBuilder extends
// @@protoc_insertion_point(interface_extends:com.qingfeng.proto.NickName)
com.google.protobuf.MessageOrBuilder {
/**
* <code>string nickName = 1;</code>
* @return The nickName.
*/
java.lang.String getNickName();
/**
* <code>string nickName = 1;</code>
* @return The bytes for nickName.
*/
com.google.protobuf.ByteString
getNickNameBytes();
}
/**
* <pre>
* 定义一个新的Name对象
* </pre>
*
* Protobuf type {@code com.qingfeng.proto.NickName}
*/
public static final class NickName extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:com.qingfeng.proto.NickName)
NickNameOrBuilder {
private static final long serialVersionUID = 0L;
// Use NickName.newBuilder() to construct.
private NickName(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private NickName() {
nickName_ = "";
}
@java.lang.Override
@SuppressWarnings({"unused"})
protected java.lang.Object newInstance(
UnusedPrivateParameter unused) {
return new NickName();
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private NickName(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
if (extensionRegistry == null) {
throw new java.lang.NullPointerException();
}
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
com.google.protobuf.UnknownFieldSet.newBuilder();
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
case 10: {
java.lang.String s = input.readStringRequireUtf8();
nickName_ = s;
break;
}
default: {
if (!parseUnknownField(
input, unknownFields, extensionRegistry, tag)) {
done = true;
}
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(this);
} catch (com.google.protobuf.UninitializedMessageException e) {
throw e.asInvalidProtocolBufferException().setUnfinishedMessage(this);
} catch (java.io.IOException e) {
throw new com.google.protobuf.InvalidProtocolBufferException(
e).setUnfinishedMessage(this);
} finally {
this.unknownFields = unknownFields.build();
makeExtensionsImmutable();
}
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return com.qingfeng.proto.UserProto.internal_static_com_qingfeng_proto_NickName_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return com.qingfeng.proto.UserProto.internal_static_com_qingfeng_proto_NickName_fieldAccessorTable
.ensureFieldAccessorsInitialized(
com.qingfeng.proto.UserProto.NickName.class, com.qingfeng.proto.UserProto.NickName.Builder.class);
}
public static final int NICKNAME_FIELD_NUMBER = 1;
private volatile java.lang.Object nickName_;
/**
* <code>string nickName = 1;</code>
* @return The nickName.
*/
@java.lang.Override
public java.lang.String getNickName() {
java.lang.Object ref = nickName_;
if (ref instanceof java.lang.String) {
return (java.lang.String) ref;
} else {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
nickName_ = s;
return s;
}
}
/**
* <code>string nickName = 1;</code>
* @return The bytes for nickName.
*/
@java.lang.Override
public com.google.protobuf.ByteString
getNickNameBytes() {
java.lang.Object ref = nickName_;
if (ref instanceof java.lang.String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
nickName_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(nickName_)) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 1, nickName_);
}
unknownFields.writeTo(output);
}
@java.lang.Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(nickName_)) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, nickName_);
}
size += unknownFields.getSerializedSize();
memoizedSize = size;
return size;
}
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof com.qingfeng.proto.UserProto.NickName)) {
return super.equals(obj);
}
com.qingfeng.proto.UserProto.NickName other = (com.qingfeng.proto.UserProto.NickName) obj;
if (!getNickName()
.equals(other.getNickName())) return false;
if (!unknownFields.equals(other.unknownFields)) return false;
return true;
}
@java.lang.Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + NICKNAME_FIELD_NUMBER;
hash = (53 * hash) + getNickName().hashCode();
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
public static com.qingfeng.proto.UserProto.NickName parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static com.qingfeng.proto.UserProto.NickName parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static com.qingfeng.proto.UserProto.NickName parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static com.qingfeng.proto.UserProto.NickName parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static com.qingfeng.proto.UserProto.NickName parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static com.qingfeng.proto.UserProto.NickName parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static com.qingfeng.proto.UserProto.NickName parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static com.qingfeng.proto.UserProto.NickName parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static com.qingfeng.proto.UserProto.NickName parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static com.qingfeng.proto.UserProto.NickName parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static com.qingfeng.proto.UserProto.NickName parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static com.qingfeng.proto.UserProto.NickName parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
@java.lang.Override
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(com.qingfeng.proto.UserProto.NickName prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
@java.lang.Override
public Builder toBuilder() {
return this == DEFAULT_INSTANCE
? new Builder() : new Builder().mergeFrom(this);
}
@java.lang.Override
protected Builder newBuilderForType(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* <pre>
* 定义一个新的Name对象
* </pre>
*
* Protobuf type {@code com.qingfeng.proto.NickName}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:com.qingfeng.proto.NickName)
com.qingfeng.proto.UserProto.NickNameOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return com.qingfeng.proto.UserProto.internal_static_com_qingfeng_proto_NickName_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return com.qingfeng.proto.UserProto.internal_static_com_qingfeng_proto_NickName_fieldAccessorTable
.ensureFieldAccessorsInitialized(
com.qingfeng.proto.UserProto.NickName.class, com.qingfeng.proto.UserProto.NickName.Builder.class);
}
// Construct using com.qingfeng.proto.UserProto.NickName.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
}
}
@java.lang.Override
public Builder clear() {
super.clear();
nickName_ = "";
return this;
}
@java.lang.Override
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return com.qingfeng.proto.UserProto.internal_static_com_qingfeng_proto_NickName_descriptor;
}
@java.lang.Override
public com.qingfeng.proto.UserProto.NickName getDefaultInstanceForType() {
return com.qingfeng.proto.UserProto.NickName.getDefaultInstance();
}
@java.lang.Override
public com.qingfeng.proto.UserProto.NickName build() {
com.qingfeng.proto.UserProto.NickName result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@java.lang.Override
public com.qingfeng.proto.UserProto.NickName buildPartial() {
com.qingfeng.proto.UserProto.NickName result = new com.qingfeng.proto.UserProto.NickName(this);
result.nickName_ = nickName_;
onBuilt();
return result;
}
@java.lang.Override
public Builder clone() {
return super.clone();
}
@java.lang.Override
public Builder setField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.setField(field, value);
}
@java.lang.Override
public Builder clearField(
com.google.protobuf.Descriptors.FieldDescriptor field) {
return super.clearField(field);
}
@java.lang.Override
public Builder clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
@java.lang.Override
public Builder setRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
int index, java.lang.Object value) {
return super.setRepeatedField(field, index, value);
}
@java.lang.Override
public Builder addRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.addRepeatedField(field, value);
}
@java.lang.Override
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof com.qingfeng.proto.UserProto.NickName) {
return mergeFrom((com.qingfeng.proto.UserProto.NickName)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(com.qingfeng.proto.UserProto.NickName other) {
if (other == com.qingfeng.proto.UserProto.NickName.getDefaultInstance()) return this;
if (!other.getNickName().isEmpty()) {
nickName_ = other.nickName_;
onChanged();
}
this.mergeUnknownFields(other.unknownFields);
onChanged();
return this;
}
@java.lang.Override
public final boolean isInitialized() {
return true;
}
@java.lang.Override
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
com.qingfeng.proto.UserProto.NickName parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (com.qingfeng.proto.UserProto.NickName) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private java.lang.Object nickName_ = "";
/**
* <code>string nickName = 1;</code>
* @return The nickName.
*/
public java.lang.String getNickName() {
java.lang.Object ref = nickName_;
if (!(ref instanceof java.lang.String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
nickName_ = s;
return s;
} else {
return (java.lang.String) ref;
}
}
/**
* <code>string nickName = 1;</code>
* @return The bytes for nickName.
*/
public com.google.protobuf.ByteString
getNickNameBytes() {
java.lang.Object ref = nickName_;
if (ref instanceof String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
nickName_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
/**
* <code>string nickName = 1;</code>
* @param value The nickName to set.
* @return This builder for chaining.
*/
public Builder setNickName(
java.lang.String value) {
if (value == null) {
throw new NullPointerException();
}
nickName_ = value;
onChanged();
return this;
}
/**
* <code>string nickName = 1;</code>
* @return This builder for chaining.
*/
public Builder clearNickName() {
nickName_ = getDefaultInstance().getNickName();
onChanged();
return this;
}
/**
* <code>string nickName = 1;</code>
* @param value The bytes for nickName to set.
* @return This builder for chaining.
*/
public Builder setNickNameBytes(
com.google.protobuf.ByteString value) {
if (value == null) {
throw new NullPointerException();
}
checkByteStringIsUtf8(value);
nickName_ = value;
onChanged();
return this;
}
@java.lang.Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@java.lang.Override
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:com.qingfeng.proto.NickName)
}
// @@protoc_insertion_point(class_scope:com.qingfeng.proto.NickName)
private static final com.qingfeng.proto.UserProto.NickName DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new com.qingfeng.proto.UserProto.NickName();
}
public static com.qingfeng.proto.UserProto.NickName getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<NickName>
PARSER = new com.google.protobuf.AbstractParser<NickName>() {
@java.lang.Override
public NickName parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new NickName(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<NickName> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<NickName> getParserForType() {
return PARSER;
}
@java.lang.Override
public com.qingfeng.proto.UserProto.NickName getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
public interface MapVauleObjectOrBuilder extends
// @@protoc_insertion_point(interface_extends:com.qingfeng.proto.MapVauleObject)
com.google.protobuf.MessageOrBuilder {
/**
* <code>string code = 1;</code>
* @return The code.
*/
java.lang.String getCode();
/**
* <code>string code = 1;</code>
* @return The bytes for code.
*/
com.google.protobuf.ByteString
getCodeBytes();
/**
* <code>string name = 2;</code>
* @return The name.
*/
java.lang.String getName();
/**
* <code>string name = 2;</code>
* @return The bytes for name.
*/
com.google.protobuf.ByteString
getNameBytes();
}
/**
* <pre>
* 定义 Map 的 value 对象
* </pre>
*
* Protobuf type {@code com.qingfeng.proto.MapVauleObject}
*/
public static final class MapVauleObject extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:com.qingfeng.proto.MapVauleObject)
MapVauleObjectOrBuilder {
private static final long serialVersionUID = 0L;
// Use MapVauleObject.newBuilder() to construct.
private MapVauleObject(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private MapVauleObject() {
code_ = "";
name_ = "";
}
@java.lang.Override
@SuppressWarnings({"unused"})
protected java.lang.Object newInstance(
UnusedPrivateParameter unused) {
return new MapVauleObject();
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private MapVauleObject(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
if (extensionRegistry == null) {
throw new java.lang.NullPointerException();
}
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
com.google.protobuf.UnknownFieldSet.newBuilder();
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
case 10: {
java.lang.String s = input.readStringRequireUtf8();
code_ = s;
break;
}
case 18: {
java.lang.String s = input.readStringRequireUtf8();
name_ = s;
break;
}
default: {
if (!parseUnknownField(
input, unknownFields, extensionRegistry, tag)) {
done = true;
}
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(this);
} catch (com.google.protobuf.UninitializedMessageException e) {
throw e.asInvalidProtocolBufferException().setUnfinishedMessage(this);
} catch (java.io.IOException e) {
throw new com.google.protobuf.InvalidProtocolBufferException(
e).setUnfinishedMessage(this);
} finally {
this.unknownFields = unknownFields.build();
makeExtensionsImmutable();
}
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return com.qingfeng.proto.UserProto.internal_static_com_qingfeng_proto_MapVauleObject_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return com.qingfeng.proto.UserProto.internal_static_com_qingfeng_proto_MapVauleObject_fieldAccessorTable
.ensureFieldAccessorsInitialized(
com.qingfeng.proto.UserProto.MapVauleObject.class, com.qingfeng.proto.UserProto.MapVauleObject.Builder.class);
}
public static final int CODE_FIELD_NUMBER = 1;
private volatile java.lang.Object code_;
/**
* <code>string code = 1;</code>
* @return The code.
*/
@java.lang.Override
public java.lang.String getCode() {
java.lang.Object ref = code_;
if (ref instanceof java.lang.String) {
return (java.lang.String) ref;
} else {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
code_ = s;
return s;
}
}
/**
* <code>string code = 1;</code>
* @return The bytes for code.
*/
@java.lang.Override
public com.google.protobuf.ByteString
getCodeBytes() {
java.lang.Object ref = code_;
if (ref instanceof java.lang.String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
code_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
public static final int NAME_FIELD_NUMBER = 2;
private volatile java.lang.Object name_;
/**
* <code>string name = 2;</code>
* @return The name.
*/
@java.lang.Override
public java.lang.String getName() {
java.lang.Object ref = name_;
if (ref instanceof java.lang.String) {
return (java.lang.String) ref;
} else {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
name_ = s;
return s;
}
}
/**
* <code>string name = 2;</code>
* @return The bytes for name.
*/
@java.lang.Override
public com.google.protobuf.ByteString
getNameBytes() {
java.lang.Object ref = name_;
if (ref instanceof java.lang.String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
name_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(code_)) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 1, code_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 2, name_);
}
unknownFields.writeTo(output);
}
@java.lang.Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(code_)) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, code_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, name_);
}
size += unknownFields.getSerializedSize();
memoizedSize = size;
return size;
}
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof com.qingfeng.proto.UserProto.MapVauleObject)) {
return super.equals(obj);
}
com.qingfeng.proto.UserProto.MapVauleObject other = (com.qingfeng.proto.UserProto.MapVauleObject) obj;
if (!getCode()
.equals(other.getCode())) return false;
if (!getName()
.equals(other.getName())) return false;
if (!unknownFields.equals(other.unknownFields)) return false;
return true;
}
@java.lang.Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + CODE_FIELD_NUMBER;
hash = (53 * hash) + getCode().hashCode();
hash = (37 * hash) + NAME_FIELD_NUMBER;
hash = (53 * hash) + getName().hashCode();
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
public static com.qingfeng.proto.UserProto.MapVauleObject parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static com.qingfeng.proto.UserProto.MapVauleObject parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static com.qingfeng.proto.UserProto.MapVauleObject parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static com.qingfeng.proto.UserProto.MapVauleObject parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static com.qingfeng.proto.UserProto.MapVauleObject parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static com.qingfeng.proto.UserProto.MapVauleObject parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static com.qingfeng.proto.UserProto.MapVauleObject parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static com.qingfeng.proto.UserProto.MapVauleObject parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static com.qingfeng.proto.UserProto.MapVauleObject parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static com.qingfeng.proto.UserProto.MapVauleObject parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static com.qingfeng.proto.UserProto.MapVauleObject parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static com.qingfeng.proto.UserProto.MapVauleObject parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
@java.lang.Override
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(com.qingfeng.proto.UserProto.MapVauleObject prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
@java.lang.Override
public Builder toBuilder() {
return this == DEFAULT_INSTANCE
? new Builder() : new Builder().mergeFrom(this);
}
@java.lang.Override
protected Builder newBuilderForType(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* <pre>
* 定义 Map 的 value 对象
* </pre>
*
* Protobuf type {@code com.qingfeng.proto.MapVauleObject}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:com.qingfeng.proto.MapVauleObject)
com.qingfeng.proto.UserProto.MapVauleObjectOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return com.qingfeng.proto.UserProto.internal_static_com_qingfeng_proto_MapVauleObject_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return com.qingfeng.proto.UserProto.internal_static_com_qingfeng_proto_MapVauleObject_fieldAccessorTable
.ensureFieldAccessorsInitialized(
com.qingfeng.proto.UserProto.MapVauleObject.class, com.qingfeng.proto.UserProto.MapVauleObject.Builder.class);
}
// Construct using com.qingfeng.proto.UserProto.MapVauleObject.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
}
}
@java.lang.Override
public Builder clear() {
super.clear();
code_ = "";
name_ = "";
return this;
}
@java.lang.Override
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return com.qingfeng.proto.UserProto.internal_static_com_qingfeng_proto_MapVauleObject_descriptor;
}
@java.lang.Override
public com.qingfeng.proto.UserProto.MapVauleObject getDefaultInstanceForType() {
return com.qingfeng.proto.UserProto.MapVauleObject.getDefaultInstance();
}
@java.lang.Override
public com.qingfeng.proto.UserProto.MapVauleObject build() {
com.qingfeng.proto.UserProto.MapVauleObject result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@java.lang.Override
public com.qingfeng.proto.UserProto.MapVauleObject buildPartial() {
com.qingfeng.proto.UserProto.MapVauleObject result = new com.qingfeng.proto.UserProto.MapVauleObject(this);
result.code_ = code_;
result.name_ = name_;
onBuilt();
return result;
}
@java.lang.Override
public Builder clone() {
return super.clone();
}
@java.lang.Override
public Builder setField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.setField(field, value);
}
@java.lang.Override
public Builder clearField(
com.google.protobuf.Descriptors.FieldDescriptor field) {
return super.clearField(field);
}
@java.lang.Override
public Builder clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
@java.lang.Override
public Builder setRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
int index, java.lang.Object value) {
return super.setRepeatedField(field, index, value);
}
@java.lang.Override
public Builder addRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.addRepeatedField(field, value);
}
@java.lang.Override
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof com.qingfeng.proto.UserProto.MapVauleObject) {
return mergeFrom((com.qingfeng.proto.UserProto.MapVauleObject)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(com.qingfeng.proto.UserProto.MapVauleObject other) {
if (other == com.qingfeng.proto.UserProto.MapVauleObject.getDefaultInstance()) return this;
if (!other.getCode().isEmpty()) {
code_ = other.code_;
onChanged();
}
if (!other.getName().isEmpty()) {
name_ = other.name_;
onChanged();
}
this.mergeUnknownFields(other.unknownFields);
onChanged();
return this;
}
@java.lang.Override
public final boolean isInitialized() {
return true;
}
@java.lang.Override
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
com.qingfeng.proto.UserProto.MapVauleObject parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (com.qingfeng.proto.UserProto.MapVauleObject) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private java.lang.Object code_ = "";
/**
* <code>string code = 1;</code>
* @return The code.
*/
public java.lang.String getCode() {
java.lang.Object ref = code_;
if (!(ref instanceof java.lang.String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
code_ = s;
return s;
} else {
return (java.lang.String) ref;
}
}
/**
* <code>string code = 1;</code>
* @return The bytes for code.
*/
public com.google.protobuf.ByteString
getCodeBytes() {
java.lang.Object ref = code_;
if (ref instanceof String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
code_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
/**
* <code>string code = 1;</code>
* @param value The code to set.
* @return This builder for chaining.
*/
public Builder setCode(
java.lang.String value) {
if (value == null) {
throw new NullPointerException();
}
code_ = value;
onChanged();
return this;
}
/**
* <code>string code = 1;</code>
* @return This builder for chaining.
*/
public Builder clearCode() {
code_ = getDefaultInstance().getCode();
onChanged();
return this;
}
/**
* <code>string code = 1;</code>
* @param value The bytes for code to set.
* @return This builder for chaining.
*/
public Builder setCodeBytes(
com.google.protobuf.ByteString value) {
if (value == null) {
throw new NullPointerException();
}
checkByteStringIsUtf8(value);
code_ = value;
onChanged();
return this;
}
private java.lang.Object name_ = "";
/**
* <code>string name = 2;</code>
* @return The name.
*/
public java.lang.String getName() {
java.lang.Object ref = name_;
if (!(ref instanceof java.lang.String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
name_ = s;
return s;
} else {
return (java.lang.String) ref;
}
}
/**
* <code>string name = 2;</code>
* @return The bytes for name.
*/
public com.google.protobuf.ByteString
getNameBytes() {
java.lang.Object ref = name_;
if (ref instanceof String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
name_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
/**
* <code>string name = 2;</code>
* @param value The name to set.
* @return This builder for chaining.
*/
public Builder setName(
java.lang.String value) {
if (value == null) {
throw new NullPointerException();
}
name_ = value;
onChanged();
return this;
}
/**
* <code>string name = 2;</code>
* @return This builder for chaining.
*/
public Builder clearName() {
name_ = getDefaultInstance().getName();
onChanged();
return this;
}
/**
* <code>string name = 2;</code>
* @param value The bytes for name to set.
* @return This builder for chaining.
*/
public Builder setNameBytes(
com.google.protobuf.ByteString value) {
if (value == null) {
throw new NullPointerException();
}
checkByteStringIsUtf8(value);
name_ = value;
onChanged();
return this;
}
@java.lang.Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@java.lang.Override
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:com.qingfeng.proto.MapVauleObject)
}
// @@protoc_insertion_point(class_scope:com.qingfeng.proto.MapVauleObject)
private static final com.qingfeng.proto.UserProto.MapVauleObject DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new com.qingfeng.proto.UserProto.MapVauleObject();
}
public static com.qingfeng.proto.UserProto.MapVauleObject getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<MapVauleObject>
PARSER = new com.google.protobuf.AbstractParser<MapVauleObject>() {
@java.lang.Override
public MapVauleObject parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new MapVauleObject(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<MapVauleObject> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<MapVauleObject> getParserForType() {
return PARSER;
}
@java.lang.Override
public com.qingfeng.proto.UserProto.MapVauleObject getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_com_qingfeng_proto_User_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_com_qingfeng_proto_User_fieldAccessorTable;
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_com_qingfeng_proto_User_MapEntry_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_com_qingfeng_proto_User_MapEntry_fieldAccessorTable;
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_com_qingfeng_proto_User_MapObjectEntry_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_com_qingfeng_proto_User_MapObjectEntry_fieldAccessorTable;
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_com_qingfeng_proto_NickName_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_com_qingfeng_proto_NickName_fieldAccessorTable;
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_com_qingfeng_proto_MapVauleObject_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_com_qingfeng_proto_MapVauleObject_fieldAccessorTable;
public static com.google.protobuf.Descriptors.FileDescriptor
getDescriptor() {
return descriptor;
}
private static com.google.protobuf.Descriptors.FileDescriptor
descriptor;
static {
java.lang.String[] descriptorData = {
"\n\nUser.proto\022\022com.qingfeng.proto\"\335\002\n\004Use" +
"r\022\n\n\002id\030\001 \001(\005\022\014\n\004code\030\002 \001(\t\022\014\n\004name\030\003 \001(" +
"\t\022.\n\010nickName\030\004 \001(\0132\034.com.qingfeng.proto" +
".NickName\022\017\n\007strList\030\005 \003(\t\022.\n\003map\030\006 \003(\0132" +
"!.com.qingfeng.proto.User.MapEntry\022:\n\tma" +
"pObject\030\007 \003(\0132\'.com.qingfeng.proto.User." +
"MapObjectEntry\032*\n\010MapEntry\022\013\n\003key\030\001 \001(\t\022" +
"\r\n\005value\030\002 \001(\t:\0028\001\032T\n\016MapObjectEntry\022\013\n\003" +
"key\030\001 \001(\t\0221\n\005value\030\002 \001(\0132\".com.qingfeng." +
"proto.MapVauleObject:\0028\001\"\034\n\010NickName\022\020\n\010" +
"nickName\030\001 \001(\t\",\n\016MapVauleObject\022\014\n\004code" +
"\030\001 \001(\t\022\014\n\004name\030\002 \001(\tB\037\n\022com.qingfeng.pro" +
"toB\tUserProtob\006proto3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] {
});
internal_static_com_qingfeng_proto_User_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_com_qingfeng_proto_User_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_com_qingfeng_proto_User_descriptor,
new java.lang.String[] { "Id", "Code", "Name", "NickName", "StrList", "Map", "MapObject", });
internal_static_com_qingfeng_proto_User_MapEntry_descriptor =
internal_static_com_qingfeng_proto_User_descriptor.getNestedTypes().get(0);
internal_static_com_qingfeng_proto_User_MapEntry_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_com_qingfeng_proto_User_MapEntry_descriptor,
new java.lang.String[] { "Key", "Value", });
internal_static_com_qingfeng_proto_User_MapObjectEntry_descriptor =
internal_static_com_qingfeng_proto_User_descriptor.getNestedTypes().get(1);
internal_static_com_qingfeng_proto_User_MapObjectEntry_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_com_qingfeng_proto_User_MapObjectEntry_descriptor,
new java.lang.String[] { "Key", "Value", });
internal_static_com_qingfeng_proto_NickName_descriptor =
getDescriptor().getMessageTypes().get(1);
internal_static_com_qingfeng_proto_NickName_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_com_qingfeng_proto_NickName_descriptor,
new java.lang.String[] { "NickName", });
internal_static_com_qingfeng_proto_MapVauleObject_descriptor =
getDescriptor().getMessageTypes().get(2);
internal_static_com_qingfeng_proto_MapVauleObject_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_com_qingfeng_proto_MapVauleObject_descriptor,
new java.lang.String[] { "Code", "Name", });
}
// @@protoc_insertion_point(outer_class_scope)
}
新建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转换
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;
}
修改实体转换
完整的测试类
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);
}
}