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

Little endian decode [feature request] #12

Open
kinguru opened this issue May 8, 2022 · 0 comments
Open

Little endian decode [feature request] #12

kinguru opened this issue May 8, 2022 · 0 comments

Comments

@kinguru
Copy link

kinguru commented May 8, 2022

Dear Dave,
could you please add Little Endian guid bytes order support? It's need when Guid is shortened in another application, which default is Little Endian. The solution is easy. In decode method, need to convert Guid byte array to hex string before creating a Guid:

byte[] blob = Convert.FromBase64String(base64);
var hexString = ToHexString(blob);
var guid = new Guid(hexString);

ToHexString could be implemented like:

static string ToHexString(byte[] bytes)
{
    var str1 = BitConverter.ToString(bytes);
    return str1.Replace("-", "");
}

or another more clear algorithm is to swap byte[] bytes, instead of convert to HexString

result[0] = blob[3];
result[1] = blob[2];
result[2] = blob[1];
result[3] = blob[0];
result[4] = blob[5];
result[5] = blob[4];
result[6] = blob[7];
result[7] = blob[6];
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