private static ScriptObject ReadObject(Script script, ScorpioReader reader, string type, bool hasSign, Invalid invalid) { object value = ReadField(reader, type); if (value != null) { invalid.value = TableUtil.IsInvalid(value); return(script.CreateObject(value)); } else { ScriptTable ret = Read(script, reader, type, hasSign); invalid.value = (bool)ret.GetValue("IsInvalid").ObjectValue; return(ret); } }
private static ScriptObject ReadObject(Script script, ScorpioReader reader, ScriptTable tableManager, string fileName, string type, bool message, Invalid invalid) { object value = ReadField(reader, type); if (value != null) { invalid.value = TableUtil.IsInvalid(value); return(script.CreateObject(value)); } else { ScriptTable ret = Read(script, reader, tableManager, fileName, type, message); if (!message) { invalid.value = ret.GetValue("IsInvalid").LogicOperation(); } return(ret); } }
public static ScriptTable Read(Script script, ScorpioReader reader, string tableName, bool hasSign) { ScriptTable table = script.CreateTable(); ScriptArray layout = (ScriptArray)script.GetValue(tableName); bool isInvalid = true; int sign = hasSign ? reader.ReadInt32() : 0; for (int i = 0; i < layout.Count(); ++i) { ScriptObject config = layout.GetValue(i); if (!hasSign || ScorpioUtil.HasSign(sign, ScorpioUtil.ToInt32(config.GetValue(Index).ObjectValue))) { string name = (string)config.GetValue(Name).ObjectValue; string type = (string)config.GetValue(Type).ObjectValue; bool array = (bool)config.GetValue(Array).ObjectValue; Invalid invalid = new Invalid(); if (array) { int count = reader.ReadInt32(); ScriptArray value = script.CreateArray(); for (int j = 0; j < count; ++j) { value.Add(ReadObject(script, reader, type, hasSign, invalid)); } table.SetValue(name, value); if (count > 0) { isInvalid = false; } } else { table.SetValue(name, ReadObject(script, reader, type, hasSign, invalid)); if (!invalid.value) { isInvalid = false; } } } } table.SetValue("IsInvalid", script.CreateBool(isInvalid)); return(table); }
//读取excel文件数据内容 public static ScriptTable ReadDatas(Script script, ScriptTable tableManager, string fileName, string layoutTableName, string keyName, string MD5) { ScriptTable ret = script.CreateTable(); ScorpioReader reader = new ScorpioReader(TableUtil.GetBuffer(fileName)); int iRow = TableUtil.ReadHead(reader, fileName, MD5); ScriptTable data = null; double key = 0; for (int i = 0; i < iRow; ++i) { data = ScorpioSerializer.Read(script, reader, tableManager, fileName, layoutTableName, false); key = ScorpioUtil.ToDouble(data.GetValue(keyName).ObjectValue); if (ret.HasValue(key)) { throw new System.Exception("文件[" + fileName + "]有重复项 ID : " + key); } ret.SetValue(key, data); data.SetValue("ID", script.CreateDouble(key)); } return(ret); }
private static object ReadField(ScorpioReader reader, string type) { if (type == BoolType) { return(reader.ReadBool()); } else if (type == Int8Type) { return(reader.ReadInt8()); } else if (type == Int16Type) { return(reader.ReadInt16()); } else if (type == Int32Type || type == IntType) { return(reader.ReadInt32()); } else if (type == Int64Type) { return(reader.ReadInt64()); } else if (type == FloatType) { return(reader.ReadFloat()); } else if (type == DoubleType) { return(reader.ReadDouble()); } else if (type == StringType) { return(reader.ReadString()); } else if (type == BytesType) { return(reader.ReadBytes()); } return(null); }
/// <summary> /// 读取一个网络协议或者一行table数据 /// </summary> /// <param name="script">脚本引擎对象</param> /// <param name="reader">读取类</param> /// <param name="tableManager">tableManager类</param> /// <param name="fileName">table用文件名字</param> /// <param name="layoutTableName">结构名字</param> /// <param name="message">是否是网络协议</param> private static ScriptTable Read(Script script, ScorpioReader reader, ScriptTable tableManager, string fileName, string layoutTableName, bool message) { ScriptTable table = script.CreateTable(); ScriptArray layout = (ScriptArray)script.GetValue(layoutTableName); int sign = message ? reader.ReadInt32() : 0; bool isInvalid = true; string id = null; for (int i = 0; i < layout.Count(); ++i) { ScriptObject config = layout.GetValue(i); if (message && !ScorpioUtil.HasSign(sign, ScorpioUtil.ToInt32(config.GetValue(Index).ObjectValue))) { continue; } string name = config.GetValue(Name).ToString(); //字段名字 string type = config.GetValue(Type).ToString(); //字段类型 bool array = config.GetValue(Array).LogicOperation(); //是否是数组 Invalid invalid = new Invalid(); //本行是否是无效行 if (array) { int count = reader.ReadInt32(); //读取元素个数 ScriptArray value = script.CreateArray(); for (int j = 0; j < count; ++j) { value.Add(ReadObject(script, reader, tableManager, fileName, type, message, invalid)); } table.SetValue(name, value); if (count > 0) { isInvalid = false; } } else { if (message) { table.SetValue(name, ReadObject(script, reader, tableManager, fileName, type, message, invalid)); } else { ScriptTable attribute = config.GetValue(Attribute) as ScriptTable; if (attribute.Count() == 0) { var obj = ReadObject(script, reader, tableManager, fileName, type, message, invalid); table.SetValue(name, obj); if (!invalid.value) { isInvalid = false; } if (string.IsNullOrEmpty(id)) { id = ScorpioUtil.ToInt32(obj.ObjectValue).ToString(); } } else { ReadObject(script, reader, tableManager, fileName, type, message, invalid); //先读取一个值 如果是多国语言 生成数据的时候会写入一个空字符串 table.SetValue(name, script.CreateObject(tableManager.GetValue("getValue").call(attribute, fileName, name, id))); } } } } if (!message) { table.SetValue("IsInvalid", script.CreateBool(isInvalid)); } return(table); }