-
Notifications
You must be signed in to change notification settings - Fork 42
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
Conversion to and from mixed-endian byte strings #48
Comments
I've been pointed to https://docs.microsoft.com/en-us/previous-versions/aa379358(v%3Dvs.80) which claims typedef struct _GUID {
unsigned long Data1;
unsigned short Data2;
unsigned short Data3;
unsigned char Data4[8];
} GUID, UUID; so your code above would only be correct when the host order is little-endian. What is your use-case for this serialization format? is it for C FFI purposes or something else? |
My use case is reading column data from SQL Server. For that, I'm using the odbc package. This package has, however, no particular representation of a UUID, so instead, for I've noticed that when I use Other people have made corroborating observations. The explanation could be that
and
When I convert the bytes using the above |
@ploeh I see; however in this case I'd advocate that it should be the database library's responsibility to know how to decode/encode the types supported by the respective database; and in fact, that's what e.g. postgresql-simple does. However, I can't bring this up myself at https://github.com/fpco/odbc/issues as I've been banned by FPComplete. |
I don't mind taking the issue to odbc instead. Ultimately, I can just keep my working solution in my own code base, where it already works. I did think that I'd ask here first, though, since this might be a problem with As the Wikipedia entry suggests, this could be an issue with any As I did spend a few hours figuring all this out, I thought I'd offer the solution at the place where it'd be most generally available to other users, thereby saving others from similarly wasted time. |
If you get this encoding via OLE/COM, this means via FFI, now? In that case you'd typically not get it via a |
That's a good point; I hadn't thought that through. It's true that when interacting with the odbc package, I take advantage of the feature that already turns SQL Server's native |
Microsoft tends to encode UUIDs in a mixed-endian format.
There's plenty of evidence of this. Ask me how I know 😉
It'd be useful if the uuid library also provided conversions to and from this format. I created this conversion to
ByteString
:I've yet to attempt the reverse conversion, but I think it'll look similar.
Is there any interest in getting this into the library? If so, I'll be happy to attempt a pull request.
The text was updated successfully, but these errors were encountered: