Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
rodaine committed Oct 2, 2023
1 parent ce1cbad commit 230dafa
Showing 1 changed file with 13 additions and 28 deletions.
41 changes: 13 additions & 28 deletions internal/evaluator/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go/buf/validate"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoregistry"
"google.golang.org/protobuf/runtime/protoimpl"
)

Expand Down Expand Up @@ -70,39 +69,25 @@ func resolveExt[D protoreflect.Descriptor, C proto.Message](
desc D,
extType protoreflect.ExtensionType,
) (constraints C) {
opts := desc.Options().ProtoReflect()
fDesc := extType.TypeDescriptor()

if opts.Has(fDesc) {
msg := opts.Get(fDesc).Message().Interface()
if m, ok := msg.(C); ok {
return m
num := extType.TypeDescriptor().Number()
var msg proto.Message
proto.RangeExtensions(desc.Options(), func(typ protoreflect.ExtensionType, i interface{}) bool {
if num != typ.TypeDescriptor().Number() {
return true
}
}

unknown := opts.GetUnknown()
if len(unknown) == 0 {
return constraints
}
msg, _ = i.(proto.Message)
return false
})

opts = opts.Type().New()
var resolver protoregistry.Types
if err := resolver.RegisterExtension(extType); err != nil {
if msg == nil {
return constraints
}
_ = proto.UnmarshalOptions{Resolver: &resolver}.Unmarshal(unknown, opts.Interface())

if opts.Has(fDesc) {
msg := opts.Get(fDesc).Message().Interface()
if m, ok := msg.(C); ok {
return m
}
}
msg := opts.Get(fDesc).Message().Interface()
if m, ok := msg.(C); ok {
} else if m, ok := msg.(C); ok {
return m
}

constraints = constraints.ProtoReflect().New().Interface().(C)

Check failure on line 88 in internal/evaluator/resolver.go

View workflow job for this annotation

GitHub Actions / Go (stable)

Error return value is not checked (errcheck)
b, _ := proto.Marshal(msg)
_ = proto.Unmarshal(b, constraints)
return constraints
}

Expand Down

0 comments on commit 230dafa

Please sign in to comment.