go-bot

Форк
0
43 строки · 1018.0 Байт
1
// 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

5
package proto
6

7
import (
8
	"fmt"
9

10
	"google.golang.org/protobuf/reflect/protoreflect"
11
)
12

13
// Reset clears every field in the message.
14
// The resulting message shares no observable memory with its previous state
15
// other than the memory for the message itself.
16
func Reset(m Message) {
17
	if mr, ok := m.(interface{ Reset() }); ok && hasProtoMethods {
18
		mr.Reset()
19
		return
20
	}
21
	resetMessage(m.ProtoReflect())
22
}
23

24
func resetMessage(m protoreflect.Message) {
25
	if !m.IsValid() {
26
		panic(fmt.Sprintf("cannot reset invalid %v message", m.Descriptor().FullName()))
27
	}
28

29
	// Clear all known fields.
30
	fds := m.Descriptor().Fields()
31
	for i := 0; i < fds.Len(); i++ {
32
		m.Clear(fds.Get(i))
33
	}
34

35
	// Clear extension fields.
36
	m.Range(func(fd protoreflect.FieldDescriptor, _ protoreflect.Value) bool {
37
		m.Clear(fd)
38
		return true
39
	})
40

41
	// Clear unknown fields.
42
	m.SetUnknown(nil)
43
}
44

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.