예제 #1
0
        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;
        }
예제 #2
0
        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?");
        }
예제 #3
0
 public override object OnRead(ByteObjectReader reader, Type defaultItemType)
 {
     return reader.Ushort();
 }