Support Fetching Protobuf Field Names
jeffutter opened this issue · comments
I was wondering if there is any way to get the field names when decoding a protobuf. It seems that protofish
only returns a Value
object with a Message
which has field numbers and values.
It seems like the Message
may also have a MessageRef
which (with a protofish
context) can be converted to a MessageInfo
on which you could message_info.get_field(number).name
to get the field name.
That seems to be the supported way to get field names from protofish
but requires the protofish
context which schema_registry_converter
doesn't expose.
Is there some way to get at that context, or a better way to get field names out of a protobuf?
I'm not sure using the ProtoRawDecoder, which returns this as result would be viable? I rather keep the API small. Althrough the context is already there, so an additional deserialize_with_context
could be added easily.
Thanks for the quick reply!
I took a look at what ProtoRawDecoder
gives me, as far as I can see that won't be useable (I might be missing something). It gives me the bytes and the schema as a string. With those two things I will still need to parse out the bytes - so that leads me back to Protofish. However, I think I'll only have the single Schema provided as a string, not the entire context including the needed referenced schemas.
Let me know if I'm missing something there - right now this is only for an exploratory project so I'm OK with using some kind of janky workaround for the timebeing if there is one.
Not really a workaround for now. There are issues with adding more info with other serializers as well. So I can pick this up as one of those.
Fixed and released as 3.1.0
👏 Thanks @gklijs I think that'll do exactly what I need