| OLD | NEW |
| 1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
| 2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
| 3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
| 4 // | 4 // |
| 5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
| 6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
| 7 // met: | 7 // met: |
| 8 // | 8 // |
| 9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
| 10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 import com.google.protobuf.AbstractMessageLite.Builder.LimitedInputStream; | 33 import com.google.protobuf.AbstractMessageLite.Builder.LimitedInputStream; |
| 34 import com.google.protobuf.GeneratedMessageLite.EqualsVisitor.NotEqualsException
; | 34 import com.google.protobuf.GeneratedMessageLite.EqualsVisitor.NotEqualsException
; |
| 35 import com.google.protobuf.Internal.BooleanList; | 35 import com.google.protobuf.Internal.BooleanList; |
| 36 import com.google.protobuf.Internal.DoubleList; | 36 import com.google.protobuf.Internal.DoubleList; |
| 37 import com.google.protobuf.Internal.FloatList; | 37 import com.google.protobuf.Internal.FloatList; |
| 38 import com.google.protobuf.Internal.IntList; | 38 import com.google.protobuf.Internal.IntList; |
| 39 import com.google.protobuf.Internal.LongList; | 39 import com.google.protobuf.Internal.LongList; |
| 40 import com.google.protobuf.Internal.ProtobufList; | 40 import com.google.protobuf.Internal.ProtobufList; |
| 41 import com.google.protobuf.WireFormat.FieldType; | 41 import com.google.protobuf.WireFormat.FieldType; |
| 42 |
| 42 import java.io.IOException; | 43 import java.io.IOException; |
| 43 import java.io.InputStream; | 44 import java.io.InputStream; |
| 44 import java.io.ObjectStreamException; | 45 import java.io.ObjectStreamException; |
| 45 import java.io.Serializable; | 46 import java.io.Serializable; |
| 46 import java.lang.reflect.InvocationTargetException; | 47 import java.lang.reflect.InvocationTargetException; |
| 47 import java.lang.reflect.Method; | 48 import java.lang.reflect.Method; |
| 48 import java.util.ArrayList; | 49 import java.util.ArrayList; |
| 49 import java.util.Collections; | 50 import java.util.Collections; |
| 50 import java.util.Iterator; | 51 import java.util.Iterator; |
| 51 import java.util.List; | 52 import java.util.List; |
| 52 import java.util.Map; | 53 import java.util.Map; |
| 53 | 54 |
| 54 /** | 55 /** |
| 55 * Lite version of {@link GeneratedMessage}. | 56 * Lite version of {@link GeneratedMessage}. |
| 56 * | 57 * |
| 57 * @author kenton@google.com Kenton Varda | 58 * @author kenton@google.com Kenton Varda |
| 58 */ | 59 */ |
| 59 public abstract class GeneratedMessageLite< | 60 public abstract class GeneratedMessageLite< |
| 60 MessageType extends GeneratedMessageLite<MessageType, BuilderType>, | 61 MessageType extends GeneratedMessageLite<MessageType, BuilderType>, |
| 61 BuilderType extends GeneratedMessageLite.Builder<MessageType, BuilderType>> | 62 BuilderType extends GeneratedMessageLite.Builder<MessageType, BuilderType>> |
| 62 extends AbstractMessageLite<MessageType, BuilderType> { | 63 extends AbstractMessageLite<MessageType, BuilderType> { |
| 63 | 64 |
| 64 /** For use by generated code only. Lazily initialized to reduce allocations.
*/ | 65 /** For use by generated code only. Lazily initialized to reduce allocations.
*/ |
| 65 protected UnknownFieldSetLite unknownFields = UnknownFieldSetLite.getDefaultIn
stance(); | 66 protected UnknownFieldSetLite unknownFields = UnknownFieldSetLite.getDefaultIn
stance(); |
| 66 | 67 |
| 67 /** For use by generated code only. */ | 68 /** For use by generated code only. */ |
| 68 protected int memoizedSerializedSize = -1; | 69 protected int memoizedSerializedSize = -1; |
| 69 | 70 |
| 70 @Override | 71 @Override |
| 71 @SuppressWarnings("unchecked") // Guaranteed by runtime. | 72 @SuppressWarnings("unchecked") // Guaranteed by runtime. |
| 72 public final Parser<MessageType> getParserForType() { | 73 public final Parser<MessageType> getParserForType() { |
| 73 return (Parser<MessageType>) dynamicMethod(MethodToInvoke.GET_PARSER); | 74 return (Parser<MessageType>) dynamicMethod(MethodToInvoke.GET_PARSER); |
| 74 } | 75 } |
| 75 | 76 |
| 76 @Override | 77 @Override |
| 77 @SuppressWarnings("unchecked") // Guaranteed by runtime. | 78 @SuppressWarnings("unchecked") // Guaranteed by runtime. |
| 78 public final MessageType getDefaultInstanceForType() { | 79 public final MessageType getDefaultInstanceForType() { |
| 79 return (MessageType) dynamicMethod(MethodToInvoke.GET_DEFAULT_INSTANCE); | 80 return (MessageType) dynamicMethod(MethodToInvoke.GET_DEFAULT_INSTANCE); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 105 @SuppressWarnings("unchecked") // Guaranteed by runtime | 106 @SuppressWarnings("unchecked") // Guaranteed by runtime |
| 106 @Override | 107 @Override |
| 107 public int hashCode() { | 108 public int hashCode() { |
| 108 if (memoizedHashCode == 0) { | 109 if (memoizedHashCode == 0) { |
| 109 HashCodeVisitor visitor = new HashCodeVisitor(); | 110 HashCodeVisitor visitor = new HashCodeVisitor(); |
| 110 visit(visitor, (MessageType) this); | 111 visit(visitor, (MessageType) this); |
| 111 memoizedHashCode = visitor.hashCode; | 112 memoizedHashCode = visitor.hashCode; |
| 112 } | 113 } |
| 113 return memoizedHashCode; | 114 return memoizedHashCode; |
| 114 } | 115 } |
| 115 | 116 |
| 116 @SuppressWarnings("unchecked") // Guaranteed by runtime | 117 @SuppressWarnings("unchecked") // Guaranteed by runtime |
| 117 int hashCode(HashCodeVisitor visitor) { | 118 int hashCode(HashCodeVisitor visitor) { |
| 118 if (memoizedHashCode == 0) { | 119 if (memoizedHashCode == 0) { |
| 119 int inProgressHashCode = visitor.hashCode; | 120 int inProgressHashCode = visitor.hashCode; |
| 120 visitor.hashCode = 0; | 121 visitor.hashCode = 0; |
| 121 visit(visitor, (MessageType) this); | 122 visit(visitor, (MessageType) this); |
| 122 memoizedHashCode = visitor.hashCode; | 123 memoizedHashCode = visitor.hashCode; |
| 123 visitor.hashCode = inProgressHashCode; | 124 visitor.hashCode = inProgressHashCode; |
| 124 } | 125 } |
| 125 return memoizedHashCode; | 126 return memoizedHashCode; |
| 126 } | 127 } |
| 127 | 128 |
| 128 @SuppressWarnings("unchecked") // Guaranteed by isInstance + runtime | 129 @SuppressWarnings("unchecked") // Guaranteed by isInstance + runtime |
| 129 @Override | 130 @Override |
| 130 public boolean equals(Object other) { | 131 public boolean equals(Object other) { |
| 131 if (this == other) { | 132 if (this == other) { |
| 132 return true; | 133 return true; |
| 133 } | 134 } |
| 134 | 135 |
| 135 if (!getDefaultInstanceForType().getClass().isInstance(other)) { | 136 if (!getDefaultInstanceForType().getClass().isInstance(other)) { |
| 136 return false; | 137 return false; |
| 137 } | 138 } |
| 138 | 139 |
| 139 try { | 140 try { |
| 140 visit(EqualsVisitor.INSTANCE, (MessageType) other); | 141 visit(EqualsVisitor.INSTANCE, (MessageType) other); |
| 141 } catch (NotEqualsException e) { | 142 } catch (NotEqualsException e) { |
| 142 return false; | 143 return false; |
| 143 } | 144 } |
| 144 return true; | 145 return true; |
| 145 } | 146 } |
| 146 | 147 |
| 147 /** | 148 /** |
| 148 * Same as {@link #equals(Object)} but throws {@code NotEqualsException}. | 149 * Same as {@link #equals(Object)} but throws {@code NotEqualsException}. |
| 149 */ | 150 */ |
| 150 @SuppressWarnings("unchecked") // Guaranteed by isInstance + runtime | 151 @SuppressWarnings("unchecked") // Guaranteed by isInstance + runtime |
| 151 boolean equals(EqualsVisitor visitor, MessageLite other) { | 152 boolean equals(EqualsVisitor visitor, MessageLite other) { |
| 152 if (this == other) { | 153 if (this == other) { |
| 153 return true; | 154 return true; |
| 154 } | 155 } |
| 155 | 156 |
| 156 if (!getDefaultInstanceForType().getClass().isInstance(other)) { | 157 if (!getDefaultInstanceForType().getClass().isInstance(other)) { |
| 157 return false; | 158 return false; |
| 158 } | 159 } |
| 159 | 160 |
| 160 visit(visitor, (MessageType) other); | 161 visit(visitor, (MessageType) other); |
| 161 return true; | 162 return true; |
| 162 } | 163 } |
| 163 | 164 |
| 164 // The general strategy for unknown fields is to use an UnknownFieldSetLite th
at is treated as | 165 // The general strategy for unknown fields is to use an UnknownFieldSetLite th
at is treated as |
| 165 // mutable during the parsing constructor and immutable after. This allows us
to avoid | 166 // mutable during the parsing constructor and immutable after. This allows us
to avoid |
| 166 // any unnecessary intermediary allocations while reducing the generated code
size. | 167 // any unnecessary intermediary allocations while reducing the generated code
size. |
| 167 | 168 |
| 168 /** | 169 /** |
| 169 * Lazily initializes unknown fields. | 170 * Lazily initializes unknown fields. |
| 170 */ | 171 */ |
| 171 private final void ensureUnknownFieldsInitialized() { | 172 private final void ensureUnknownFieldsInitialized() { |
| 172 if (unknownFields == UnknownFieldSetLite.getDefaultInstance()) { | 173 if (unknownFields == UnknownFieldSetLite.getDefaultInstance()) { |
| 173 unknownFields = UnknownFieldSetLite.newInstance(); | 174 unknownFields = UnknownFieldSetLite.newInstance(); |
| 174 } | 175 } |
| 175 } | 176 } |
| 176 | 177 |
| 177 /** | 178 /** |
| 178 * Called by subclasses to parse an unknown field. For use by generated code o
nly. | 179 * Called by subclasses to parse an unknown field. For use by generated code o
nly. |
| 179 * | 180 * |
| 180 * @return {@code true} unless the tag is an end-group tag. | 181 * @return {@code true} unless the tag is an end-group tag. |
| 181 */ | 182 */ |
| 182 protected boolean parseUnknownField(int tag, CodedInputStream input) throws IO
Exception { | 183 protected boolean parseUnknownField(int tag, CodedInputStream input) throws IO
Exception { |
| 183 // This will avoid the allocation of unknown fields when a group tag is enco
untered. | 184 // This will avoid the allocation of unknown fields when a group tag is enco
untered. |
| 184 if (WireFormat.getTagWireType(tag) == WireFormat.WIRETYPE_END_GROUP) { | 185 if (WireFormat.getTagWireType(tag) == WireFormat.WIRETYPE_END_GROUP) { |
| 185 return false; | 186 return false; |
| 186 } | 187 } |
| 187 | 188 |
| 188 ensureUnknownFieldsInitialized(); | 189 ensureUnknownFieldsInitialized(); |
| 189 return unknownFields.mergeFieldFrom(tag, input); | 190 return unknownFields.mergeFieldFrom(tag, input); |
| 190 } | 191 } |
| 191 | 192 |
| 192 /** | 193 /** |
| 193 * Called by subclasses to parse an unknown field. For use by generated code o
nly. | 194 * Called by subclasses to parse an unknown field. For use by generated code o
nly. |
| 194 */ | 195 */ |
| 195 protected void mergeVarintField(int tag, int value) { | 196 protected void mergeVarintField(int tag, int value) { |
| 196 ensureUnknownFieldsInitialized(); | 197 ensureUnknownFieldsInitialized(); |
| 197 unknownFields.mergeVarintField(tag, value); | 198 unknownFields.mergeVarintField(tag, value); |
| 198 } | 199 } |
| 199 | 200 |
| 200 /** | 201 /** |
| 201 * Called by subclasses to parse an unknown field. For use by generated code o
nly. | 202 * Called by subclasses to parse an unknown field. For use by generated code o
nly. |
| 202 */ | 203 */ |
| 203 protected void mergeLengthDelimitedField(int fieldNumber, ByteString value) { | 204 protected void mergeLengthDelimitedField(int fieldNumber, ByteString value) { |
| 204 ensureUnknownFieldsInitialized(); | 205 ensureUnknownFieldsInitialized(); |
| 205 unknownFields.mergeLengthDelimitedField(fieldNumber, value); | 206 unknownFields.mergeLengthDelimitedField(fieldNumber, value); |
| 206 } | 207 } |
| 207 | 208 |
| 208 /** | 209 /** |
| 209 * Called by subclasses to complete parsing. For use by generated code only. | 210 * Called by subclasses to complete parsing. For use by generated code only. |
| 210 */ | 211 */ |
| 211 protected void makeImmutable() { | 212 protected void makeImmutable() { |
| 212 dynamicMethod(MethodToInvoke.MAKE_IMMUTABLE); | 213 dynamicMethod(MethodToInvoke.MAKE_IMMUTABLE); |
| 213 | 214 |
| 214 unknownFields.makeImmutable(); | 215 unknownFields.makeImmutable(); |
| 215 } | 216 } |
| 216 | 217 |
| 217 @Override | 218 @Override |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 * Same as {@link #dynamicMethod(MethodToInvoke, Object, Object)} with {@code
null} padding. | 285 * Same as {@link #dynamicMethod(MethodToInvoke, Object, Object)} with {@code
null} padding. |
| 285 */ | 286 */ |
| 286 protected Object dynamicMethod(MethodToInvoke method) { | 287 protected Object dynamicMethod(MethodToInvoke method) { |
| 287 return dynamicMethod(method, null, null); | 288 return dynamicMethod(method, null, null); |
| 288 } | 289 } |
| 289 | 290 |
| 290 void visit(Visitor visitor, MessageType other) { | 291 void visit(Visitor visitor, MessageType other) { |
| 291 dynamicMethod(MethodToInvoke.VISIT, visitor, other); | 292 dynamicMethod(MethodToInvoke.VISIT, visitor, other); |
| 292 unknownFields = visitor.visitUnknownFields(unknownFields, other.unknownField
s); | 293 unknownFields = visitor.visitUnknownFields(unknownFields, other.unknownField
s); |
| 293 } | 294 } |
| 294 | 295 |
| 295 /** | 296 /** |
| 296 * Merge some unknown fields into the {@link UnknownFieldSetLite} for this | 297 * Merge some unknown fields into the {@link UnknownFieldSetLite} for this |
| 297 * message. | 298 * message. |
| 298 * | 299 * |
| 299 * <p>For use by generated code only. | 300 * <p>For use by generated code only. |
| 300 */ | 301 */ |
| 301 protected final void mergeUnknownFields(UnknownFieldSetLite unknownFields) { | 302 protected final void mergeUnknownFields(UnknownFieldSetLite unknownFields) { |
| 302 this.unknownFields = UnknownFieldSetLite.mutableCopyOf(this.unknownFields, u
nknownFields); | 303 this.unknownFields = UnknownFieldSetLite.mutableCopyOf(this.unknownFields, u
nknownFields); |
| 303 } | 304 } |
| 304 | 305 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 (BuilderType) getDefaultInstanceForType().newBuilderForType(); | 352 (BuilderType) getDefaultInstanceForType().newBuilderForType(); |
| 352 builder.mergeFrom(buildPartial()); | 353 builder.mergeFrom(buildPartial()); |
| 353 return builder; | 354 return builder; |
| 354 } | 355 } |
| 355 | 356 |
| 356 @Override | 357 @Override |
| 357 public MessageType buildPartial() { | 358 public MessageType buildPartial() { |
| 358 if (isBuilt) { | 359 if (isBuilt) { |
| 359 return instance; | 360 return instance; |
| 360 } | 361 } |
| 361 | 362 |
| 362 instance.makeImmutable(); | 363 instance.makeImmutable(); |
| 363 | 364 |
| 364 isBuilt = true; | 365 isBuilt = true; |
| 365 return instance; | 366 return instance; |
| 366 } | 367 } |
| 367 | 368 |
| 368 @Override | 369 @Override |
| 369 public final MessageType build() { | 370 public final MessageType build() { |
| 370 MessageType result = buildPartial(); | 371 MessageType result = buildPartial(); |
| 371 if (!result.isInitialized()) { | 372 if (!result.isInitialized()) { |
| 372 throw newUninitializedMessageException(result); | 373 throw newUninitializedMessageException(result); |
| 373 } | 374 } |
| 374 return result; | 375 return result; |
| 375 } | 376 } |
| 376 | 377 |
| 377 @Override | 378 @Override |
| 378 protected BuilderType internalMergeFrom(MessageType message) { | 379 protected BuilderType internalMergeFrom(MessageType message) { |
| 379 return mergeFrom(message); | 380 return mergeFrom(message); |
| 380 } | 381 } |
| 381 | 382 |
| 382 /** All subclasses implement this. */ | 383 /** All subclasses implement this. */ |
| 383 public BuilderType mergeFrom(MessageType message) { | 384 public BuilderType mergeFrom(MessageType message) { |
| 384 copyOnWrite(); | 385 copyOnWrite(); |
| 385 instance.visit(MergeFromVisitor.INSTANCE, message); | 386 instance.visit(MergeFromVisitor.INSTANCE, message); |
| 386 return (BuilderType) this; | 387 return (BuilderType) this; |
| 387 } | 388 } |
| 388 | 389 |
| 389 @Override | 390 @Override |
| 390 public MessageType getDefaultInstanceForType() { | 391 public MessageType getDefaultInstanceForType() { |
| 391 return defaultInstance; | 392 return defaultInstance; |
| 392 } | 393 } |
| 393 | 394 |
| 394 @Override | 395 @Override |
| 395 public BuilderType mergeFrom( | 396 public BuilderType mergeFrom( |
| 396 com.google.protobuf.CodedInputStream input, | 397 com.google.protobuf.CodedInputStream input, |
| 397 com.google.protobuf.ExtensionRegistryLite extensionRegistry) | 398 com.google.protobuf.ExtensionRegistryLite extensionRegistry) |
| 398 throws IOException { | 399 throws IOException { |
| 399 copyOnWrite(); | 400 copyOnWrite(); |
| 400 try { | 401 try { |
| 401 instance.dynamicMethod(MethodToInvoke.MERGE_FROM_STREAM, input, extensio
nRegistry); | 402 instance.dynamicMethod(MethodToInvoke.MERGE_FROM_STREAM, input, extensio
nRegistry); |
| 402 } catch (RuntimeException e) { | 403 } catch (RuntimeException e) { |
| 403 if (e.getCause() instanceof IOException) { | 404 if (e.getCause() instanceof IOException) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 extensions = extensions.clone(); | 459 extensions = extensions.clone(); |
| 459 } | 460 } |
| 460 extensions.mergeFrom(((ExtendableMessage) other).extensions); | 461 extensions.mergeFrom(((ExtendableMessage) other).extensions); |
| 461 } | 462 } |
| 462 | 463 |
| 463 @Override | 464 @Override |
| 464 final void visit(Visitor visitor, MessageType other) { | 465 final void visit(Visitor visitor, MessageType other) { |
| 465 super.visit(visitor, other); | 466 super.visit(visitor, other); |
| 466 extensions = visitor.visitExtensions(extensions, other.extensions); | 467 extensions = visitor.visitExtensions(extensions, other.extensions); |
| 467 } | 468 } |
| 468 | 469 |
| 469 /** | 470 /** |
| 470 * Parse an unknown field or an extension. For use by generated code only. | 471 * Parse an unknown field or an extension. For use by generated code only. |
| 471 * | 472 * |
| 472 * <p>For use by generated code only. | 473 * <p>For use by generated code only. |
| 473 * | 474 * |
| 474 * @return {@code true} unless the tag is an end-group tag. | 475 * @return {@code true} unless the tag is an end-group tag. |
| 475 */ | 476 */ |
| 476 protected <MessageType extends MessageLite> boolean parseUnknownField( | 477 protected <MessageType extends MessageLite> boolean parseUnknownField( |
| 477 MessageType defaultInstance, | 478 MessageType defaultInstance, |
| 478 CodedInputStream input, | 479 CodedInputStream input, |
| 479 ExtensionRegistryLite extensionRegistry, | 480 ExtensionRegistryLite extensionRegistry, |
| 480 int tag) throws IOException { | 481 int tag) throws IOException { |
| 482 int wireType = WireFormat.getTagWireType(tag); |
| 481 int fieldNumber = WireFormat.getTagFieldNumber(tag); | 483 int fieldNumber = WireFormat.getTagFieldNumber(tag); |
| 482 | 484 |
| 483 // TODO(dweis): How much bytecode would be saved by not requiring the gene
rated code to | 485 // TODO(dweis): How much bytecode would be saved by not requiring the gene
rated code to |
| 484 // provide the default instance? | 486 // provide the default instance? |
| 485 GeneratedExtension<MessageType, ?> extension = extensionRegistry.findLiteE
xtensionByNumber( | 487 GeneratedExtension<MessageType, ?> extension = extensionRegistry.findLiteE
xtensionByNumber( |
| 486 defaultInstance, fieldNumber); | 488 defaultInstance, fieldNumber); |
| 487 | 489 |
| 488 return parseExtension(input, extensionRegistry, extension, tag, fieldNumbe
r); | |
| 489 } | |
| 490 | |
| 491 private boolean parseExtension( | |
| 492 CodedInputStream input, | |
| 493 ExtensionRegistryLite extensionRegistry, | |
| 494 GeneratedExtension<?, ?> extension, | |
| 495 int tag, | |
| 496 int fieldNumber) | |
| 497 throws IOException { | |
| 498 int wireType = WireFormat.getTagWireType(tag); | |
| 499 boolean unknown = false; | 490 boolean unknown = false; |
| 500 boolean packed = false; | 491 boolean packed = false; |
| 501 if (extension == null) { | 492 if (extension == null) { |
| 502 unknown = true; // Unknown field. | 493 unknown = true; // Unknown field. |
| 503 } else if (wireType == FieldSet.getWireFormatForFieldType( | 494 } else if (wireType == FieldSet.getWireFormatForFieldType( |
| 504 extension.descriptor.getLiteType(), | 495 extension.descriptor.getLiteType(), |
| 505 false /* isPacked */)) { | 496 false /* isPacked */)) { |
| 506 packed = false; // Normal, unpacked value. | 497 packed = false; // Normal, unpacked value. |
| 507 } else if (extension.descriptor.isRepeated && | 498 } else if (extension.descriptor.isRepeated && |
| 508 extension.descriptor.type.isPackable() && | 499 extension.descriptor.type.isPackable() && |
| 509 wireType == FieldSet.getWireFormatForFieldType( | 500 wireType == FieldSet.getWireFormatForFieldType( |
| 510 extension.descriptor.getLiteType(), | 501 extension.descriptor.getLiteType(), |
| 511 true /* isPacked */)) { | 502 true /* isPacked */)) { |
| 512 packed = true; // Packed value. | 503 packed = true; // Packed value. |
| 513 } else { | 504 } else { |
| 514 unknown = true; // Wrong wire type. | 505 unknown = true; // Wrong wire type. |
| 515 } | 506 } |
| 516 | 507 |
| 517 if (unknown) { // Unknown field or wrong wire type. Skip. | 508 if (unknown) { // Unknown field or wrong wire type. Skip. |
| 518 return parseUnknownField(tag, input); | 509 return parseUnknownField(tag, input); |
| 519 } | 510 } |
| 520 | 511 |
| 521 if (packed) { | 512 if (packed) { |
| 522 int length = input.readRawVarint32(); | 513 int length = input.readRawVarint32(); |
| 523 int limit = input.pushLimit(length); | 514 int limit = input.pushLimit(length); |
| 524 if (extension.descriptor.getLiteType() == WireFormat.FieldType.ENUM) { | 515 if (extension.descriptor.getLiteType() == WireFormat.FieldType.ENUM) { |
| 525 while (input.getBytesUntilLimit() > 0) { | 516 while (input.getBytesUntilLimit() > 0) { |
| 526 int rawValue = input.readEnum(); | 517 int rawValue = input.readEnum(); |
| 527 Object value = | 518 Object value = |
| 528 extension.descriptor.getEnumType().findValueByNumber(rawValue); | 519 extension.descriptor.getEnumType().findValueByNumber(rawValue); |
| 529 if (value == null) { | 520 if (value == null) { |
| 530 // If the number isn't recognized as a valid value for this | 521 // If the number isn't recognized as a valid value for this |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 } | 580 } |
| 590 | 581 |
| 591 if (extension.descriptor.isRepeated()) { | 582 if (extension.descriptor.isRepeated()) { |
| 592 extensions.addRepeatedField(extension.descriptor, | 583 extensions.addRepeatedField(extension.descriptor, |
| 593 extension.singularToFieldSetType(value)); | 584 extension.singularToFieldSetType(value)); |
| 594 } else { | 585 } else { |
| 595 extensions.setField(extension.descriptor, | 586 extensions.setField(extension.descriptor, |
| 596 extension.singularToFieldSetType(value)); | 587 extension.singularToFieldSetType(value)); |
| 597 } | 588 } |
| 598 } | 589 } |
| 590 |
| 599 return true; | 591 return true; |
| 600 } | 592 } |
| 601 | 593 |
| 602 /** | |
| 603 * Parse an unknown field or an extension. For use by generated code only. | |
| 604 * | |
| 605 * <p>For use by generated code only. | |
| 606 * | |
| 607 * @return {@code true} unless the tag is an end-group tag. | |
| 608 */ | |
| 609 protected <MessageType extends MessageLite> boolean parseUnknownFieldAsMessa
geSet( | |
| 610 MessageType defaultInstance, | |
| 611 CodedInputStream input, | |
| 612 ExtensionRegistryLite extensionRegistry, | |
| 613 int tag) | |
| 614 throws IOException { | |
| 615 | |
| 616 if (tag == WireFormat.MESSAGE_SET_ITEM_TAG) { | |
| 617 mergeMessageSetExtensionFromCodedStream(defaultInstance, input, extensio
nRegistry); | |
| 618 return true; | |
| 619 } | |
| 620 | |
| 621 // TODO(dweis): Do we really want to support non message set wire format i
n message sets? | |
| 622 // Full runtime does... So we do for now. | |
| 623 int wireType = WireFormat.getTagWireType(tag); | |
| 624 if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) { | |
| 625 return parseUnknownField(defaultInstance, input, extensionRegistry, tag)
; | |
| 626 } else { | |
| 627 // TODO(dweis): Should we throw on invalid input? Full runtime does not.
.. | |
| 628 return input.skipField(tag); | |
| 629 } | |
| 630 } | |
| 631 | |
| 632 /** | |
| 633 * Merges the message set from the input stream; requires message set wire f
ormat. | |
| 634 * | |
| 635 * @param defaultInstance the default instance of the containing message we
are parsing in | |
| 636 * @param input the stream to parse from | |
| 637 * @param extensionRegistry the registry to use when parsing | |
| 638 */ | |
| 639 private <MessageType extends MessageLite> void mergeMessageSetExtensionFromC
odedStream( | |
| 640 MessageType defaultInstance, | |
| 641 CodedInputStream input, | |
| 642 ExtensionRegistryLite extensionRegistry) | |
| 643 throws IOException { | |
| 644 // The wire format for MessageSet is: | |
| 645 // message MessageSet { | |
| 646 // repeated group Item = 1 { | |
| 647 // required int32 typeId = 2; | |
| 648 // required bytes message = 3; | |
| 649 // } | |
| 650 // } | |
| 651 // "typeId" is the extension's field number. The extension can only be | |
| 652 // a message type, where "message" contains the encoded bytes of that | |
| 653 // message. | |
| 654 // | |
| 655 // In practice, we will probably never see a MessageSet item in which | |
| 656 // the message appears before the type ID, or where either field does not | |
| 657 // appear exactly once. However, in theory such cases are valid, so we | |
| 658 // should be prepared to accept them. | |
| 659 | |
| 660 int typeId = 0; | |
| 661 ByteString rawBytes = null; // If we encounter "message" before "typeId" | |
| 662 GeneratedExtension<?, ?> extension = null; | |
| 663 | |
| 664 // Read bytes from input, if we get it's type first then parse it eagerly, | |
| 665 // otherwise we store the raw bytes in a local variable. | |
| 666 while (true) { | |
| 667 final int tag = input.readTag(); | |
| 668 if (tag == 0) { | |
| 669 break; | |
| 670 } | |
| 671 | |
| 672 if (tag == WireFormat.MESSAGE_SET_TYPE_ID_TAG) { | |
| 673 typeId = input.readUInt32(); | |
| 674 if (typeId != 0) { | |
| 675 extension = extensionRegistry.findLiteExtensionByNumber(defaultInsta
nce, typeId); | |
| 676 } | |
| 677 | |
| 678 } else if (tag == WireFormat.MESSAGE_SET_MESSAGE_TAG) { | |
| 679 if (typeId != 0) { | |
| 680 if (extension != null) { | |
| 681 // We already know the type, so we can parse directly from the | |
| 682 // input with no copying. Hooray! | |
| 683 eagerlyMergeMessageSetExtension(input, extension, extensionRegistr
y, typeId); | |
| 684 rawBytes = null; | |
| 685 continue; | |
| 686 } | |
| 687 } | |
| 688 // We haven't seen a type ID yet or we want parse message lazily. | |
| 689 rawBytes = input.readBytes(); | |
| 690 | |
| 691 } else { // Unknown tag. Skip it. | |
| 692 if (!input.skipField(tag)) { | |
| 693 break; // End of group | |
| 694 } | |
| 695 } | |
| 696 } | |
| 697 input.checkLastTagWas(WireFormat.MESSAGE_SET_ITEM_END_TAG); | |
| 698 | |
| 699 // Process the raw bytes. | |
| 700 if (rawBytes != null && typeId != 0) { // Zero is not a valid type ID. | |
| 701 if (extension != null) { // We known the type | |
| 702 mergeMessageSetExtensionFromBytes(rawBytes, extensionRegistry, extensi
on); | |
| 703 } else { // We don't know how to parse this. Ignore it. | |
| 704 if (rawBytes != null) { | |
| 705 mergeLengthDelimitedField(typeId, rawBytes); | |
| 706 } | |
| 707 } | |
| 708 } | |
| 709 } | |
| 710 | |
| 711 private void eagerlyMergeMessageSetExtension( | |
| 712 CodedInputStream input, | |
| 713 GeneratedExtension<?, ?> extension, | |
| 714 ExtensionRegistryLite extensionRegistry, | |
| 715 int typeId) | |
| 716 throws IOException { | |
| 717 int fieldNumber = typeId; | |
| 718 int tag = WireFormat.makeTag(typeId, WireFormat.WIRETYPE_LENGTH_DELIMITED)
; | |
| 719 parseExtension(input, extensionRegistry, extension, tag, fieldNumber); | |
| 720 } | |
| 721 | |
| 722 private void mergeMessageSetExtensionFromBytes( | |
| 723 ByteString rawBytes, | |
| 724 ExtensionRegistryLite extensionRegistry, | |
| 725 GeneratedExtension<?, ?> extension) | |
| 726 throws IOException { | |
| 727 MessageLite.Builder subBuilder = null; | |
| 728 MessageLite existingValue = (MessageLite) extensions.getField(extension.de
scriptor); | |
| 729 if (existingValue != null) { | |
| 730 subBuilder = existingValue.toBuilder(); | |
| 731 } | |
| 732 if (subBuilder == null) { | |
| 733 subBuilder = extension.getMessageDefaultInstance().newBuilderForType(); | |
| 734 } | |
| 735 rawBytes.newCodedInput().readMessage(subBuilder, extensionRegistry); | |
| 736 MessageLite value = subBuilder.build(); | |
| 737 | |
| 738 extensions.setField(extension.descriptor, extension.singularToFieldSetType
(value)); | |
| 739 } | |
| 740 | |
| 741 private void verifyExtensionContainingType( | 594 private void verifyExtensionContainingType( |
| 742 final GeneratedExtension<MessageType, ?> extension) { | 595 final GeneratedExtension<MessageType, ?> extension) { |
| 743 if (extension.getContainingTypeDefaultInstance() != | 596 if (extension.getContainingTypeDefaultInstance() != |
| 744 getDefaultInstanceForType()) { | 597 getDefaultInstanceForType()) { |
| 745 // This can only happen if someone uses unchecked operations. | 598 // This can only happen if someone uses unchecked operations. |
| 746 throw new IllegalArgumentException( | 599 throw new IllegalArgumentException( |
| 747 "This extension is for a different message type. Please make " + | 600 "This extension is for a different message type. Please make " + |
| 748 "sure that you are not suppressing any generics type warnings."); | 601 "sure that you are not suppressing any generics type warnings."); |
| 749 } | 602 } |
| 750 } | 603 } |
| 751 | 604 |
| 752 /** Check if a singular extension is present. */ | 605 /** Check if a singular extension is present. */ |
| 753 @Override | 606 @Override |
| 754 public final <Type> boolean hasExtension(final ExtensionLite<MessageType, Ty
pe> extension) { | 607 public final <Type> boolean hasExtension(final ExtensionLite<MessageType, Ty
pe> extension) { |
| 755 GeneratedExtension<MessageType, Type> extensionLite = | 608 GeneratedExtension<MessageType, Type> extensionLite = |
| 756 checkIsLite(extension); | 609 checkIsLite(extension); |
| 757 | 610 |
| 758 verifyExtensionContainingType(extensionLite); | 611 verifyExtensionContainingType(extensionLite); |
| 759 return extensions.hasField(extensionLite.descriptor); | 612 return extensions.hasField(extensionLite.descriptor); |
| 760 } | 613 } |
| 761 | 614 |
| 762 /** Get the number of elements in a repeated extension. */ | 615 /** Get the number of elements in a repeated extension. */ |
| 763 @Override | 616 @Override |
| 764 public final <Type> int getExtensionCount( | 617 public final <Type> int getExtensionCount( |
| 765 final ExtensionLite<MessageType, List<Type>> extension) { | 618 final ExtensionLite<MessageType, List<Type>> extension) { |
| 766 GeneratedExtension<MessageType, List<Type>> extensionLite = | 619 GeneratedExtension<MessageType, List<Type>> extensionLite = |
| 767 checkIsLite(extension); | 620 checkIsLite(extension); |
| 768 | 621 |
| 769 verifyExtensionContainingType(extensionLite); | 622 verifyExtensionContainingType(extensionLite); |
| 770 return extensions.getRepeatedFieldCount(extensionLite.descriptor); | 623 return extensions.getRepeatedFieldCount(extensionLite.descriptor); |
| 771 } | 624 } |
| 772 | 625 |
| 773 /** Get the value of an extension. */ | 626 /** Get the value of an extension. */ |
| 774 @Override | 627 @Override |
| 775 @SuppressWarnings("unchecked") | 628 @SuppressWarnings("unchecked") |
| 776 public final <Type> Type getExtension(final ExtensionLite<MessageType, Type>
extension) { | 629 public final <Type> Type getExtension(final ExtensionLite<MessageType, Type>
extension) { |
| 777 GeneratedExtension<MessageType, Type> extensionLite = | 630 GeneratedExtension<MessageType, Type> extensionLite = |
| 778 checkIsLite(extension); | 631 checkIsLite(extension); |
| 779 | 632 |
| 780 verifyExtensionContainingType(extensionLite); | 633 verifyExtensionContainingType(extensionLite); |
| 781 final Object value = extensions.getField(extensionLite.descriptor); | 634 final Object value = extensions.getField(extensionLite.descriptor); |
| 782 if (value == null) { | 635 if (value == null) { |
| 783 return extensionLite.defaultValue; | 636 return extensionLite.defaultValue; |
| 784 } else { | 637 } else { |
| 785 return (Type) extensionLite.fromFieldSetType(value); | 638 return (Type) extensionLite.fromFieldSetType(value); |
| 786 } | 639 } |
| 787 } | 640 } |
| 788 | 641 |
| 789 /** Get one element of a repeated extension. */ | 642 /** Get one element of a repeated extension. */ |
| (...skipping 10 matching lines...) Expand all Loading... |
| 800 } | 653 } |
| 801 | 654 |
| 802 /** Called by subclasses to check if all extensions are initialized. */ | 655 /** Called by subclasses to check if all extensions are initialized. */ |
| 803 protected boolean extensionsAreInitialized() { | 656 protected boolean extensionsAreInitialized() { |
| 804 return extensions.isInitialized(); | 657 return extensions.isInitialized(); |
| 805 } | 658 } |
| 806 | 659 |
| 807 @Override | 660 @Override |
| 808 protected final void makeImmutable() { | 661 protected final void makeImmutable() { |
| 809 super.makeImmutable(); | 662 super.makeImmutable(); |
| 810 | 663 |
| 811 extensions.makeImmutable(); | 664 extensions.makeImmutable(); |
| 812 } | 665 } |
| 813 | 666 |
| 814 /** | 667 /** |
| 815 * Used by subclasses to serialize extensions. Extension ranges may be | 668 * Used by subclasses to serialize extensions. Extension ranges may be |
| 816 * interleaved with field numbers, but we must write them in canonical | 669 * interleaved with field numbers, but we must write them in canonical |
| 817 * (sorted by field number) order. ExtensionWriter helps us write | 670 * (sorted by field number) order. ExtensionWriter helps us write |
| 818 * individual ranges of extensions at once. | 671 * individual ranges of extensions at once. |
| 819 */ | 672 */ |
| 820 protected class ExtensionWriter { | 673 protected class ExtensionWriter { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 874 * Lite equivalent of {@link GeneratedMessage.ExtendableBuilder}. | 727 * Lite equivalent of {@link GeneratedMessage.ExtendableBuilder}. |
| 875 */ | 728 */ |
| 876 @SuppressWarnings("unchecked") | 729 @SuppressWarnings("unchecked") |
| 877 public abstract static class ExtendableBuilder< | 730 public abstract static class ExtendableBuilder< |
| 878 MessageType extends ExtendableMessage<MessageType, BuilderType>, | 731 MessageType extends ExtendableMessage<MessageType, BuilderType>, |
| 879 BuilderType extends ExtendableBuilder<MessageType, BuilderType>> | 732 BuilderType extends ExtendableBuilder<MessageType, BuilderType>> |
| 880 extends Builder<MessageType, BuilderType> | 733 extends Builder<MessageType, BuilderType> |
| 881 implements ExtendableMessageOrBuilder<MessageType, BuilderType> { | 734 implements ExtendableMessageOrBuilder<MessageType, BuilderType> { |
| 882 protected ExtendableBuilder(MessageType defaultInstance) { | 735 protected ExtendableBuilder(MessageType defaultInstance) { |
| 883 super(defaultInstance); | 736 super(defaultInstance); |
| 884 | 737 |
| 885 // TODO(dweis): This is kind of an unnecessary clone since we construct a | 738 // TODO(dweis): This is kind of an unnecessary clone since we construct a |
| 886 // new instance in the parent constructor which makes the extensions | 739 // new instance in the parent constructor which makes the extensions |
| 887 // immutable. This extra allocation shouldn't matter in practice | 740 // immutable. This extra allocation shouldn't matter in practice |
| 888 // though. | 741 // though. |
| 889 instance.extensions = instance.extensions.clone(); | 742 instance.extensions = instance.extensions.clone(); |
| 890 } | 743 } |
| 891 | 744 |
| 892 // For immutable message conversion. | 745 // For immutable message conversion. |
| 893 void internalSetExtensionSet(FieldSet<ExtensionDescriptor> extensions) { | 746 void internalSetExtensionSet(FieldSet<ExtensionDescriptor> extensions) { |
| 894 copyOnWrite(); | 747 copyOnWrite(); |
| 895 instance.extensions = extensions; | 748 instance.extensions = extensions; |
| 896 } | 749 } |
| 897 | 750 |
| 898 @Override | 751 @Override |
| 899 protected void copyOnWrite() { | 752 protected void copyOnWrite() { |
| 900 if (!isBuilt) { | 753 if (!isBuilt) { |
| 901 return; | 754 return; |
| 902 } | 755 } |
| 903 | 756 |
| 904 super.copyOnWrite(); | 757 super.copyOnWrite(); |
| 905 instance.extensions = instance.extensions.clone(); | 758 instance.extensions = instance.extensions.clone(); |
| 906 } | 759 } |
| 907 | 760 |
| 908 @Override | 761 @Override |
| 909 public final MessageType buildPartial() { | 762 public final MessageType buildPartial() { |
| 910 if (isBuilt) { | 763 if (isBuilt) { |
| 911 return instance; | 764 return instance; |
| 912 } | 765 } |
| 913 | 766 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 947 } | 800 } |
| 948 | 801 |
| 949 /** Get one element of a repeated extension. */ | 802 /** Get one element of a repeated extension. */ |
| 950 @Override | 803 @Override |
| 951 @SuppressWarnings("unchecked") | 804 @SuppressWarnings("unchecked") |
| 952 public final <Type> Type getExtension( | 805 public final <Type> Type getExtension( |
| 953 final ExtensionLite<MessageType, List<Type>> extension, final int index)
{ | 806 final ExtensionLite<MessageType, List<Type>> extension, final int index)
{ |
| 954 return instance.getExtension(extension, index); | 807 return instance.getExtension(extension, index); |
| 955 } | 808 } |
| 956 | 809 |
| 810 // This is implemented here only to work around an apparent bug in the |
| 811 // Java compiler and/or build system. See bug #1898463. The mere presence |
| 812 // of this dummy clone() implementation makes it go away. |
| 813 @Override |
| 814 public BuilderType clone() { |
| 815 return super.clone(); |
| 816 } |
| 817 |
| 957 /** Set the value of an extension. */ | 818 /** Set the value of an extension. */ |
| 958 public final <Type> BuilderType setExtension( | 819 public final <Type> BuilderType setExtension( |
| 959 final ExtensionLite<MessageType, Type> extension, | 820 final ExtensionLite<MessageType, Type> extension, |
| 960 final Type value) { | 821 final Type value) { |
| 961 GeneratedExtension<MessageType, Type> extensionLite = | 822 GeneratedExtension<MessageType, Type> extensionLite = |
| 962 checkIsLite(extension); | 823 checkIsLite(extension); |
| 963 | 824 |
| 964 verifyExtensionContainingType(extensionLite); | 825 verifyExtensionContainingType(extensionLite); |
| 965 copyOnWrite(); | 826 copyOnWrite(); |
| 966 instance.extensions.setField(extensionLite.descriptor, extensionLite.toFie
ldSetType(value)); | 827 instance.extensions.setField(extensionLite.descriptor, extensionLite.toFie
ldSetType(value)); |
| 967 return (BuilderType) this; | 828 return (BuilderType) this; |
| 968 } | 829 } |
| 969 | 830 |
| 970 /** Set the value of one element of a repeated extension. */ | 831 /** Set the value of one element of a repeated extension. */ |
| 971 public final <Type> BuilderType setExtension( | 832 public final <Type> BuilderType setExtension( |
| 972 final ExtensionLite<MessageType, List<Type>> extension, | 833 final ExtensionLite<MessageType, List<Type>> extension, |
| 973 final int index, final Type value) { | 834 final int index, final Type value) { |
| 974 GeneratedExtension<MessageType, List<Type>> extensionLite = | 835 GeneratedExtension<MessageType, List<Type>> extensionLite = |
| 975 checkIsLite(extension); | 836 checkIsLite(extension); |
| 976 | 837 |
| 977 verifyExtensionContainingType(extensionLite); | 838 verifyExtensionContainingType(extensionLite); |
| 978 copyOnWrite(); | 839 copyOnWrite(); |
| 979 instance.extensions.setRepeatedField( | 840 instance.extensions.setRepeatedField( |
| 980 extensionLite.descriptor, index, extensionLite.singularToFieldSetType(
value)); | 841 extensionLite.descriptor, index, extensionLite.singularToFieldSetType(
value)); |
| 981 return (BuilderType) this; | 842 return (BuilderType) this; |
| 982 } | 843 } |
| 983 | 844 |
| 984 /** Append a value to a repeated extension. */ | 845 /** Append a value to a repeated extension. */ |
| 985 public final <Type> BuilderType addExtension( | 846 public final <Type> BuilderType addExtension( |
| 986 final ExtensionLite<MessageType, List<Type>> extension, | 847 final ExtensionLite<MessageType, List<Type>> extension, |
| 987 final Type value) { | 848 final Type value) { |
| 988 GeneratedExtension<MessageType, List<Type>> extensionLite = | 849 GeneratedExtension<MessageType, List<Type>> extensionLite = |
| 989 checkIsLite(extension); | 850 checkIsLite(extension); |
| 990 | 851 |
| 991 verifyExtensionContainingType(extensionLite); | 852 verifyExtensionContainingType(extensionLite); |
| 992 copyOnWrite(); | 853 copyOnWrite(); |
| 993 instance.extensions.addRepeatedField( | 854 instance.extensions.addRepeatedField( |
| 994 extensionLite.descriptor, extensionLite.singularToFieldSetType(value))
; | 855 extensionLite.descriptor, extensionLite.singularToFieldSetType(value))
; |
| 995 return (BuilderType) this; | 856 return (BuilderType) this; |
| 996 } | 857 } |
| 997 | 858 |
| 998 /** Clear an extension. */ | 859 /** Clear an extension. */ |
| 999 public final <Type> BuilderType clearExtension( | 860 public final <Type> BuilderType clearExtension( |
| 1000 final ExtensionLite<MessageType, ?> extension) { | 861 final ExtensionLite<MessageType, ?> extension) { |
| 1001 GeneratedExtension<MessageType, ?> extensionLite = checkIsLite(extension); | 862 GeneratedExtension<MessageType, ?> extensionLite = checkIsLite(extension); |
| 1002 | 863 |
| 1003 verifyExtensionContainingType(extensionLite); | 864 verifyExtensionContainingType(extensionLite); |
| 1004 copyOnWrite(); | 865 copyOnWrite(); |
| 1005 instance.extensions.clearField(extensionLite.descriptor); | 866 instance.extensions.clearField(extensionLite.descriptor); |
| 1006 return (BuilderType) this; | 867 return (BuilderType) this; |
| 1007 } | 868 } |
| 1008 } | 869 } |
| 1009 | 870 |
| 1010 // ----------------------------------------------------------------- | 871 // ----------------------------------------------------------------- |
| 1011 | 872 |
| 1012 /** For use by generated code only. */ | 873 /** For use by generated code only. */ |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1289 | 1150 |
| 1290 /** | 1151 /** |
| 1291 * A serialized (serializable) form of the generated message. Stores the | 1152 * A serialized (serializable) form of the generated message. Stores the |
| 1292 * message as a class name and a byte array. | 1153 * message as a class name and a byte array. |
| 1293 */ | 1154 */ |
| 1294 protected static final class SerializedForm implements Serializable { | 1155 protected static final class SerializedForm implements Serializable { |
| 1295 | 1156 |
| 1296 public static SerializedForm of(MessageLite message) { | 1157 public static SerializedForm of(MessageLite message) { |
| 1297 return new SerializedForm(message); | 1158 return new SerializedForm(message); |
| 1298 } | 1159 } |
| 1299 | 1160 |
| 1300 private static final long serialVersionUID = 0L; | 1161 private static final long serialVersionUID = 0L; |
| 1301 | 1162 |
| 1302 private final String messageClassName; | 1163 private final String messageClassName; |
| 1303 private final byte[] asBytes; | 1164 private final byte[] asBytes; |
| 1304 | 1165 |
| 1305 /** | 1166 /** |
| 1306 * Creates the serialized form by calling {@link com.google.protobuf.Message
Lite#toByteArray}. | 1167 * Creates the serialized form by calling {@link com.google.protobuf.Message
Lite#toByteArray}. |
| 1307 * @param regularForm the message to serialize | 1168 * @param regularForm the message to serialize |
| 1308 */ | 1169 */ |
| 1309 SerializedForm(MessageLite regularForm) { | 1170 SerializedForm(MessageLite regularForm) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1323 java.lang.reflect.Field defaultInstanceField = | 1184 java.lang.reflect.Field defaultInstanceField = |
| 1324 messageClass.getDeclaredField("DEFAULT_INSTANCE"); | 1185 messageClass.getDeclaredField("DEFAULT_INSTANCE"); |
| 1325 defaultInstanceField.setAccessible(true); | 1186 defaultInstanceField.setAccessible(true); |
| 1326 MessageLite defaultInstance = (MessageLite) defaultInstanceField.get(nul
l); | 1187 MessageLite defaultInstance = (MessageLite) defaultInstanceField.get(nul
l); |
| 1327 return defaultInstance.newBuilderForType() | 1188 return defaultInstance.newBuilderForType() |
| 1328 .mergeFrom(asBytes) | 1189 .mergeFrom(asBytes) |
| 1329 .buildPartial(); | 1190 .buildPartial(); |
| 1330 } catch (ClassNotFoundException e) { | 1191 } catch (ClassNotFoundException e) { |
| 1331 throw new RuntimeException("Unable to find proto buffer class: " + messa
geClassName, e); | 1192 throw new RuntimeException("Unable to find proto buffer class: " + messa
geClassName, e); |
| 1332 } catch (NoSuchFieldException e) { | 1193 } catch (NoSuchFieldException e) { |
| 1333 return readResolveFallback(); | 1194 throw new RuntimeException("Unable to find DEFAULT_INSTANCE in " + messa
geClassName, e); |
| 1334 } catch (SecurityException e) { | 1195 } catch (SecurityException e) { |
| 1335 throw new RuntimeException("Unable to call DEFAULT_INSTANCE in " + messa
geClassName, e); | 1196 throw new RuntimeException("Unable to call DEFAULT_INSTANCE in " + messa
geClassName, e); |
| 1336 } catch (IllegalAccessException e) { | 1197 } catch (IllegalAccessException e) { |
| 1337 throw new RuntimeException("Unable to call parsePartialFrom", e); | 1198 throw new RuntimeException("Unable to call parsePartialFrom", e); |
| 1338 } catch (InvalidProtocolBufferException e) { | 1199 } catch (InvalidProtocolBufferException e) { |
| 1339 throw new RuntimeException("Unable to understand proto buffer", e); | 1200 throw new RuntimeException("Unable to understand proto buffer", e); |
| 1340 } | 1201 } |
| 1341 } | 1202 } |
| 1342 | |
| 1343 /** | |
| 1344 * @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1
generated code. | |
| 1345 */ | |
| 1346 @Deprecated | |
| 1347 private Object readResolveFallback() throws ObjectStreamException { | |
| 1348 try { | |
| 1349 Class<?> messageClass = Class.forName(messageClassName); | |
| 1350 java.lang.reflect.Field defaultInstanceField = | |
| 1351 messageClass.getDeclaredField("defaultInstance"); | |
| 1352 defaultInstanceField.setAccessible(true); | |
| 1353 MessageLite defaultInstance = (MessageLite) defaultInstanceField.get(nul
l); | |
| 1354 return defaultInstance.newBuilderForType() | |
| 1355 .mergeFrom(asBytes) | |
| 1356 .buildPartial(); | |
| 1357 } catch (ClassNotFoundException e) { | |
| 1358 throw new RuntimeException("Unable to find proto buffer class: " + messa
geClassName, e); | |
| 1359 } catch (NoSuchFieldException e) { | |
| 1360 throw new RuntimeException("Unable to find defaultInstance in " + messag
eClassName, e); | |
| 1361 } catch (SecurityException e) { | |
| 1362 throw new RuntimeException("Unable to call defaultInstance in " + messag
eClassName, e); | |
| 1363 } catch (IllegalAccessException e) { | |
| 1364 throw new RuntimeException("Unable to call parsePartialFrom", e); | |
| 1365 } catch (InvalidProtocolBufferException e) { | |
| 1366 throw new RuntimeException("Unable to understand proto buffer", e); | |
| 1367 } | |
| 1368 } | |
| 1369 } | 1203 } |
| 1370 | 1204 |
| 1371 /** | 1205 /** |
| 1372 * Checks that the {@link Extension} is Lite and returns it as a | 1206 * Checks that the {@link Extension} is Lite and returns it as a |
| 1373 * {@link GeneratedExtension}. | 1207 * {@link GeneratedExtension}. |
| 1374 */ | 1208 */ |
| 1375 private static < | 1209 private static < |
| 1376 MessageType extends ExtendableMessage<MessageType, BuilderType>, | 1210 MessageType extends ExtendableMessage<MessageType, BuilderType>, |
| 1377 BuilderType extends ExtendableBuilder<MessageType, BuilderType>, | 1211 BuilderType extends ExtendableBuilder<MessageType, BuilderType>, |
| 1378 T> | 1212 T> |
| 1379 GeneratedExtension<MessageType, T> checkIsLite( | 1213 GeneratedExtension<MessageType, T> checkIsLite( |
| 1380 ExtensionLite<MessageType, T> extension) { | 1214 ExtensionLite<MessageType, T> extension) { |
| 1381 if (!extension.isLite()) { | 1215 if (!extension.isLite()) { |
| 1382 throw new IllegalArgumentException("Expected a lite extension."); | 1216 throw new IllegalArgumentException("Expected a lite extension."); |
| 1383 } | 1217 } |
| 1384 | 1218 |
| 1385 return (GeneratedExtension<MessageType, T>) extension; | 1219 return (GeneratedExtension<MessageType, T>) extension; |
| 1386 } | 1220 } |
| 1387 | 1221 |
| 1388 /** | 1222 /** |
| 1389 * A static helper method for checking if a message is initialized, optionally
memoizing. | 1223 * A static helper method for checking if a message is initialized, optionally
memoizing. |
| 1390 * <p> | 1224 * <p> |
| 1391 * For use by generated code only. | 1225 * For use by generated code only. |
| 1392 */ | 1226 */ |
| 1393 protected static final <T extends GeneratedMessageLite<T, ?>> boolean isInitia
lized( | 1227 protected static final <T extends GeneratedMessageLite<T, ?>> boolean isInitia
lized( |
| 1394 T message, boolean shouldMemoize) { | 1228 T message, boolean shouldMemoize) { |
| 1395 return message.dynamicMethod(MethodToInvoke.IS_INITIALIZED, shouldMemoize) !
= null; | 1229 return message.dynamicMethod(MethodToInvoke.IS_INITIALIZED, shouldMemoize) !
= null; |
| 1396 } | 1230 } |
| 1397 | 1231 |
| 1398 protected static final <T extends GeneratedMessageLite<T, ?>> void makeImmutab
le(T message) { | 1232 protected static final <T extends GeneratedMessageLite<T, ?>> void makeImmutab
le(T message) { |
| 1399 message.dynamicMethod(MethodToInvoke.MAKE_IMMUTABLE); | 1233 message.dynamicMethod(MethodToInvoke.MAKE_IMMUTABLE); |
| 1400 } | 1234 } |
| 1401 | 1235 |
| 1402 protected static IntList emptyIntList() { | 1236 protected static IntList emptyIntList() { |
| 1403 return IntArrayList.emptyList(); | 1237 return IntArrayList.emptyList(); |
| 1404 } | 1238 } |
| 1405 | 1239 |
| 1406 protected static IntList mutableCopy(IntList list) { | 1240 protected static IntList mutableCopy(IntList list) { |
| 1407 int size = list.size(); | 1241 int size = list.size(); |
| 1408 return list.mutableCopyWithCapacity( | 1242 return list.mutableCopyWithCapacity( |
| 1409 size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2); | 1243 size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2); |
| 1410 } | 1244 } |
| 1411 | 1245 |
| 1412 protected static LongList emptyLongList() { | 1246 protected static LongList emptyLongList() { |
| 1413 return LongArrayList.emptyList(); | 1247 return LongArrayList.emptyList(); |
| 1414 } | 1248 } |
| 1415 | 1249 |
| 1416 protected static LongList mutableCopy(LongList list) { | 1250 protected static LongList mutableCopy(LongList list) { |
| 1417 int size = list.size(); | 1251 int size = list.size(); |
| 1418 return list.mutableCopyWithCapacity( | 1252 return list.mutableCopyWithCapacity( |
| 1419 size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2); | 1253 size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2); |
| 1420 } | 1254 } |
| 1421 | 1255 |
| 1422 protected static FloatList emptyFloatList() { | 1256 protected static FloatList emptyFloatList() { |
| 1423 return FloatArrayList.emptyList(); | 1257 return FloatArrayList.emptyList(); |
| 1424 } | 1258 } |
| 1425 | 1259 |
| 1426 protected static FloatList mutableCopy(FloatList list) { | 1260 protected static FloatList mutableCopy(FloatList list) { |
| 1427 int size = list.size(); | 1261 int size = list.size(); |
| 1428 return list.mutableCopyWithCapacity( | 1262 return list.mutableCopyWithCapacity( |
| 1429 size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2); | 1263 size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2); |
| 1430 } | 1264 } |
| 1431 | 1265 |
| 1432 protected static DoubleList emptyDoubleList() { | 1266 protected static DoubleList emptyDoubleList() { |
| 1433 return DoubleArrayList.emptyList(); | 1267 return DoubleArrayList.emptyList(); |
| 1434 } | 1268 } |
| 1435 | 1269 |
| 1436 protected static DoubleList mutableCopy(DoubleList list) { | 1270 protected static DoubleList mutableCopy(DoubleList list) { |
| 1437 int size = list.size(); | 1271 int size = list.size(); |
| 1438 return list.mutableCopyWithCapacity( | 1272 return list.mutableCopyWithCapacity( |
| 1439 size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2); | 1273 size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2); |
| 1440 } | 1274 } |
| 1441 | 1275 |
| 1442 protected static BooleanList emptyBooleanList() { | 1276 protected static BooleanList emptyBooleanList() { |
| 1443 return BooleanArrayList.emptyList(); | 1277 return BooleanArrayList.emptyList(); |
| 1444 } | 1278 } |
| 1445 | 1279 |
| 1446 protected static BooleanList mutableCopy(BooleanList list) { | 1280 protected static BooleanList mutableCopy(BooleanList list) { |
| 1447 int size = list.size(); | 1281 int size = list.size(); |
| 1448 return list.mutableCopyWithCapacity( | 1282 return list.mutableCopyWithCapacity( |
| 1449 size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2); | 1283 size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2); |
| 1450 } | 1284 } |
| 1451 | 1285 |
| 1452 protected static <E> ProtobufList<E> emptyProtobufList() { | 1286 protected static <E> ProtobufList<E> emptyProtobufList() { |
| 1453 return ProtobufArrayList.emptyList(); | 1287 return ProtobufArrayList.emptyList(); |
| 1454 } | 1288 } |
| 1455 | 1289 |
| 1456 protected static <E> ProtobufList<E> mutableCopy(ProtobufList<E> list) { | 1290 protected static <E> ProtobufList<E> mutableCopy(ProtobufList<E> list) { |
| 1457 int size = list.size(); | 1291 int size = list.size(); |
| 1458 return list.mutableCopyWithCapacity( | 1292 return list.mutableCopyWithCapacity( |
| 1459 size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2); | 1293 size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2); |
| 1460 } | 1294 } |
| 1461 | 1295 |
| 1462 /** | 1296 /** |
| 1463 * A {@link Parser} implementation that delegates to the default instance. | 1297 * A {@link Parser} implementation that delegates to the default instance. |
| 1464 * <p> | 1298 * <p> |
| 1465 * For use by generated code only. | 1299 * For use by generated code only. |
| 1466 */ | 1300 */ |
| 1467 protected static class DefaultInstanceBasedParser<T extends GeneratedMessageLi
te<T, ?>> | 1301 protected static class DefaultInstanceBasedParser<T extends GeneratedMessageLi
te<T, ?>> |
| 1468 extends AbstractParser<T> { | 1302 extends AbstractParser<T> { |
| 1469 | 1303 |
| 1470 private T defaultInstance; | 1304 private T defaultInstance; |
| 1471 | 1305 |
| 1472 public DefaultInstanceBasedParser(T defaultInstance) { | 1306 public DefaultInstanceBasedParser(T defaultInstance) { |
| 1473 this.defaultInstance = defaultInstance; | 1307 this.defaultInstance = defaultInstance; |
| 1474 } | 1308 } |
| 1475 | 1309 |
| 1476 @Override | 1310 @Override |
| 1477 public T parsePartialFrom(CodedInputStream input, ExtensionRegistryLite exte
nsionRegistry) | 1311 public T parsePartialFrom(CodedInputStream input, ExtensionRegistryLite exte
nsionRegistry) |
| 1478 throws InvalidProtocolBufferException { | 1312 throws InvalidProtocolBufferException { |
| 1479 return GeneratedMessageLite.parsePartialFrom(defaultInstance, input, exten
sionRegistry); | 1313 return GeneratedMessageLite.parsePartialFrom(defaultInstance, input, exten
sionRegistry); |
| 1480 } | 1314 } |
| 1481 } | 1315 } |
| 1482 | 1316 |
| 1483 /** | 1317 /** |
| 1484 * A static helper method for parsing a partial from input using the extension
registry and the | 1318 * A static helper method for parsing a partial from input using the extension
registry and the |
| 1485 * instance. | 1319 * instance. |
| 1486 */ | 1320 */ |
| 1487 // TODO(dweis): Should this verify that the last tag was 0? | 1321 // TODO(dweis): Should this verify that the last tag was 0? |
| 1488 static <T extends GeneratedMessageLite<T, ?>> T parsePartialFrom( | 1322 static <T extends GeneratedMessageLite<T, ?>> T parsePartialFrom( |
| 1489 T instance, CodedInputStream input, ExtensionRegistryLite extensionRegistr
y) | 1323 T instance, CodedInputStream input, ExtensionRegistryLite extensionRegistr
y) |
| 1490 throws InvalidProtocolBufferException { | 1324 throws InvalidProtocolBufferException { |
| 1491 @SuppressWarnings("unchecked") // Guaranteed by protoc | 1325 @SuppressWarnings("unchecked") // Guaranteed by protoc |
| 1492 T result = (T) instance.dynamicMethod(MethodToInvoke.NEW_MUTABLE_INSTANCE); | 1326 T result = (T) instance.dynamicMethod(MethodToInvoke.NEW_MUTABLE_INSTANCE); |
| 1493 try { | 1327 try { |
| 1494 result.dynamicMethod(MethodToInvoke.MERGE_FROM_STREAM, input, extensionReg
istry); | 1328 result.dynamicMethod(MethodToInvoke.MERGE_FROM_STREAM, input, extensionReg
istry); |
| 1495 result.makeImmutable(); | 1329 result.makeImmutable(); |
| 1496 } catch (RuntimeException e) { | 1330 } catch (RuntimeException e) { |
| 1497 if (e.getCause() instanceof InvalidProtocolBufferException) { | 1331 if (e.getCause() instanceof InvalidProtocolBufferException) { |
| 1498 throw (InvalidProtocolBufferException) e.getCause(); | 1332 throw (InvalidProtocolBufferException) e.getCause(); |
| 1499 } | 1333 } |
| 1500 throw e; | 1334 throw e; |
| 1501 } | 1335 } |
| 1502 return result; | 1336 return result; |
| 1503 } | 1337 } |
| 1504 | 1338 |
| 1505 protected static <T extends GeneratedMessageLite<T, ?>> T parsePartialFrom( | 1339 protected static <T extends GeneratedMessageLite<T, ?>> T parsePartialFrom( |
| 1506 T defaultInstance, | 1340 T defaultInstance, |
| 1507 CodedInputStream input) | 1341 CodedInputStream input) |
| 1508 throws InvalidProtocolBufferException { | 1342 throws InvalidProtocolBufferException { |
| 1509 return parsePartialFrom(defaultInstance, input, ExtensionRegistryLite.getEmp
tyRegistry()); | 1343 return parsePartialFrom(defaultInstance, input, ExtensionRegistryLite.getEmp
tyRegistry()); |
| 1510 } | 1344 } |
| 1511 | 1345 |
| 1512 /** | 1346 /** |
| 1513 * Helper method to check if message is initialized. | 1347 * Helper method to check if message is initialized. |
| 1514 * | 1348 * |
| 1515 * @throws InvalidProtocolBufferException if it is not initialized. | 1349 * @throws InvalidProtocolBufferException if it is not initialized. |
| 1516 * @return The message to check. | 1350 * @return The message to check. |
| 1517 */ | 1351 */ |
| 1518 private static <T extends GeneratedMessageLite<T, ?>> T checkMessageInitialize
d(T message) | 1352 private static <T extends GeneratedMessageLite<T, ?>> T checkMessageInitialize
d(T message) |
| 1519 throws InvalidProtocolBufferException { | 1353 throws InvalidProtocolBufferException { |
| 1520 if (message != null && !message.isInitialized()) { | 1354 if (message != null && !message.isInitialized()) { |
| 1521 throw message.newUninitializedMessageException() | 1355 throw message.newUninitializedMessageException() |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1532 return checkMessageInitialized( | 1366 return checkMessageInitialized( |
| 1533 parseFrom(defaultInstance, data, ExtensionRegistryLite.getEmptyRegistry(
))); | 1367 parseFrom(defaultInstance, data, ExtensionRegistryLite.getEmptyRegistry(
))); |
| 1534 } | 1368 } |
| 1535 | 1369 |
| 1536 // Validates last tag. | 1370 // Validates last tag. |
| 1537 protected static <T extends GeneratedMessageLite<T, ?>> T parseFrom( | 1371 protected static <T extends GeneratedMessageLite<T, ?>> T parseFrom( |
| 1538 T defaultInstance, ByteString data, ExtensionRegistryLite extensionRegistr
y) | 1372 T defaultInstance, ByteString data, ExtensionRegistryLite extensionRegistr
y) |
| 1539 throws InvalidProtocolBufferException { | 1373 throws InvalidProtocolBufferException { |
| 1540 return checkMessageInitialized(parsePartialFrom(defaultInstance, data, exten
sionRegistry)); | 1374 return checkMessageInitialized(parsePartialFrom(defaultInstance, data, exten
sionRegistry)); |
| 1541 } | 1375 } |
| 1542 | 1376 |
| 1543 // This is a special case since we want to verify that the last tag is 0. We a
ssume we exhaust the | 1377 // This is a special case since we want to verify that the last tag is 0. We a
ssume we exhaust the |
| 1544 // ByteString. | 1378 // ByteString. |
| 1545 private static <T extends GeneratedMessageLite<T, ?>> T parsePartialFrom( | 1379 private static <T extends GeneratedMessageLite<T, ?>> T parsePartialFrom( |
| 1546 T defaultInstance, ByteString data, ExtensionRegistryLite extensionRegistr
y) | 1380 T defaultInstance, ByteString data, ExtensionRegistryLite extensionRegistr
y) |
| 1547 throws InvalidProtocolBufferException { | 1381 throws InvalidProtocolBufferException { |
| 1548 T message; | 1382 T message; |
| 1549 try { | 1383 try { |
| 1550 CodedInputStream input = data.newCodedInput(); | 1384 CodedInputStream input = data.newCodedInput(); |
| 1551 message = parsePartialFrom(defaultInstance, input, extensionRegistry); | 1385 message = parsePartialFrom(defaultInstance, input, extensionRegistry); |
| 1552 try { | 1386 try { |
| 1553 input.checkLastTagWas(0); | 1387 input.checkLastTagWas(0); |
| 1554 } catch (InvalidProtocolBufferException e) { | 1388 } catch (InvalidProtocolBufferException e) { |
| 1555 throw e.setUnfinishedMessage(message); | 1389 throw e.setUnfinishedMessage(message); |
| 1556 } | 1390 } |
| 1557 return message; | 1391 return message; |
| 1558 } catch (InvalidProtocolBufferException e) { | 1392 } catch (InvalidProtocolBufferException e) { |
| 1559 throw e; | 1393 throw e; |
| 1560 } | 1394 } |
| 1561 } | 1395 } |
| 1562 | 1396 |
| 1563 // This is a special case since we want to verify that the last tag is 0. We a
ssume we exhaust the | 1397 // This is a special case since we want to verify that the last tag is 0. We a
ssume we exhaust the |
| 1564 // ByteString. | 1398 // ByteString. |
| 1565 private static <T extends GeneratedMessageLite<T, ?>> T parsePartialFrom( | 1399 private static <T extends GeneratedMessageLite<T, ?>> T parsePartialFrom( |
| 1566 T defaultInstance, byte[] data, ExtensionRegistryLite extensionRegistry) | 1400 T defaultInstance, byte[] data, ExtensionRegistryLite extensionRegistry) |
| 1567 throws InvalidProtocolBufferException { | 1401 throws InvalidProtocolBufferException { |
| 1568 T message; | 1402 T message; |
| 1569 try { | 1403 try { |
| 1570 CodedInputStream input = CodedInputStream.newInstance(data); | 1404 CodedInputStream input = CodedInputStream.newInstance(data); |
| 1571 message = parsePartialFrom(defaultInstance, input, extensionRegistry); | 1405 message = parsePartialFrom(defaultInstance, input, extensionRegistry); |
| 1572 try { | 1406 try { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1636 ExtensionRegistryLite.getEmptyRegistry())); | 1470 ExtensionRegistryLite.getEmptyRegistry())); |
| 1637 } | 1471 } |
| 1638 | 1472 |
| 1639 // Validates last tag. | 1473 // Validates last tag. |
| 1640 protected static <T extends GeneratedMessageLite<T, ?>> T parseDelimitedFrom( | 1474 protected static <T extends GeneratedMessageLite<T, ?>> T parseDelimitedFrom( |
| 1641 T defaultInstance, InputStream input, ExtensionRegistryLite extensionRegis
try) | 1475 T defaultInstance, InputStream input, ExtensionRegistryLite extensionRegis
try) |
| 1642 throws InvalidProtocolBufferException { | 1476 throws InvalidProtocolBufferException { |
| 1643 return checkMessageInitialized( | 1477 return checkMessageInitialized( |
| 1644 parsePartialDelimitedFrom(defaultInstance, input, extensionRegistry)); | 1478 parsePartialDelimitedFrom(defaultInstance, input, extensionRegistry)); |
| 1645 } | 1479 } |
| 1646 | 1480 |
| 1647 private static <T extends GeneratedMessageLite<T, ?>> T parsePartialDelimitedF
rom( | 1481 private static <T extends GeneratedMessageLite<T, ?>> T parsePartialDelimitedF
rom( |
| 1648 T defaultInstance, | 1482 T defaultInstance, |
| 1649 InputStream input, | 1483 InputStream input, |
| 1650 ExtensionRegistryLite extensionRegistry) | 1484 ExtensionRegistryLite extensionRegistry) |
| 1651 throws InvalidProtocolBufferException { | 1485 throws InvalidProtocolBufferException { |
| 1652 int size; | 1486 int size; |
| 1653 try { | 1487 try { |
| 1654 int firstByte = input.read(); | 1488 int firstByte = input.read(); |
| 1655 if (firstByte == -1) { | 1489 if (firstByte == -1) { |
| 1656 return null; | 1490 return null; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1689 Object visitOneofBoolean(boolean minePresent, Object mine, Object other); | 1523 Object visitOneofBoolean(boolean minePresent, Object mine, Object other); |
| 1690 Object visitOneofInt(boolean minePresent, Object mine, Object other); | 1524 Object visitOneofInt(boolean minePresent, Object mine, Object other); |
| 1691 Object visitOneofDouble(boolean minePresent, Object mine, Object other); | 1525 Object visitOneofDouble(boolean minePresent, Object mine, Object other); |
| 1692 Object visitOneofFloat(boolean minePresent, Object mine, Object other); | 1526 Object visitOneofFloat(boolean minePresent, Object mine, Object other); |
| 1693 Object visitOneofLong(boolean minePresent, Object mine, Object other); | 1527 Object visitOneofLong(boolean minePresent, Object mine, Object other); |
| 1694 Object visitOneofString(boolean minePresent, Object mine, Object other); | 1528 Object visitOneofString(boolean minePresent, Object mine, Object other); |
| 1695 Object visitOneofByteString(boolean minePresent, Object mine, Object other); | 1529 Object visitOneofByteString(boolean minePresent, Object mine, Object other); |
| 1696 Object visitOneofLazyMessage(boolean minePresent, Object mine, Object other)
; | 1530 Object visitOneofLazyMessage(boolean minePresent, Object mine, Object other)
; |
| 1697 Object visitOneofMessage(boolean minePresent, Object mine, Object other); | 1531 Object visitOneofMessage(boolean minePresent, Object mine, Object other); |
| 1698 void visitOneofNotSet(boolean minePresent); | 1532 void visitOneofNotSet(boolean minePresent); |
| 1699 | 1533 |
| 1700 /** | 1534 /** |
| 1701 * Message fields use null sentinals. | 1535 * Message fields use null sentinals. |
| 1702 */ | 1536 */ |
| 1703 <T extends MessageLite> T visitMessage(T mine, T other); | 1537 <T extends MessageLite> T visitMessage(T mine, T other); |
| 1704 LazyFieldLite visitLazyMessage(LazyFieldLite mine, LazyFieldLite other); | 1538 LazyFieldLite visitLazyMessage( |
| 1539 boolean minePresent, LazyFieldLite mine, boolean otherPresent, LazyField
Lite other); |
| 1705 | 1540 |
| 1706 <T> ProtobufList<T> visitList(ProtobufList<T> mine, ProtobufList<T> other); | 1541 <T> ProtobufList<T> visitList(ProtobufList<T> mine, ProtobufList<T> other); |
| 1707 BooleanList visitBooleanList(BooleanList mine, BooleanList other); | 1542 BooleanList visitBooleanList(BooleanList mine, BooleanList other); |
| 1708 IntList visitIntList(IntList mine, IntList other); | 1543 IntList visitIntList(IntList mine, IntList other); |
| 1709 DoubleList visitDoubleList(DoubleList mine, DoubleList other); | 1544 DoubleList visitDoubleList(DoubleList mine, DoubleList other); |
| 1710 FloatList visitFloatList(FloatList mine, FloatList other); | 1545 FloatList visitFloatList(FloatList mine, FloatList other); |
| 1711 LongList visitLongList(LongList mine, LongList other); | 1546 LongList visitLongList(LongList mine, LongList other); |
| 1712 FieldSet<ExtensionDescriptor> visitExtensions( | 1547 FieldSet<ExtensionDescriptor> visitExtensions( |
| 1713 FieldSet<ExtensionDescriptor> mine, FieldSet<ExtensionDescriptor> other)
; | 1548 FieldSet<ExtensionDescriptor> mine, FieldSet<ExtensionDescriptor> other)
; |
| 1714 UnknownFieldSetLite visitUnknownFields(UnknownFieldSetLite mine, UnknownFiel
dSetLite other); | 1549 UnknownFieldSetLite visitUnknownFields(UnknownFieldSetLite mine, UnknownFiel
dSetLite other); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1844 throw NOT_EQUALS; | 1679 throw NOT_EQUALS; |
| 1845 } | 1680 } |
| 1846 | 1681 |
| 1847 @Override | 1682 @Override |
| 1848 public Object visitOneofLazyMessage(boolean minePresent, Object mine, Object
other) { | 1683 public Object visitOneofLazyMessage(boolean minePresent, Object mine, Object
other) { |
| 1849 if (minePresent && mine.equals(other)) { | 1684 if (minePresent && mine.equals(other)) { |
| 1850 return mine; | 1685 return mine; |
| 1851 } | 1686 } |
| 1852 throw NOT_EQUALS; | 1687 throw NOT_EQUALS; |
| 1853 } | 1688 } |
| 1854 | 1689 |
| 1855 @Override | 1690 @Override |
| 1856 public Object visitOneofMessage(boolean minePresent, Object mine, Object oth
er) { | 1691 public Object visitOneofMessage(boolean minePresent, Object mine, Object oth
er) { |
| 1857 if (minePresent && ((GeneratedMessageLite<?, ?>) mine).equals(this, (Messa
geLite) other)) { | 1692 if (minePresent && ((GeneratedMessageLite<?, ?>) mine).equals(this, (Messa
geLite) other)) { |
| 1858 return mine; | 1693 return mine; |
| 1859 } | 1694 } |
| 1860 throw NOT_EQUALS; | 1695 throw NOT_EQUALS; |
| 1861 } | 1696 } |
| 1862 | 1697 |
| 1863 @Override | 1698 @Override |
| 1864 public void visitOneofNotSet(boolean minePresent) { | 1699 public void visitOneofNotSet(boolean minePresent) { |
| 1865 if (minePresent) { | 1700 if (minePresent) { |
| 1866 throw NOT_EQUALS; | 1701 throw NOT_EQUALS; |
| 1867 } | 1702 } |
| 1868 } | 1703 } |
| 1869 | 1704 |
| 1870 @Override | 1705 @Override |
| 1871 public <T extends MessageLite> T visitMessage(T mine, T other) { | 1706 public <T extends MessageLite> T visitMessage(T mine, T other) { |
| 1872 if (mine == null && other == null) { | 1707 if (mine == null && other == null) { |
| 1873 return null; | 1708 return null; |
| 1874 } | 1709 } |
| 1875 | 1710 |
| 1876 if (mine == null || other == null) { | 1711 if (mine == null || other == null) { |
| 1877 throw NOT_EQUALS; | 1712 throw NOT_EQUALS; |
| 1878 } | 1713 } |
| 1879 | 1714 |
| 1880 ((GeneratedMessageLite<?, ?>) mine).equals(this, other); | 1715 ((GeneratedMessageLite<?, ?>) mine).equals(this, other); |
| 1881 | 1716 |
| 1882 return mine; | 1717 return mine; |
| 1883 } | 1718 } |
| 1884 | 1719 |
| 1885 @Override | 1720 @Override |
| 1886 public LazyFieldLite visitLazyMessage( | 1721 public LazyFieldLite visitLazyMessage( |
| 1887 LazyFieldLite mine, LazyFieldLite other) { | 1722 boolean minePresent, LazyFieldLite mine, boolean otherPresent, LazyField
Lite other) { |
| 1888 if (mine == null && other == null) { | 1723 if (!minePresent && !otherPresent) { |
| 1889 return null; | 1724 return mine; |
| 1890 } | 1725 } else if (minePresent && otherPresent && mine.equals(other)) { |
| 1891 if (mine == null || other == null) { | |
| 1892 throw NOT_EQUALS; | |
| 1893 } | |
| 1894 if (mine.equals(other)) { | |
| 1895 return mine; | 1726 return mine; |
| 1896 } | 1727 } |
| 1897 throw NOT_EQUALS; | 1728 throw NOT_EQUALS; |
| 1898 } | 1729 } |
| 1899 | 1730 |
| 1900 @Override | 1731 @Override |
| 1901 public <T> ProtobufList<T> visitList(ProtobufList<T> mine, ProtobufList<T> o
ther) { | 1732 public <T> ProtobufList<T> visitList(ProtobufList<T> mine, ProtobufList<T> o
ther) { |
| 1902 if (!mine.equals(other)) { | 1733 if (!mine.equals(other)) { |
| 1903 throw NOT_EQUALS; | 1734 throw NOT_EQUALS; |
| 1904 } | 1735 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1975 } | 1806 } |
| 1976 | 1807 |
| 1977 /** | 1808 /** |
| 1978 * Implements hashCode by accumulating state. | 1809 * Implements hashCode by accumulating state. |
| 1979 */ | 1810 */ |
| 1980 private static class HashCodeVisitor implements Visitor { | 1811 private static class HashCodeVisitor implements Visitor { |
| 1981 | 1812 |
| 1982 // The caller must ensure that the visitor is invoked parameterized with thi
s and this such that | 1813 // The caller must ensure that the visitor is invoked parameterized with thi
s and this such that |
| 1983 // other is this. This is required due to how oneof cases are handled. See t
he class comment | 1814 // other is this. This is required due to how oneof cases are handled. See t
he class comment |
| 1984 // on Visitor for more information. | 1815 // on Visitor for more information. |
| 1985 | 1816 |
| 1986 private int hashCode = 0; | 1817 private int hashCode = 0; |
| 1987 | 1818 |
| 1988 @Override | 1819 @Override |
| 1989 public boolean visitBoolean( | 1820 public boolean visitBoolean( |
| 1990 boolean minePresent, boolean mine, boolean otherPresent, boolean other)
{ | 1821 boolean minePresent, boolean mine, boolean otherPresent, boolean other)
{ |
| 1991 hashCode = (53 * hashCode) + Internal.hashBoolean(mine); | 1822 hashCode = (53 * hashCode) + Internal.hashBoolean(mine); |
| 1992 return mine; | 1823 return mine; |
| 1993 } | 1824 } |
| 1994 | 1825 |
| 1995 @Override | 1826 @Override |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2071 public Object visitOneofByteString(boolean minePresent, Object mine, Object
other) { | 1902 public Object visitOneofByteString(boolean minePresent, Object mine, Object
other) { |
| 2072 hashCode = (53 * hashCode) + mine.hashCode(); | 1903 hashCode = (53 * hashCode) + mine.hashCode(); |
| 2073 return mine; | 1904 return mine; |
| 2074 } | 1905 } |
| 2075 | 1906 |
| 2076 @Override | 1907 @Override |
| 2077 public Object visitOneofLazyMessage(boolean minePresent, Object mine, Object
other) { | 1908 public Object visitOneofLazyMessage(boolean minePresent, Object mine, Object
other) { |
| 2078 hashCode = (53 * hashCode) + mine.hashCode(); | 1909 hashCode = (53 * hashCode) + mine.hashCode(); |
| 2079 return mine; | 1910 return mine; |
| 2080 } | 1911 } |
| 2081 | 1912 |
| 2082 @Override | 1913 @Override |
| 2083 public Object visitOneofMessage(boolean minePresent, Object mine, Object oth
er) { | 1914 public Object visitOneofMessage(boolean minePresent, Object mine, Object oth
er) { |
| 2084 return visitMessage((MessageLite) mine, (MessageLite) other); | 1915 return visitMessage((MessageLite) mine, (MessageLite) other); |
| 2085 } | 1916 } |
| 2086 | 1917 |
| 2087 @Override | 1918 @Override |
| 2088 public void visitOneofNotSet(boolean minePresent) { | 1919 public void visitOneofNotSet(boolean minePresent) { |
| 2089 if (minePresent) { | 1920 if (minePresent) { |
| 2090 throw new IllegalStateException(); // Can't happen if other == this. | 1921 throw new IllegalStateException(); // Can't happen if other == this. |
| 2091 } | 1922 } |
| 2092 } | 1923 } |
| 2093 | 1924 |
| 2094 @Override | 1925 @Override |
| 2095 public <T extends MessageLite> T visitMessage(T mine, T other) { | 1926 public <T extends MessageLite> T visitMessage(T mine, T other) { |
| 2096 final int protoHash; | 1927 final int protoHash; |
| 2097 if (mine != null) { | 1928 if (mine != null) { |
| 2098 if (mine instanceof GeneratedMessageLite) { | 1929 if (mine instanceof GeneratedMessageLite) { |
| 2099 protoHash = ((GeneratedMessageLite) mine).hashCode(this); | 1930 protoHash = ((GeneratedMessageLite) mine).hashCode(this); |
| 2100 } else { | 1931 } else { |
| 2101 protoHash = mine.hashCode(); | 1932 protoHash = mine.hashCode(); |
| 2102 } | 1933 } |
| 2103 } else { | 1934 } else { |
| 2104 protoHash = 37; | 1935 protoHash = 37; |
| 2105 } | 1936 } |
| 2106 hashCode = (53 * hashCode) + protoHash; | 1937 hashCode = (53 * hashCode) + protoHash; |
| 2107 return mine; | 1938 return mine; |
| 2108 } | 1939 } |
| 2109 | 1940 |
| 2110 @Override | 1941 @Override |
| 2111 public LazyFieldLite visitLazyMessage(LazyFieldLite mine, LazyFieldLite othe
r) { | 1942 public LazyFieldLite visitLazyMessage( |
| 2112 final int protoHash; | 1943 boolean minePresent, LazyFieldLite mine, boolean otherPresent, LazyField
Lite other) { |
| 2113 if (mine != null) { | 1944 hashCode = (53 * hashCode) + mine.hashCode(); |
| 2114 protoHash = mine.hashCode(); | |
| 2115 } else { | |
| 2116 protoHash = 37; | |
| 2117 } | |
| 2118 hashCode = (53 * hashCode) + protoHash; | |
| 2119 return mine; | 1945 return mine; |
| 2120 } | 1946 } |
| 2121 | 1947 |
| 2122 @Override | 1948 @Override |
| 2123 public <T> ProtobufList<T> visitList(ProtobufList<T> mine, ProtobufList<T> o
ther) { | 1949 public <T> ProtobufList<T> visitList(ProtobufList<T> mine, ProtobufList<T> o
ther) { |
| 2124 hashCode = (53 * hashCode) + mine.hashCode(); | 1950 hashCode = (53 * hashCode) + mine.hashCode(); |
| 2125 return mine; | 1951 return mine; |
| 2126 } | 1952 } |
| 2127 | 1953 |
| 2128 @Override | 1954 @Override |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2163 return mine; | 1989 return mine; |
| 2164 } | 1990 } |
| 2165 | 1991 |
| 2166 @Override | 1992 @Override |
| 2167 public UnknownFieldSetLite visitUnknownFields( | 1993 public UnknownFieldSetLite visitUnknownFields( |
| 2168 UnknownFieldSetLite mine, | 1994 UnknownFieldSetLite mine, |
| 2169 UnknownFieldSetLite other) { | 1995 UnknownFieldSetLite other) { |
| 2170 hashCode = (53 * hashCode) + mine.hashCode(); | 1996 hashCode = (53 * hashCode) + mine.hashCode(); |
| 2171 return mine; | 1997 return mine; |
| 2172 } | 1998 } |
| 2173 | 1999 |
| 2174 @Override | 2000 @Override |
| 2175 public <K, V> MapFieldLite<K, V> visitMap(MapFieldLite<K, V> mine, MapFieldL
ite<K, V> other) { | 2001 public <K, V> MapFieldLite<K, V> visitMap(MapFieldLite<K, V> mine, MapFieldL
ite<K, V> other) { |
| 2176 hashCode = (53 * hashCode) + mine.hashCode(); | 2002 hashCode = (53 * hashCode) + mine.hashCode(); |
| 2177 return mine; | 2003 return mine; |
| 2178 } | 2004 } |
| 2179 } | 2005 } |
| 2180 | 2006 |
| 2181 /** | 2007 /** |
| 2182 * Implements field merging semantics over the visitor interface. | 2008 * Implements field merging semantics over the visitor interface. |
| 2183 */ | 2009 */ |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2231 return other; | 2057 return other; |
| 2232 } | 2058 } |
| 2233 | 2059 |
| 2234 @Override | 2060 @Override |
| 2235 public Object visitOneofInt(boolean minePresent, Object mine, Object other)
{ | 2061 public Object visitOneofInt(boolean minePresent, Object mine, Object other)
{ |
| 2236 return other; | 2062 return other; |
| 2237 } | 2063 } |
| 2238 | 2064 |
| 2239 @Override | 2065 @Override |
| 2240 public Object visitOneofDouble(boolean minePresent, Object mine, Object othe
r) { | 2066 public Object visitOneofDouble(boolean minePresent, Object mine, Object othe
r) { |
| 2241 return other; | 2067 return other; |
| 2242 } | 2068 } |
| 2243 | 2069 |
| 2244 @Override | 2070 @Override |
| 2245 public Object visitOneofFloat(boolean minePresent, Object mine, Object other
) { | 2071 public Object visitOneofFloat(boolean minePresent, Object mine, Object other
) { |
| 2246 return other; | 2072 return other; |
| 2247 } | 2073 } |
| 2248 | 2074 |
| 2249 @Override | 2075 @Override |
| 2250 public Object visitOneofLong(boolean minePresent, Object mine, Object other)
{ | 2076 public Object visitOneofLong(boolean minePresent, Object mine, Object other)
{ |
| 2251 return other; | 2077 return other; |
| 2252 } | 2078 } |
| 2253 | 2079 |
| 2254 @Override | 2080 @Override |
| 2255 public Object visitOneofString(boolean minePresent, Object mine, Object othe
r) { | 2081 public Object visitOneofString(boolean minePresent, Object mine, Object othe
r) { |
| 2256 return other; | 2082 return other; |
| 2257 } | 2083 } |
| 2258 | 2084 |
| 2259 @Override | 2085 @Override |
| 2260 public Object visitOneofByteString(boolean minePresent, Object mine, Object
other) { | 2086 public Object visitOneofByteString(boolean minePresent, Object mine, Object
other) { |
| 2261 return other; | 2087 return other; |
| 2262 } | 2088 } |
| 2263 | 2089 |
| 2264 @Override | 2090 @Override |
| 2265 public Object visitOneofLazyMessage(boolean minePresent, Object mine, Object
other) { | 2091 public Object visitOneofLazyMessage(boolean minePresent, Object mine, Object
other) { |
| 2266 LazyFieldLite lazy = minePresent ? (LazyFieldLite) mine : new LazyFieldLit
e(); | 2092 if (minePresent) { |
| 2267 lazy.merge((LazyFieldLite) other); | 2093 LazyFieldLite lazy = (LazyFieldLite) mine; |
| 2268 return lazy; | 2094 lazy.merge((LazyFieldLite) other); |
| 2095 return lazy; |
| 2096 } |
| 2097 return other; |
| 2269 } | 2098 } |
| 2270 | 2099 |
| 2271 @Override | 2100 @Override |
| 2272 public Object visitOneofMessage(boolean minePresent, Object mine, Object oth
er) { | 2101 public Object visitOneofMessage(boolean minePresent, Object mine, Object oth
er) { |
| 2273 if (minePresent) { | 2102 if (minePresent) { |
| 2274 return visitMessage((MessageLite) mine, (MessageLite) other); | 2103 return visitMessage((MessageLite) mine, (MessageLite) other); |
| 2275 } | 2104 } |
| 2276 return other; | 2105 return other; |
| 2277 } | 2106 } |
| 2278 | 2107 |
| 2279 @Override | 2108 @Override |
| 2280 public void visitOneofNotSet(boolean minePresent) { | 2109 public void visitOneofNotSet(boolean minePresent) { |
| 2281 return; | 2110 return; |
| 2282 } | 2111 } |
| 2283 | 2112 |
| 2284 @SuppressWarnings("unchecked") // Guaranteed by runtime. | 2113 @SuppressWarnings("unchecked") // Guaranteed by runtime. |
| 2285 @Override | 2114 @Override |
| 2286 public <T extends MessageLite> T visitMessage(T mine, T other) { | 2115 public <T extends MessageLite> T visitMessage(T mine, T other) { |
| 2287 if (mine != null && other != null) { | 2116 if (mine != null && other != null) { |
| 2288 return (T) mine.toBuilder().mergeFrom(other).build(); | 2117 return (T) mine.toBuilder().mergeFrom(other).build(); |
| 2289 } | 2118 } |
| 2290 | 2119 |
| 2291 return mine != null ? mine : other; | 2120 return mine != null ? mine : other; |
| 2292 } | 2121 } |
| 2293 | 2122 |
| 2294 @Override | 2123 @Override |
| 2295 public LazyFieldLite visitLazyMessage(LazyFieldLite mine, LazyFieldLite othe
r) { | 2124 public LazyFieldLite visitLazyMessage( |
| 2296 if (other != null) { | 2125 boolean minePresent, LazyFieldLite mine, boolean otherPresent, LazyField
Lite other) { |
| 2297 if (mine == null) { | 2126 // LazyFieldLite's are never null so we can just copy across. Necessary to
avoid leakage |
| 2298 mine = new LazyFieldLite(); | 2127 // from builder into immutable message. |
| 2299 } | 2128 // TODO(dweis): Change to null sentinels? |
| 2300 mine.merge(other); | 2129 mine.merge(other); |
| 2301 } | |
| 2302 return mine; | 2130 return mine; |
| 2303 } | 2131 } |
| 2304 | 2132 |
| 2305 @Override | 2133 @Override |
| 2306 public <T> ProtobufList<T> visitList(ProtobufList<T> mine, ProtobufList<T> o
ther) { | 2134 public <T> ProtobufList<T> visitList(ProtobufList<T> mine, ProtobufList<T> o
ther) { |
| 2307 int size = mine.size(); | 2135 int size = mine.size(); |
| 2308 int otherSize = other.size(); | 2136 int otherSize = other.size(); |
| 2309 if (size > 0 && otherSize > 0) { | 2137 if (size > 0 && otherSize > 0) { |
| 2310 if (!mine.isModifiable()) { | 2138 if (!mine.isModifiable()) { |
| 2311 mine = mine.mutableCopyWithCapacity(size + otherSize); | 2139 mine = mine.mutableCopyWithCapacity(size + otherSize); |
| 2312 } | 2140 } |
| 2313 mine.addAll(other); | 2141 mine.addAll(other); |
| 2314 } | 2142 } |
| 2315 | 2143 |
| 2316 return size > 0 ? mine : other; | 2144 return size > 0 ? mine : other; |
| 2317 } | 2145 } |
| 2318 | 2146 |
| 2319 @Override | 2147 @Override |
| 2320 public BooleanList visitBooleanList(BooleanList mine, BooleanList other) { | 2148 public BooleanList visitBooleanList(BooleanList mine, BooleanList other) { |
| 2321 int size = mine.size(); | 2149 int size = mine.size(); |
| 2322 int otherSize = other.size(); | 2150 int otherSize = other.size(); |
| 2323 if (size > 0 && otherSize > 0) { | 2151 if (size > 0 && otherSize > 0) { |
| 2324 if (!mine.isModifiable()) { | 2152 if (!mine.isModifiable()) { |
| 2325 mine = mine.mutableCopyWithCapacity(size + otherSize); | 2153 mine = mine.mutableCopyWithCapacity(size + otherSize); |
| 2326 } | 2154 } |
| 2327 mine.addAll(other); | 2155 mine.addAll(other); |
| 2328 } | 2156 } |
| 2329 | 2157 |
| 2330 return size > 0 ? mine : other; | 2158 return size > 0 ? mine : other; |
| 2331 } | 2159 } |
| 2332 | 2160 |
| 2333 @Override | 2161 @Override |
| 2334 public IntList visitIntList(IntList mine, IntList other) { | 2162 public IntList visitIntList(IntList mine, IntList other) { |
| 2335 int size = mine.size(); | 2163 int size = mine.size(); |
| 2336 int otherSize = other.size(); | 2164 int otherSize = other.size(); |
| 2337 if (size > 0 && otherSize > 0) { | 2165 if (size > 0 && otherSize > 0) { |
| 2338 if (!mine.isModifiable()) { | 2166 if (!mine.isModifiable()) { |
| 2339 mine = mine.mutableCopyWithCapacity(size + otherSize); | 2167 mine = mine.mutableCopyWithCapacity(size + otherSize); |
| 2340 } | 2168 } |
| 2341 mine.addAll(other); | 2169 mine.addAll(other); |
| 2342 } | 2170 } |
| 2343 | 2171 |
| 2344 return size > 0 ? mine : other; | 2172 return size > 0 ? mine : other; |
| 2345 } | 2173 } |
| 2346 | 2174 |
| 2347 @Override | 2175 @Override |
| 2348 public DoubleList visitDoubleList(DoubleList mine, DoubleList other) { | 2176 public DoubleList visitDoubleList(DoubleList mine, DoubleList other) { |
| 2349 int size = mine.size(); | 2177 int size = mine.size(); |
| 2350 int otherSize = other.size(); | 2178 int otherSize = other.size(); |
| 2351 if (size > 0 && otherSize > 0) { | 2179 if (size > 0 && otherSize > 0) { |
| 2352 if (!mine.isModifiable()) { | 2180 if (!mine.isModifiable()) { |
| 2353 mine = mine.mutableCopyWithCapacity(size + otherSize); | 2181 mine = mine.mutableCopyWithCapacity(size + otherSize); |
| 2354 } | 2182 } |
| 2355 mine.addAll(other); | 2183 mine.addAll(other); |
| 2356 } | 2184 } |
| 2357 | 2185 |
| 2358 return size > 0 ? mine : other; | 2186 return size > 0 ? mine : other; |
| 2359 } | 2187 } |
| 2360 | 2188 |
| 2361 @Override | 2189 @Override |
| 2362 public FloatList visitFloatList(FloatList mine, FloatList other) { | 2190 public FloatList visitFloatList(FloatList mine, FloatList other) { |
| 2363 int size = mine.size(); | 2191 int size = mine.size(); |
| 2364 int otherSize = other.size(); | 2192 int otherSize = other.size(); |
| 2365 if (size > 0 && otherSize > 0) { | 2193 if (size > 0 && otherSize > 0) { |
| 2366 if (!mine.isModifiable()) { | 2194 if (!mine.isModifiable()) { |
| 2367 mine = mine.mutableCopyWithCapacity(size + otherSize); | 2195 mine = mine.mutableCopyWithCapacity(size + otherSize); |
| 2368 } | 2196 } |
| 2369 mine.addAll(other); | 2197 mine.addAll(other); |
| 2370 } | 2198 } |
| 2371 | 2199 |
| 2372 return size > 0 ? mine : other; | 2200 return size > 0 ? mine : other; |
| 2373 } | 2201 } |
| 2374 | 2202 |
| 2375 @Override | 2203 @Override |
| 2376 public LongList visitLongList(LongList mine, LongList other) { | 2204 public LongList visitLongList(LongList mine, LongList other) { |
| 2377 int size = mine.size(); | 2205 int size = mine.size(); |
| 2378 int otherSize = other.size(); | 2206 int otherSize = other.size(); |
| 2379 if (size > 0 && otherSize > 0) { | 2207 if (size > 0 && otherSize > 0) { |
| 2380 if (!mine.isModifiable()) { | 2208 if (!mine.isModifiable()) { |
| 2381 mine = mine.mutableCopyWithCapacity(size + otherSize); | 2209 mine = mine.mutableCopyWithCapacity(size + otherSize); |
| 2382 } | 2210 } |
| 2383 mine.addAll(other); | 2211 mine.addAll(other); |
| 2384 } | 2212 } |
| 2385 | 2213 |
| 2386 return size > 0 ? mine : other; | 2214 return size > 0 ? mine : other; |
| 2387 } | 2215 } |
| 2388 | 2216 |
| 2389 @Override | 2217 @Override |
| 2390 public FieldSet<ExtensionDescriptor> visitExtensions( | 2218 public FieldSet<ExtensionDescriptor> visitExtensions( |
| 2391 FieldSet<ExtensionDescriptor> mine, | 2219 FieldSet<ExtensionDescriptor> mine, |
| 2392 FieldSet<ExtensionDescriptor> other) { | 2220 FieldSet<ExtensionDescriptor> other) { |
| 2393 if (mine.isImmutable()) { | 2221 if (mine.isImmutable()) { |
| 2394 mine = mine.clone(); | 2222 mine = mine.clone(); |
| 2395 } | 2223 } |
| 2396 mine.mergeFrom(other); | 2224 mine.mergeFrom(other); |
| 2397 return mine; | 2225 return mine; |
| 2398 } | 2226 } |
| 2399 | 2227 |
| 2400 @Override | 2228 @Override |
| 2401 public UnknownFieldSetLite visitUnknownFields( | 2229 public UnknownFieldSetLite visitUnknownFields( |
| 2402 UnknownFieldSetLite mine, | 2230 UnknownFieldSetLite mine, |
| 2403 UnknownFieldSetLite other) { | 2231 UnknownFieldSetLite other) { |
| 2404 return other == UnknownFieldSetLite.getDefaultInstance() | 2232 return other == UnknownFieldSetLite.getDefaultInstance() |
| 2405 ? mine : UnknownFieldSetLite.mutableCopyOf(mine, other); | 2233 ? mine : UnknownFieldSetLite.mutableCopyOf(mine, other); |
| 2406 } | 2234 } |
| 2407 | 2235 |
| 2408 @Override | 2236 @Override |
| 2409 public <K, V> MapFieldLite<K, V> visitMap(MapFieldLite<K, V> mine, MapFieldL
ite<K, V> other) { | 2237 public <K, V> MapFieldLite<K, V> visitMap(MapFieldLite<K, V> mine, MapFieldL
ite<K, V> other) { |
| 2410 if (!other.isEmpty()) { | 2238 mine.mergeFrom(other); |
| 2411 if (!mine.isMutable()) { | |
| 2412 mine = mine.mutableCopy(); | |
| 2413 } | |
| 2414 mine.mergeFrom(other); | |
| 2415 } | |
| 2416 return mine; | 2239 return mine; |
| 2417 } | 2240 } |
| 2418 } | 2241 } |
| 2419 } | 2242 } |
| OLD | NEW |