public int Deserialize(byte[] ropBytes, int startIndex)
{
int index = startIndex;
this.size = 0;
this.RecipientFlags = (ushort)BitConverter.ToInt16(ropBytes, index);
index += sizeof(ushort);
bool tflag, dflag, eflag, oflag, iflag, uflag;
int recipientTye = 0;
tflag = dflag = eflag = oflag = iflag = uflag = false;
if ((this.RecipientFlags & (ushort)TestSuites.Common.RecipientFlags.T) > 0)
{
tflag = true;
}
if ((this.RecipientFlags & (ushort)TestSuites.Common.RecipientFlags.D) > 0)
{
dflag = true;
}
if ((this.RecipientFlags & (ushort)TestSuites.Common.RecipientFlags.E) > 0)
{
eflag = true;
}
recipientTye = this.RecipientFlags & (ushort)TestSuites.Common.RecipientFlags.PersonalDistributionList2;
if ((this.RecipientFlags & (ushort)TestSuites.Common.RecipientFlags.O) > 0)
{
oflag = true;
}
if ((this.RecipientFlags & (ushort)TestSuites.Common.RecipientFlags.I) > 0)
{
iflag = true;
}
if ((this.RecipientFlags & (ushort)TestSuites.Common.RecipientFlags.U) > 0)
{
uflag = true;
}
switch (recipientTye)
{
case (ushort)TestSuites.Common.RecipientFlags.X500DN:
this.AddressPrfixUsed = ropBytes[index++];
this.DisplayType = ropBytes[index++];
int bytesLen = 0;
bool isFound = false;
// Find the string with '\0' end
for (int i = index; i < ropBytes.Length; i++)
{
bytesLen++;
if (ropBytes[i] == 0)
{
isFound = true;
break;
}
}
if (!isFound)
{
throw new ParseException("String too long or not found");
}
else
{
X500DN = new byte[bytesLen];
Array.Copy(ropBytes, index, X500DN, 0, bytesLen - 1);
index += bytesLen;
}
break;
case (ushort)TestSuites.Common.RecipientFlags.PersonalDistributionList1:
case (ushort)TestSuites.Common.RecipientFlags.PersonalDistributionList2:
this.EntryIdSize = (ushort)BitConverter.ToInt16(ropBytes, index);
index += 2;
this.EntryId = new byte[this.EntryIdSize];
Array.Copy(ropBytes, index, this.EntryId, 0, this.EntryIdSize);
index += this.EntryIdSize;
this.SearchKeySize = (ushort)BitConverter.ToInt16(ropBytes, index);
index += 2;
this.SearchKey = new byte[this.SearchKeySize];
Array.Copy(ropBytes, index, this.SearchKey, 0, this.SearchKeySize);
index += this.SearchKeySize;
break;
case (ushort)TestSuites.Common.RecipientFlags.None:
if (oflag == true)
{
bytesLen = 0;
isFound = false;
// Find the string with '\0' end
for (int i = index; i < ropBytes.Length; i++)
{
bytesLen++;
if (ropBytes[i] == 0)
{
isFound = true;
break;
}
}
if (!isFound)
{
throw new ParseException("String too long or not found");
}
else
{
this.AddressType = new byte[bytesLen];
Array.Copy(ropBytes, index, this.AddressType, 0, bytesLen - 1);
index += bytesLen;
}
}
break;
}
if (eflag == true)
{
int bytesLen = 0;
bool isFound = false;
if (uflag == true)
{
for (int i = index; i < ropBytes.Length; i += 2)
{
bytesLen += 2;
if ((ropBytes[i] == 0) && (ropBytes[i + 1] == 0))
{
isFound = true;
break;
}
}
}
else
{
// Find the string with '\0' end
for (int i = index; i < ropBytes.Length; i++)
{
bytesLen++;
if (ropBytes[i] == 0)
{
isFound = true;
break;
}
}
}
if (!isFound)
{
throw new ParseException("String too long or not found");
}
else
{
this.EmailAddress = new byte[bytesLen];
Array.Copy(ropBytes, index, this.EmailAddress, 0, bytesLen - 1);
index += bytesLen;
}
}
if (dflag == true)
{
int bytesLen = 0;
bool isFound = false;
if (uflag == true)
{
for (int i = index; i < ropBytes.Length; i += 2)
{
bytesLen += 2;
if ((ropBytes[i] == 0) && (ropBytes[i + 1] == 0))
{
isFound = true;
break;
}
}
}
else
{
// Find the string with '\0' end
for (int i = index; i < ropBytes.Length; i++)
{
bytesLen++;
if (ropBytes[i] == 0)
{
isFound = true;
break;
}
}
}
if (!isFound)
{
throw new ParseException("String too long or not found");
}
else
{
if (uflag == true)
{
this.DisplayName = new byte[bytesLen];
Array.Copy(ropBytes, index, this.DisplayName, 0, bytesLen);
index += bytesLen;
}
else
{
this.DisplayName = new byte[bytesLen];
Array.Copy(ropBytes, index, this.DisplayName, 0, bytesLen);
index += bytesLen;
}
}
}
if (iflag == true)
{
int bytesLen = 0;
bool isFound = false;
if (uflag == true)
{
for (int i = index; i < ropBytes.Length; i += 2)
{
bytesLen += 2;
if ((ropBytes[i] == 0) && (ropBytes[i + 1] == 0))
{
isFound = true;
break;
}
}
}
else
{
// Find the string with '\0' end
for (int i = index; i < ropBytes.Length; i++)
{
bytesLen++;
if (ropBytes[i] == 0)
{
isFound = true;
break;
}
}
}
if (!isFound)
{
throw new ParseException("String too long or not found");
}
else
{
if (uflag == true)
{
this.SimpleDisplayName = new byte[bytesLen];
Array.Copy(ropBytes, index, this.SimpleDisplayName, 0, bytesLen);
index += bytesLen;
}
else
{
this.SimpleDisplayName = new byte[bytesLen];
Array.Copy(ropBytes, index, this.SimpleDisplayName, 0, bytesLen);
index += bytesLen;
}
}
}
if (tflag == true)
{
int bytesLen = 0;
bool isFound = false;
if (uflag == true)
{
for (int i = index; i < ropBytes.Length; i += 2)
{
bytesLen += 2;
if ((ropBytes[i] == 0) && (ropBytes[i + 1] == 0))
{
isFound = true;
break;
}
}
}
else
{
// Find the string with '\0' end
for (int i = index; i < ropBytes.Length; i++)
{
bytesLen++;
if (ropBytes[i] == 0)
{
isFound = true;
break;
}
}
}
if (!isFound)
{
throw new ParseException("String too long or not found");
}
else
{
if (uflag == true)
{
this.TransmittableDisplayName = new byte[bytesLen];
Array.Copy(ropBytes, index, this.TransmittableDisplayName, 0, bytesLen);
index += bytesLen;
}
else
{
this.TransmittableDisplayName = new byte[bytesLen];
Array.Copy(ropBytes, index, this.TransmittableDisplayName, 0, bytesLen);
index += bytesLen;
}
}
}
this.RecipientColumnCount = (ushort)BitConverter.ToInt16(ropBytes, index);
index += sizeof(ushort);
Context.Instance.PropertyBytes = ropBytes;
Context.Instance.CurIndex = index;
this.RecipientProperties = new PropertyRow();
this.RecipientProperties.Parse(Context.Instance);
index = Context.Instance.CurIndex;
this.size = index - startIndex;
this.serializedBuffer = new byte[this.size];
Array.Copy(ropBytes, startIndex, this.serializedBuffer, 0, this.size);
return index - startIndex;
}
}