blob: fd8b78660bc802c76bd141d815b9df0d097f0532 [file] [log] [blame]
Joe Tsai378c1322019-04-25 23:48:08 -07001// Copyright 2019 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style.
3// license that can be found in the LICENSE file.
4
5package proto
6
7import "google.golang.org/protobuf/reflect/protoreflect"
8
9// Reset clears every field in the message.
10func Reset(m Message) {
11 // TODO: Document memory aliasing guarantees.
12 // TODO: Add fast-path for reset?
13 resetMessage(m.ProtoReflect())
14}
15
16func resetMessage(m protoreflect.Message) {
17 m.Range(func(fd protoreflect.FieldDescriptor, _ protoreflect.Value) bool {
18 m.Clear(fd)
19 return true
20 })
21 if m.GetUnknown() != nil {
22 m.SetUnknown(nil)
23 }
24}