| 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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 // in the case that the extension registries are not the same then we might
in the future if we | 277 // in the case that the extension registries are not the same then we might
in the future if we |
| 278 // need to serialze and parse a message again. | 278 // need to serialze and parse a message again. |
| 279 if (this.value == null && other.value != null) { | 279 if (this.value == null && other.value != null) { |
| 280 setValue(mergeValueAndBytes(other.value, this.delayedBytes, this.extension
Registry)); | 280 setValue(mergeValueAndBytes(other.value, this.delayedBytes, this.extension
Registry)); |
| 281 return; | 281 return; |
| 282 } else if (this.value != null && other.value == null) { | 282 } else if (this.value != null && other.value == null) { |
| 283 setValue(mergeValueAndBytes(this.value, other.delayedBytes, other.extensio
nRegistry)); | 283 setValue(mergeValueAndBytes(this.value, other.delayedBytes, other.extensio
nRegistry)); |
| 284 return; | 284 return; |
| 285 } | 285 } |
| 286 | 286 |
| 287 // At this point we have two fully parsed messages. | 287 // At this point we have two fully parsed messages. We can't merge directly
from one to the |
| 288 setValue(this.value.toBuilder().mergeFrom(other.value).build()); | 288 // other because only generated builder code contains methods to mergeFrom a
nother parsed |
| 289 // message. We have to serialize one instance and then merge the bytes into
the other. This may |
| 290 // drop extensions from one of the messages if one of the values had an exte
nsion set on it |
| 291 // directly. |
| 292 // |
| 293 // To mitigate this we prefer serializing a message that has an extension re
gistry, and |
| 294 // therefore a chance that all extensions set on it are in that registry. |
| 295 // |
| 296 // NOTE: The check for other.extensionRegistry not being null must come firs
t because at this |
| 297 // point in time if other.extensionRegistry is not null then this.extensionR
egistry will not be |
| 298 // null either. |
| 299 if (other.extensionRegistry != null) { |
| 300 setValue(mergeValueAndBytes(this.value, other.toByteString(), other.extens
ionRegistry)); |
| 301 return; |
| 302 } else if (this.extensionRegistry != null) { |
| 303 setValue(mergeValueAndBytes(other.value, this.toByteString(), this.extensi
onRegistry)); |
| 304 return; |
| 305 } else { |
| 306 // All extensions from the other message will be dropped because we have n
o registry. |
| 307 setValue(mergeValueAndBytes(this.value, other.toByteString(), EMPTY_REGIST
RY)); |
| 308 return; |
| 309 } |
| 289 } | 310 } |
| 290 | 311 |
| 291 /** | 312 /** |
| 292 * Merges another instance's contents from a stream. | 313 * Merges another instance's contents from a stream. |
| 293 * | 314 * |
| 294 * <p>LazyField is not thread-safe for write access. Synchronizations are need
ed | 315 * <p>LazyField is not thread-safe for write access. Synchronizations are need
ed |
| 295 * under read/write situations. | 316 * under read/write situations. |
| 296 */ | 317 */ |
| 297 public void mergeFrom(CodedInputStream input, ExtensionRegistryLite extensionR
egistry) | 318 public void mergeFrom(CodedInputStream input, ExtensionRegistryLite extensionR
egistry) |
| 298 throws IOException { | 319 throws IOException { |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 | 449 |
| 429 private static void checkArguments(ExtensionRegistryLite extensionRegistry, By
teString bytes) { | 450 private static void checkArguments(ExtensionRegistryLite extensionRegistry, By
teString bytes) { |
| 430 if (extensionRegistry == null) { | 451 if (extensionRegistry == null) { |
| 431 throw new NullPointerException("found null ExtensionRegistry"); | 452 throw new NullPointerException("found null ExtensionRegistry"); |
| 432 } | 453 } |
| 433 if (bytes == null) { | 454 if (bytes == null) { |
| 434 throw new NullPointerException("found null ByteString"); | 455 throw new NullPointerException("found null ByteString"); |
| 435 } | 456 } |
| 436 } | 457 } |
| 437 } | 458 } |
| OLD | NEW |