github.com/imannamdari/v2ray-core/v5@v5.0.5/common/protoext/extensions.go (about) 1 package protoext 2 3 import ( 4 "github.com/golang/protobuf/proto" 5 "google.golang.org/protobuf/reflect/protoreflect" 6 "google.golang.org/protobuf/types/descriptorpb" 7 ) 8 9 //go:generate go run github.com/imannamdari/v2ray-core/v5/common/errors/errorgen 10 11 func GetMessageOptions(msgDesc protoreflect.MessageDescriptor) (*MessageOpt, error) { 12 msgOpt := msgDesc.Options().(*descriptorpb.MessageOptions) 13 msgOptRet, err := proto.GetExtension(msgOpt, E_MessageOpt) 14 if err != nil { 15 return nil, newError("unable to parse extension from message").Base(err) 16 } 17 return msgOptRet.(*MessageOpt), nil 18 } 19 20 func GetFieldOptions(fieldDesc protoreflect.FieldDescriptor) (*FieldOpt, error) { 21 fieldOpt := fieldDesc.Options().(*descriptorpb.FieldOptions) 22 msgOptRet, err := proto.GetExtension(fieldOpt, E_FieldOpt) 23 if err != nil { 24 return nil, newError("unable to parse extension from message").Base(err) 25 } 26 return msgOptRet.(*FieldOpt), nil 27 }