Rules for evolving union members

38 views
Skip to first unread message

Andrew Sun

unread,
May 1, 2023, 5:35:45 PM5/1/23
to capn...@googlegroups.com
Suppose I have a schema that looks like this:

struct Foo {
    union {
        bar @0 :Void;
        baz @1 :UInt64;
        # ...
    }

    # ...
}

Now suppose I want to add information to union member bar, or I want to add more fields to baz. What options do I have to do this in a forwards- and backwards-compatible manner?

Would this be the "correct" way to evolve the schema?

struct Foo {
    union {
        bar :group {
            unused @0 :Void;
            foo @2 :UInt32;
            bar @3 :OtherStruct;
            # ...
        }
        baz :group {
            a @1 :UInt64;
            b @4 :Text;
            # ...
        }
        # ...
    }

    # ...
}


Kenton Varda

unread,
May 1, 2023, 5:38:04 PM5/1/23
to Andrew Sun, capn...@googlegroups.com
Hi Andrew,

Yes, you got it right. Annoyingly you will have to keep that unused Void in there, but at least it doesn't take any space on the wire.

-Kenton

--
You received this message because you are subscribed to the Google Groups "Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capnproto+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/capnproto/b4a83e9d-9145-4127-b9a6-aefc9500c1b2%40app.fastmail.com.
Reply all
Reply to author
Forward
0 new messages