protobuf-go/cmd/protoc-gen-go/internal_gengo/api_flags.go
Joe Tsai fb3ff727f0 cmd/protoc-gen-go: refactor logic to be more compartmentalized
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>
2019-07-19 08:16:51 +00:00

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
}