Customise Unmarshalling Behaviour

20 views
Skip to first unread message

Ben

unread,
Jun 12, 2026, 11:42:07 AM (yesterday) Jun 12
to Protocol Buffers
I have a number of protobufs with uuid fields. In order to use the fields in my code (in my case, in golang) I have to write either wrapper structs for every message type or I must manually convert them into uuids at point of use, which requires extensive error checking. Either way requires extensive boiler plate.

Is there a relatively simple way to get the go generator to output the uuid.UUID type instead of []byte?

Thanks,

Ben

Em Rauch

unread,
Jun 12, 2026, 11:54:48 AM (yesterday) Jun 12
to Ben, Protocol Buffers
Narrowly UUID is actually candidate for something we have considered support for, but there's a lot of ecosystem issues with introducing new types and so we don't have immediate plans for it (https://github.com/protocolbuffers/protobuf/issues/25159 is the tracking issue for that category of thing)

In general Protobuf libraries intentionally does not support layering up arbitrary user types on top. There's many problems with supporting that shape of API, including that you create a problem of having content which is valid as per the schema but where only in your additional special handling it is invalid. One of the lessons of required fields being harmful is that its actually better for the parse to only validate that we can parse it, and leave "this thing matches the schema but may need to be rejected due to additional expectations of my application code" as a second pass pushed into the application code layer instead of coupling it to the protobuf structs / protobuf parse point.

We do know that isn't ideal for all usecases, but its the balance that we have settled on as globally best decision for the Protobuf libraries.

Thanks!


--
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 protobuf+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/protobuf/6df4b8e6-68d8-4ebc-8dc9-5531fb2bdbfen%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages