private object ReadFieldVector(IDataReader reader, D2oFieldDefinition field, int vectorDimension)
        {
            int count = reader.ReadInt();

            Type vectorType = field.FieldType;

            for (int i = 0; i < vectorDimension; i++)
            {
                vectorType = vectorType.GetGenericArguments()[0];
            }

            lock (objectCreators) // We sometimes have error on objectCreators.Add(vectorType, creator) : mainlock allready in the dictionary
                if (!objectCreators.ContainsKey(vectorType))
                {
                    Func <object[], object> creator = CreateObjectBuilder(vectorType, new FieldInfo[0]);

                    objectCreators.Add(vectorType, creator);
                }

            var result = objectCreators[vectorType](new object[0]) as IList;

            for (int i = 0; i < count; i++)
            {
                vectorDimension++;
                // i didn't found a way to have thez correct dimension so i just add "- 1"
                result.Add(ReadField(reader, field, field.VectorTypes[vectorDimension - 1].Item1, vectorDimension));
                vectorDimension--;
            }

            return(result);
        }
Esempio n. 2
0
        private void WriteFieldVector(BigEndianWriter writer, D2oFieldDefinition field, IList list, int vectorDimension)
        {
            writer.WriteInt(list.Count);

            for (int i = 0; i < list.Count; i++)
            {
                vectorDimension++;
                WriteField(writer, field, field.VectorTypes[vectorDimension - 1].Item1, list[i], vectorDimension);
                vectorDimension--;
            }
        }
        private object ReadField(IDataReader reader, D2oFieldDefinition field, D2oFieldType typeId,
                                 int vectorDimension = 0)
        {
            try
            {
                switch (typeId)
                {
                case D2oFieldType.Int:
                    return(ReadFieldInt(reader));

                case D2oFieldType.Bool:
                    return(ReadFieldBool(reader));

                case D2oFieldType.String:
                    return(ReadFieldUTF(reader));

                case D2oFieldType.Double:
                    return(ReadFieldDouble(reader));

                case D2oFieldType.I18N:
                    return(ReadFieldI18n(reader));

                case D2oFieldType.UInt:
                    return(ReadFieldUInt(reader));

                case D2oFieldType.List:
                    return(ReadFieldVector(reader, field, vectorDimension));

                default:
                    return(ReadFieldObject(reader));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(string.Format("[D2O] Can't read field {0} for exception {1}.", field.Name, ex.Message));
                return(null);
            }
        }
Esempio n. 4
0
        private void WriteField(BigEndianWriter writer, D2oFieldDefinition field, D2oFieldType typeId, dynamic obj, int vectorDimension = 0)
        {
            switch (typeId)
            {
            case D2oFieldType.Int:
                WriteFieldInt(writer, (int)obj);
                break;

            case D2oFieldType.Bool:
                WriteFieldBool(writer, obj);
                break;

            case D2oFieldType.String:
                WriteFieldUTF(writer, obj);
                break;

            case D2oFieldType.Double:
                WriteFieldDouble(writer, obj);
                break;

            case D2oFieldType.I18N:
                WriteFieldI18n(writer, (int)obj);
                break;

            case D2oFieldType.UInt:
                WriteFieldUInt(writer, (uint)obj);
                break;

            case D2oFieldType.List:
                WriteFieldVector(writer, field, obj, vectorDimension);
                break;

            default:
                WriteFieldObject(writer, obj);
                break;
            }
        }