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 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 # an end-group tag. | 635 # an end-group tag. |
636 raise _DecodeError('Unexpected end-group tag.') | 636 raise _DecodeError('Unexpected end-group tag.') |
637 return new_pos | 637 return new_pos |
638 return DecodeField | 638 return DecodeField |
639 | 639 |
640 | 640 |
641 # -------------------------------------------------------------------- | 641 # -------------------------------------------------------------------- |
642 | 642 |
643 MESSAGE_SET_ITEM_TAG = encoder.TagBytes(1, wire_format.WIRETYPE_START_GROUP) | 643 MESSAGE_SET_ITEM_TAG = encoder.TagBytes(1, wire_format.WIRETYPE_START_GROUP) |
644 | 644 |
645 def MessageSetItemDecoder(descriptor): | 645 def MessageSetItemDecoder(extensions_by_number): |
646 """Returns a decoder for a MessageSet item. | 646 """Returns a decoder for a MessageSet item. |
647 | 647 |
648 The parameter is the message Descriptor. | 648 The parameter is the _extensions_by_number map for the message class. |
649 | 649 |
650 The message set message looks like this: | 650 The message set message looks like this: |
651 message MessageSet { | 651 message MessageSet { |
652 repeated group Item = 1 { | 652 repeated group Item = 1 { |
653 required int32 type_id = 2; | 653 required int32 type_id = 2; |
654 required string message = 3; | 654 required string message = 3; |
655 } | 655 } |
656 } | 656 } |
657 """ | 657 """ |
658 | 658 |
(...skipping 28 matching lines...) Expand all Loading... |
687 raise _DecodeError('Missing group end tag.') | 687 raise _DecodeError('Missing group end tag.') |
688 | 688 |
689 if pos > end: | 689 if pos > end: |
690 raise _DecodeError('Truncated message.') | 690 raise _DecodeError('Truncated message.') |
691 | 691 |
692 if type_id == -1: | 692 if type_id == -1: |
693 raise _DecodeError('MessageSet item missing type_id.') | 693 raise _DecodeError('MessageSet item missing type_id.') |
694 if message_start == -1: | 694 if message_start == -1: |
695 raise _DecodeError('MessageSet item missing message.') | 695 raise _DecodeError('MessageSet item missing message.') |
696 | 696 |
697 extension = message.Extensions._FindExtensionByNumber(type_id) | 697 extension = extensions_by_number.get(type_id) |
698 if extension is not None: | 698 if extension is not None: |
699 value = field_dict.get(extension) | 699 value = field_dict.get(extension) |
700 if value is None: | 700 if value is None: |
701 value = field_dict.setdefault( | 701 value = field_dict.setdefault( |
702 extension, extension.message_type._concrete_class()) | 702 extension, extension.message_type._concrete_class()) |
703 if value._InternalParse(buffer, message_start,message_end) != message_end: | 703 if value._InternalParse(buffer, message_start,message_end) != message_end: |
704 # The only reason _InternalParse would return early is if it encountered | 704 # The only reason _InternalParse would return early is if it encountered |
705 # an end-group tag. | 705 # an end-group tag. |
706 raise _DecodeError('Unexpected end-group tag.') | 706 raise _DecodeError('Unexpected end-group tag.') |
707 else: | 707 else: |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 tag (in which case the calling loop should break). | 845 tag (in which case the calling loop should break). |
846 """ | 846 """ |
847 | 847 |
848 # The wire type is always in the first byte since varints are little-endian. | 848 # The wire type is always in the first byte since varints are little-endian. |
849 wire_type = ord(tag_bytes[0:1]) & wiretype_mask | 849 wire_type = ord(tag_bytes[0:1]) & wiretype_mask |
850 return WIRETYPE_TO_SKIPPER[wire_type](buffer, pos, end) | 850 return WIRETYPE_TO_SKIPPER[wire_type](buffer, pos, end) |
851 | 851 |
852 return SkipField | 852 return SkipField |
853 | 853 |
854 SkipField = _FieldSkipper() | 854 SkipField = _FieldSkipper() |
OLD | NEW |