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

RFC4122 compatible binary representation for GUID #53354

Closed
huoyaoyuan opened this issue May 27, 2021 · 8 comments
Closed

RFC4122 compatible binary representation for GUID #53354

huoyaoyuan opened this issue May 27, 2021 · 8 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Runtime
Milestone

Comments

@huoyaoyuan
Copy link
Member

Background and Motivation

Previous discussions: #23868 #29523
Currently, the Guid type uses "MS quirk" binary representation. It's hard to use it to communicate with RFC4122 compatible (all-BigEndian) representations.

Proposed API

namespace System
{
    public struct Guid
    {
        public Guid(byte[]);
        public Guid(ReadOnlySpan<byte>);
+        public static Guid FromBigEndian(ReadOnlySpan<byte>);

        public byte[] ToByteArray();
+        public byte[] ToBigEndianByteArray();

        public bool TryWriteBytes(Span<byte>);
+        public bool TryWriteBigEndianBytes(Span<byte>);
    }
}

Usage Examples

Guid guid = new Guid("00112233-4455-6677-8899-aabbccddeeff");
var bytes = guid.ToBigEndianByteArray();
// Gets an array encodes bytes in the same order of string representation

Alternative Designs

Use a new type duplicates the api surface of Guid.

Risks

People may get confused about which representation to use.

@huoyaoyuan huoyaoyuan added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label May 27, 2021
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label May 27, 2021
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@AaronRobinsonMSFT
Copy link
Member

@GrabYourPitchforks I think you previously had some thoughts in this area. Perspective on this proposal?

@ghost
Copy link

ghost commented May 27, 2021

Tagging subscribers to this area: @tannergooding
See info in area-owners.md if you want to be subscribed.

Issue Details

Background and Motivation

Previous discussions: #23868 #29523
Currently, the Guid type uses "MS quirk" binary representation. It's hard to use it to communicate with RFC4122 compatible (all-BigEndian) representations.

Proposed API

namespace System
{
    public struct Guid
    {
        public Guid(byte[]);
        public Guid(ReadOnlySpan<byte>);
+        public static Guid FromBigEndian(ReadOnlySpan<byte>);

        public byte[] ToByteArray();
+        public byte[] ToBigEndianByteArray();

        public bool TryWriteBytes(Span<byte>);
+        public bool TryWriteBigEndianBytes(Span<byte>);
    }
}

Usage Examples

Guid guid = new Guid("00112233-4455-6677-8899-aabbccddeeff");
var bytes = guid.ToBigEndianByteArray();
// Gets an array encodes bytes in the same order of string representation

Alternative Designs

Use a new type duplicates the api surface of Guid.

Risks

People may get confused about which representation to use.

Author: huoyaoyuan
Assignees: -
Labels:

api-suggestion, area-System.Runtime, untriaged

Milestone: -

@GrabYourPitchforks
Copy link
Member

IMO this direction solves the heartache I had with #23868. It's not adding new GUID factories, so it shouldn't contribute to significant consumer confusion. It's just allowing users to control how the structure is converted to / from a binary blob.

@tannergooding tannergooding removed the untriaged New issue has not been triaged by the area owner label Jul 12, 2021
@tannergooding tannergooding added this to the Future milestone Jul 12, 2021
@danmoseley
Copy link
Member

@GrabYourPitchforks based on your comment above, should we mark as ready for review?

@tannergooding
Copy link
Member

I wonder if users are going to expect a TryWriteBigEndian API to match RFC4122 when the format of Guid itself is the Microsoft representation.

Having the name TryWriteRfc4122Bytes might be a "better" name in some sense due to that. Having a BigEndian API without a corresponding LittleEndian API is another concern.

@huoyaoyuan
Copy link
Member Author

huoyaoyuan commented Aug 23, 2022

Should the name be discussed during API review? I'm somehow OK with Rfc4122 in the name, but generally I haven't seen spec ids mentioned much in .NET APIs.

My original idea was mentioning "RFC4122 compatible" and "Microsoft OLE compatible" in xml doc.

@huoyaoyuan
Copy link
Member Author

Closed in favor of #86798.

@ghost ghost locked as resolved and limited conversation to collaborators Jul 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Runtime
Projects
None yet
Development

No branches or pull requests

5 participants