jamescourtney / FlatSharp

Fast, idiomatic C# implementation of Flatbuffers
Apache License 2.0
497 stars 50 forks source link

Unions of 41 types cause a compilation error #307

Closed shadowbane1000 closed 1 year ago

shadowbane1000 commented 1 year ago

Again working with autogenerated fbs files. I'm going from a schema definition language that allows inheritance, so I flatten the inheritance down with unions. I used to only do one level of flattening, but that still leaves union entries with just the base type in them. When I resolved this, and recursively resolve inheritance in to the unions, I end up with unions with more than the limit of 30 types in them. If I get time, I'll put together a pull request increasing the number of these.

Perhaps generating code on the fly for these would be a better approach?

shadowbane1000 commented 1 year ago

Hmm.. changing one number in the code hardly seems worthy of a pull request, but I'll see about putting one together.

shadowbane1000 commented 1 year ago

https://github.com/jamescourtney/FlatSharp/pull/308

jamescourtney commented 1 year ago

Approving the PR. Very surprised that someone found that limit of 30.

Perhaps generating code on the fly for these would be a better approach?

Technically if you're using FBS files, we do generate custom implementations of IFlatBufferUnion<T1, T2, ..., TX>. This is to expose named union members so you'd have Dog instead of Item3. Technically for this PR, we should only need to increase the number of interfaces and not the number of implementations, since you're using FBS files (I presume). However, I don't think it hurts anything beyond exploding the size of FlatSharp.Runtime to include the extra types.

shadowbane1000 commented 1 year ago

Yes, I'm using FBS. Do you know when you might be able to release a version with this change in it?

jamescourtney commented 1 year ago

I'm going to merge one more change and will push 6.3.3 after that.

jamescourtney commented 1 year ago

6.3.3 is published with your changes and a new Visitor pattern for working with unions.