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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 * prototype directly. | 357 * prototype directly. |
358 */ | 358 */ |
359 MergeTarget newMergeTargetForField( | 359 MergeTarget newMergeTargetForField( |
360 Descriptors.FieldDescriptor descriptor, | 360 Descriptors.FieldDescriptor descriptor, |
361 Message defaultInstance); | 361 Message defaultInstance); |
362 | 362 |
363 /** | 363 /** |
364 * Finishes the merge and returns the underlying object. | 364 * Finishes the merge and returns the underlying object. |
365 */ | 365 */ |
366 Object finish(); | 366 Object finish(); |
| 367 |
367 } | 368 } |
368 | 369 |
369 static class BuilderAdapter implements MergeTarget { | 370 static class BuilderAdapter implements MergeTarget { |
370 | 371 |
371 private final Message.Builder builder; | 372 private final Message.Builder builder; |
372 | 373 |
373 @Override | 374 @Override |
374 public Descriptors.Descriptor getDescriptorForType() { | 375 public Descriptors.Descriptor getDescriptorForType() { |
375 return builder.getDescriptorForType(); | 376 return builder.getDescriptorForType(); |
376 } | 377 } |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 && builder instanceof GeneratedMessage.Builder) { | 542 && builder instanceof GeneratedMessage.Builder) { |
542 return WireFormat.Utf8Validation.LAZY; | 543 return WireFormat.Utf8Validation.LAZY; |
543 } | 544 } |
544 return WireFormat.Utf8Validation.LOOSE; | 545 return WireFormat.Utf8Validation.LOOSE; |
545 } | 546 } |
546 | 547 |
547 @Override | 548 @Override |
548 public Object finish() { | 549 public Object finish() { |
549 return builder.buildPartial(); | 550 return builder.buildPartial(); |
550 } | 551 } |
| 552 |
551 } | 553 } |
552 | 554 |
553 | 555 |
554 static class ExtensionAdapter implements MergeTarget { | 556 static class ExtensionAdapter implements MergeTarget { |
555 | 557 |
556 private final FieldSet<Descriptors.FieldDescriptor> extensions; | 558 private final FieldSet<Descriptors.FieldDescriptor> extensions; |
557 | 559 |
558 ExtensionAdapter(FieldSet<Descriptors.FieldDescriptor> extensions) { | 560 ExtensionAdapter(FieldSet<Descriptors.FieldDescriptor> extensions) { |
559 this.extensions = extensions; | 561 this.extensions = extensions; |
560 } | 562 } |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 } | 706 } |
705 // TODO(liujisi): support lazy strings for ExtesnsionSet. | 707 // TODO(liujisi): support lazy strings for ExtesnsionSet. |
706 return WireFormat.Utf8Validation.LOOSE; | 708 return WireFormat.Utf8Validation.LOOSE; |
707 } | 709 } |
708 | 710 |
709 @Override | 711 @Override |
710 public Object finish() { | 712 public Object finish() { |
711 throw new UnsupportedOperationException( | 713 throw new UnsupportedOperationException( |
712 "finish() called on FieldSet object"); | 714 "finish() called on FieldSet object"); |
713 } | 715 } |
| 716 |
714 } | 717 } |
715 | 718 |
716 /** | 719 /** |
717 * Parses a single field into MergeTarget. The target can be Message.Builder, | 720 * Parses a single field into MergeTarget. The target can be Message.Builder, |
718 * FieldSet or MutableMessage. | 721 * FieldSet or MutableMessage. |
719 * | 722 * |
720 * Package-private because it is used by GeneratedMessage.ExtendableMessage. | 723 * Package-private because it is used by GeneratedMessage.ExtendableMessage. |
721 * | 724 * |
722 * @param tag The tag, which should have already been read. | 725 * @param tag The tag, which should have already been read. |
723 * @return {@code true} unless the tag is an end-group tag. | 726 * @return {@code true} unless the tag is an end-group tag. |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
981 CodedInputStream input, | 984 CodedInputStream input, |
982 ExtensionRegistry.ExtensionInfo extension, | 985 ExtensionRegistry.ExtensionInfo extension, |
983 ExtensionRegistryLite extensionRegistry, | 986 ExtensionRegistryLite extensionRegistry, |
984 MergeTarget target) throws IOException { | 987 MergeTarget target) throws IOException { |
985 Descriptors.FieldDescriptor field = extension.descriptor; | 988 Descriptors.FieldDescriptor field = extension.descriptor; |
986 Object value = target.parseMessage(input, extensionRegistry, field, | 989 Object value = target.parseMessage(input, extensionRegistry, field, |
987 extension.defaultInstance); | 990 extension.defaultInstance); |
988 target.setField(field, value); | 991 target.setField(field, value); |
989 } | 992 } |
990 } | 993 } |
OLD | NEW |