public override object OnRead(ByteObjectReader reader, Type defaultItemType) { var structType = reader.Type(defaultItemType); var rule = ByteUtils.GetRule(structType); if (rule != null) return rule.OnReadInternal(reader); var obj = Activator.CreateInstance(structType); //todo var fields = usedFields.GetUnical(structType); if (fields == null) fields = ByteUtils.GetSerializeFields(structType); var fieldCount = reader.Ushort(); for (int i = 0; i < fieldCount; i++) { var fieldName = reader.String(); var value = reader.Complex(null); var field = fields.FirstOrDefault(x => x.Name == fieldName); if (field != null) { field.SetValue(obj, value); } } return obj; }
public override object OnRead(ByteObjectReader reader, Type defaultItemType) { var itemType = reader.Type(defaultItemType); var length = reader.Int(); var array = Array.CreateInstance(itemType, length); for (int i = 0; i < length; i++) { var item = reader.Complex(itemType); array.SetValue(item, i); } return array; }
public override object OnRead(ByteObjectReader reader, Type defaultItemType) { var itemType = reader.Type(defaultItemType); var rank = reader.Int(); var lengths = new int[rank]; for (int i = 0; i < rank; i++) lengths[i] = reader.Int(); var array = Array.CreateInstance(itemType, lengths); var indexes = new int[rank]; DimensionalReadResoursy(reader, array, itemType, 0, indexes); return array; }
public override object OnRead(ByteObjectReader reader, Type defaultItemType) { var type = reader.Byte(); if (type == IsDefinition) { var handleIndex = reader.position - sizeof(byte); var classType = reader.Type(defaultItemType); var rule = ByteUtils.GetRule(classType); if (rule != null) { return rule.OnReadInternal(reader); } else { var obj = Activator.CreateInstance(classType); //todo reader.classHashtable[handleIndex] = obj; var fields = usedFields.GetUnical(classType); if (fields == null) fields = ByteUtils.GetSerializeFields(classType); var fieldCount = reader.Ushort(); for (int i = 0; i < fieldCount; i++) { var fieldName = reader.String(); var value = reader.Complex(null); var field = fields.FirstOrDefault(x => x.Name == fieldName); if (field != null) { field.SetValue(obj, value); } } return obj; } } if (type == IsGoto) { var handleIndex = reader.Int(); return reader.classHashtable[handleIndex]; } throw new Exception("Wtf?"); }