private static bool TryWriteVariableWidthMembersToObject <T>(ref ComplianceSerializationDescription <T> description, ref T parsedObject, byte[] blob, int startIndex, int totalLength, ComplianceSerializer.VariableWidthType widthType, bool continueDeserialization, out int index, ref StringBuilder errorBuilder) where T : class, new() { if (!continueDeserialization) { index = startIndex; return(continueDeserialization); } index = startIndex; if (startIndex >= totalLength) { errorBuilder.AppendFormat("StartIndex:{0} is bigger than blob length:{1}", startIndex, totalLength); return(false); } byte b = blob[index++]; if (b > 0) { List <int> list = new List <int>(); for (byte b2 = 0; b2 < b; b2 += 1) { if (index + 4 > totalLength) { errorBuilder.AppendFormat("Blob length:{0} is not sufficient to read the field-width from index:{1}.", totalLength, index); return(false); } int item = ComplianceSerializer.ReadIntFromBlob(blob, index); list.Add(item); index += 4; } byte b3 = 0; foreach (int num in list) { if (num > 0) { if (index + num > totalLength) { errorBuilder.AppendFormat("Blob length:{0} is not sufficient to read the field of size:{1} from index:{2}.", totalLength, num, index); return(false); } if (widthType == ComplianceSerializer.VariableWidthType.String) { string @string = Encoding.UTF8.GetString(blob, index, num); description.TrySetStringProperty(parsedObject, b3, @string); index += num; } else { byte[] array = new byte[num]; Array.Copy(blob, index, array, 0, num); description.TrySetBlobProperty(parsedObject, b3, array); index += num; } } b3 += 1; } return(true); } return(true); }
private static List <Tuple <int, byte[]> > GetVariableWidthMemberBytes <T>(ComplianceSerializationDescription <T> description, T inputObject, ComplianceSerializer.VariableWidthType widthType) where T : class, new() { List <Tuple <int, byte[]> > list = new List <Tuple <int, byte[]> >(); byte b = (byte)description.TotalStringFields; if (widthType == ComplianceSerializer.VariableWidthType.Blob) { b = (byte)description.TotalBlobFields; } for (byte b2 = 0; b2 < b; b2 += 1) { int item = 0; byte[] array = null; string text; if (widthType == ComplianceSerializer.VariableWidthType.Blob) { if (inputObject != null && description.TryGetBlobProperty(inputObject, b2, out array) && array != null) { item = array.Length; } } else if (inputObject != null && description.TryGetStringProperty(inputObject, b2, out text) && text != null) { array = Encoding.UTF8.GetBytes(text); item = array.Length; } list.Add(new Tuple <int, byte[]>(item, array)); } return(list); }