code: def EnumDecoder(
      field_number, is_repeated, is_packed, key, new_default
  ):
      enum_type = key.enum_type
      if is_packed:
          local_DecodeVarint = _DecodeVarint
  
          def DecodePackedField(buffer, pos, end, message, field_dict):
              value = field_dict.get(key)
              if value is None:
                  value = field_dict.setdefault(
                      key, new_default(message)
                  )
              (endpoint, pos) = local_DecodeVarint(buffer, pos)
              endpoint += pos
              if endpoint > end:
                  raise _DecodeError("Truncated message.")
              while pos < endpoint:
                  value_start_pos = pos
                  (element, pos) = _DecodeSignedVarint32(buffer, pos)
                  if element in enum_type.values_by_number:
                      value.append(element)
                  else:
                      if not message._unknown_fields:
                          message._unknown_fields = []
                      tag_bytes = encoder.TagBytes(
                          field_number, wire_format.WIRETYPE_VARINT
                      )
                      message._unknown_fields.append(
                          (tag_bytes, buffer[value_start_pos:pos])
                      )
              if pos > endpoint:
                  if element in enum_type.values_by_number:
                      del value[-1]  # Discard corrupt value.
                  else:
                      del message._unknown_fields[-1]
                  raise _DecodeError("Packed element was truncated.")
              return pos
  
          return DecodePackedField
      elif is_repeated:
          tag_bytes = encoder.TagBytes(
              field_number, wire_format.WIRETYPE_VARINT
          )
          tag_len = len(tag_bytes)
  
          def DecodeRepeatedField(
              buffer, pos, end, message, field_dict
          ):
              value = field_dict.get(key)
              if value is None:
                  value = field_dict.setdefault(
                      key, new_default(message)
                  )
              while 1:
                  (element, new_pos) = _DecodeSignedVarint32(
                      buffer, pos
                  )
                  if element in enum_type.values_by_number:
                      value.append(element)
                  else:
                      if not message._unknown_fields:
                          message._unknown_fields = []
                      message._unknown_fields.append(
                          (tag_bytes, buffer[pos:new_pos])
                      )
                  # Predict that the next tag is another copy of the same repeated
                  # field.
                  pos = new_pos + tag_len
                  if buffer[new_pos:pos] != tag_bytes or new_pos >= end:
                      # Prediction failed.  Return.
                      if new_pos > end:
                          raise _DecodeError("Truncated message.")
                      return new_pos
  
          return DecodeRepeatedField
      else:
  
          def DecodeField(buffer, pos, end, message, field_dict):
              value_start_pos = pos
              (enum_value, pos) = _DecodeSignedVarint32(buffer, pos)
              if pos > end:
                  raise _DecodeError("Truncated message.")
              if enum_value in enum_type.values_by_number:
                  field_dict[key] = enum_value
              else:
                  if not message._unknown_fields:
                      message._unknown_fields = []
                  tag_bytes = encoder.TagBytes(
                      field_number, wire_format.WIRETYPE_VARINT
                  )
                  message._unknown_fields.append(
                      (tag_bytes, buffer[value_start_pos:pos])
                  )
              return pos
  
          return DecodeField
  
imports: import struct
  import six
  from google.protobuf.internal import encoder
  from google.protobuf.internal import wire_format
  from google.protobuf import message
label_desc: Use image node_id 9 for calling a global function with example usage: EnumDecoder(field_number, is_repeated, is_packed, key, new_default) and returns: DecodePackedField, pos, DecodeRepeatedField, DecodeField, pos, new_pos