Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(600)

Side by Side Diff: third_party/protobuf/python/google/protobuf/internal/decoder.py

Issue 21208003: Update protobuf to r428, part 1. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 # http://code.google.com/p/protobuf/ 3 # http://code.google.com/p/protobuf/
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 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 569
570 type_id_tag_bytes = encoder.TagBytes(2, wire_format.WIRETYPE_VARINT) 570 type_id_tag_bytes = encoder.TagBytes(2, wire_format.WIRETYPE_VARINT)
571 message_tag_bytes = encoder.TagBytes(3, wire_format.WIRETYPE_LENGTH_DELIMITED) 571 message_tag_bytes = encoder.TagBytes(3, wire_format.WIRETYPE_LENGTH_DELIMITED)
572 item_end_tag_bytes = encoder.TagBytes(1, wire_format.WIRETYPE_END_GROUP) 572 item_end_tag_bytes = encoder.TagBytes(1, wire_format.WIRETYPE_END_GROUP)
573 573
574 local_ReadTag = ReadTag 574 local_ReadTag = ReadTag
575 local_DecodeVarint = _DecodeVarint 575 local_DecodeVarint = _DecodeVarint
576 local_SkipField = SkipField 576 local_SkipField = SkipField
577 577
578 def DecodeItem(buffer, pos, end, message, field_dict): 578 def DecodeItem(buffer, pos, end, message, field_dict):
579 message_set_item_start = pos
579 type_id = -1 580 type_id = -1
580 message_start = -1 581 message_start = -1
581 message_end = -1 582 message_end = -1
582 583
583 # Technically, type_id and message can appear in any order, so we need 584 # Technically, type_id and message can appear in any order, so we need
584 # a little loop here. 585 # a little loop here.
585 while 1: 586 while 1:
586 (tag_bytes, pos) = local_ReadTag(buffer, pos) 587 (tag_bytes, pos) = local_ReadTag(buffer, pos)
587 if tag_bytes == type_id_tag_bytes: 588 if tag_bytes == type_id_tag_bytes:
588 (type_id, pos) = local_DecodeVarint(buffer, pos) 589 (type_id, pos) = local_DecodeVarint(buffer, pos)
(...skipping 18 matching lines...) Expand all
607 extension = extensions_by_number.get(type_id) 608 extension = extensions_by_number.get(type_id)
608 if extension is not None: 609 if extension is not None:
609 value = field_dict.get(extension) 610 value = field_dict.get(extension)
610 if value is None: 611 if value is None:
611 value = field_dict.setdefault( 612 value = field_dict.setdefault(
612 extension, extension.message_type._concrete_class()) 613 extension, extension.message_type._concrete_class())
613 if value._InternalParse(buffer, message_start,message_end) != message_end: 614 if value._InternalParse(buffer, message_start,message_end) != message_end:
614 # The only reason _InternalParse would return early is if it encountered 615 # The only reason _InternalParse would return early is if it encountered
615 # an end-group tag. 616 # an end-group tag.
616 raise _DecodeError('Unexpected end-group tag.') 617 raise _DecodeError('Unexpected end-group tag.')
618 else:
619 if not message._unknown_fields:
620 message._unknown_fields = []
621 message._unknown_fields.append((MESSAGE_SET_ITEM_TAG,
622 buffer[message_set_item_start:pos]))
617 623
618 return pos 624 return pos
619 625
620 return DecodeItem 626 return DecodeItem
621 627
622 # -------------------------------------------------------------------- 628 # --------------------------------------------------------------------
623 # Optimization is not as heavy here because calls to SkipField() are rare, 629 # Optimization is not as heavy here because calls to SkipField() are rare,
624 # except for handling end-group tags. 630 # except for handling end-group tags.
625 631
626 def _SkipVarint(buffer, pos, end): 632 def _SkipVarint(buffer, pos, end):
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 tag (in which case the calling loop should break). 711 tag (in which case the calling loop should break).
706 """ 712 """
707 713
708 # The wire type is always in the first byte since varints are little-endian. 714 # The wire type is always in the first byte since varints are little-endian.
709 wire_type = local_ord(tag_bytes[0]) & wiretype_mask 715 wire_type = local_ord(tag_bytes[0]) & wiretype_mask
710 return WIRETYPE_TO_SKIPPER[wire_type](buffer, pos, end) 716 return WIRETYPE_TO_SKIPPER[wire_type](buffer, pos, end)
711 717
712 return SkipField 718 return SkipField
713 719
714 SkipField = _FieldSkipper() 720 SkipField = _FieldSkipper()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698