Read structs recursively on get struct size and build struct from bytes.

This commit is contained in:
Marcos Pereira
2016-03-09 14:30:20 +00:00
parent d3f5a8d099
commit 3e877cad7c

View File

@@ -49,6 +49,9 @@ namespace S7.Net.Types
numBytes++;
numBytes += 4;
break;
default:
numBytes += GetStructSize(info.FieldType);
break;
}
}
return (int)numBytes;
@@ -146,6 +149,14 @@ namespace S7.Net.Types
bytes[(int)numBytes + 3] }));
numBytes += 4;
break;
default:
var buffer = new byte[GetStructSize(info.FieldType)];
if (buffer.Length == 0)
continue;
Buffer.BlockCopy(bytes, (int)Math.Ceiling(numBytes), buffer, 0, buffer.Length);
info.SetValue(structValue, FromBytes(info.FieldType, buffer));
numBytes += buffer.Length;
break;
}
}
return structValue;