[#19] Client: Use specific classes for search
Signed-off-by: Pavel Gross <p.gross@yando.com>
This commit is contained in:
parent
3206abc33e
commit
35fe791406
27 changed files with 320 additions and 123 deletions
|
@ -7,18 +7,49 @@ public static class UUIDExtension
|
|||
{
|
||||
public static Guid ToUuid(this ByteString id)
|
||||
{
|
||||
return Guid.Parse(BitConverter.ToString(id.ToByteArray()).Replace("-", ""));
|
||||
var bytes = id.ToByteArray();
|
||||
|
||||
var orderedBytes = GetGuidBytesDirectOrder(bytes);
|
||||
|
||||
return new Guid(orderedBytes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serializes Guid to binary representation in direct order bytes format
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] ToBytes(this Guid id)
|
||||
{
|
||||
var str = id.ToString("N");
|
||||
var len = str.Length;
|
||||
var bytes = new byte[len/2];
|
||||
var bytes = id.ToByteArray();
|
||||
|
||||
for (int i = 0; i < len; i += 2)
|
||||
bytes[i/2] = Convert.ToByte(str.Substring(i, 2), 16);
|
||||
|
||||
return bytes;
|
||||
var orderedBytes = GetGuidBytesDirectOrder(bytes);
|
||||
|
||||
return orderedBytes;
|
||||
}
|
||||
|
||||
private static byte[] GetGuidBytesDirectOrder(byte[] source)
|
||||
{
|
||||
if (source.Length != 16)
|
||||
throw new ArgumentException("Wrong uuid binary format");
|
||||
|
||||
return [
|
||||
source[3],
|
||||
source[2],
|
||||
source[1],
|
||||
source[0],
|
||||
source[5],
|
||||
source[4],
|
||||
source[7],
|
||||
source[6],
|
||||
source[8],
|
||||
source[9],
|
||||
source[10],
|
||||
source[11],
|
||||
source[12],
|
||||
source[13],
|
||||
source[14],
|
||||
source[15]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue