private object ReadField(IDataReader reader, D2oFieldDefinition field, D2oFieldType typeId, int vectorDimension = 0) { 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)); } }
private void WriteFieldVector(IDataWriter writer, D2oFieldDefinition field, IList list, int vectorDimension) { writer.WriteInt(list.Count); for (var i = 0; i < list.Count; i++) { WriteField(writer, field, field.VectorTypes[vectorDimension], ++vectorDimension); } }
private object ReadFieldVector(IDataReader reader, D2oFieldDefinition field, int vectorDimension) { var count = reader.ReadInt(); var vectorType = field.FieldType; for (var 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)) { var creator = CreateObjectBuilder(vectorType); ObjectCreators.Add(vectorType, creator); } } var result = ObjectCreators[vectorType](new object[0]) as IList; for (var i = 0; i < count; i++) { vectorDimension++; try { var obj = ReadField(reader, field, field.VectorTypes[vectorDimension - 1].Item1, vectorDimension); result.Add(obj); } catch { } vectorDimension--; } return(result); }
private void WriteField(IDataWriter writer, D2oFieldDefinition field, dynamic obj, int vectorDimension = 0) { switch (field.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, obj); break; case D2oFieldType.UInt: WriteFieldUInt(writer, (uint)obj); break; case D2oFieldType.List: WriteFieldVector(writer, field, obj, vectorDimension); break; default: WriteFieldObject(writer, obj); break; } }