Source File
properties.go
Belonging Package
github.com/golang/protobuf/proto
package proto
import (
)
Prop []*Properties
OneofTypes map[string]*OneofProperties
}
Prop *Properties
}
func ( *Properties) () string {
:= .Wire
+= "," + strconv.Itoa(.Tag)
if .Required {
+= ",req"
}
if .Optional {
+= ",opt"
}
if .Repeated {
+= ",rep"
}
if .Packed {
+= ",packed"
}
+= ",name=" + .OrigName
if .JSONName != "" {
+= ",json=" + .JSONName
}
if len(.Enum) > 0 {
+= ",enum=" + .Enum
}
if len(.Weak) > 0 {
+= ",weak=" + .Weak
}
if .Proto3 {
+= ",proto3"
}
if .Oneof {
+= ",oneof"
}
if .HasDefault {
+= ",def=" + .Default
}
return
}
for len() > 0 {
:= strings.IndexByte(, ',')
if < 0 {
= len()
}
switch := [:]; {
case strings.HasPrefix(, "name="):
.OrigName = [len("name="):]
case strings.HasPrefix(, "json="):
.JSONName = [len("json="):]
case strings.HasPrefix(, "enum="):
.Enum = [len("enum="):]
case strings.HasPrefix(, "weak="):
.Weak = [len("weak="):]
case strings.Trim(, "0123456789") == "":
, := strconv.ParseUint(, 10, 32)
.Tag = int()
case == "opt":
.Optional = true
case == "req":
.Required = true
case == "rep":
.Repeated = true
case == "varint" || == "zigzag32" || == "zigzag64":
.Wire =
.WireType = WireVarint
case == "fixed32":
.Wire =
.WireType = WireFixed32
case == "fixed64":
.Wire =
.WireType = WireFixed64
case == "bytes":
.Wire =
.WireType = WireBytes
case == "group":
.Wire =
.WireType = WireStartGroup
case == "packed":
.Packed = true
case == "proto3":
.Proto3 = true
case == "oneof":
.Oneof = true
.HasDefault = true
.Default, = [len("def="):], len()
}
= strings.TrimPrefix([:], ",")
}
}
func ( *Properties) ( reflect.Type, , string, *reflect.StructField) {
.Name =
.OrigName =
if == "" {
return
}
.Parse()
if != nil && .Kind() == reflect.Map {
.MapKeyProp = new(Properties)
.MapKeyProp.(nil, "Key", .Tag.Get("protobuf_key"), nil)
.MapValProp = new(Properties)
.MapValProp.(nil, "Value", .Tag.Get("protobuf_val"), nil)
}
}
var propertiesCache sync.Map // map[reflect.Type]*StructProperties
func ( reflect.Type) *StructProperties {
if , := propertiesCache.Load(); {
return .(*StructProperties)
}
, := propertiesCache.LoadOrStore(, newProperties())
return .(*StructProperties)
}
func ( reflect.Type) *StructProperties {
if .Kind() != reflect.Struct {
panic(fmt.Sprintf("%v is not a generated message in the open-struct API", ))
}
var bool
:= new(StructProperties)
if {
var []interface{}
if , := reflect.PtrTo().MethodByName("XXX_OneofFuncs"); {
= .Func.Call([]reflect.Value{reflect.Zero(.Type.In(0))})[3].Interface().([]interface{})
}
if , := reflect.PtrTo().MethodByName("XXX_OneofWrappers"); {
= .Func.Call([]reflect.Value{reflect.Zero(.Type.In(0))})[0].Interface().([]interface{})
}
if , := reflect.Zero(reflect.PtrTo()).Interface().(protoreflect.ProtoMessage); {
if , := .ProtoReflect().(interface{ () *protoimpl.MessageInfo }); {
= .().OneofWrappers
}
}
.OneofTypes = make(map[string]*OneofProperties)
for , := range {
:= &OneofProperties{
Type: reflect.ValueOf().Type(), // *T
Prop: new(Properties),
}
:= .Type.Elem().Field(0)
.Prop.Name = .Name
.Prop.Parse(.Tag.Get("protobuf"))
var bool
for := 0; < .NumField() && !; ++ {
if .Type.AssignableTo(.Field().Type) {
.Field =
= true
}
}
if ! {
panic(fmt.Sprintf("%v is not a generated message in the open-struct API", ))
}
.OneofTypes[.Prop.OrigName] =
}
}
return
}
func ( *StructProperties) () int { return len(.Prop) }
func ( *StructProperties) (, int) bool { return false }
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin 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 @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |