-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[C#] Fix retrieving enumeration vectors as arrays #5457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The code duplication is unfortunate, but if this makes the code more compatible with all possible types, that is probably essential. Should we somehow mark the |
|
There is But on second thought, I think we should just stop generating them now for vectors of enums, considering that they never worked in the first place. I doubt anyone is relying on their existence. Your thoughts? |
|
Yup, if before they produced errors when used in that combination, remove them. But still good to mark them as deprecated. The former attribute sounds right to me. |
|
Are you going to mark it deprecated? |
|
No, I can't mark generated code deprecated if it's removed. |
|
I was referring to the non-enum |
|
Oh. Well I don't think there is a particular need to deprecate it in other cases. They still provide a slight performance increase where they work. |
|
Hi @aardappel, can I get an update on whether this can be accepted? |
|
@naine As I said, I was wondering wether you were going to mark the non-enum Block functions as deprecated? |
|
They offer a performance boost for primitive types so I wasn't planning to, no. Do you disagree with this? |
|
Ok, I guess I misunderstood our previous discussion then. Thanks :) |
* [C#] Fix retrieving enumeration vectors as arrays * [C#] Don't generate CreateVectorBlock for enums
Follow-up to #5419
The C#
ByteBufferclass features a number of generic methods which are employed mostly when dealing with vectors. The generic methods work using a static table of type sizes, and do not support any type not in the table, including the enum types generated from flatbuffer schemas. They also use theBuffer.BlockCopymethod to copy directly between the backing byte array and strongly typed arrays returned to or supplied from the user, and this method does not work with enum-typed arrays.The C# code generator works around
ByteBuffer's lack of support for enum types by casting to/from the generated enum types when using the variousGet*/Put*methods for reading/writing individual integer values. But for some generated code this work-around is not applicable, and flatc generates code which invokes the genericByteBuffermethods using enum types, which will always throw at runtime.I considered first attempting to address the limitations in
ByteBufferinstead, but saw no way to do this without negatively impacting either performance or compatibility.My solution modifies the generator to avoid calling the generic methods with enum types:
Create*VectorBlock()methods now delegate to theirCreate*Vector()counterparts, which are semantically identical but slower. They should really be removed but I kept them there for backwards compatibility.Get*Array()methods now directly create an array and copy data into it in a loop instead of calling__vector_as_array<T>(). Data is read into the array the same way the standard accessors for enum vectors read from the buffer, by using a specificGet*()method and casting to the enum type. The loop is roughly modelled after similar loops generated inCreate*Vector()methods.