protobuf是一个google提供的序列化与反序列化的项目
如果想使用protobuf,首先需要下载protobuf的编译器
根据系统选择对应的protoc编译器 下载完成后,需要在项目中声明一个*.proto的文件作为数据格式的声明文件
新建:Student.proto
syntax = "proto2";
//必须指定一个package
package com.mjy.protobuf;
option optimize_for = SPEED;
option java_package = "com.mjy.protobuf";
option java_outer_classname = "DataInfo";
message Student {
//name = 1并不表示name的value为1,1为参数的一个序号
required string name = 1;
optional int32 age = 2;
optional string address = 3;
}
使用命令编译该文件
D:/middleware/protoc-3.20.0-win64/bin/protoc.exe --java_out=src/main/java src/main/resources/proto/Student.proto
编译后将在指定package中生成一个java类,注意生成的类不能修改:
public class TestProto {
//使用google protobuf将数据序列化与反序列化
public static void main(String[] args) throws Exception {
Student student = DataInfo.Student.newBuilder().setName("张三").setAge(20).setAddress("北京").build();
//序列化
byte[] arr = student.toByteArray();
System.out.println(arr.length); //18
//反序列化
Student student2 = DataInfo.Student.parseFrom(arr);
System.out.println(student2.getName()); //张三
System.out.println(student2.getAge()); //20
System.out.println(student2.getAddress()); //北京
}
}
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: src/main/resources/proto/Student.proto
package com.mjy.protobuf;
public final class DataInfo {
private DataInfo() {}
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 StudentOrBuilder extends
// @@protoc_insertion_point(interface_extends:com.mjy.protobuf.Student)
com.google.protobuf.MessageOrBuilder {
/**
* <pre>
*name = 1并不表示name的value为1,1为参数的一个序号
* </pre>
*
* <code>required string name = 1;</code>
* @return Whether the name field is set.
*/
boolean hasName();
/**
* <pre>
*name = 1并不表示name的value为1,1为参数的一个序号
* </pre>
*
* <code>required string name = 1;</code>
* @return The name.
*/
java.lang.String getName();
/**
* <pre>
*name = 1并不表示name的value为1,1为参数的一个序号
* </pre>
*
* <code>required string name = 1;</code>
* @return The bytes for name.
*/
com.google.protobuf.ByteString
getNameBytes();
/**
* <code>optional int32 age = 2;</code>
* @return Whether the age field is set.
*/
boolean hasAge();
/**
* <code>optional int32 age = 2;</code>
* @return The age.
*/
int getAge();
/**
* <code>optional string address = 3;</code>
* @return Whether the address field is set.
*/
boolean hasAddress();
/**
* <code>optional string address = 3;</code>
* @return The address.
*/
java.lang.String getAddress();
/**
* <code>optional string address = 3;</code>
* @return The bytes for address.
*/
com.google.protobuf.ByteString
getAddressBytes();
}
/**
* Protobuf type {@code com.mjy.protobuf.Student}
*/
public static final class Student extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:com.mjy.protobuf.Student)
StudentOrBuilder {
private static final long serialVersionUID = 0L;
// Use Student.newBuilder() to construct.
private Student(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private Student() {
name_ = "";
address_ = "";
}
@java.lang.Override
@SuppressWarnings({"unused"})
protected java.lang.Object newInstance(
UnusedPrivateParameter unused) {
return new Student();
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private Student(
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 10: {
com.google.protobuf.ByteString bs = input.readBytes();
bitField0_ |= 0x00000001;
name_ = bs;
break;
}
case 16: {
bitField0_ |= 0x00000002;
age_ = input.readInt32();
break;
}
case 26: {
com.google.protobuf.ByteString bs = input.readBytes();
bitField0_ |= 0x00000004;
address_ = bs;
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.mjy.protobuf.DataInfo.internal_static_com_mjy_protobuf_Student_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return com.mjy.protobuf.DataInfo.internal_static_com_mjy_protobuf_Student_fieldAccessorTable
.ensureFieldAccessorsInitialized(
com.mjy.protobuf.DataInfo.Student.class, com.mjy.protobuf.DataInfo.Student.Builder.class);
}
private int bitField0_;
public static final int NAME_FIELD_NUMBER = 1;
private volatile java.lang.Object name_;
/**
* <pre>
*name = 1并不表示name的value为1,1为参数的一个序号
* </pre>
*
* <code>required string name = 1;</code>
* @return Whether the name field is set.
*/
@java.lang.Override
public boolean hasName() {
return ((bitField0_ & 0x00000001) != 0);
}
/**
* <pre>
*name = 1并不表示name的value为1,1为参数的一个序号
* </pre>
*
* <code>required string name = 1;</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();
if (bs.isValidUtf8()) {
name_ = s;
}
return s;
}
}
/**
* <pre>
*name = 1并不表示name的value为1,1为参数的一个序号
* </pre>
*
* <code>required string name = 1;</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 AGE_FIELD_NUMBER = 2;
private int age_;
/**
* <code>optional int32 age = 2;</code>
* @return Whether the age field is set.
*/
@java.lang.Override
public boolean hasAge() {
return ((bitField0_ & 0x00000002) != 0);
}
/**
* <code>optional int32 age = 2;</code>
* @return The age.
*/
@java.lang.Override
public int getAge() {
return age_;
}
public static final int ADDRESS_FIELD_NUMBER = 3;
private volatile java.lang.Object address_;
/**
* <code>optional string address = 3;</code>
* @return Whether the address field is set.
*/
@java.lang.Override
public boolean hasAddress() {
return ((bitField0_ & 0x00000004) != 0);
}
/**
* <code>optional string address = 3;</code>
* @return The address.
*/
@java.lang.Override
public java.lang.String getAddress() {
java.lang.Object ref = address_;
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();
if (bs.isValidUtf8()) {
address_ = s;
}
return s;
}
}
/**
* <code>optional string address = 3;</code>
* @return The bytes for address.
*/
@java.lang.Override
public com.google.protobuf.ByteString
getAddressBytes() {
java.lang.Object ref = address_;
if (ref instanceof java.lang.String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
address_ = 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;
if (!hasName()) {
memoizedIsInitialized = 0;
return false;
}
memoizedIsInitialized = 1;
return true;
}
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (((bitField0_ & 0x00000001) != 0)) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_);
}
if (((bitField0_ & 0x00000002) != 0)) {
output.writeInt32(2, age_);
}
if (((bitField0_ & 0x00000004) != 0)) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 3, address_);
}
unknownFields.writeTo(output);
}
@java.lang.Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (((bitField0_ & 0x00000001) != 0)) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_);
}
if (((bitField0_ & 0x00000002) != 0)) {
size += com.google.protobuf.CodedOutputStream
.computeInt32Size(2, age_);
}
if (((bitField0_ & 0x00000004) != 0)) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, address_);
}
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.mjy.protobuf.DataInfo.Student)) {
return super.equals(obj);
}
com.mjy.protobuf.DataInfo.Student other = (com.mjy.protobuf.DataInfo.Student) obj;
if (hasName() != other.hasName()) return false;
if (hasName()) {
if (!getName()
.equals(other.getName())) return false;
}
if (hasAge() != other.hasAge()) return false;
if (hasAge()) {
if (getAge()
!= other.getAge()) return false;
}
if (hasAddress() != other.hasAddress()) return false;
if (hasAddress()) {
if (!getAddress()
.equals(other.getAddress())) 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();
if (hasName()) {
hash = (37 * hash) + NAME_FIELD_NUMBER;
hash = (53 * hash) + getName().hashCode();
}
if (hasAge()) {
hash = (37 * hash) + AGE_FIELD_NUMBER;
hash = (53 * hash) + getAge();
}
if (hasAddress()) {
hash = (37 * hash) + ADDRESS_FIELD_NUMBER;
hash = (53 * hash) + getAddress().hashCode();
}
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
public static com.mjy.protobuf.DataInfo.Student parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static com.mjy.protobuf.DataInfo.Student parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static com.mjy.protobuf.DataInfo.Student parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static com.mjy.protobuf.DataInfo.Student parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static com.mjy.protobuf.DataInfo.Student parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static com.mjy.protobuf.DataInfo.Student parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static com.mjy.protobuf.DataInfo.Student parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static com.mjy.protobuf.DataInfo.Student 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.mjy.protobuf.DataInfo.Student parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static com.mjy.protobuf.DataInfo.Student 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.mjy.protobuf.DataInfo.Student parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static com.mjy.protobuf.DataInfo.Student 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.mjy.protobuf.DataInfo.Student 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;
}
/**
* Protobuf type {@code com.mjy.protobuf.Student}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:com.mjy.protobuf.Student)
com.mjy.protobuf.DataInfo.StudentOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return com.mjy.protobuf.DataInfo.internal_static_com_mjy_protobuf_Student_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return com.mjy.protobuf.DataInfo.internal_static_com_mjy_protobuf_Student_fieldAccessorTable
.ensureFieldAccessorsInitialized(
com.mjy.protobuf.DataInfo.Student.class, com.mjy.protobuf.DataInfo.Student.Builder.class);
}
// Construct using com.mjy.protobuf.DataInfo.Student.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();
name_ = "";
bitField0_ = (bitField0_ & ~0x00000001);
age_ = 0;
bitField0_ = (bitField0_ & ~0x00000002);
address_ = "";
bitField0_ = (bitField0_ & ~0x00000004);
return this;
}
@java.lang.Override
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return com.mjy.protobuf.DataInfo.internal_static_com_mjy_protobuf_Student_descriptor;
}
@java.lang.Override
public com.mjy.protobuf.DataInfo.Student getDefaultInstanceForType() {
return com.mjy.protobuf.DataInfo.Student.getDefaultInstance();
}
@java.lang.Override
public com.mjy.protobuf.DataInfo.Student build() {
com.mjy.protobuf.DataInfo.Student result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@java.lang.Override
public com.mjy.protobuf.DataInfo.Student buildPartial() {
com.mjy.protobuf.DataInfo.Student result = new com.mjy.protobuf.DataInfo.Student(this);
int from_bitField0_ = bitField0_;
int to_bitField0_ = 0;
if (((from_bitField0_ & 0x00000001) != 0)) {
to_bitField0_ |= 0x00000001;
}
result.name_ = name_;
if (((from_bitField0_ & 0x00000002) != 0)) {
result.age_ = age_;
to_bitField0_ |= 0x00000002;
}
if (((from_bitField0_ & 0x00000004) != 0)) {
to_bitField0_ |= 0x00000004;
}
result.address_ = address_;
result.bitField0_ = to_bitField0_;
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.mjy.protobuf.DataInfo.Student) {
return mergeFrom((com.mjy.protobuf.DataInfo.Student)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(com.mjy.protobuf.DataInfo.Student other) {
if (other == com.mjy.protobuf.DataInfo.Student.getDefaultInstance()) return this;
if (other.hasName()) {
bitField0_ |= 0x00000001;
name_ = other.name_;
onChanged();
}
if (other.hasAge()) {
setAge(other.getAge());
}
if (other.hasAddress()) {
bitField0_ |= 0x00000004;
address_ = other.address_;
onChanged();
}
this.mergeUnknownFields(other.unknownFields);
onChanged();
return this;
}
@java.lang.Override
public final boolean isInitialized() {
if (!hasName()) {
return false;
}
return true;
}
@java.lang.Override
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
com.mjy.protobuf.DataInfo.Student parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (com.mjy.protobuf.DataInfo.Student) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private int bitField0_;
private java.lang.Object name_ = "";
/**
* <pre>
*name = 1并不表示name的value为1,1为参数的一个序号
* </pre>
*
* <code>required string name = 1;</code>
* @return Whether the name field is set.
*/
public boolean hasName() {
return ((bitField0_ & 0x00000001) != 0);
}
/**
* <pre>
*name = 1并不表示name的value为1,1为参数的一个序号
* </pre>
*
* <code>required string name = 1;</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();
if (bs.isValidUtf8()) {
name_ = s;
}
return s;
} else {
return (java.lang.String) ref;
}
}
/**
* <pre>
*name = 1并不表示name的value为1,1为参数的一个序号
* </pre>
*
* <code>required string name = 1;</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;
}
}
/**
* <pre>
*name = 1并不表示name的value为1,1为参数的一个序号
* </pre>
*
* <code>required string name = 1;</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();
}
bitField0_ |= 0x00000001;
name_ = value;
onChanged();
return this;
}
/**
* <pre>
*name = 1并不表示name的value为1,1为参数的一个序号
* </pre>
*
* <code>required string name = 1;</code>
* @return This builder for chaining.
*/
public Builder clearName() {
bitField0_ = (bitField0_ & ~0x00000001);
name_ = getDefaultInstance().getName();
onChanged();
return this;
}
/**
* <pre>
*name = 1并不表示name的value为1,1为参数的一个序号
* </pre>
*
* <code>required string name = 1;</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();
}
bitField0_ |= 0x00000001;
name_ = value;
onChanged();
return this;
}
private int age_ ;
/**
* <code>optional int32 age = 2;</code>
* @return Whether the age field is set.
*/
@java.lang.Override
public boolean hasAge() {
return ((bitField0_ & 0x00000002) != 0);
}
/**
* <code>optional int32 age = 2;</code>
* @return The age.
*/
@java.lang.Override
public int getAge() {
return age_;
}
/**
* <code>optional int32 age = 2;</code>
* @param value The age to set.
* @return This builder for chaining.
*/
public Builder setAge(int value) {
bitField0_ |= 0x00000002;
age_ = value;
onChanged();
return this;
}
/**
* <code>optional int32 age = 2;</code>
* @return This builder for chaining.
*/
public Builder clearAge() {
bitField0_ = (bitField0_ & ~0x00000002);
age_ = 0;
onChanged();
return this;
}
private java.lang.Object address_ = "";
/**
* <code>optional string address = 3;</code>
* @return Whether the address field is set.
*/
public boolean hasAddress() {
return ((bitField0_ & 0x00000004) != 0);
}
/**
* <code>optional string address = 3;</code>
* @return The address.
*/
public java.lang.String getAddress() {
java.lang.Object ref = address_;
if (!(ref instanceof java.lang.String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
if (bs.isValidUtf8()) {
address_ = s;
}
return s;
} else {
return (java.lang.String) ref;
}
}
/**
* <code>optional string address = 3;</code>
* @return The bytes for address.
*/
public com.google.protobuf.ByteString
getAddressBytes() {
java.lang.Object ref = address_;
if (ref instanceof String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
address_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
/**
* <code>optional string address = 3;</code>
* @param value The address to set.
* @return This builder for chaining.
*/
public Builder setAddress(
java.lang.String value) {
if (value == null) {
throw new NullPointerException();
}
bitField0_ |= 0x00000004;
address_ = value;
onChanged();
return this;
}
/**
* <code>optional string address = 3;</code>
* @return This builder for chaining.
*/
public Builder clearAddress() {
bitField0_ = (bitField0_ & ~0x00000004);
address_ = getDefaultInstance().getAddress();
onChanged();
return this;
}
/**
* <code>optional string address = 3;</code>
* @param value The bytes for address to set.
* @return This builder for chaining.
*/
public Builder setAddressBytes(
com.google.protobuf.ByteString value) {
if (value == null) {
throw new NullPointerException();
}
bitField0_ |= 0x00000004;
address_ = 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.mjy.protobuf.Student)
}
// @@protoc_insertion_point(class_scope:com.mjy.protobuf.Student)
private static final com.mjy.protobuf.DataInfo.Student DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new com.mjy.protobuf.DataInfo.Student();
}
public static com.mjy.protobuf.DataInfo.Student getDefaultInstance() {
return DEFAULT_INSTANCE;
}
@java.lang.Deprecated public static final com.google.protobuf.Parser<Student>
PARSER = new com.google.protobuf.AbstractParser<Student>() {
@java.lang.Override
public Student parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new Student(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<Student> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<Student> getParserForType() {
return PARSER;
}
@java.lang.Override
public com.mjy.protobuf.DataInfo.Student getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_com_mjy_protobuf_Student_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_com_mjy_protobuf_Student_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&src/main/resources/proto/Student.proto" +
"\022\020com.mjy.protobuf\"5\n\007Student\022\014\n\004name\030\001 " +
"\002(\t\022\013\n\003age\030\002 \001(\005\022\017\n\007address\030\003 \001(\tB\036\n\020com" +
".mjy.protobufB\010DataInfoH\001"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] {
});
internal_static_com_mjy_protobuf_Student_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_com_mjy_protobuf_Student_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_com_mjy_protobuf_Student_descriptor,
new java.lang.String[] { "Name", "Age", "Address", });
}
// @@protoc_insertion_point(outer_class_scope)
}