private static bool TryWriteFixedWidthFieldsToObject <T>(ref ComplianceSerializationDescription <T> description, ref T parsedObject, byte[] blob, int startIndex, int width, ComplianceSerializer.FixedWidthType widthType, int totalLength, 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[startIndex]; index++; for (byte b2 = 0; b2 < b; b2 += 1) { if (index + width > totalLength) { errorBuilder.AppendFormat("Blob length:{0} is not sufficient to read the field from index:{1}.", totalLength, index); return(false); } switch (widthType) { case ComplianceSerializer.FixedWidthType.Byte: description.TrySetByteProperty(parsedObject, b2, blob[index]); break; case ComplianceSerializer.FixedWidthType.Short: { short value = ComplianceSerializer.ReadShortFromBlob(blob, index); description.TrySetShortProperty(parsedObject, b2, value); break; } case ComplianceSerializer.FixedWidthType.Int: { int value2 = ComplianceSerializer.ReadIntFromBlob(blob, index); description.TrySetIntegerProperty(parsedObject, b2, value2); break; } case ComplianceSerializer.FixedWidthType.Long: { long value3 = ComplianceSerializer.ReadLongFromBlob(blob, index); description.TrySetLongProperty(parsedObject, b2, value3); break; } case ComplianceSerializer.FixedWidthType.Double: { double value4 = ComplianceSerializer.ReadDoubleFromBlob(blob, index); description.TrySetDoubleProperty(parsedObject, b2, value4); break; } case ComplianceSerializer.FixedWidthType.Guid: { Guid value5 = ComplianceSerializer.ReadGuidFromBlob(blob, index); description.TrySetGuidProperty(parsedObject, b2, value5); break; } default: throw new ArgumentException("widthType"); } index += width; } return(true); }
private static int WriteFixedWidthFieldsToBlob <T>(ref ComplianceSerializationDescription <T> description, ref T inputObject, byte[] blob, int startIndex, int width, ComplianceSerializer.FixedWidthType widthType, int totalFields) where T : class, new() { byte b = Convert.ToByte(totalFields); blob[startIndex] = b; int num = startIndex + 1; for (byte b2 = 0; b2 < b; b2 += 1) { switch (widthType) { case ComplianceSerializer.FixedWidthType.Byte: { byte b3 = 0; description.TryGetByteProperty(inputObject, b2, out b3); blob[num] = b3; break; } case ComplianceSerializer.FixedWidthType.Short: { short shortValue = 0; description.TryGetShortProperty(inputObject, b2, out shortValue); ComplianceSerializer.WriteShortToBlob(blob, num, shortValue); break; } case ComplianceSerializer.FixedWidthType.Int: { int intValue = 0; description.TryGetIntegerProperty(inputObject, b2, out intValue); ComplianceSerializer.WriteIntToBlob(blob, num, intValue); break; } case ComplianceSerializer.FixedWidthType.Long: { long longValue = 0L; description.TryGetLongProperty(inputObject, b2, out longValue); ComplianceSerializer.WriteLongToBlob(blob, num, longValue); break; } case ComplianceSerializer.FixedWidthType.Double: { double doubleValue = 0.0; description.TryGetDoubleProperty(inputObject, b2, out doubleValue); ComplianceSerializer.WriteDoubleToBlob(blob, num, doubleValue); break; } case ComplianceSerializer.FixedWidthType.Guid: { Guid empty = Guid.Empty; description.TryGetGuidProperty(inputObject, b2, out empty); ComplianceSerializer.WriteGuidToBlob(blob, num, empty); break; } default: throw new ArgumentException("widthType"); } num += width; } return(num); }