mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-01-04 02:38:50 +00:00
fb3ff727f0
This CL makes no feature changes except to move code around. The only change to the actual generated code is the placement of the default constants and variables. They move because the new logic generates all methods together, while previously the constants were interspersed in-between. Change-Id: I45932d5aeec5ba45180fb255ea17898beb6c3bd2 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/186878 Reviewed-by: Herbie Ong <herbie@google.com>
36 lines
771 B
Go
36 lines
771 B
Go
// 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 internal_gengo
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"google.golang.org/protobuf/compiler/protogen"
|
|
)
|
|
|
|
// messageAPIFlags provides flags that control the generated API.
|
|
type messageAPIFlags struct {
|
|
WeakMapField bool
|
|
}
|
|
|
|
var messageAPIFlagsCache sync.Map
|
|
|
|
func loadMessageAPIFlags(message *protogen.Message) messageAPIFlags {
|
|
if flags, ok := messageAPIFlagsCache.Load(message); ok {
|
|
return flags.(messageAPIFlags)
|
|
}
|
|
|
|
var flags messageAPIFlags
|
|
for _, field := range message.Fields {
|
|
if field.Desc.IsWeak() {
|
|
flags.WeakMapField = true
|
|
break
|
|
}
|
|
}
|
|
|
|
messageAPIFlagsCache.Store(message, flags)
|
|
return flags
|
|
}
|