public async Task <SLComponent> LoadAsync(SLComponent root, string name) { var path = $"{name}.slc"; if (!File.Exists(path)) { return(null); } using (var fs = File.OpenRead(path)) { var buffer = Library.Locator.BufferPool.GetBuffer(1 << 16); Library.Logger.Assert(buffer.Length >= fs.Length, "overflow buffer"); var n = await fs.ReadAsync(buffer, 0, (int)fs.Length); if (n == 0) { return(null); } var reader = new Library.Reader(buffer, n); var com = Serialization.ReadComponent(ref reader); defaultLink(root, com); return(com); } }
public void OnDeserialized(ref Library.Reader reader, SLComponent streamingComponent) { var read = reader.ReadInt(out int t); type = (PointerType)t; if (type == PointerType.Text) { read &= reader.ReadString(out string text); this = SLPointer.Text(text); } }
public static SLComponent ReadComponent(ref Library.Reader reader) { var read = reader.ReadInt(out int comCount); if (!read) { return(null); } var fakeRoot = SLComponent.Factory.Create(null, ComponentType.Root); var comList = new List <SLComponent>(comCount); for (int i = 0; i != comCount; i++) { read &= reader.ReadInt(out int comType); read &= reader.ReadInt(out int fakeIndex); if (!read) { return(null); } var com = SLComponent.Factory.Create(fakeRoot, (ComponentType)comType, fakeIndex); comList.Add(com); } for (int i = 0; i != comList.Count; i++) { comList[i].OnDeserialized(ref reader, fakeRoot); } read &= reader.ReadInt(out int ctxCount); if (!read) { return(null); } if (ctxCount > 0) { var stream = reader.GetStream(); var ctxList = Library.SerializeHelper.DeserializeFromMemory(stream) as Dictionary <int, object>; var ctxIter = ctxList.GetEnumerator(); while (ctxIter.MoveNext()) { var com3 = fakeRoot.Find(ctxIter.Current.Key).First(); com3.Context = ctxIter.Current.Value; } } SLComponent.Factory.Destroy(null, fakeRoot); return(comList[0]); }
public void OnDeserialized(ref Library.Reader reader, SLComponent streamingComponent) { var read = true; read &= reader.ReadInt(out int groupCount); Library.Logger.Assert(read, "[OnDeserialized] fail to read component: linkedCount"); for (int i = 0; i != groupCount; i++) { var ptr = new SLPointer(); ptr.OnDeserialized(ref reader, null); read &= reader.ReadInt(out int childCount); Library.Logger.Assert(read, "[OnDeserialized] fail to read component: type|value|rootFakeIndex|childCount"); var wrapper = new SLWrapper(); for (int k = 0; k != childCount; k++) { read &= reader.ReadInt(out int fakeIndex); Library.Logger.Assert(read, "[OnDeserialized] fail to read component: fakeIndex"); var child = streamingComponent.Find(fakeIndex); wrapper.Add(child.First()); } _groups.Add(ptr, wrapper); } read &= reader.ReadInt(out int propCount); Library.Logger.Assert(read, "[OnDeserialized] fail to read component: propCount"); for (int i = 0; i != propCount; i++) { read &= reader.ReadInt(out int propIndex); read &= reader.ReadInt(out int propSize); Library.Logger.Assert(read, "[OnDeserialized] fail to read component: propIndex|propSize"); var propType = Property.PropertyAttribute.GetProperty(propIndex); unsafe { var propPtr = this.Get(propType); reader.ReadMemory((void *)propPtr, propSize); } } }