func (d decoder) unmarshalFields(m pref.Message, skipTypeURL bool) error {
	messageDesc := m.Descriptor()
	if !flags.ProtoLegacy && messageset.IsMessageSet(messageDesc) {
		return errors.New("no support for proto1 MessageSets")
	}

	var seenNums set.Ints
	var seenOneofs set.Ints
	fieldDescs := messageDesc.Fields()
	for {
		// Read field name.
		tok, err := d.Read()
		if err != nil {
			return err
		}
		switch tok.Kind() {
		default:
			return d.unexpectedTokenError(tok)
		case json.ObjectClose:
			return nil
		case json.Name:
			// Continue below.
		}

		name := tok.Name()
		// Unmarshaling a non-custom embedded message in Any will contain the
		// JSON field "@type" which should be skipped because it is not a field
		// of the embedded message, but simply an artifact of the Any format.
		if skipTypeURL && name == "@type" {
			d.Read()
			continue
		}

		// Get the FieldDescriptor.
		var fd pref.FieldDescriptor
		if strings.HasPrefix(name, "[") && strings.HasSuffix(name, "]") {
			// Only extension names are in [name] format.
			extName := pref.FullName(name[1 : len(name)-1])
			extType, err := d.findExtension(extName)
			if err != nil && err != protoregistry.NotFound {
				return d.newError(tok.Pos(), "unable to resolve %s: %v", tok.RawString(), err)
			}
			if extType != nil {
				fd = extType.TypeDescriptor()
				if !messageDesc.ExtensionRanges().Has(fd.Number()) || fd.ContainingMessage().FullName() != messageDesc.FullName() {
					return d.newError(tok.Pos(), "message %v cannot be extended by %v", messageDesc.FullName(), fd.FullName())
				}
			}
		} else {
			// The name can either be the JSON name or the proto field name.
			fd = fieldDescs.ByJSONName(name)
			if fd == nil {
				fd = fieldDescs.ByName(pref.Name(name))
				if fd == nil {
					// The proto name of a group field is in all lowercase,
					// while the textual field name is the group message name.
					gd := fieldDescs.ByName(pref.Name(strings.ToLower(name)))
					if gd != nil && gd.Kind() == pref.GroupKind && gd.Message().Name() == pref.Name(name) {
						fd = gd
					}
				} else if fd.Kind() == pref.GroupKind && fd.Message().Name() != pref.Name(name) {
					fd = nil // reset since field name is actually the message name
				}
			}
		}
		if flags.ProtoLegacy {
			if fd != nil && fd.IsWeak() && fd.Message().IsPlaceholder() {
				fd = nil // reset since the weak reference is not linked in
			}
		}

		if fd == nil {
			// Field is unknown.
			if d.opts.DiscardUnknown {
				if err := d.skipJSONValue(); err != nil {
					return err
				}
				continue
			}
			return d.newError(tok.Pos(), "unknown field %v", tok.RawString())
		}

		// Do not allow duplicate fields.
		num := uint64(fd.Number())
		if seenNums.Has(num) {
			return d.newError(tok.Pos(), "duplicate field %v", tok.RawString())
		}
		seenNums.Set(num)

		// No need to set values for JSON null unless the field type is
		// google.protobuf.Value or google.protobuf.NullValue.
		if tok, _ := d.Peek(); tok.Kind() == json.Null && !isKnownValue(fd) && !isNullValue(fd) {
			d.Read()
			continue
		}

		switch {
		case fd.IsList():
			list := m.Mutable(fd).List()
			if err := d.unmarshalList(list, fd); err != nil {
				return err
			}
		case fd.IsMap():
			mmap := m.Mutable(fd).Map()
			if err := d.unmarshalMap(mmap, fd); err != nil {
				return err
			}
		default:
			// If field is a oneof, check if it has already been set.
			if od := fd.ContainingOneof(); od != nil {
				idx := uint64(od.Index())
				if seenOneofs.Has(idx) {
					return d.newError(tok.Pos(), "error parsing %s, oneof %v is already set", tok.RawString(), od.FullName())
				}
				seenOneofs.Set(idx)
			}

			// Required or optional fields.
			if err := d.unmarshalSingular(m, fd); err != nil {
				return err
			}
		}
	}
}
// unmarshalFields unmarshals the fields into the given protoreflect.Message.
unmarshalFields unmarshals the fields into the given protoreflect.Message.
// unmarshalFields unmarshals the fields into the given protoreflect . Message .
func (d decoder) unmarshalFields(m pref.Message, skipTypeURL bool) error {
	messageDesc := m.Descriptor()
	if !flags.ProtoLegacy && messageset.IsMessageSet(messageDesc) {
		return errors.New("no support for proto1 MessageSets")
	}
	var seenNums set.Ints
	var seenOneofs set.Ints
	fieldDescs := messageDesc.Fields()
	for {
		tok, err := d.Read()
		if err != nil {
			return err
		}
		switch tok.Kind() {
		default:
			return d.unexpectedTokenError(tok)
		case json.ObjectClose:
			return nil
		case json.Name:
		}
		name := tok.Name()
		if skipTypeURL && name == "@type" {
			d.Read()
			continue
		}
		var fd pref.FieldDescriptor
		if strings.HasPrefix(name, "[") && strings.HasSuffix(name, "]") {
			extName := pref.FullName(name[1 : len(name)-1])
			extType, err := d.findExtension(extName)
			if err != nil && err != protoregistry.NotFound {
				return d.newError(tok.Pos(), "unable to resolve %s: %v", tok.RawString(), err)
			}
			if extType != nil {
				fd = extType.TypeDescriptor()
				if !messageDesc.ExtensionRanges().Has(fd.Number()) || fd.ContainingMessage().FullName() != messageDesc.FullName() {
					return d.newError(tok.Pos(), "message %v cannot be extended by %v", messageDesc.FullName(), fd.FullName())
				}
			}
		} else {
			fd = fieldDescs.ByJSONName(name)
			if fd == nil {
				fd = fieldDescs.ByName(pref.Name(name))
				if fd == nil {
					gd := fieldDescs.ByName(pref.Name(strings.ToLower(name)))
					if gd != nil && gd.Kind() == pref.GroupKind && gd.Message().Name() == pref.Name(name) {
						fd = gd
					}
				} else if fd.Kind() == pref.GroupKind && fd.Message().Name() != pref.Name(name) {
					fd = nil 
				}
			}
		}
		if flags.ProtoLegacy {
			if fd != nil && fd.IsWeak() && fd.Message().IsPlaceholder() {
				fd = nil 
			}
		}
		if fd == nil {
			if d.opts.DiscardUnknown {
				if err := d.skipJSONValue(); err != nil {
					return err
				}
				continue
			}
			return d.newError(tok.Pos(), "unknown field %v", tok.RawString())
		}
		num := uint64(fd.Number())
		if seenNums.Has(num) {
			return d.newError(tok.Pos(), "duplicate field %v", tok.RawString())
		}
		seenNums.Set(num)
		if tok, _ := d.Peek(); tok.Kind() == json.Null && !isKnownValue(fd) && !isNullValue(fd) {
			d.Read()
			continue
		}
		switch {
		case fd.IsList():
			list := m.Mutable(fd).List()
			if err := d.unmarshalList(list, fd); err != nil {
				return err
			}
		case fd.IsMap():
			mmap := m.Mutable(fd).Map()
			if err := d.unmarshalMap(mmap, fd); err != nil {
				return err
			}
		default:
			if od := fd.ContainingOneof(); od != nil {
				idx := uint64(od.Index())
				if seenOneofs.Has(idx) {
					return d.newError(tok.Pos(), "error parsing %s, oneof %v is already set", tok.RawString(), od.FullName())
				}
				seenOneofs.Set(idx)
			}
			if err := d.unmarshalSingular(m, fd); err != nil {
				return err
			}
		}
	}
}
func ( d decoder ) unmarshalFields ( m pref . Message , skipTypeURL bool ) error { messageDesc := m . Descriptor ( ) if ! flags . ProtoLegacy && messageset . IsMessageSet ( messageDesc ) { return errors . New ( " " ) } var seenNums set . Ints var seenOneofs set . Ints fieldDescs := messageDesc . Fields ( ) for { tok , err := d . Read ( ) if err != nil { return err } switch tok . Kind ( ) { default : return d . unexpectedTokenError ( tok ) case json . ObjectClose : return nil case json . Name : } name := tok . Name ( ) if skipTypeURL && name == " " { d . Read ( ) continue } var fd pref . FieldDescriptor if strings . HasPrefix ( name , " " ) && strings . HasSuffix ( name , " " ) { extName := pref . FullName ( name [ 1 : len ( name ) - 1 ] ) extType , err := d . findExtension ( extName ) if err != nil && err != protoregistry . NotFound { return d . newError ( tok . Pos ( ) , " " , tok . RawString ( ) , err ) } if extType != nil { fd = extType . TypeDescriptor ( ) if ! messageDesc . ExtensionRanges ( ) . Has ( fd . Number ( ) ) || fd . ContainingMessage ( ) . FullName ( ) != messageDesc . FullName ( ) { return d . newError ( tok . Pos ( ) , " " , messageDesc . FullName ( ) , fd . FullName ( ) ) } } } else { fd = fieldDescs . ByJSONName ( name ) if fd == nil { fd = fieldDescs . ByName ( pref . Name ( name ) ) if fd == nil { gd := fieldDescs . ByName ( pref . Name ( strings . ToLower ( name ) ) ) if gd != nil && gd . Kind ( ) == pref . GroupKind && gd . Message ( ) . Name ( ) == pref . Name ( name ) { fd = gd } } else if fd . Kind ( ) == pref . GroupKind && fd . Message ( ) . Name ( ) != pref . Name ( name ) { fd = nil } } } if flags . ProtoLegacy { if fd != nil && fd . IsWeak ( ) && fd . Message ( ) . IsPlaceholder ( ) { fd = nil } } if fd == nil { if d . opts . DiscardUnknown { if err := d . skipJSONValue ( ) ; err != nil { return err } continue } return d . newError ( tok . Pos ( ) , " " , tok . RawString ( ) ) } num := uint64 ( fd . Number ( ) ) if seenNums . Has ( num ) { return d . newError ( tok . Pos ( ) , " " , tok . RawString ( ) ) } seenNums . Set ( num ) if tok , _ := d . Peek ( ) ; tok . Kind ( ) == json . Null && ! isKnownValue ( fd ) && ! isNullValue ( fd ) { d . Read ( ) continue } switch { case fd . IsList ( ) : list := m . Mutable ( fd ) . List ( ) if err := d . unmarshalList ( list , fd ) ; err != nil { return err } case fd . IsMap ( ) : mmap := m . Mutable ( fd ) . Map ( ) if err := d . unmarshalMap ( mmap , fd ) ; err != nil { return err } default : if od := fd . ContainingOneof ( ) ; od != nil { idx := uint64 ( od . Index ( ) ) if seenOneofs . Has ( idx ) { return d . newError ( tok . Pos ( ) , " " , tok . RawString ( ) , od . FullName ( ) ) } seenOneofs . Set ( idx ) } if err := d . unmarshalSingular ( m , fd ) ; err != nil { return err } } } }
unmarshalFields unmarshals the fields into the given protoreflect.Message.
unmarshalFields unmarshals the fields into the given protoreflect . Message .
// Read field name. // Continue below. // Unmarshaling a non-custom embedded message in Any will contain the // JSON field "@type" which should be skipped because it is not a field // of the embedded message, but simply an artifact of the Any format. // Get the FieldDescriptor. // Only extension names are in [name] format. // The name can either be the JSON name or the proto field name. // The proto name of a group field is in all lowercase, // while the textual field name is the group message name. // reset since field name is actually the message name // reset since the weak reference is not linked in // Field is unknown. // Do not allow duplicate fields. // No need to set values for JSON null unless the field type is // google.protobuf.Value or google.protobuf.NullValue. // If field is a oneof, check if it has already been set. // Required or optional fields.