Skip to content

Commit

Permalink
don't create a string when converting from bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Roddie committed Jan 15, 2024
1 parent 6ed7797 commit b45ae36
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions CBOR/PeterO/Cbor/CBORUuidConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,9 @@ public Guid FromCBORObject(CBORObject obj) {
throw new CBORException("Must have outermost tag 37");
}
_ = ValidateObject(obj);
byte[] bytes = obj.GetByteString();
var guidChars = new char[36];
string hex = "0123456789abcdef";
var index = 0;
for (int i = 0; i < 16; ++i) {
if (i == 4 || i == 6 || i == 8 || i == 10) {
guidChars[index++] = '-';
}
guidChars[index++] = hex[(bytes[i] >> 4) & 15];
guidChars[index++] = hex[bytes[i] & 15];
}
var guidString = new String(guidChars);
return new Guid(guidString);
byte[] b2 = obj.GetByteString();
byte[] bytes = { b2[3], b2[2], b2[1], b2[0], b2[5], b2[4], b2[7], b2[6], b2[8], b2[9], b2[10], b2[11], b2[12], b2[13], b2[14], b2[15] };
return new Guid(bytes);
}
}
}

0 comments on commit b45ae36

Please sign in to comment.