Source File
discard.go
Belonging Package
github.com/golang/protobuf/proto
// Copyright 2019 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package protoimport ()// DiscardUnknown recursively discards all unknown fields from this message// and all embedded messages.//// When unmarshaling a message with unrecognized fields, the tags and values// of such fields are preserved in the Message. This allows a later call to// marshal to be able to produce a message that continues to have those// unrecognized fields. To avoid this, DiscardUnknown is used to// explicitly clear the unknown fields after unmarshaling.func ( Message) {if != nil {discardUnknown(MessageReflect())}}func discardUnknown( protoreflect.Message) {.Range(func( protoreflect.FieldDescriptor, protoreflect.Value) bool {switch {// Handle singular message.case .Cardinality() != protoreflect.Repeated:if .Message() != nil {(.Get().Message())}// Handle list of messages.case .IsList():if .Message() != nil {:= .Get().List()for := 0; < .Len(); ++ {(.Get().Message())}}// Handle map of messages.case .IsMap():if .MapValue().Message() != nil {:= .Get().Map().Range(func( protoreflect.MapKey, protoreflect.Value) bool {(.Message())return true})}}return true})// Discard unknown fields.if len(.GetUnknown()) > 0 {.SetUnknown(nil)}}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |