public static PermanentEntryID ParsePermanentEntryIDFromBytes(byte[] bytes)
{
int index = 0;
// The count size of the buffer
uint size = BitConverter.ToUInt32(bytes, index);
index += 4;
PermanentEntryID entryID = new PermanentEntryID();
entryID.IDType = bytes[index++];
entryID.R1 = bytes[index++];
entryID.R2 = bytes[index++];
entryID.R3 = bytes[index++];
byte[] bytesGUID = new byte[16];
Array.Copy(bytes, index, bytesGUID, 0, 16);
entryID.ProviderUID = new Guid(bytesGUID);
index += 16;
// R4: 4 bytes
entryID.R4 = (uint)BitConverter.ToInt32(bytes, index);
index += 4;
// DisplayType: 4 bytes
entryID.DisplayTypeString = (DisplayTypeValues)BitConverter.ToInt32(bytes, index);
index += 4;
// DistinguishedName: variable
entryID.DistinguishedName = System.Text.Encoding.Default.GetString(bytes, index, bytes.Length - index - 1);
return entryID;
}