Google的Protobuf在业界非常流行,很多商业项目选择Protobuf作为编解码框架,这里一起回顾一下Protobuf 的优点。
(1)在谷歌内部长期使用,产品成熟度高:
(2)跨语言,支持多种语言,包括C十十、java和Python.
(3)编码后的消息更小,更加有利于存储和传输:
(4)编解码的性能非常高:
(5)支持不同协议版本的前向兼容:
(6)支辫定义可选和必选字段。本章主要内容包括:
1.Protobuf的入门
2.开发支持Protobuf的Netty服务端
3.开发支持Protobuf的Netty客户端
4.运行基于Netty开发的Protobuf例程
8.1 Protobuf的入门
Protobuf是一个灵活、高效、结构化的数据序列化框架,相比于XML等传统的序列化工具,它更小,更快,更简单。Protobuf支持数据结构化一次可以到处使用,甚至跨语言使用,通过代码生成工具可以自动生成不同语言版本的源代码,甚至可以在使用不同版本的数据结构j进程间进行数据传递,实现数据结构的前向兼容。
下面我们通过一个简单的例程来学习如何使用Protobuf对POJO对象进行编解码,然后,我们以这个例程为基础,学习如何在Netty中对POJO对象迸行Protobuf编解码,并在两个进程之间进行通信和数据交换
8.1.1 Protobuf开发环境搭建
1.SubscribeReq.proto和SubscribeResp.proto
1 package lqy7_protobuf_140; 2 option java_package = "lqy7_protobuf_140"; 3 option java_outer_classname = "SubscribeReqProto"; 4 5 message SubscribeReq{ 6 required int32 subReqID = 1; 7 required string userName = 2; 8 required string productName = 3; 9 repeated string address = 4; 10 }
1 package lqy7_protobuf_140; 2 option java_package = "lqy7_protobuf_140"; 3 option java_outer_classname = "SubscribeRespProto"; 4 5 message SubscribeResp{ 6 required int32 subReqID = 1; 7 required int32 respCode = 2; 8 required string desc = 3; 9 }
windows指令
protoc.exe --java_out=./ SubscribeReq.proto
protoc.exe --java_out=./ SubscribeResp.proto
生成的SubscribeReqProto.java
1 // Generated by the protocol buffer compiler. DO NOT EDIT! 2 // source: SubscribeReq.proto 3 4 package lqy7_protobuf_140; 5 6 public final class SubscribeReqProto { 7 private SubscribeReqProto() {} 8 public static void registerAllExtensions( 9 com.google.protobuf.ExtensionRegistry registry) { 10 } 11 public interface SubscribeReqOrBuilder 12 extends com.google.protobuf.MessageOrBuilder { 13 14 // required int32 subReqID = 1; 15 /** 16 * <code>required int32 subReqID = 1;</code> 17 */ 18 boolean hasSubReqID(); 19 /** 20 * <code>required int32 subReqID = 1;</code> 21 */ 22 int getSubReqID(); 23 24 // required string userName = 2; 25 /** 26 * <code>required string userName = 2;</code> 27 */ 28 boolean hasUserName(); 29 /** 30 * <code>required string userName = 2;</code> 31 */ 32 java.lang.String getUserName(); 33 /** 34 * <code>required string userName = 2;</code> 35 */ 36 com.google.protobuf.ByteString 37 getUserNameBytes(); 38 39 // required string productName = 3; 40 /** 41 * <code>required string productName = 3;</code> 42 */ 43 boolean hasProductName(); 44 /** 45 * <code>required string productName = 3;</code> 46 */ 47 java.lang.String getProductName(); 48 /** 49 * <code>required string productName = 3;</code> 50 */ 51 com.google.protobuf.ByteString 52 getProductNameBytes(); 53 54 // repeated string address = 4; 55 /** 56 * <code>repeated string address = 4;</code> 57 */ 58 java.util.List<java.lang.String> 59 getAddressList(); 60 /** 61 * <code>repeated string address = 4;</code> 62 */ 63 int getAddressCount(); 64 /** 65 * <code>repeated string address = 4;</code> 66 */ 67 java.lang.String getAddress(int index); 68 /** 69 * <code>repeated string address = 4;</code> 70 */ 71 com.google.protobuf.ByteString 72 getAddressBytes(int index); 73 } 74 /** 75 * Protobuf type {@code lqy7_protobuf_140.SubscribeReq} 76 */ 77 public static final class SubscribeReq extends 78 com.google.protobuf.GeneratedMessage 79 implements SubscribeReqOrBuilder { 80 // Use SubscribeReq.newBuilder() to construct. 81 private SubscribeReq(com.google.protobuf.GeneratedMessage.Builder<?> builder) { 82 super(builder); 83 this.unknownFields = builder.getUnknownFields(); 84 } 85 private SubscribeReq(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } 86 87 private static final SubscribeReq defaultInstance; 88 public static SubscribeReq getDefaultInstance() { 89 return defaultInstance; 90 } 91 92 public SubscribeReq getDefaultInstanceForType() { 93 return defaultInstance; 94 } 95 96 private final com.google.protobuf.UnknownFieldSet unknownFields; 97 @java.lang.Override 98 public final com.google.protobuf.UnknownFieldSet 99 getUnknownFields() { 100 return this.unknownFields; 101 } 102 private SubscribeReq( 103 com.google.protobuf.CodedInputStream input, 104 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 105 throws com.google.protobuf.InvalidProtocolBufferException { 106 initFields(); 107 int mutable_bitField0_ = 0; 108 com.google.protobuf.UnknownFieldSet.Builder unknownFields = 109 com.google.protobuf.UnknownFieldSet.newBuilder(); 110 try { 111 boolean done = false; 112 while (!done) { 113 int tag = input.readTag(); 114 switch (tag) { 115 case 0: 116 done = true; 117 break; 118 default: { 119 if (!parseUnknownField(input, unknownFields, 120 extensionRegistry, tag)) { 121 done = true; 122 } 123 break; 124 } 125 case 8: { 126 bitField0_ |= 0x00000001; 127 subReqID_ = input.readInt32(); 128 break; 129 } 130 case 18: { 131 bitField0_ |= 0x00000002; 132 userName_ = input.readBytes(); 133 break; 134 } 135 case 26: { 136 bitField0_ |= 0x00000004; 137 productName_ = input.readBytes(); 138 break; 139 } 140 case 34: { 141 if (!((mutable_bitField0_ & 0x00000008) == 0x00000008)) { 142 address_ = new com.google.protobuf.LazyStringArrayList(); 143 mutable_bitField0_ |= 0x00000008; 144 } 145 address_.add(input.readBytes()); 146 break; 147 } 148 } 149 } 150 } catch (com.google.protobuf.InvalidProtocolBufferException e) { 151 throw e.setUnfinishedMessage(this); 152 } catch (java.io.IOException e) { 153 throw new com.google.protobuf.InvalidProtocolBufferException( 154 e.getMessage()).setUnfinishedMessage(this); 155 } finally { 156 if (((mutable_bitField0_ & 0x00000008) == 0x00000008)) { 157 address_ = new com.google.protobuf.UnmodifiableLazyStringList(address_); 158 } 159 this.unknownFields = unknownFields.build(); 160 makeExtensionsImmutable(); 161 } 162 } 163 public static final com.google.protobuf.Descriptors.Descriptor 164 getDescriptor() { 165 return lqy7_protobuf_140.SubscribeReqProto.internal_static_lqy7_protobuf_140_SubscribeReq_descriptor; 166 } 167 168 protected com.google.protobuf.GeneratedMessage.FieldAccessorTable 169 internalGetFieldAccessorTable() { 170 return lqy7_protobuf_140.SubscribeReqProto.internal_static_lqy7_protobuf_140_SubscribeReq_fieldAccessorTable 171 .ensureFieldAccessorsInitialized( 172 lqy7_protobuf_140.SubscribeReqProto.SubscribeReq.class, lqy7_protobuf_140.SubscribeReqProto.SubscribeReq.Builder.class); 173 } 174 175 public static com.google.protobuf.Parser<SubscribeReq> PARSER = 176 new com.google.protobuf.AbstractParser<SubscribeReq>() { 177 public SubscribeReq parsePartialFrom( 178 com.google.protobuf.CodedInputStream input, 179 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 180 throws com.google.protobuf.InvalidProtocolBufferException { 181 return new SubscribeReq(input, extensionRegistry); 182 } 183 }; 184 185 @java.lang.Override 186 public com.google.protobuf.Parser<SubscribeReq> getParserForType() { 187 return PARSER; 188 } 189 190 private int bitField0_; 191 // required int32 subReqID = 1; 192 public static final int SUBREQID_FIELD_NUMBER = 1; 193 private int subReqID_; 194 /** 195 * <code>required int32 subReqID = 1;</code> 196 */ 197 public boolean hasSubReqID() { 198 return ((bitField0_ & 0x00000001) == 0x00000001); 199 } 200 /** 201 * <code>required int32 subReqID = 1;</code> 202 */ 203 public int getSubReqID() { 204 return subReqID_; 205 } 206 207 // required string userName = 2; 208 public static final int USERNAME_FIELD_NUMBER = 2; 209 private java.lang.Object userName_; 210 /** 211 * <code>required string userName = 2;</code> 212 */ 213 public boolean hasUserName() { 214 return ((bitField0_ & 0x00000002) == 0x00000002); 215 } 216 /** 217 * <code>required string userName = 2;</code> 218 */ 219 public java.lang.String getUserName() { 220 java.lang.Object ref = userName_; 221 if (ref instanceof java.lang.String) { 222 return (java.lang.String) ref; 223 } else { 224 com.google.protobuf.ByteString bs = 225 (com.google.protobuf.ByteString) ref; 226 java.lang.String s = bs.toStringUtf8(); 227 if (bs.isValidUtf8()) { 228 userName_ = s; 229 } 230 return s; 231 } 232 } 233 /** 234 * <code>required string userName = 2;</code> 235 */ 236 public com.google.protobuf.ByteString 237 getUserNameBytes() { 238 java.lang.Object ref = userName_; 239 if (ref instanceof java.lang.String) { 240 com.google.protobuf.ByteString b = 241 com.google.protobuf.ByteString.copyFromUtf8( 242 (java.lang.String) ref); 243 userName_ = b; 244 return b; 245 } else { 246 return (com.google.protobuf.ByteString) ref; 247 } 248 } 249 250 // required string productName = 3; 251 public static final int PRODUCTNAME_FIELD_NUMBER = 3; 252 private java.lang.Object productName_; 253 /** 254 * <code>required string productName = 3;</code> 255 */ 256 public boolean hasProductName() { 257 return ((bitField0_ & 0x00000004) == 0x00000004); 258 } 259 /** 260 * <code>required string productName = 3;</code> 261 */ 262 public java.lang.String getProductName() { 263 java.lang.Object ref = productName_; 264 if (ref instanceof java.lang.String) { 265 return (java.lang.String) ref; 266 } else { 267 com.google.protobuf.ByteString bs = 268 (com.google.protobuf.ByteString) ref; 269 java.lang.String s = bs.toStringUtf8(); 270 if (bs.isValidUtf8()) { 271 productName_ = s; 272 } 273 return s; 274 } 275 } 276 /** 277 * <code>required string productName = 3;</code> 278 */ 279 public com.google.protobuf.ByteString 280 getProductNameBytes() { 281 java.lang.Object ref = productName_; 282 if (ref instanceof java.lang.String) { 283 com.google.protobuf.ByteString b = 284 com.google.protobuf.ByteString.copyFromUtf8( 285 (java.lang.String) ref); 286 productName_ = b; 287 return b; 288 } else { 289 return (com.google.protobuf.ByteString) ref; 290 } 291 } 292 293 // repeated string address = 4; 294 public static final int ADDRESS_FIELD_NUMBER = 4; 295 private com.google.protobuf.LazyStringList address_; 296 /** 297 * <code>repeated string address = 4;</code> 298 */ 299 public java.util.List<java.lang.String> 300 getAddressList() { 301 return address_; 302 } 303 /** 304 * <code>repeated string address = 4;</code> 305 */ 306 public int getAddressCount() { 307 return address_.size(); 308 } 309 /** 310 * <code>repeated string address = 4;</code> 311 */ 312 public java.lang.String getAddress(int index) { 313 return address_.get(index); 314 } 315 /** 316 * <code>repeated string address = 4;</code> 317 */ 318 public com.google.protobuf.ByteString 319 getAddressBytes(int index) { 320 return address_.getByteString(index); 321 } 322 323 private void initFields() { 324 subReqID_ = 0; 325 userName_ = ""; 326 productName_ = ""; 327 address_ = com.google.protobuf.LazyStringArrayList.EMPTY; 328 } 329 private byte memoizedIsInitialized = -1; 330 public final boolean isInitialized() { 331 byte isInitialized = memoizedIsInitialized; 332 if (isInitialized != -1) return isInitialized == 1; 333 334 if (!hasSubReqID()) { 335 memoizedIsInitialized = 0; 336 return false; 337 } 338 if (!hasUserName()) { 339 memoizedIsInitialized = 0; 340 return false; 341 } 342 if (!hasProductName()) { 343 memoizedIsInitialized = 0; 344 return false; 345 } 346 memoizedIsInitialized = 1; 347 return true; 348 } 349 350 public void writeTo(com.google.protobuf.CodedOutputStream output) 351 throws java.io.IOException { 352 getSerializedSize(); 353 if (((bitField0_ & 0x00000001) == 0x00000001)) { 354 output.writeInt32(1, subReqID_); 355 } 356 if (((bitField0_ & 0x00000002) == 0x00000002)) { 357 output.writeBytes(2, getUserNameBytes()); 358 } 359 if (((bitField0_ & 0x00000004) == 0x00000004)) { 360 output.writeBytes(3, getProductNameBytes()); 361 } 362 for (int i = 0; i < address_.size(); i++) { 363 output.writeBytes(4, address_.getByteString(i)); 364 } 365 getUnknownFields().writeTo(output); 366 } 367 368 private int memoizedSerializedSize = -1; 369 public int getSerializedSize() { 370 int size = memoizedSerializedSize; 371 if (size != -1) return size; 372 373 size = 0; 374 if (((bitField0_ & 0x00000001) == 0x00000001)) { 375 size += com.google.protobuf.CodedOutputStream 376 .computeInt32Size(1, subReqID_); 377 } 378 if (((bitField0_ & 0x00000002) == 0x00000002)) { 379 size += com.google.protobuf.CodedOutputStream 380 .computeBytesSize(2, getUserNameBytes()); 381 } 382 if (((bitField0_ & 0x00000004) == 0x00000004)) { 383 size += com.google.protobuf.CodedOutputStream 384 .computeBytesSize(3, getProductNameBytes()); 385 } 386 { 387 int dataSize = 0; 388 for (int i = 0; i < address_.size(); i++) { 389 dataSize += com.google.protobuf.CodedOutputStream 390 .computeBytesSizeNoTag(address_.getByteString(i)); 391 } 392 size += dataSize; 393 size += 1 * getAddressList().size(); 394 } 395 size += getUnknownFields().getSerializedSize(); 396 memoizedSerializedSize = size; 397 return size; 398 } 399 400 private static final long serialVersionUID = 0L; 401 @java.lang.Override 402 protected java.lang.Object writeReplace() 403 throws java.io.ObjectStreamException { 404 return super.writeReplace(); 405 } 406 407 public static lqy7_protobuf_140.SubscribeReqProto.SubscribeReq parseFrom( 408 com.google.protobuf.ByteString data) 409 throws com.google.protobuf.InvalidProtocolBufferException { 410 return PARSER.parseFrom(data); 411 } 412 public static lqy7_protobuf_140.SubscribeReqProto.SubscribeReq parseFrom( 413 com.google.protobuf.ByteString data, 414 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 415 throws com.google.protobuf.InvalidProtocolBufferException { 416 return PARSER.parseFrom(data, extensionRegistry); 417 } 418 public static lqy7_protobuf_140.SubscribeReqProto.SubscribeReq parseFrom(byte[] data) 419 throws com.google.protobuf.InvalidProtocolBufferException { 420 return PARSER.parseFrom(data); 421 } 422 public static lqy7_protobuf_140.SubscribeReqProto.SubscribeReq parseFrom( 423 byte[] data, 424 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 425 throws com.google.protobuf.InvalidProtocolBufferException { 426 return PARSER.parseFrom(data, extensionRegistry); 427 } 428 public static lqy7_protobuf_140.SubscribeReqProto.SubscribeReq parseFrom(java.io.InputStream input) 429 throws java.io.IOException { 430 return PARSER.parseFrom(input); 431 } 432 public static lqy7_protobuf_140.SubscribeReqProto.SubscribeReq parseFrom( 433 java.io.InputStream input, 434 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 435 throws java.io.IOException { 436 return PARSER.parseFrom(input, extensionRegistry); 437 } 438 public static lqy7_protobuf_140.SubscribeReqProto.SubscribeReq parseDelimitedFrom(java.io.InputStream input) 439 throws java.io.IOException { 440 return PARSER.parseDelimitedFrom(input); 441 } 442 public static lqy7_protobuf_140.SubscribeReqProto.SubscribeReq parseDelimitedFrom( 443 java.io.InputStream input, 444 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 445 throws java.io.IOException { 446 return PARSER.parseDelimitedFrom(input, extensionRegistry); 447 } 448 public static lqy7_protobuf_140.SubscribeReqProto.SubscribeReq parseFrom( 449 com.google.protobuf.CodedInputStream input) 450 throws java.io.IOException { 451 return PARSER.parseFrom(input); 452 } 453 public static lqy7_protobuf_140.SubscribeReqProto.SubscribeReq parseFrom( 454 com.google.protobuf.CodedInputStream input, 455 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 456 throws java.io.IOException { 457 return PARSER.parseFrom(input, extensionRegistry); 458 } 459 460 public static Builder newBuilder() { return Builder.create(); } 461 public Builder newBuilderForType() { return newBuilder(); } 462 public static Builder newBuilder(lqy7_protobuf_140.SubscribeReqProto.SubscribeReq prototype) { 463 return newBuilder().mergeFrom(prototype); 464 } 465 public Builder toBuilder() { return newBuilder(this); } 466 467 @java.lang.Override 468 protected Builder newBuilderForType( 469 com.google.protobuf.GeneratedMessage.BuilderParent parent) { 470 Builder builder = new Builder(parent); 471 return builder; 472 } 473 /** 474 * Protobuf type {@code lqy7_protobuf_140.SubscribeReq} 475 */ 476 public static final class Builder extends 477 com.google.protobuf.GeneratedMessage.Builder<Builder> 478 implements lqy7_protobuf_140.SubscribeReqProto.SubscribeReqOrBuilder { 479 public static final com.google.protobuf.Descriptors.Descriptor 480 getDescriptor() { 481 return lqy7_protobuf_140.SubscribeReqProto.internal_static_lqy7_protobuf_140_SubscribeReq_descriptor; 482 } 483 484 protected com.google.protobuf.GeneratedMessage.FieldAccessorTable 485 internalGetFieldAccessorTable() { 486 return lqy7_protobuf_140.SubscribeReqProto.internal_static_lqy7_protobuf_140_SubscribeReq_fieldAccessorTable 487 .ensureFieldAccessorsInitialized( 488 lqy7_protobuf_140.SubscribeReqProto.SubscribeReq.class, lqy7_protobuf_140.SubscribeReqProto.SubscribeReq.Builder.class); 489 } 490 491 // Construct using lqy7_protobuf_140.SubscribeReqProto.SubscribeReq.newBuilder() 492 private Builder() { 493 maybeForceBuilderInitialization(); 494 } 495 496 private Builder( 497 com.google.protobuf.GeneratedMessage.BuilderParent parent) { 498 super(parent); 499 maybeForceBuilderInitialization(); 500 } 501 private void maybeForceBuilderInitialization() { 502 if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { 503 } 504 } 505 private static Builder create() { 506 return new Builder(); 507 } 508 509 public Builder clear() { 510 super.clear(); 511 subReqID_ = 0; 512 bitField0_ = (bitField0_ & ~0x00000001); 513 userName_ = ""; 514 bitField0_ = (bitField0_ & ~0x00000002); 515 productName_ = ""; 516 bitField0_ = (bitField0_ & ~0x00000004); 517 address_ = com.google.protobuf.LazyStringArrayList.EMPTY; 518 bitField0_ = (bitField0_ & ~0x00000008); 519 return this; 520 } 521 522 public Builder clone() { 523 return create().mergeFrom(buildPartial()); 524 } 525 526 public com.google.protobuf.Descriptors.Descriptor 527 getDescriptorForType() { 528 return lqy7_protobuf_140.SubscribeReqProto.internal_static_lqy7_protobuf_140_SubscribeReq_descriptor; 529 } 530 531 public lqy7_protobuf_140.SubscribeReqProto.SubscribeReq getDefaultInstanceForType() { 532 return lqy7_protobuf_140.SubscribeReqProto.SubscribeReq.getDefaultInstance(); 533 } 534 535 public lqy7_protobuf_140.SubscribeReqProto.SubscribeReq build() { 536 lqy7_protobuf_140.SubscribeReqProto.SubscribeReq result = buildPartial(); 537 if (!result.isInitialized()) { 538 throw newUninitializedMessageException(result); 539 } 540 return result; 541 } 542 543 public lqy7_protobuf_140.SubscribeReqProto.SubscribeReq buildPartial() { 544 lqy7_protobuf_140.SubscribeReqProto.SubscribeReq result = new lqy7_protobuf_140.SubscribeReqProto.SubscribeReq(this); 545 int from_bitField0_ = bitField0_; 546 int to_bitField0_ = 0; 547 if (((from_bitField0_ & 0x00000001) == 0x00000001)) { 548 to_bitField0_ |= 0x00000001; 549 } 550 result.subReqID_ = subReqID_; 551 if (((from_bitField0_ & 0x00000002) == 0x00000002)) { 552 to_bitField0_ |= 0x00000002; 553 } 554 result.userName_ = userName_; 555 if (((from_bitField0_ & 0x00000004) == 0x00000004)) { 556 to_bitField0_ |= 0x00000004; 557 } 558 result.productName_ = productName_; 559 if (((bitField0_ & 0x00000008) == 0x00000008)) { 560 address_ = new com.google.protobuf.UnmodifiableLazyStringList( 561 address_); 562 bitField0_ = (bitField0_ & ~0x00000008); 563 } 564 result.address_ = address_; 565 result.bitField0_ = to_bitField0_; 566 onBuilt(); 567 return result; 568 } 569 570 public Builder mergeFrom(com.google.protobuf.Message other) { 571 if (other instanceof lqy7_protobuf_140.SubscribeReqProto.SubscribeReq) { 572 return mergeFrom((lqy7_protobuf_140.SubscribeReqProto.SubscribeReq)other); 573 } else { 574 super.mergeFrom(other); 575 return this; 576 } 577 } 578 579 public Builder mergeFrom(lqy7_protobuf_140.SubscribeReqProto.SubscribeReq other) { 580 if (other == lqy7_protobuf_140.SubscribeReqProto.SubscribeReq.getDefaultInstance()) return this; 581 if (other.hasSubReqID()) { 582 setSubReqID(other.getSubReqID()); 583 } 584 if (other.hasUserName()) { 585 bitField0_ |= 0x00000002; 586 userName_ = other.userName_; 587 onChanged(); 588 } 589 if (other.hasProductName()) { 590 bitField0_ |= 0x00000004; 591 productName_ = other.productName_; 592 onChanged(); 593 } 594 if (!other.address_.isEmpty()) { 595 if (address_.isEmpty()) { 596 address_ = other.address_; 597 bitField0_ = (bitField0_ & ~0x00000008); 598 } else { 599 ensureAddressIsMutable(); 600 address_.addAll(other.address_); 601 } 602 onChanged(); 603 } 604 this.mergeUnknownFields(other.getUnknownFields()); 605 return this; 606 } 607 608 public final boolean isInitialized() { 609 if (!hasSubReqID()) { 610 611 return false; 612 } 613 if (!hasUserName()) { 614 615 return false; 616 } 617 if (!hasProductName()) { 618 619 return false; 620 } 621 return true; 622 } 623 624 public Builder mergeFrom( 625 com.google.protobuf.CodedInputStream input, 626 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 627 throws java.io.IOException { 628 lqy7_protobuf_140.SubscribeReqProto.SubscribeReq parsedMessage = null; 629 try { 630 parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); 631 } catch (com.google.protobuf.InvalidProtocolBufferException e) { 632 parsedMessage = (lqy7_protobuf_140.SubscribeReqProto.SubscribeReq) e.getUnfinishedMessage(); 633 throw e; 634 } finally { 635 if (parsedMessage != null) { 636 mergeFrom(parsedMessage); 637 } 638 } 639 return this; 640 } 641 private int bitField0_; 642 643 // required int32 subReqID = 1; 644 private int subReqID_ ; 645 /** 646 * <code>required int32 subReqID = 1;</code> 647 */ 648 public boolean hasSubReqID() { 649 return ((bitField0_ & 0x00000001) == 0x00000001); 650 } 651 /** 652 * <code>required int32 subReqID = 1;</code> 653 */ 654 public int getSubReqID() { 655 return subReqID_; 656 } 657 /** 658 * <code>required int32 subReqID = 1;</code> 659 */ 660 public Builder setSubReqID(int value) { 661 bitField0_ |= 0x00000001; 662 subReqID_ = value; 663 onChanged(); 664 return this; 665 } 666 /** 667 * <code>required int32 subReqID = 1;</code> 668 */ 669 public Builder clearSubReqID() { 670 bitField0_ = (bitField0_ & ~0x00000001); 671 subReqID_ = 0; 672 onChanged(); 673 return this; 674 } 675 676 // required string userName = 2; 677 private java.lang.Object userName_ = ""; 678 /** 679 * <code>required string userName = 2;</code> 680 */ 681 public boolean hasUserName() { 682 return ((bitField0_ & 0x00000002) == 0x00000002); 683 } 684 /** 685 * <code>required string userName = 2;</code> 686 */ 687 public java.lang.String getUserName() { 688 java.lang.Object ref = userName_; 689 if (!(ref instanceof java.lang.String)) { 690 java.lang.String s = ((com.google.protobuf.ByteString) ref) 691 .toStringUtf8(); 692 userName_ = s; 693 return s; 694 } else { 695 return (java.lang.String) ref; 696 } 697 } 698 /** 699 * <code>required string userName = 2;</code> 700 */ 701 public com.google.protobuf.ByteString 702 getUserNameBytes() { 703 java.lang.Object ref = userName_; 704 if (ref instanceof String) { 705 com.google.protobuf.ByteString b = 706 com.google.protobuf.ByteString.copyFromUtf8( 707 (java.lang.String) ref); 708 userName_ = b; 709 return b; 710 } else { 711 return (com.google.protobuf.ByteString) ref; 712 } 713 } 714 /** 715 * <code>required string userName = 2;</code> 716 */ 717 public Builder setUserName( 718 java.lang.String value) { 719 if (value == null) { 720 throw new NullPointerException(); 721 } 722 bitField0_ |= 0x00000002; 723 userName_ = value; 724 onChanged(); 725 return this; 726 } 727 /** 728 * <code>required string userName = 2;</code> 729 */ 730 public Builder clearUserName() { 731 bitField0_ = (bitField0_ & ~0x00000002); 732 userName_ = getDefaultInstance().getUserName(); 733 onChanged(); 734 return this; 735 } 736 /** 737 * <code>required string userName = 2;</code> 738 */ 739 public Builder setUserNameBytes( 740 com.google.protobuf.ByteString value) { 741 if (value == null) { 742 throw new NullPointerException(); 743 } 744 bitField0_ |= 0x00000002; 745 userName_ = value; 746 onChanged(); 747 return this; 748 } 749 750 // required string productName = 3; 751 private java.lang.Object productName_ = ""; 752 /** 753 * <code>required string productName = 3;</code> 754 */ 755 public boolean hasProductName() { 756 return ((bitField0_ & 0x00000004) == 0x00000004); 757 } 758 /** 759 * <code>required string productName = 3;</code> 760 */ 761 public java.lang.String getProductName() { 762 java.lang.Object ref = productName_; 763 if (!(ref instanceof java.lang.String)) { 764 java.lang.String s = ((com.google.protobuf.ByteString) ref) 765 .toStringUtf8(); 766 productName_ = s; 767 return s; 768 } else { 769 return (java.lang.String) ref; 770 } 771 } 772 /** 773 * <code>required string productName = 3;</code> 774 */ 775 public com.google.protobuf.ByteString 776 getProductNameBytes() { 777 java.lang.Object ref = productName_; 778 if (ref instanceof String) { 779 com.google.protobuf.ByteString b = 780 com.google.protobuf.ByteString.copyFromUtf8( 781 (java.lang.String) ref); 782 productName_ = b; 783 return b; 784 } else { 785 return (com.google.protobuf.ByteString) ref; 786 } 787 } 788 /** 789 * <code>required string productName = 3;</code> 790 */ 791 public Builder setProductName( 792 java.lang.String value) { 793 if (value == null) { 794 throw new NullPointerException(); 795 } 796 bitField0_ |= 0x00000004; 797 productName_ = value; 798 onChanged(); 799 return this; 800 } 801 /** 802 * <code>required string productName = 3;</code> 803 */ 804 public Builder clearProductName() { 805 bitField0_ = (bitField0_ & ~0x00000004); 806 productName_ = getDefaultInstance().getProductName(); 807 onChanged(); 808 return this; 809 } 810 /** 811 * <code>required string productName = 3;</code> 812 */ 813 public Builder setProductNameBytes( 814 com.google.protobuf.ByteString value) { 815 if (value == null) { 816 throw new NullPointerException(); 817 } 818 bitField0_ |= 0x00000004; 819 productName_ = value; 820 onChanged(); 821 return this; 822 } 823 824 // repeated string address = 4; 825 private com.google.protobuf.LazyStringList address_ = com.google.protobuf.LazyStringArrayList.EMPTY; 826 private void ensureAddressIsMutable() { 827 if (!((bitField0_ & 0x00000008) == 0x00000008)) { 828 address_ = new com.google.protobuf.LazyStringArrayList(address_); 829 bitField0_ |= 0x00000008; 830 } 831 } 832 /** 833 * <code>repeated string address = 4;</code> 834 */ 835 public java.util.List<java.lang.String> 836 getAddressList() { 837 return java.util.Collections.unmodifiableList(address_); 838 } 839 /** 840 * <code>repeated string address = 4;</code> 841 */ 842 public int getAddressCount() { 843 return address_.size(); 844 } 845 /** 846 * <code>repeated string address = 4;</code> 847 */ 848 public java.lang.String getAddress(int index) { 849 return address_.get(index); 850 } 851 /** 852 * <code>repeated string address = 4;</code> 853 */ 854 public com.google.protobuf.ByteString 855 getAddressBytes(int index) { 856 return address_.getByteString(index); 857 } 858 /** 859 * <code>repeated string address = 4;</code> 860 */ 861 public Builder setAddress( 862 int index, java.lang.String value) { 863 if (value == null) { 864 throw new NullPointerException(); 865 } 866 ensureAddressIsMutable(); 867 address_.set(index, value); 868 onChanged(); 869 return this; 870 } 871 /** 872 * <code>repeated string address = 4;</code> 873 */ 874 public Builder addAddress( 875 java.lang.String value) { 876 if (value == null) { 877 throw new NullPointerException(); 878 } 879 ensureAddressIsMutable(); 880 address_.add(value); 881 onChanged(); 882 return this; 883 } 884 /** 885 * <code>repeated string address = 4;</code> 886 */ 887 public Builder addAllAddress( 888 java.lang.Iterable<java.lang.String> values) { 889 ensureAddressIsMutable(); 890 super.addAll(values, address_); 891 onChanged(); 892 return this; 893 } 894 /** 895 * <code>repeated string address = 4;</code> 896 */ 897 public Builder clearAddress() { 898 address_ = com.google.protobuf.LazyStringArrayList.EMPTY; 899 bitField0_ = (bitField0_ & ~0x00000008); 900 onChanged(); 901 return this; 902 } 903 /** 904 * <code>repeated string address = 4;</code> 905 */ 906 public Builder addAddressBytes( 907 com.google.protobuf.ByteString value) { 908 if (value == null) { 909 throw new NullPointerException(); 910 } 911 ensureAddressIsMutable(); 912 address_.add(value); 913 onChanged(); 914 return this; 915 } 916 917 // @@protoc_insertion_point(builder_scope:lqy7_protobuf_140.SubscribeReq) 918 } 919 920 static { 921 defaultInstance = new SubscribeReq(true); 922 defaultInstance.initFields(); 923 } 924 925 // @@protoc_insertion_point(class_scope:lqy7_protobuf_140.SubscribeReq) 926 } 927 928 private static com.google.protobuf.Descriptors.Descriptor 929 internal_static_lqy7_protobuf_140_SubscribeReq_descriptor; 930 private static 931 com.google.protobuf.GeneratedMessage.FieldAccessorTable 932 internal_static_lqy7_protobuf_140_SubscribeReq_fieldAccessorTable; 933 934 public static com.google.protobuf.Descriptors.FileDescriptor 935 getDescriptor() { 936 return descriptor; 937 } 938 private static com.google.protobuf.Descriptors.FileDescriptor 939 descriptor; 940 static { 941 java.lang.String[] descriptorData = { 942 "\n\022SubscribeReq.proto\022\021lqy7_protobuf_140\"" + 943 "X\n\014SubscribeReq\022\020\n\010subReqID\030\001 \002(\005\022\020\n\010use" + 944 "rName\030\002 \002(\t\022\023\n\013productName\030\003 \002(\t\022\017\n\007addr" + 945 "ess\030\004 \003(\tB&\n\021lqy7_protobuf_140B\021Subscrib" + 946 "eReqProto" 947 }; 948 com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = 949 new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { 950 public com.google.protobuf.ExtensionRegistry assignDescriptors( 951 com.google.protobuf.Descriptors.FileDescriptor root) { 952 descriptor = root; 953 internal_static_lqy7_protobuf_140_SubscribeReq_descriptor = 954 getDescriptor().getMessageTypes().get(0); 955 internal_static_lqy7_protobuf_140_SubscribeReq_fieldAccessorTable = new 956 com.google.protobuf.GeneratedMessage.FieldAccessorTable( 957 internal_static_lqy7_protobuf_140_SubscribeReq_descriptor, 958 new java.lang.String[] { "SubReqID", "UserName", "ProductName", "Address", }); 959 return null; 960 } 961 }; 962 com.google.protobuf.Descriptors.FileDescriptor 963 .internalBuildGeneratedFileFrom(descriptorData, 964 new com.google.protobuf.Descriptors.FileDescriptor[] { 965 }, assigner); 966 } 967 968 // @@protoc_insertion_point(outer_class_scope) 969 }
生成的SubscribeRespProto.java
1 // Generated by the protocol buffer compiler. DO NOT EDIT! 2 // source: SubscribeResp.proto 3 4 package lqy7_protobuf_140; 5 6 public final class SubscribeRespProto { 7 private SubscribeRespProto() {} 8 public static void registerAllExtensions( 9 com.google.protobuf.ExtensionRegistry registry) { 10 } 11 public interface SubscribeRespOrBuilder 12 extends com.google.protobuf.MessageOrBuilder { 13 14 // required int32 subReqID = 1; 15 /** 16 * <code>required int32 subReqID = 1;</code> 17 */ 18 boolean hasSubReqID(); 19 /** 20 * <code>required int32 subReqID = 1;</code> 21 */ 22 int getSubReqID(); 23 24 // required int32 respCode = 2; 25 /** 26 * <code>required int32 respCode = 2;</code> 27 */ 28 boolean hasRespCode(); 29 /** 30 * <code>required int32 respCode = 2;</code> 31 */ 32 int getRespCode(); 33 34 // required string desc = 3; 35 /** 36 * <code>required string desc = 3;</code> 37 */ 38 boolean hasDesc(); 39 /** 40 * <code>required string desc = 3;</code> 41 */ 42 java.lang.String getDesc(); 43 /** 44 * <code>required string desc = 3;</code> 45 */ 46 com.google.protobuf.ByteString 47 getDescBytes(); 48 } 49 /** 50 * Protobuf type {@code lqy7_protobuf_140.SubscribeResp} 51 */ 52 public static final class SubscribeResp extends 53 com.google.protobuf.GeneratedMessage 54 implements SubscribeRespOrBuilder { 55 // Use SubscribeResp.newBuilder() to construct. 56 private SubscribeResp(com.google.protobuf.GeneratedMessage.Builder<?> builder) { 57 super(builder); 58 this.unknownFields = builder.getUnknownFields(); 59 } 60 private SubscribeResp(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } 61 62 private static final SubscribeResp defaultInstance; 63 public static SubscribeResp getDefaultInstance() { 64 return defaultInstance; 65 } 66 67 public SubscribeResp getDefaultInstanceForType() { 68 return defaultInstance; 69 } 70 71 private final com.google.protobuf.UnknownFieldSet unknownFields; 72 @java.lang.Override 73 public final com.google.protobuf.UnknownFieldSet 74 getUnknownFields() { 75 return this.unknownFields; 76 } 77 private SubscribeResp( 78 com.google.protobuf.CodedInputStream input, 79 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 80 throws com.google.protobuf.InvalidProtocolBufferException { 81 initFields(); 82 int mutable_bitField0_ = 0; 83 com.google.protobuf.UnknownFieldSet.Builder unknownFields = 84 com.google.protobuf.UnknownFieldSet.newBuilder(); 85 try { 86 boolean done = false; 87 while (!done) { 88 int tag = input.readTag(); 89 switch (tag) { 90 case 0: 91 done = true; 92 break; 93 default: { 94 if (!parseUnknownField(input, unknownFields, 95 extensionRegistry, tag)) { 96 done = true; 97 } 98 break; 99 } 100 case 8: { 101 bitField0_ |= 0x00000001; 102 subReqID_ = input.readInt32(); 103 break; 104 } 105 case 16: { 106 bitField0_ |= 0x00000002; 107 respCode_ = input.readInt32(); 108 break; 109 } 110 case 26: { 111 bitField0_ |= 0x00000004; 112 desc_ = input.readBytes(); 113 break; 114 } 115 } 116 } 117 } catch (com.google.protobuf.InvalidProtocolBufferException e) { 118 throw e.setUnfinishedMessage(this); 119 } catch (java.io.IOException e) { 120 throw new com.google.protobuf.InvalidProtocolBufferException( 121 e.getMessage()).setUnfinishedMessage(this); 122 } finally { 123 this.unknownFields = unknownFields.build(); 124 makeExtensionsImmutable(); 125 } 126 } 127 public static final com.google.protobuf.Descriptors.Descriptor 128 getDescriptor() { 129 return lqy7_protobuf_140.SubscribeRespProto.internal_static_lqy7_protobuf_140_SubscribeResp_descriptor; 130 } 131 132 protected com.google.protobuf.GeneratedMessage.FieldAccessorTable 133 internalGetFieldAccessorTable() { 134 return lqy7_protobuf_140.SubscribeRespProto.internal_static_lqy7_protobuf_140_SubscribeResp_fieldAccessorTable 135 .ensureFieldAccessorsInitialized( 136 lqy7_protobuf_140.SubscribeRespProto.SubscribeResp.class, lqy7_protobuf_140.SubscribeRespProto.SubscribeResp.Builder.class); 137 } 138 139 public static com.google.protobuf.Parser<SubscribeResp> PARSER = 140 new com.google.protobuf.AbstractParser<SubscribeResp>() { 141 public SubscribeResp parsePartialFrom( 142 com.google.protobuf.CodedInputStream input, 143 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 144 throws com.google.protobuf.InvalidProtocolBufferException { 145 return new SubscribeResp(input, extensionRegistry); 146 } 147 }; 148 149 @java.lang.Override 150 public com.google.protobuf.Parser<SubscribeResp> getParserForType() { 151 return PARSER; 152 } 153 154 private int bitField0_; 155 // required int32 subReqID = 1; 156 public static final int SUBREQID_FIELD_NUMBER = 1; 157 private int subReqID_; 158 /** 159 * <code>required int32 subReqID = 1;</code> 160 */ 161 public boolean hasSubReqID() { 162 return ((bitField0_ & 0x00000001) == 0x00000001); 163 } 164 /** 165 * <code>required int32 subReqID = 1;</code> 166 */ 167 public int getSubReqID() { 168 return subReqID_; 169 } 170 171 // required int32 respCode = 2; 172 public static final int RESPCODE_FIELD_NUMBER = 2; 173 private int respCode_; 174 /** 175 * <code>required int32 respCode = 2;</code> 176 */ 177 public boolean hasRespCode() { 178 return ((bitField0_ & 0x00000002) == 0x00000002); 179 } 180 /** 181 * <code>required int32 respCode = 2;</code> 182 */ 183 public int getRespCode() { 184 return respCode_; 185 } 186 187 // required string desc = 3; 188 public static final int DESC_FIELD_NUMBER = 3; 189 private java.lang.Object desc_; 190 /** 191 * <code>required string desc = 3;</code> 192 */ 193 public boolean hasDesc() { 194 return ((bitField0_ & 0x00000004) == 0x00000004); 195 } 196 /** 197 * <code>required string desc = 3;</code> 198 */ 199 public java.lang.String getDesc() { 200 java.lang.Object ref = desc_; 201 if (ref instanceof java.lang.String) { 202 return (java.lang.String) ref; 203 } else { 204 com.google.protobuf.ByteString bs = 205 (com.google.protobuf.ByteString) ref; 206 java.lang.String s = bs.toStringUtf8(); 207 if (bs.isValidUtf8()) { 208 desc_ = s; 209 } 210 return s; 211 } 212 } 213 /** 214 * <code>required string desc = 3;</code> 215 */ 216 public com.google.protobuf.ByteString 217 getDescBytes() { 218 java.lang.Object ref = desc_; 219 if (ref instanceof java.lang.String) { 220 com.google.protobuf.ByteString b = 221 com.google.protobuf.ByteString.copyFromUtf8( 222 (java.lang.String) ref); 223 desc_ = b; 224 return b; 225 } else { 226 return (com.google.protobuf.ByteString) ref; 227 } 228 } 229 230 private void initFields() { 231 subReqID_ = 0; 232 respCode_ = 0; 233 desc_ = ""; 234 } 235 private byte memoizedIsInitialized = -1; 236 public final boolean isInitialized() { 237 byte isInitialized = memoizedIsInitialized; 238 if (isInitialized != -1) return isInitialized == 1; 239 240 if (!hasSubReqID()) { 241 memoizedIsInitialized = 0; 242 return false; 243 } 244 if (!hasRespCode()) { 245 memoizedIsInitialized = 0; 246 return false; 247 } 248 if (!hasDesc()) { 249 memoizedIsInitialized = 0; 250 return false; 251 } 252 memoizedIsInitialized = 1; 253 return true; 254 } 255 256 public void writeTo(com.google.protobuf.CodedOutputStream output) 257 throws java.io.IOException { 258 getSerializedSize(); 259 if (((bitField0_ & 0x00000001) == 0x00000001)) { 260 output.writeInt32(1, subReqID_); 261 } 262 if (((bitField0_ & 0x00000002) == 0x00000002)) { 263 output.writeInt32(2, respCode_); 264 } 265 if (((bitField0_ & 0x00000004) == 0x00000004)) { 266 output.writeBytes(3, getDescBytes()); 267 } 268 getUnknownFields().writeTo(output); 269 } 270 271 private int memoizedSerializedSize = -1; 272 public int getSerializedSize() { 273 int size = memoizedSerializedSize; 274 if (size != -1) return size; 275 276 size = 0; 277 if (((bitField0_ & 0x00000001) == 0x00000001)) { 278 size += com.google.protobuf.CodedOutputStream 279 .computeInt32Size(1, subReqID_); 280 } 281 if (((bitField0_ & 0x00000002) == 0x00000002)) { 282 size += com.google.protobuf.CodedOutputStream 283 .computeInt32Size(2, respCode_); 284 } 285 if (((bitField0_ & 0x00000004) == 0x00000004)) { 286 size += com.google.protobuf.CodedOutputStream 287 .computeBytesSize(3, getDescBytes()); 288 } 289 size += getUnknownFields().getSerializedSize(); 290 memoizedSerializedSize = size; 291 return size; 292 } 293 294 private static final long serialVersionUID = 0L; 295 @java.lang.Override 296 protected java.lang.Object writeReplace() 297 throws java.io.ObjectStreamException { 298 return super.writeReplace(); 299 } 300 301 public static lqy7_protobuf_140.SubscribeRespProto.SubscribeResp parseFrom( 302 com.google.protobuf.ByteString data) 303 throws com.google.protobuf.InvalidProtocolBufferException { 304 return PARSER.parseFrom(data); 305 } 306 public static lqy7_protobuf_140.SubscribeRespProto.SubscribeResp parseFrom( 307 com.google.protobuf.ByteString data, 308 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 309 throws com.google.protobuf.InvalidProtocolBufferException { 310 return PARSER.parseFrom(data, extensionRegistry); 311 } 312 public static lqy7_protobuf_140.SubscribeRespProto.SubscribeResp parseFrom(byte[] data) 313 throws com.google.protobuf.InvalidProtocolBufferException { 314 return PARSER.parseFrom(data); 315 } 316 public static lqy7_protobuf_140.SubscribeRespProto.SubscribeResp parseFrom( 317 byte[] data, 318 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 319 throws com.google.protobuf.InvalidProtocolBufferException { 320 return PARSER.parseFrom(data, extensionRegistry); 321 } 322 public static lqy7_protobuf_140.SubscribeRespProto.SubscribeResp parseFrom(java.io.InputStream input) 323 throws java.io.IOException { 324 return PARSER.parseFrom(input); 325 } 326 public static lqy7_protobuf_140.SubscribeRespProto.SubscribeResp parseFrom( 327 java.io.InputStream input, 328 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 329 throws java.io.IOException { 330 return PARSER.parseFrom(input, extensionRegistry); 331 } 332 public static lqy7_protobuf_140.SubscribeRespProto.SubscribeResp parseDelimitedFrom(java.io.InputStream input) 333 throws java.io.IOException { 334 return PARSER.parseDelimitedFrom(input); 335 } 336 public static lqy7_protobuf_140.SubscribeRespProto.SubscribeResp parseDelimitedFrom( 337 java.io.InputStream input, 338 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 339 throws java.io.IOException { 340 return PARSER.parseDelimitedFrom(input, extensionRegistry); 341 } 342 public static lqy7_protobuf_140.SubscribeRespProto.SubscribeResp parseFrom( 343 com.google.protobuf.CodedInputStream input) 344 throws java.io.IOException { 345 return PARSER.parseFrom(input); 346 } 347 public static lqy7_protobuf_140.SubscribeRespProto.SubscribeResp parseFrom( 348 com.google.protobuf.CodedInputStream input, 349 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 350 throws java.io.IOException { 351 return PARSER.parseFrom(input, extensionRegistry); 352 } 353 354 public static Builder newBuilder() { return Builder.create(); } 355 public Builder newBuilderForType() { return newBuilder(); } 356 public static Builder newBuilder(lqy7_protobuf_140.SubscribeRespProto.SubscribeResp prototype) { 357 return newBuilder().mergeFrom(prototype); 358 } 359 public Builder toBuilder() { return newBuilder(this); } 360 361 @java.lang.Override 362 protected Builder newBuilderForType( 363 com.google.protobuf.GeneratedMessage.BuilderParent parent) { 364 Builder builder = new Builder(parent); 365 return builder; 366 } 367 /** 368 * Protobuf type {@code lqy7_protobuf_140.SubscribeResp} 369 */ 370 public static final class Builder extends 371 com.google.protobuf.GeneratedMessage.Builder<Builder> 372 implements lqy7_protobuf_140.SubscribeRespProto.SubscribeRespOrBuilder { 373 public static final com.google.protobuf.Descriptors.Descriptor 374 getDescriptor() { 375 return lqy7_protobuf_140.SubscribeRespProto.internal_static_lqy7_protobuf_140_SubscribeResp_descriptor; 376 } 377 378 protected com.google.protobuf.GeneratedMessage.FieldAccessorTable 379 internalGetFieldAccessorTable() { 380 return lqy7_protobuf_140.SubscribeRespProto.internal_static_lqy7_protobuf_140_SubscribeResp_fieldAccessorTable 381 .ensureFieldAccessorsInitialized( 382 lqy7_protobuf_140.SubscribeRespProto.SubscribeResp.class, lqy7_protobuf_140.SubscribeRespProto.SubscribeResp.Builder.class); 383 } 384 385 // Construct using lqy7_protobuf_140.SubscribeRespProto.SubscribeResp.newBuilder() 386 private Builder() { 387 maybeForceBuilderInitialization(); 388 } 389 390 private Builder( 391 com.google.protobuf.GeneratedMessage.BuilderParent parent) { 392 super(parent); 393 maybeForceBuilderInitialization(); 394 } 395 private void maybeForceBuilderInitialization() { 396 if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { 397 } 398 } 399 private static Builder create() { 400 return new Builder(); 401 } 402 403 public Builder clear() { 404 super.clear(); 405 subReqID_ = 0; 406 bitField0_ = (bitField0_ & ~0x00000001); 407 respCode_ = 0; 408 bitField0_ = (bitField0_ & ~0x00000002); 409 desc_ = ""; 410 bitField0_ = (bitField0_ & ~0x00000004); 411 return this; 412 } 413 414 public Builder clone() { 415 return create().mergeFrom(buildPartial()); 416 } 417 418 public com.google.protobuf.Descriptors.Descriptor 419 getDescriptorForType() { 420 return lqy7_protobuf_140.SubscribeRespProto.internal_static_lqy7_protobuf_140_SubscribeResp_descriptor; 421 } 422 423 public lqy7_protobuf_140.SubscribeRespProto.SubscribeResp getDefaultInstanceForType() { 424 return lqy7_protobuf_140.SubscribeRespProto.SubscribeResp.getDefaultInstance(); 425 } 426 427 public lqy7_protobuf_140.SubscribeRespProto.SubscribeResp build() { 428 lqy7_protobuf_140.SubscribeRespProto.SubscribeResp result = buildPartial(); 429 if (!result.isInitialized()) { 430 throw newUninitializedMessageException(result); 431 } 432 return result; 433 } 434 435 public lqy7_protobuf_140.SubscribeRespProto.SubscribeResp buildPartial() { 436 lqy7_protobuf_140.SubscribeRespProto.SubscribeResp result = new lqy7_protobuf_140.SubscribeRespProto.SubscribeResp(this); 437 int from_bitField0_ = bitField0_; 438 int to_bitField0_ = 0; 439 if (((from_bitField0_ & 0x00000001) == 0x00000001)) { 440 to_bitField0_ |= 0x00000001; 441 } 442 result.subReqID_ = subReqID_; 443 if (((from_bitField0_ & 0x00000002) == 0x00000002)) { 444 to_bitField0_ |= 0x00000002; 445 } 446 result.respCode_ = respCode_; 447 if (((from_bitField0_ & 0x00000004) == 0x00000004)) { 448 to_bitField0_ |= 0x00000004; 449 } 450 result.desc_ = desc_; 451 result.bitField0_ = to_bitField0_; 452 onBuilt(); 453 return result; 454 } 455 456 public Builder mergeFrom(com.google.protobuf.Message other) { 457 if (other instanceof lqy7_protobuf_140.SubscribeRespProto.SubscribeResp) { 458 return mergeFrom((lqy7_protobuf_140.SubscribeRespProto.SubscribeResp)other); 459 } else { 460 super.mergeFrom(other); 461 return this; 462 } 463 } 464 465 public Builder mergeFrom(lqy7_protobuf_140.SubscribeRespProto.SubscribeResp other) { 466 if (other == lqy7_protobuf_140.SubscribeRespProto.SubscribeResp.getDefaultInstance()) return this; 467 if (other.hasSubReqID()) { 468 setSubReqID(other.getSubReqID()); 469 } 470 if (other.hasRespCode()) { 471 setRespCode(other.getRespCode()); 472 } 473 if (other.hasDesc()) { 474 bitField0_ |= 0x00000004; 475 desc_ = other.desc_; 476 onChanged(); 477 } 478 this.mergeUnknownFields(other.getUnknownFields()); 479 return this; 480 } 481 482 public final boolean isInitialized() { 483 if (!hasSubReqID()) { 484 485 return false; 486 } 487 if (!hasRespCode()) { 488 489 return false; 490 } 491 if (!hasDesc()) { 492 493 return false; 494 } 495 return true; 496 } 497 498 public Builder mergeFrom( 499 com.google.protobuf.CodedInputStream input, 500 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 501 throws java.io.IOException { 502 lqy7_protobuf_140.SubscribeRespProto.SubscribeResp parsedMessage = null; 503 try { 504 parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); 505 } catch (com.google.protobuf.InvalidProtocolBufferException e) { 506 parsedMessage = (lqy7_protobuf_140.SubscribeRespProto.SubscribeResp) e.getUnfinishedMessage(); 507 throw e; 508 } finally { 509 if (parsedMessage != null) { 510 mergeFrom(parsedMessage); 511 } 512 } 513 return this; 514 } 515 private int bitField0_; 516 517 // required int32 subReqID = 1; 518 private int subReqID_ ; 519 /** 520 * <code>required int32 subReqID = 1;</code> 521 */ 522 public boolean hasSubReqID() { 523 return ((bitField0_ & 0x00000001) == 0x00000001); 524 } 525 /** 526 * <code>required int32 subReqID = 1;</code> 527 */ 528 public int getSubReqID() { 529 return subReqID_; 530 } 531 /** 532 * <code>required int32 subReqID = 1;</code> 533 */ 534 public Builder setSubReqID(int value) { 535 bitField0_ |= 0x00000001; 536 subReqID_ = value; 537 onChanged(); 538 return this; 539 } 540 /** 541 * <code>required int32 subReqID = 1;</code> 542 */ 543 public Builder clearSubReqID() { 544 bitField0_ = (bitField0_ & ~0x00000001); 545 subReqID_ = 0; 546 onChanged(); 547 return this; 548 } 549 550 // required int32 respCode = 2; 551 private int respCode_ ; 552 /** 553 * <code>required int32 respCode = 2;</code> 554 */ 555 public boolean hasRespCode() { 556 return ((bitField0_ & 0x00000002) == 0x00000002); 557 } 558 /** 559 * <code>required int32 respCode = 2;</code> 560 */ 561 public int getRespCode() { 562 return respCode_; 563 } 564 /** 565 * <code>required int32 respCode = 2;</code> 566 */ 567 public Builder setRespCode(int value) { 568 bitField0_ |= 0x00000002; 569 respCode_ = value; 570 onChanged(); 571 return this; 572 } 573 /** 574 * <code>required int32 respCode = 2;</code> 575 */ 576 public Builder clearRespCode() { 577 bitField0_ = (bitField0_ & ~0x00000002); 578 respCode_ = 0; 579 onChanged(); 580 return this; 581 } 582 583 // required string desc = 3; 584 private java.lang.Object desc_ = ""; 585 /** 586 * <code>required string desc = 3;</code> 587 */ 588 public boolean hasDesc() { 589 return ((bitField0_ & 0x00000004) == 0x00000004); 590 } 591 /** 592 * <code>required string desc = 3;</code> 593 */ 594 public java.lang.String getDesc() { 595 java.lang.Object ref = desc_; 596 if (!(ref instanceof java.lang.String)) { 597 java.lang.String s = ((com.google.protobuf.ByteString) ref) 598 .toStringUtf8(); 599 desc_ = s; 600 return s; 601 } else { 602 return (java.lang.String) ref; 603 } 604 } 605 /** 606 * <code>required string desc = 3;</code> 607 */ 608 public com.google.protobuf.ByteString 609 getDescBytes() { 610 java.lang.Object ref = desc_; 611 if (ref instanceof String) { 612 com.google.protobuf.ByteString b = 613 com.google.protobuf.ByteString.copyFromUtf8( 614 (java.lang.String) ref); 615 desc_ = b; 616 return b; 617 } else { 618 return (com.google.protobuf.ByteString) ref; 619 } 620 } 621 /** 622 * <code>required string desc = 3;</code> 623 */ 624 public Builder setDesc( 625 java.lang.String value) { 626 if (value == null) { 627 throw new NullPointerException(); 628 } 629 bitField0_ |= 0x00000004; 630 desc_ = value; 631 onChanged(); 632 return this; 633 } 634 /** 635 * <code>required string desc = 3;</code> 636 */ 637 public Builder clearDesc() { 638 bitField0_ = (bitField0_ & ~0x00000004); 639 desc_ = getDefaultInstance().getDesc(); 640 onChanged(); 641 return this; 642 } 643 /** 644 * <code>required string desc = 3;</code> 645 */ 646 public Builder setDescBytes( 647 com.google.protobuf.ByteString value) { 648 if (value == null) { 649 throw new NullPointerException(); 650 } 651 bitField0_ |= 0x00000004; 652 desc_ = value; 653 onChanged(); 654 return this; 655 } 656 657 // @@protoc_insertion_point(builder_scope:lqy7_protobuf_140.SubscribeResp) 658 } 659 660 static { 661 defaultInstance = new SubscribeResp(true); 662 defaultInstance.initFields(); 663 } 664 665 // @@protoc_insertion_point(class_scope:lqy7_protobuf_140.SubscribeResp) 666 } 667 668 private static com.google.protobuf.Descriptors.Descriptor 669 internal_static_lqy7_protobuf_140_SubscribeResp_descriptor; 670 private static 671 com.google.protobuf.GeneratedMessage.FieldAccessorTable 672 internal_static_lqy7_protobuf_140_SubscribeResp_fieldAccessorTable; 673 674 public static com.google.protobuf.Descriptors.FileDescriptor 675 getDescriptor() { 676 return descriptor; 677 } 678 private static com.google.protobuf.Descriptors.FileDescriptor 679 descriptor; 680 static { 681 java.lang.String[] descriptorData = { 682 "\n\023SubscribeResp.proto\022\021lqy7_protobuf_140" + 683 "\"A\n\rSubscribeResp\022\020\n\010subReqID\030\001 \002(\005\022\020\n\010r" + 684 "espCode\030\002 \002(\005\022\014\n\004desc\030\003 \002(\tB\‘\n\021lqy7_prot" + 685 "obuf_140B\022SubscribeRespProto" 686 }; 687 com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = 688 new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { 689 public com.google.protobuf.ExtensionRegistry assignDescriptors( 690 com.google.protobuf.Descriptors.FileDescriptor root) { 691 descriptor = root; 692 internal_static_lqy7_protobuf_140_SubscribeResp_descriptor = 693 getDescriptor().getMessageTypes().get(0); 694 internal_static_lqy7_protobuf_140_SubscribeResp_fieldAccessorTable = new 695 com.google.protobuf.GeneratedMessage.FieldAccessorTable( 696 internal_static_lqy7_protobuf_140_SubscribeResp_descriptor, 697 new java.lang.String[] { "SubReqID", "RespCode", "Desc", }); 698 return null; 699 } 700 }; 701 com.google.protobuf.Descriptors.FileDescriptor 702 .internalBuildGeneratedFileFrom(descriptorData, 703 new com.google.protobuf.Descriptors.FileDescriptor[] { 704 }, assigner); 705 } 706 707 // @@protoc_insertion_point(outer_class_scope) 708 }
(中级篇 NettyNIO编解码开发)第八章-Google Protobuf 编解码-1
原文:http://www.cnblogs.com/crazylqy/p/4901342.html