fastJSON反序列化列表(fastJSON Deserialization List)
所以,从我之前的一个问题开始, 我正在尝试保存一个蓝图,这只是一堆游戏对象/实体的设置。 我现在将组件(及其设置)存储为List <IEntityComponent>(IEntityComponent是任何组件的接口),包含在名为ComponentTable的类中。 我只想序列化这个列表,并且所有私有的东西都不是序列化的,只是为了加快查找速度(以内存为代价)。 这序列化正确,甚至反序列化没有任何错误,但我注意到componentTable不正确反序列化。
它创建了ComponentTable的实例,但实际上从未向其添加值。 因此,它不是包含CameraComponent,VelocityComponent和InputComponent的Component表,而只是一个空的ComponentTable。
{ "$types" : { "ECS.Framework.Collections.Blueprint, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" : "1", "ECS.Features.Core.CameraComponent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" : "2", "ECS.Features.Core.VelocityComponent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" : "3", "InputComponent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" : "4" }, "$type" : "1", "Components" : [ { "$type" : "2", "Tag" : "MainCamera", "Test" : "0, 0, 0", "BackgroundColour" : "0, 0, 1, 1", "ViewportRect" : "10, 10 : 10, 10", "Orthographic" : false, "FieldOfView" : 60, "OrthoSize" : 5, "Depth" : 0, "OcclusionCulling" : true, "HDR" : false, "Enabled" : true }, { "$type" : "3", "Enabled" : true, "CurrentVelocity" : "0, 0, 0" }, { "$type" : "4", "TEST" : 0, "Enabled" : true } ], "Children" : [ ], "Parent" : "" }
这是它如何保存,所以它看起来像是正确保存。 我只控制向量,矩形和颜色的序列化/序列化,因为任何单值类型都会导致错误。
我相信它是正确的序列化,但由于某种原因它不会反序列化为componentTable。 有谁知道fastJSON是否有这种继承的问题(让一个类继承List <customClass>?
理想情况下,我希望它继承为Dictionary <Type,IEntityComponent>,但fastJSON不会序列化Type,只是将其保存为'System.Mono',然后在序列化时导致错误。
编辑:这里是蓝图和组件表类
public sealed class Blueprint { public ComponentTable Components { get; private set; } public List<string> Children { get; set; } public string Parent { get; set; } public Blueprint() { Components = new ComponentTable(); Children = new List<string>(); Parent = ""; } public Blueprint(Blueprint _blueprint) { Children = new List<string>(_blueprint.Children); Parent = _blueprint.Parent; } } public class ComponentTable : List<IEntityComponent> { private Dictionary<Type, IEntityComponent> Components { get; set; } #region Constructors public ComponentTable() { Components = new Dictionary<Type, IEntityComponent>(); } #endregion #region Base Function Overrides public void Add(Type _type) { if (Components.ContainsKey(_type)) return; InternalAdd(_type, (IEntityComponent)Activator.CreateInstance(_type)); } public new void Add(IEntityComponent _component) { InternalAdd(_component.GetType(), _component); } public void Add<T>() where T : IEntityComponent { Add(typeof(T)); } private void InternalAdd(Type _type, IEntityComponent _component) { if (Components.ContainsKey(_type)) throw new InvalidOperationException("Component already contained"); Components.Add(_type, _component); base.Add(_component); } public bool Remove(Type _type) { if (Components.ContainsKey(_type)) return InternalRemove(_type, Components[_type]); return false; } public new bool Remove(IEntityComponent _component) { return InternalRemove(_component.GetType(), _component); } public bool Remove<T>() where T : IEntityComponent { return Remove(typeof(T)); } private bool InternalRemove(Type _type, IEntityComponent _component) { if (!Components.ContainsKey(_type)) return false; Components.Remove(_type); return base.Remove(_component); } public IEntityComponent Get(Type _type) { if (Contains(_type)) return Components[_type]; return null; } public T Get<T>() where T : IEntityComponent { return (T)Get(typeof(T)); } public bool TryGetValue(Type _type, out IEntityComponent _component) { return Components.TryGetValue(_type, out _component); } public bool TryGetValue<T>(out IEntityComponent _component) where T : IEntityComponent { return TryGetValue(typeof(T), out _component); } public bool Contains(Type _type) { return Components.ContainsKey(_type); } public new bool Contains(IEntityComponent _component) { return Contains(_component.GetType()); } public bool Contains<T>() where T : IEntityComponent { return Contains(typeof(T)); } #endregion }
So sort of a build on from a previous question of mine. I am trying to save a blueprint, which is just a heap of settings for a gameobject/Entity. I'm now storing the components (And their settings) as a List < IEntityComponent > (IEntityComponent is the interface for any component) wrapped in a class called ComponentTable. I only want to serialize the list, and all the private stuff is not serialized, and is just for faster look ups (At the price of memory). This serializes properly and even deserializes without any errors, but i noticed the componentTable isn't deserializing PROPERLY.
It creates an instance of ComponentTable, but never actually adds the values to it. So instead of a Component table containing CameraComponent, VelocityComponent and InputComponent, it just just an empty ComponentTable.
{ "$types" : { "ECS.Framework.Collections.Blueprint, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" : "1", "ECS.Features.Core.CameraComponent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" : "2", "ECS.Features.Core.VelocityComponent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" : "3", "InputComponent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" : "4" }, "$type" : "1", "Components" : [ { "$type" : "2", "Tag" : "MainCamera", "Test" : "0, 0, 0", "BackgroundColour" : "0, 0, 1, 1", "ViewportRect" : "10, 10 : 10, 10", "Orthographic" : false, "FieldOfView" : 60, "OrthoSize" : 5, "Depth" : 0, "OcclusionCulling" : true, "HDR" : false, "Enabled" : true }, { "$type" : "3", "Enabled" : true, "CurrentVelocity" : "0, 0, 0" }, { "$type" : "4", "TEST" : 0, "Enabled" : true } ], "Children" : [ ], "Parent" : "" }
This is how it saves, so it seems like it is saving correctly. I am only controlling the serialization/serialization of the Vectors, Rect and colors, as any unity value types cause errors.
I believe it is serializing properly, but for some reason it is not deserializing into the componentTable. Does anyone know if fastJSON has problems with this kind of inheritance (Making a class inherit from a List< customClass >?
Ideally i would have it inherit as a Dictionary< Type, IEntityComponent >, but fastJSON wont serialize the Type, just saves it as 'System.Mono' then causes an error when serializing.
Edit: Here are the blueprint and component Table classes
public sealed class Blueprint { public ComponentTable Components { get; private set; } public List<string> Children { get; set; } public string Parent { get; set; } public Blueprint() { Components = new ComponentTable(); Children = new List<string>(); Parent = ""; } public Blueprint(Blueprint _blueprint) { Children = new List<string>(_blueprint.Children); Parent = _blueprint.Parent; } } public class ComponentTable : List<IEntityComponent> { private Dictionary<Type, IEntityComponent> Components { get; set; } #region Constructors public ComponentTable() { Components = new Dictionary<Type, IEntityComponent>(); } #endregion #region Base Function Overrides public void Add(Type _type) { if (Components.ContainsKey(_type)) return; InternalAdd(_type, (IEntityComponent)Activator.CreateInstance(_type)); } public new void Add(IEntityComponent _component) { InternalAdd(_component.GetType(), _component); } public void Add<T>() where T : IEntityComponent { Add(typeof(T)); } private void InternalAdd(Type _type, IEntityComponent _component) { if (Components.ContainsKey(_type)) throw new InvalidOperationException("Component already contained"); Components.Add(_type, _component); base.Add(_component); } public bool Remove(Type _type) { if (Components.ContainsKey(_type)) return InternalRemove(_type, Components[_type]); return false; } public new bool Remove(IEntityComponent _component) { return InternalRemove(_component.GetType(), _component); } public bool Remove<T>() where T : IEntityComponent { return Remove(typeof(T)); } private bool InternalRemove(Type _type, IEntityComponent _component) { if (!Components.ContainsKey(_type)) return false; Components.Remove(_type); return base.Remove(_component); } public IEntityComponent Get(Type _type) { if (Contains(_type)) return Components[_type]; return null; } public T Get<T>() where T : IEntityComponent { return (T)Get(typeof(T)); } public bool TryGetValue(Type _type, out IEntityComponent _component) { return Components.TryGetValue(_type, out _component); } public bool TryGetValue<T>(out IEntityComponent _component) where T : IEntityComponent { return TryGetValue(typeof(T), out _component); } public bool Contains(Type _type) { return Components.ContainsKey(_type); } public new bool Contains(IEntityComponent _component) { return Contains(_component.GetType()); } public bool Contains<T>() where T : IEntityComponent { return Contains(typeof(T)); } #endregion }
原文:https://stackoverflow.com/questions/34707871
最满意答案
看起来你需要执行以下操作来刷新缓存 - 使用Olap包装器类打开lookupMember函数返回的成员对象,如下所示 -
m = cube.lookupMember(IdentifierNode.parseIdentifier(“[Time]。[2013]。[Jul2013]”)。getSegmentList()); OlapWrapper wrapper =(OlapWrapper)m; mondrian.olap.Member MondrianMember = wrapper.unwrap(mondrian.olap.Member.class);
现在调用flush方法 -
cacheControl.flush(MondrianMember);
Looks like you need to do the following to flush the cache - unwrap the member object returned by lookupMember function using Olap wrapper class like so -
m = cube.lookupMember(IdentifierNode.parseIdentifier( "[Time].[2013].[Jul2013]").getSegmentList()); OlapWrapper wrapper = (OlapWrapper)m; mondrian.olap.Member MondrianMember = wrapper.unwrap(mondrian.olap.Member.class);
And now call the flush method -
cacheControl.flush(MondrianMember);
相关问答
更多-
这是可配置的。 从ARMv8体系结构参考手册 ,第D3-1988页: EL0可访问缓存维护说明 SCTLR_EL1.UCI位使能DC0 DC CVAU , DC CVAC , DC CVAP , DC CIVAC和IC IVAU指令的IC IVAU 。 当EL0使用这些指令因SCTLR_EL1.UCI == 0被禁用时,在EL0执行这些指令之一会产生一个陷阱到EL1,使用EC = 0x18报告。 对于这些说明,需要读取访问权限。 当SCTLR_EL1.UCI值为1时: 对于DC CVAU , DC CVAC ...
-
这是我找到的问题的解决方案。
-
在默认设置下,您的会话将存储在默认数据库连接中名为“会话”的表中 摧毁它 Below is the correct way to persist the new data in old session: Session::forget('member'); Session::flush(); Session::save(); // trigger save to old session Session::regenerate(true); // pass true to regenerate would ...
-
我不认为你在谈论查询缓存而是关于缓冲区缓存 。 查询缓存是最新SQL语句的缓存,它们永远不会刷新到磁盘。 刷新缓冲区缓存并不像刷新缓冲区日志那么重要。 日志会跟踪数据库中数据的更新执行情况。 它用于在发生故障时恢复数据库,即缓冲区高速缓存未刷新到磁盘时。 在InnoDB中有3种主要方法来刷新bufferer日志,并使用参数innodb_flush_log_at_trx_commit控制它们。 MySQL文档引用: “如果发生崩溃,你可以负担丢失一些最新提交的事务,你可以将innodb_flush_log_a ...
-
TJ - 我的赌注是你的实体永远不会在缓存中开始。 你查询了一些东西(使用了投影/选择?),它返回了你可以使用的数据......但不是Breeze可以缓存的实体。 我相信这就是PW Kad所暗示的。 你可否确认? TJ - my bet is that your entities were never in cache to begin with. You queried something perhaps (used a projection/select?) which returned data yo ...
-
蒙德里安从事实中发现维度(Mondrian find dimension from facts)[2023-10-28]
非空将做你的工作: select non empty {[Date].[Calendar].[Year].Members, [Date].[Calendar].[Quarter].Members, [Date].[Calendar].[Month].Members} * [Store].[Store].[Store].Members * [Measures].[Visits] on 0 from [YourCube] Non Empty will do your work: select non em ... -
愚蠢的我,我再次阅读文档,并明确说明(编辑): fsync()将...文件描述符fd引用的文件的所有已修改的核心内数据传输到磁盘设备...以便即使在系统崩溃后也可以检索所有已更改的信息... 这包括通过写入或刷新磁盘高速缓存(如果存在)。 Silly me, I read the documentation once again and it clearly states (redacted): fsync() transfers ... all modified in-core data of ... t ...
-
最后我自己找到了解决方案。 要定义要使用的数据库模式,我将属性模式添加到标记Table,如下所示: