2021-06-23 04:52:33 -04:00
|
|
|
package protoext
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/golang/protobuf/proto"
|
|
|
|
"google.golang.org/protobuf/reflect/protoreflect"
|
|
|
|
"google.golang.org/protobuf/types/descriptorpb"
|
|
|
|
)
|
|
|
|
|
2022-01-02 10:16:23 -05:00
|
|
|
//go:generate go run github.com/v2fly/v2ray-core/v5/common/errors/errorgen
|
2021-06-23 04:52:33 -04:00
|
|
|
|
|
|
|
func GetMessageOptions(msgDesc protoreflect.MessageDescriptor) (*MessageOpt, error) {
|
|
|
|
msgOpt := msgDesc.Options().(*descriptorpb.MessageOptions)
|
2021-11-27 04:16:41 -05:00
|
|
|
msgOptRet, err := proto.GetExtension(msgOpt, E_MessageOpt)
|
|
|
|
if err != nil {
|
2021-06-23 04:52:33 -04:00
|
|
|
return nil, newError("unable to parse extension from message").Base(err)
|
|
|
|
}
|
2021-11-27 04:16:41 -05:00
|
|
|
return msgOptRet.(*MessageOpt), nil
|
2021-06-23 04:52:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetFieldOptions(fieldDesc protoreflect.FieldDescriptor) (*FieldOpt, error) {
|
|
|
|
fieldOpt := fieldDesc.Options().(*descriptorpb.FieldOptions)
|
2021-11-27 04:16:41 -05:00
|
|
|
msgOptRet, err := proto.GetExtension(fieldOpt, E_FieldOpt)
|
|
|
|
if err != nil {
|
2021-06-23 04:52:33 -04:00
|
|
|
return nil, newError("unable to parse extension from message").Base(err)
|
|
|
|
}
|
2021-11-27 04:16:41 -05:00
|
|
|
return msgOptRet.(*FieldOpt), nil
|
2021-06-23 04:52:33 -04:00
|
|
|
}
|