I keep responding privately to people by accident. (I’ve been out of
mailing lists too long.)

1. There is not a way to dynamically enumerate the fields that form a
`oneof`. The utility of doing such a thing would have _very_ narrow utility
in general, and explaining why might be possible, but I think it would be
hard.

2. In the private message I sent, I directed you to
https://github.com/golang/protobuf/issues/1326 this issue has been fully
and thoroughly hashed out there. The overly short answer is that we were
against exposing the interface for a long time for Semantics reasons, and
now that the Opaque API is going to do away with the interface type
entirely, we will definitely not be exposing the interface type in the
future.

Am Do., 3. Juli 2025 um 11:20 Uhr schrieb X Dev <[email protected]>:

>
> Hi @Scott. Thanks for the reply
>
> 1.
> I was interested not in the type it self. Instead how to enumerate all the
> underlying types that are implementing related `oneOf` interface. And how
> to make it in general in runtime without static knowledge of that types.
> E.g.
> ```
> func ResolveUnderlyingInterfaceImplementations(interfaceType reflect.Type)
> []reflect.Type {
> }
> ```
>
> 2.
> * I understand this would not in help for the case solution still for the
> general understanding: What exactly does it violate. Do you mean leak of
> abstraction and backward capabilities?
> * Could you get an example of workarounds you mentioned. Type switch is a
> static definition approach. How might it help for enumerating types in
> runtime.
> * What is custom interfaces. Is it about just to redeclare the very same
> interfaces in the client code base
>
> Any way importing from proto compiled package some type as
> ```
> type SomeMessage struct {
>    SomeField isPrivateOneOfInterface
> }
> ```
>
> how may one defined a function returning related value or a variable for
> intermediate storage as
> ```
> var someFieldValue: protos.isPrivateOneOfInterface
>
> func ComposeSomeField() isPrivateOneOfInterface {
> }
> ```
> Could you please clarify the idea behind your workarounds
>
> Thank you
> четвер, 3 липня 2025 р. о 11:20:51 UTC+3 scott beeker пише:
>
>> Use reflect.TypeOf() to get the concrete type of a oneOf interface value.
>>
>> Package-Private Interface:
>>
>>
>>    - Exposing it could be useful for function composition but risks
>>    violating the protobuf contract.
>>
>>
>>    - Workarounds like type switches or custom interfaces can achieve
>>    similar goals without breaking encapsulation.
>>
>>
>> On Wednesday, July 2, 2025 at 9:28:45 AM UTC-7 X Dev wrote:
>>
>>> Hi guys
>>>
>>>
>>> Please, in `golang` having a oneOf field how at runtime to enumerate
>>> the types that fits the target interface (e.g. reflection)?
>>>
>>>
>>> And a sibling question why actually the interface generated for the
>>> oneOf purpose is a package private. It is really logically not to
>>> expose the interface content it self to restrict the types as described in
>>> a proto.
>>> Still the interface it self would be useful for e.g. to define a
>>> function that composes related result.
>>>
>>>
>>> Thank you
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion visit
> https://groups.google.com/d/msgid/protobuf/884ecf50-981b-4c58-94c6-3ecfd4856a38n%40googlegroups.com
> <https://groups.google.com/d/msgid/protobuf/884ecf50-981b-4c58-94c6-3ecfd4856a38n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/protobuf/CAOF_i%2BVrPSRTWBKQ%3D_WG08aRaz%3DQAVh0kBB%3DVwQofxBVAf0afQ%40mail.gmail.com.

Reply via email to