Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@fortk2
Copy link
Contributor

@fortk2 fortk2 commented Sep 10, 2019

Add element size parameter to __vector_as_arraysegment fixing issue where VectorAsBytes returns incorrect size span for multibyte element types.

Potential solution for: #5511

Add element size parameter to __vector_as_arraysegment fixing issue where VectorAsBytes returns incorrect size span for multibyte element types.
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@fortk2
Copy link
Contributor Author

fortk2 commented Sep 10, 2019

@googlebot I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@aardappel
Copy link
Collaborator

Thanks, this is a fix, but I agree that for any T that is not a byte it should return Span<T> instead. Of course, the one issue is that it refers to little-endian bytes, though not sure if there is even an implementation of C# for a big endian machine? :)

@fortk2
Copy link
Contributor Author

fortk2 commented Sep 10, 2019

Thanks, this is a fix, but I agree that for any T that is not a byte it should return Span<T> instead. Of course, the one issue is that it refers to little-endian bytes, though not sure if there is even an implementation of C# for a big endian machine? :)

I can update to return a Span. My original plan was to do something like this:
return bb.ToSpan(pos, len * ByteBuffer.SizeOf()); and use the template type to get the size but I didn't see a good way to get the appropriate size for enums so I went with the extra parameter.

For the endianness question, I guess I could just make it throw like is done in: __vector_as_array, or maybe have both versions?

@aardappel
Copy link
Collaborator

Yes, the size argument is probably faster anyway.
Yes, throwing on big endian would be a good solution.

Update codegen and Table to return typed span.
update test files
@aardappel
Copy link
Collaborator

Nice!

(CI errors unrelated).

@aardappel aardappel merged commit 2706381 into google:master Sep 11, 2019
LuckyRu pushed a commit to LuckyRu/flatbuffers that referenced this pull request Oct 2, 2020
)

* Add element size parameter to __vector_as_arraysegment

Add element size parameter to __vector_as_arraysegment fixing issue where VectorAsBytes returns incorrect size span for multibyte element types.

* Update codegen

Update codegen and Table to return typed span.

* update test files

update test files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants