Adding new field to an existing oneof field

23 views
Skip to first unread message

Afshin

unread,
Mar 29, 2020, 1:19:08 PM3/29/20
to Protocol Buffers
Hi all

When I was reading guides for protobuf 3, there was a huge limitation for oneof field. The guide states that updating a message by adding new fields to an existing oneof field is not safe. For example, if I have following message:

message TestIt {
    oneof my_field {
        DataA a = 1;
        DataB b = 2;
    }
}

I cannot update it to the this new message:

message TestIt {
    oneof my_field {
        DataA a = 1;
        DataB b = 2;
        DataC c = 3;
    }
}

I think this is a really huge limitation for oneof field and makes it useless in a lot of cases. Is there any way to achieve something similar without using Any object?

Nadav Samet

unread,
Mar 29, 2020, 2:36:08 PM3/29/20
to Afshin, Protocol Buffers
Hi Afshin, adding a new field to an existing oneof is safe. Moving existing fields into a new or existing oneof may be unsafe as described in the language guide. Sounds like the guides you have looked into are inaccurate. If you don't mind, can you provide a link?



--
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 on the web visit https://groups.google.com/d/msgid/protobuf/cdfd705b-7504-4220-93b7-0d2e3bc9c82f%40googlegroups.com.


--
-Nadav

Afshin

unread,
Mar 29, 2020, 3:02:23 PM3/29/20
to Protocol Buffers
Oh, Thanks for quick reply.
It seems that I misunderstood. I read the same link that you provided, but I thought that "Moving any fields into an existing oneof is not safe." includes adding new fields to existing one too.

Best Regards

On Sunday, March 29, 2020 at 11:06:08 PM UTC+4:30, Nadav Samet wrote:
Hi Afshin, adding a new field to an existing oneof is safe. Moving existing fields into a new or existing oneof may be unsafe as described in the language guide. Sounds like the guides you have looked into are inaccurate. If you don't mind, can you provide a link?



On Sun, Mar 29, 2020 at 10:19 AM Afshin <afsh...@gmail.com> wrote:
Hi all

When I was reading guides for protobuf 3, there was a huge limitation for oneof field. The guide states that updating a message by adding new fields to an existing oneof field is not safe. For example, if I have following message:

message TestIt {
    oneof my_field {
        DataA a = 1;
        DataB b = 2;
    }
}

I cannot update it to the this new message:

message TestIt {
    oneof my_field {
        DataA a = 1;
        DataB b = 2;
        DataC c = 3;
    }
}

I think this is a really huge limitation for oneof field and makes it useless in a lot of cases. Is there any way to achieve something similar without using Any object?

--
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 prot...@googlegroups.com.


--
-Nadav
Reply all
Reply to author
Forward
0 new messages