Re: [capnproto] Schema Refactoring and Unique IDs

2023-08-02 Thread Jonathan Shapiro
Kenton: Are the type IDs likely to have collided?

Ian: If not, you might be able to hand-annotate the impacted types
with the *already
generated* IDs and then change the file ID. This offers the possibility of
a clean changeover at the next breaking version change.

Kenton: what *other* IDs will change if the file ID is changed that Ian
might need to consider here?


Jonathan


On Wed, Aug 2, 2023 at 3:37 PM 'Kenton Varda' via Cap'n Proto <
capnproto@googlegroups.com> wrote:

> Yes, changing the file ID will change the IDs of all types declared
> within, unless they have explicitly declared their own IDs.
>
> This only really matters if you are using RPC. Type IDs of interfaces are
> part of the wire protocol. Type IDs of structs and enums are not really
> used for anything, unless your application itself is using them. So it's
> usually fine to change the type IDs of structs and enums.
>
> So if you are only using serialization, not RPC, just go ahead and change
> one of the file IDs. If you are using RPC, you will need to manually
> override the IDs of the interface types in the file to keep them consistent
> with what they were originally, and then you can change the file ID.
>
> Of course, if both files happened to declare an interface with the same
> name, those interfaces will have the same ID. In this case you have big
> problems. You will have to make a breaking change to one of those two
> interfaces.
>
> -Kenton
>
> On Tue, Aug 1, 2023 at 3:02 PM 'Ian Wilson' via Cap'n Proto <
> capnproto@googlegroups.com> wrote:
>
>> Hi all, apologies for jumping on this thread a few years later.
>>
>> I have a similar question: suppose I have 2 different capnp files with
>> the same file ID.
>>
>> # file foo.capnp
>> 0xabbeabbeabbeabbe;
>>
>> struct Foo {
>>   val @0 : UInt32;
>> };
>>
>> # file bar.capnp
>> 0xabbeabbeabbeabbe;
>>
>> struct Bar {
>>   val @1 : UInt32;
>> };
>>
>> In my project, someone copy/pasted a file leading to two different
>> schemas with the same file ID, 0xabbeabbeabbeabbe.
>> I find a use case where I want to import both of these capnp files and
>> their types into a new one - of course this runs into a compilation error
>> with the duplicate IDs.
>>
>> I'd like to generate a new file ID to replace one of these, but I'm not
>> sure if this would impact the autogenerated type IDs and break other
>> systems.
>>
>> Would merely changing the file ID affect the types that already exist in
>> these files?
>>
>> On Friday, November 27, 2020 at 7:27:09 AM UTC-8 ken...@cloudflare.com
>> wrote:
>>
>>> On Wed, Nov 25, 2020 at 3:43 PM Matt Stern  wrote:
>>>
 When I try to run capnp compile, I get the following:

 error: Import failed: /capnp/java.capnp

>>>
>>> You will need to specify the same -I flags (import path) that you
>>> normally specify to `capnp compile` when running the Java code generator.
>>>
>>> If I comment out the Java bits and just compile in C++ (which works for
 me), will this have any effect on the unique IDs for the structs in my
 schema file?

>>>
>>> No, the auto-generated IDs do not in any way depend on the contents of
>>> other files. Auto-generated IDs are constructed by concatenating the parent
>>> scope ID and the type name, and then taking a hash of that.
>>>
>>> -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+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/capnproto/2970b31f-a1aa-45ac-bc6b-a95beb0b02b9n%40googlegroups.com
>> 
>> .
>>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/capnproto/CAJouXQnk4s5N2adNTi8OwNG0SA1wzr-jrk8SzjVf3kQY%3DSrNGA%40mail.gmail.com
> 
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/capnproto/CAJdcQk2OHOawXLvmeQ-uwGotA%2BLuasd%2B7fmCswiJkSHn3AZEzQ%40mail.gmail.com.


Re: [capnproto] Schema Refactoring and Unique IDs

2023-08-02 Thread 'Kenton Varda' via Cap'n Proto
Yes, changing the file ID will change the IDs of all types declared within,
unless they have explicitly declared their own IDs.

This only really matters if you are using RPC. Type IDs of interfaces are
part of the wire protocol. Type IDs of structs and enums are not really
used for anything, unless your application itself is using them. So it's
usually fine to change the type IDs of structs and enums.

So if you are only using serialization, not RPC, just go ahead and change
one of the file IDs. If you are using RPC, you will need to manually
override the IDs of the interface types in the file to keep them consistent
with what they were originally, and then you can change the file ID.

Of course, if both files happened to declare an interface with the same
name, those interfaces will have the same ID. In this case you have big
problems. You will have to make a breaking change to one of those two
interfaces.

-Kenton

On Tue, Aug 1, 2023 at 3:02 PM 'Ian Wilson' via Cap'n Proto <
capnproto@googlegroups.com> wrote:

> Hi all, apologies for jumping on this thread a few years later.
>
> I have a similar question: suppose I have 2 different capnp files with the
> same file ID.
>
> # file foo.capnp
> 0xabbeabbeabbeabbe;
>
> struct Foo {
>   val @0 : UInt32;
> };
>
> # file bar.capnp
> 0xabbeabbeabbeabbe;
>
> struct Bar {
>   val @1 : UInt32;
> };
>
> In my project, someone copy/pasted a file leading to two different schemas
> with the same file ID, 0xabbeabbeabbeabbe.
> I find a use case where I want to import both of these capnp files and
> their types into a new one - of course this runs into a compilation error
> with the duplicate IDs.
>
> I'd like to generate a new file ID to replace one of these, but I'm not
> sure if this would impact the autogenerated type IDs and break other
> systems.
>
> Would merely changing the file ID affect the types that already exist in
> these files?
>
> On Friday, November 27, 2020 at 7:27:09 AM UTC-8 ken...@cloudflare.com
> wrote:
>
>> On Wed, Nov 25, 2020 at 3:43 PM Matt Stern  wrote:
>>
>>> When I try to run capnp compile, I get the following:
>>>
>>> error: Import failed: /capnp/java.capnp
>>>
>>
>> You will need to specify the same -I flags (import path) that you
>> normally specify to `capnp compile` when running the Java code generator.
>>
>> If I comment out the Java bits and just compile in C++ (which works for
>>> me), will this have any effect on the unique IDs for the structs in my
>>> schema file?
>>>
>>
>> No, the auto-generated IDs do not in any way depend on the contents of
>> other files. Auto-generated IDs are constructed by concatenating the parent
>> scope ID and the type name, and then taking a hash of that.
>>
>> -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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/capnproto/2970b31f-a1aa-45ac-bc6b-a95beb0b02b9n%40googlegroups.com
> 
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/capnproto/CAJouXQnk4s5N2adNTi8OwNG0SA1wzr-jrk8SzjVf3kQY%3DSrNGA%40mail.gmail.com.