Skip to content
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

Make use of BinaryPrimitives #54

Open
Apollo3zehn opened this issue Sep 21, 2021 · 2 comments
Open

Make use of BinaryPrimitives #54

Apollo3zehn opened this issue Sep 21, 2021 · 2 comments

Comments

@Apollo3zehn
Copy link
Owner

dotnet/corefx#24400

@aviatrix
Copy link

I've tried to implement this, but there was issue where there's no switch from endianness on span/memory, just on primitive types.
So, we might have to remove switching endianness on span/memory or leave it as is

public static void SwitchEndianness<T>(Span<T> dataset) where T : unmanaged
{
var size = Marshal.SizeOf<T>();
var dataset_bytes = MemoryMarshal.Cast<T, byte>(dataset);
for (int i = 0; i < dataset_bytes.Length; i += size)
{
for (int j = 0; j < size / 2; j++)
{
var i1 = i + j;
var i2 = i - j + size - 1;
byte tmp = dataset_bytes[i1];
dataset_bytes[i1] = dataset_bytes[i2];
dataset_bytes[i2] = tmp;
}
}
}

@Apollo3zehn
Copy link
Owner Author

That's good to know, thanks :-) I'll leave this issue open as a reminder to completely review the server/client API to work with different byte layouts.

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

No branches or pull requests

1 participant