示例#1
0
 public override void DeSerialize(DataReader data)
 {
     propertyType = typeStr2PropertyType(mType.type);
     if (propertyType == SerializePropertyType.Property)
     {
         var children = mType.GetChildren();
         foreach (var child in children)
         {
             SerializeProperty childProperty = new SerializeProperty(child);
             childProperty.DeSerialize(data);
             this.AddChild(childProperty);
         }
     }
     else if (propertyType == SerializePropertyType.Array)
     {
         value = readArrayValue(mType, data);
     }
     else
     {
         value = readValue(propertyType, mType, data);
     }
 }
示例#2
0
        public object readArrayValue(TypeTree typeTree, DataReader data)
        {
            var elementType = typeTree.GetChildren()[1];

            arrayLength      = data.ReadInt32();
            arrayElementType = typeStr2PropertyType(elementType.type);
            object ret = null;

            switch (arrayElementType)
            {
            case SerializePropertyType.Bool:
                ret = data.ReadBool(arrayLength);
                break;

            case SerializePropertyType.Byte:
                ret = data.ReadBytes(arrayLength);
                break;

            case SerializePropertyType.Double:
                ret = data.ReadDouble(arrayLength);
                break;

            case SerializePropertyType.Float:
                ret = data.ReadFloat(arrayLength);
                break;

            case SerializePropertyType.Int:
                ret = data.ReadInt32(arrayLength);
                break;

            case SerializePropertyType.Long:
                ret = data.ReadInt64(arrayLength);
                break;

            case SerializePropertyType.SByte:
                ret = data.ReadSbytes(arrayLength);
                break;

            case SerializePropertyType.Short:
                ret = data.ReadInt16(arrayLength);
                break;

            case SerializePropertyType.String:
                string[] stringArray = new string[arrayLength];
                for (int i = 0; i < arrayLength; i++)
                {
                    int strSize = data.ReadInt32();
                    stringArray[i] = UnicodeEncoding.UTF8.GetString(data.ReadBytes(strSize));
                    data.Align(4);
                }
                ret = stringArray;
                break;

            case SerializePropertyType.UInt:
                ret = data.ReadUint32(arrayLength);
                break;

            case SerializePropertyType.ULong:
                ret = data.ReadUInt64(arrayLength);
                break;

            case SerializePropertyType.UShort:
                ret = data.ReadUInt16(arrayLength);
                break;

            default:
                SerializeProperty[] properArray = new SerializeProperty[arrayLength];
                for (int i = 0; i < arrayLength; i++)
                {
                    SerializeProperty value = null;
                    if (arrayElementType == SerializePropertyType.Property || arrayElementType == SerializePropertyType.Array)
                    {
                        var sp = new SerializeProperty(elementType);
                        sp.DeSerialize(data);
                        value = sp;
                    }
                    properArray[i] = value;
                }
                ret = properArray;
                break;
            }

            data.Align(4);
            return(ret);
        }
        public object readArrayValue(TypeTree typeTree, DataReader data)
        {            
            var elementType = typeTree.GetChildren()[1];
            arrayLength = data.ReadInt32();
            arrayElementType = typeStr2PropertyType(elementType.type);
            object ret = null;
            switch (arrayElementType) {
                case SerializePropertyType.Bool:
                ret = data.ReadBool(arrayLength);
                break;
                case SerializePropertyType.Byte:
                ret = data.ReadBytes(arrayLength);
                break;
                case SerializePropertyType.Double:
                ret = data.ReadDouble(arrayLength);
                break;
                case SerializePropertyType.Float:
                ret = data.ReadFloat(arrayLength);
                break;
                case SerializePropertyType.Int:
                ret = data.ReadInt32(arrayLength);
                break;
                case SerializePropertyType.Long:
                ret = data.ReadInt64(arrayLength);
                break;
                case SerializePropertyType.SByte:
                ret = data.ReadSbytes(arrayLength);
                break;
                case SerializePropertyType.Short:
                ret = data.ReadInt16(arrayLength);
                break;
                case SerializePropertyType.String:
                string[] stringArray = new string[arrayLength];
                for (int i = 0; i < arrayLength; i++) {
                    int strSize = data.ReadInt32();
                    stringArray[i] = UnicodeEncoding.UTF8.GetString(data.ReadBytes(strSize));
                    data.Align(4);
                }
                ret = stringArray;
                break;
                case SerializePropertyType.UInt:
                ret = data.ReadUint32(arrayLength);
                break;
                case SerializePropertyType.ULong:
                ret = data.ReadUInt64(arrayLength);
                break;
                case SerializePropertyType.UShort:
                ret = data.ReadUInt16(arrayLength);
                break;
                default:
                SerializeProperty[] properArray = new SerializeProperty[arrayLength];
                for (int i = 0; i < arrayLength; i++) {
                    SerializeProperty value = null;
                    if (arrayElementType == SerializePropertyType.Property || arrayElementType == SerializePropertyType.Array) {
                        var sp = new SerializeProperty(elementType);
                        sp.DeSerialize(data);
                        value = sp;
                    }
                    properArray[i] = value;
                }
                ret = properArray;
                break;
            }

            data.Align(4);
            return ret;
        }