well known types are not extendable in this way, currently.

By their nature, they are not designed to support custom types as they
wouldn't exactly be well known by our definition of well known (meaning,
known to all).

On Tue, Jun 8, 2021 at 12:35 PM Raphaël Barrois <raphael.barr...@gmail.com>
wrote:

> Hi,
>
> I am currently looking at ways of extending the generated code, in order to
> add some helpers for some messages which map to standard types in our
> codebase (think UUID, IPv6 — akin to the extended features awarded to the
> well-known types).
>
>
> My goal is to be able to go from:
>
> message User {
>   example.wellknown.UUID id = 1;
> }
>
> To (for Python):
>
> >>> user.id.to_uuid()
> UUID("4fc93ada-dded-4737-9a5c-e3811c37f99d")
> >>> user.id.from_uuid(UUID("002ce13b-31bc-4332-80f9-51f83a49eb65"))
>
>
> I thought it would be possible to provide, for my own types, the same kind
> of extended features as the "well-known types" enjoy.
> However, I couldn't find how to do that in the documentation; and a look
> at the Python implementation showed that these extensions are hardcoded in
> the codebase (see
>
> https://github.com/protocolbuffers/protobuf/blob/master/python/google/protobuf/internal/python_message.py#L151-L152
> ).
>
> Have I missed some part of the documentation? What is the common pattern
> for such extensions?
>
> Thanks,
>
> --
> Raphaël Barrois
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/protobuf/a591a464-ab78-47a5-b837-29d6fdec310c%40gmail.com
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/CAJGs%2BiJe5JcTw%2BJXdQzWqagpHkcP44jJGn6v-S4uDh12ChszDA%40mail.gmail.com.

Reply via email to