-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Consider adding BitConverter overloads that accept endian option #22839
Comments
I think the enum makes it clearer to read, but if we're consistent with parameters being either bigEndian or littleEndian then the I'd call the zero-value Wikipedia also makes me wonder if we need the naming to indicate Byte endianness vs Bit endianness. (I do recall back in college and learning about Little Endian and being aghast at how it was really middle-endian, since I was thinking in terms of the bits... the "left-most" "in hardware" being Any particular middle-endian byte scheme would need specific descriptions, like PDP would probably be named something terrible like So I think:
|
I strongly prefer the second version, although I know folks will not want to add a new "Endianness" enum into a core namespace. The first option feels like an abuse of the nullable type and looks a bit unpleasant to me. If we use the first option, we should flip the |
I guess an extra cost of the enum (aside from the typedef/Intellisense cost) is that we need to validation on it, or have a convention that says all unmapped values get treated as |
While I don't particularly agree about abuse of |
Agree. The enum makes the APIs slower than they need to be. What's wrong with having endianness to be part of the API name? |
I appreciate the readability of the enum. (That said, I'm of the opinion that methods shouldn't have boolean parameters, in favor of separate methods or perhaps an enum. Because otherwise "now the method does two things") |
I like having the tri-state enum. A good goal is to let people fall into the "pit of success" -- can we give Big Endian two different name? I'd love to have an enum like this: That way the two most common things people need to do -- convert system to network and network to system -- are super easy. If we can do this without using 'big' versus 'little', that IMHO is a gain. I've never had to deal with "bit" endian-ness and IMHO adding special options for it (or even mentioning it in documentation) will only confuse our developers. |
@PeterSmithRedmond - if we're adding "Network" as an option, does that mean |
This isn't necessary with the BinaryPrimitives APIs being added in dotnet/corefx#24400. |
#22803 lists APIs we're planning to add that use
Span<byte>
instead ofbyte[]
. These and the existing methods also use the current machine's endianness. We should separately consider overloads that accept the endianness to use, rather than always using that of the current machine, e.g.or
cc: @bartonjs
The text was updated successfully, but these errors were encountered: