Commit e5ffd4a
authored
Make constraint resolution more flexible to different concrete extension types (#57)
The go proto library struggles to resolve values for extensions if the
concrete type associated with the generated source code on hand does not
match that on the descriptor of the message in question (which happens
in cases where the descriptor or message is produced at runtime). This
manifested in the protovalidate resolver where the extension could not
be found on options attached to a descriptor produced dynamically.
Unfortunately, I struggled to find a way to get the extension and its
value directly. (I'm not even sure how to get the field/ext descriptor
from the descriptor; `protoreflect.Fields.ByNumber` doesn't work). The
most straightforward solution from a few iterations was to leverage
`proto.RangeExtensions`.
There's room here for some mild optimization to short circuit in most
vanilla situations but it makes it a bit less readable. Since this only
happens once per descriptor, the optimization is overkill IMO.1 parent ce1cbad commit e5ffd4a
1 file changed
+13
-28
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | 23 | | |
25 | 24 | | |
26 | 25 | | |
| |||
70 | 69 | | |
71 | 70 | | |
72 | 71 | | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
80 | 77 | | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
87 | 81 | | |
88 | | - | |
89 | | - | |
90 | | - | |
| 82 | + | |
91 | 83 | | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
| 84 | + | |
103 | 85 | | |
104 | 86 | | |
105 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
106 | 91 | | |
107 | 92 | | |
108 | 93 | | |
| |||
0 commit comments