public RadixTree(INodeStorage nodeStorage, IValueStorage <TValue> valueStorage, ISerializer <TKey> keySerializer, int maxPrefixLength) { _nodeStorage = nodeStorage; _valueStorage = valueStorage; _keySerializer = keySerializer; MaxPrefixLength = maxPrefixLength; }
public override void Read(ref T targetObject, IValueStorage sourceObject) { VerifySerializationSanity(); if (sourceObject == null) { Debug.LogError($"Field for {typeof(T)} does not exist"); return; } ValueStorage <T> storage = sourceObject as ValueStorage <T>; if (storage == null) { Debug.LogError($"Type {typeof(T)} not compatible with serializer {sourceObject}"); return; } if (UsbSerializationContext.CollectDependencies) { return; } targetObject = storage.Value; }
public void Read(ref object targetObject, IValueStorage sourceObject) { T targetT = (T)targetObject; Read(ref targetT, sourceObject); targetObject = targetT; }
public override void Write(IValueStorage targetObject, T sourceObject) { UdonBehaviourHeapData heapStorage = UdonSharpBehaviourFormatterManager.GetHeapData(UdonSharpEditorUtility.GetBackingUdonBehaviour(sourceObject)); if (heapStorage != null) { writeDelegate(heapStorage.heapFieldValues, ref sourceObject, EditorApplication.isPlaying); } }
public override void ReadWeak(ref object targetObject, IValueStorage sourceObject) { VerifySerializationSanity(); //if (sourceObject != null && !UdonSharpUtils.IsUserJaggedArray(sourceObject.GetType())) // throw new SerializationException($"Cannot convert {targetObject.GetType()} to {typeMetadata.cSharpType}"); ConvertToCSharpArrayElement(ref targetObject, sourceObject.Value, typeMetadata.cSharpType); }
public override void Read(ref T targetObject, IValueStorage sourceObject) { UdonBehaviourHeapData heapStorage = UdonSharpBehaviourFormatterManager.GetHeapData((UdonBehaviour)sourceObject.Value); if (heapStorage != null) { readDelegate(heapStorage.heapFieldValues, ref targetObject, EditorApplication.isPlaying && !UsbSerializationContext.CurrentPolicy.IsPreBuildSerialize); } }
public override void Read(ref T targetObject, IValueStorage sourceObject) { UdonBehaviourHeapData heapStorage = UdonSharpBehaviourFormatterManager.GetHeapData((UdonBehaviour)sourceObject.Value); if (heapStorage != null) { readDelegate(heapStorage.heapFieldValues, ref targetObject, EditorApplication.isPlaying); } }
public void IntegerValueStorage_Add_AddsAmountWithoutCommodityAndChangesToAmount() { IntegerValueStorage storage1 = new IntegerValueStorage(100); AmountValueStorage storage2 = new AmountValueStorage(new Amount(200)); IValueStorage result = storage1.Add(storage2); Assert.Equal(300, result.AsLong); Assert.Equal(ValueTypeEnum.Amount, result.Type); }
internal bool IsEqualTo(IValueStorage valueStorage) { if (Storage == null) { return(valueStorage == null); } else { return(Storage.IsEqualTo(valueStorage)); } }
internal bool IsGreaterThan(IValueStorage valueStorage) { if (Storage == null) { return(false); } else { return(Storage.IsGreaterThan(valueStorage)); } }
void Init() { if (Application.isPlaying && ranInit) { return; } cComponent = GetComponent <SerializedClassTest>(); componentStorage = new SimpleValueStorage <UdonBehaviour>(uComponent); ranInit = true; }
public void IntegerValueStorage_Add_AddsAmountWithCommodityAndChangesToBalance() { string commodityName = "test-commodity"; Commodity commodity = CommodityPool.Current.Find(commodityName) ?? CommodityPool.Current.Create(commodityName); IntegerValueStorage storage1 = new IntegerValueStorage(100); AmountValueStorage storage2 = new AmountValueStorage(new Amount(200, commodity)); IValueStorage result = storage1.Add(storage2); Assert.Equal(ValueTypeEnum.Balance, result.Type); }
public override void Read(ref object targetObject, IValueStorage sourceObject) { VerifySerializationSanity(); if (sourceObject == null) { Debug.LogError($"Field for {typeof(object)} does not exist"); return; } ValueStorage <object> storage = sourceObject as ValueStorage <object>; if (storage == null) { Debug.LogError($"Type {typeof(object)} not compatible with serializer {sourceObject}"); return; } if (sourceObject.Value == null || (sourceObject.Value is UnityEngine.Object unityObject && unityObject == null)) { targetObject = null; return; } Serializer serializer = Serializer.CreatePooled(sourceObject.Value.GetType()); System.Type valueStorageType = serializer.GetUdonStorageType(); Stack <IValueStorage> varStorageStack; if (!objectValueStorageStack.TryGetValue(valueStorageType, out varStorageStack)) { varStorageStack = new Stack <IValueStorage>(); objectValueStorageStack.Add(valueStorageType, varStorageStack); } IValueStorage valueStorage; if (varStorageStack.Count > 0) { valueStorage = varStorageStack.Pop(); valueStorage.Value = sourceObject.Value; } else { valueStorage = (IValueStorage)Activator.CreateInstance(typeof(SimpleValueStorage <>).MakeGenericType(valueStorageType), sourceObject.Value); } serializer.ReadWeak(ref targetObject, valueStorage); varStorageStack.Push(valueStorage); }
public override void WriteWeak(IValueStorage targetObject, object sourceObject) { VerifySerializationSanity(); if (sourceObject != null && !UdonSharpUtils.IsUserJaggedArray(sourceObject.GetType())) { throw new SerializationException($"Cannot convert {targetObject.GetType()} to {typeMetadata.cSharpType}"); } object tarArray = targetObject.Value; ConvertToUdonArrayElement(ref tarArray, sourceObject, typeMetadata.cSharpType); targetObject.Value = tarArray; }
public override void Read(ref T targetObject, IValueStorage sourceObject) { VerifySerializationSanity(); if (sourceObject == null) { UdonSharpUtils.LogError($"Field for {typeof(T)} does not exist"); return; } if (UsbSerializationContext.CollectDependencies) { if (sourceObject.Value is UnityEngine.Object unityObject && unityObject != null) { UsbSerializationContext.Dependencies.Add(unityObject); } return; } IValueStorage storage = sourceObject as ValueStorage <T>; if (storage == null) { Type storageType = sourceObject.GetType().GetGenericArguments()[0]; if (typeof(T).IsSubclassOf(storageType)) { storage = sourceObject; } else if (targetObject != null && targetObject.GetType().IsAssignableFrom(storageType)) { storage = sourceObject; } else if (targetObject == null && storageType.IsSubclassOf(typeof(T))) { storage = sourceObject; } else { UdonSharpUtils.LogError($"Type {typeof(T)} not compatible with serializer {sourceObject}"); return; } } targetObject = (T)storage.Value; }
public override void Read(ref T targetObject, IValueStorage sourceObject) { VerifySerializationSanity(); if (sourceObject == null) { Debug.LogError($"Field for {typeof(T)} does not exist"); return; } if (UsbSerializationContext.CollectDependencies) { return; } targetObject = (T)Enum.ToObject(typeof(T), sourceObject.Value); }
public override void Write(IValueStorage targetObject, T sourceObject) { UdonBehaviour backingBehaviour = UdonSharpEditorUtility.GetBackingUdonBehaviour(sourceObject); UdonBehaviourHeapData heapStorage = UdonSharpBehaviourFormatterManager.GetHeapData(backingBehaviour); if (heapStorage == null) { return; } writeDelegate(heapStorage.heapFieldValues, ref sourceObject, EditorApplication.isPlaying && !UsbSerializationContext.CurrentPolicy.IsPreBuildSerialize); if (!UsbSerializationContext.CollectDependencies && !EditorApplication.isPlaying) { PrefabUtility.RecordPrefabInstancePropertyModifications(backingBehaviour); } }
public override void Read(ref T targetObject, IValueStorage sourceObject) { UdonBehaviour sourceBehaviour = (UdonBehaviour)sourceObject.Value; if (sourceBehaviour == null) { targetObject = null; return; } if (USBSerializationContext.currentPolicy == null) { throw new NullReferenceException("Serialization policy cannot be null"); } targetObject = (T)UdonSharpEditorUtility.GetProxyBehaviour(sourceBehaviour, ProxySerializationPolicy.NoSerialization); if (USBSerializationContext.currentDepth >= USBSerializationContext.currentPolicy.MaxSerializationDepth) { return; } if (USBSerializationContext.serializedBehaviourSet.Contains(targetObject)) { return; } USBSerializationContext.serializedBehaviourSet.Add(targetObject); USBSerializationContext.currentDepth++; try { UdonSharpBehaviourFormatterEmitter.GetFormatter <T>().Read(ref targetObject, sourceObject); } finally { USBSerializationContext.currentDepth--; if (USBSerializationContext.currentDepth <= 0) { Debug.Assert(USBSerializationContext.currentDepth == 0, "Serialization depth cannot be negative"); USBSerializationContext.serializedBehaviourSet.Clear(); } } }
private void ConvertToCSharpArrayElement(ref object targetElement, object elementValue, Type cSharpType) { if (elementValue == null) { targetElement = null; return; } if (UdonSharpUtils.IsUserJaggedArray(cSharpType)) { Array targetArray = (Array)targetElement; Array sourceArray = (Array)elementValue; if (!UsbSerializationContext.CollectDependencies) { if (targetArray == null || targetArray.Length != sourceArray.Length) { targetElement = targetArray = (Array)Activator.CreateInstance(cSharpType, sourceArray.Length); } } for (int i = 0; i < sourceArray.Length; ++i) { object elementVal = targetArray.GetValue(i); ConvertToCSharpArrayElement(ref elementVal, sourceArray.GetValue(i), cSharpType.GetElementType()); if (!UsbSerializationContext.CollectDependencies) { targetArray.SetValue(elementVal, i); } } } else if (cSharpType.IsArray) { IValueStorage innerArrayValueStorage = GetInnerValueStorage(); innerArrayValueStorage.Value = elementValue; rootArraySerializer.ReadWeak(ref targetElement, innerArrayValueStorage); innerValueStorages.Push(innerArrayValueStorage); } else { throw new Exception("Jagged array serializer requires a root array serializer"); } }
public override void Read(ref object targetObject, IValueStorage sourceObject) { VerifySerializationSanity(); if (sourceObject == null) { Debug.LogError($"Field for {typeof(object)} does not exist"); return; } ValueStorage <object> storage = sourceObject as ValueStorage <object>; if (storage == null) { Debug.LogError($"Type {typeof(object)} not compatible with serializer {sourceObject}"); return; } if (UsbSerializationContext.CollectDependencies) { return; } if (sourceObject.Value == null || (sourceObject.Value is UnityEngine.Object unityObject && unityObject == null)) { targetObject = null; return; } Serializer serializer = CreatePooled(sourceObject.Value.GetType()); Type valueStorageType = serializer.GetUdonStorageType(); ConcurrentStack <IValueStorage> varStorageStack = _objectValueStorageStack.GetOrAdd(valueStorageType, (type) => new ConcurrentStack <IValueStorage>()); if (!varStorageStack.TryPop(out var valueStorage)) { valueStorage = (IValueStorage)Activator.CreateInstance(typeof(SimpleValueStorage <>).MakeGenericType(valueStorageType), sourceObject.Value); } serializer.ReadWeak(ref targetObject, valueStorage); varStorageStack.Push(valueStorage); }
public override void Read(ref UdonSharpBehaviour targetObject, IValueStorage sourceObject) { VerifySerializationSanity(); UdonBehaviour sourceBehaviour = (UdonBehaviour)sourceObject.Value; if (sourceBehaviour == null) { targetObject = null; return; } Type behaviourType = UdonSharpProgramAsset.GetBehaviourClass(sourceBehaviour); Serializer behaviourSerializer = CreatePooled(behaviourType); object behaviourRef = targetObject; behaviourSerializer.ReadWeak(ref behaviourRef, sourceObject); targetObject = (UdonSharpBehaviour)behaviourRef; }
void ConvertToUdonArrayElement(ref object targetElement, object elementValue, System.Type cSharpType) { if (elementValue == null) { targetElement = null; return; } if (UdonSharpUtils.IsUserJaggedArray(cSharpType)) { Array targetArray = (Array)targetElement; Array sourceArray = (Array)elementValue; if (targetArray == null || targetArray.Length != sourceArray.Length) { targetElement = targetArray = (Array)Activator.CreateInstance(UdonSharpUtils.UserTypeToUdonType(cSharpType), new object[] { sourceArray.Length }); } for (int i = 0; i < sourceArray.Length; ++i) { object elementVal = targetArray.GetValue(i); ConvertToUdonArrayElement(ref elementVal, sourceArray.GetValue(i), cSharpType.GetElementType()); targetArray.SetValue(elementVal, i); } } else if (cSharpType.IsArray) { IValueStorage innerArrayValueStorage = GetInnerValueStorage(); innerArrayValueStorage.Value = targetElement; rootArraySerializer.WriteWeak(innerArrayValueStorage, elementValue); targetElement = innerArrayValueStorage.Value; innerValueStorages.Push(innerArrayValueStorage); } else { throw new Exception("Jagged array serializer requires a root array serializer"); } }
public static UdonBehaviourHeapData GetHeapData(UdonBehaviour udonBehaviour) { if (!UsbSerializationContext.UseHeapSerialization && _heapDataLookup.TryGetValue(udonBehaviour, out var heapData)) { return(heapData); } if (fieldLayout == null) { throw new NullReferenceException($"Formatter manager {typeof(UdonSharpBehaviourFormatterManager).FullName} has not been initialized."); } IHeapStorage heapStorage = CreateHeapStorage(udonBehaviour); if (heapStorage == null) { return(null); } IValueStorage[] heapFieldValues = new IValueStorage[fieldLayout.Length]; for (int i = 0; i < heapFieldValues.Length; ++i) { heapFieldValues[i] = heapStorage.GetElementStorage(fieldLayout[i]); } heapData = new UdonBehaviourHeapData() { heapStorage = heapStorage, heapFieldValues = heapFieldValues }; if (!UsbSerializationContext.UseHeapSerialization) { _heapDataLookup.Add(udonBehaviour, heapData); } return(heapData); }
public override void Read(ref T targetObject, IValueStorage sourceObject) { VerifySerializationSanity(); if (sourceObject == null) { Debug.LogError($"Field for {typeof(T)} does not exist"); return; } IValueStorage storage = sourceObject as ValueStorage <T>; if (storage == null) { System.Type storageType = sourceObject.GetType().GetGenericArguments()[0]; if (typeof(T).IsSubclassOf(storageType)) { storage = sourceObject; } else if (targetObject != null && targetObject.GetType().IsAssignableFrom(storageType)) { storage = sourceObject; } else if (targetObject == null && storageType.IsSubclassOf(typeof(T))) { storage = sourceObject; } else { Debug.LogError($"Type {typeof(T)} not compatible with serializer {sourceObject}"); return; } } targetObject = (T)storage.Value; }
public override void Write(IValueStorage targetObject, in T[] sourceObject)
public BPlusTree(INodeStorage <TKey> nodeStorage, IValueStorage <TValue> valueStorage) { _nodeStorage = nodeStorage; _valueStorage = valueStorage; }
public override void Read(ref UdonSharpBehaviour targetObject, IValueStorage sourceObject) { UdonBehaviour sourceBehaviour = (UdonBehaviour)sourceObject.Value; if (sourceBehaviour == null) { if (!UsbSerializationContext.CollectDependencies) { targetObject = null; } return; } lock (UsbSerializationContext.UsbLock) { if (UsbSerializationContext.CurrentPolicy == null) { throw new NullReferenceException("Serialization policy cannot be null"); } if (UsbSerializationContext.CollectDependencies) { UsbSerializationContext.Dependencies.Add(sourceBehaviour); } targetObject = UdonSharpEditorUtility.GetProxyBehaviour(sourceBehaviour); if (UsbSerializationContext.CurrentDepth >= UsbSerializationContext.CurrentPolicy.MaxSerializationDepth) { return; } if (UsbSerializationContext.SerializedBehaviourSet.Contains(targetObject)) { return; } UsbSerializationContext.SerializedBehaviourSet.Add(targetObject); UsbSerializationContext.CurrentDepth++; try { Type behaviourType = UdonSharpProgramAsset.GetBehaviourClass(sourceBehaviour); IFormatter formatter = UdonSharpBehaviourFormatterEmitter.GetFormatter(behaviourType); object targetSysObj = targetObject; formatter.Read(ref targetSysObj, sourceObject); if (!UsbSerializationContext.CollectDependencies) { targetObject = (UdonSharpBehaviour)targetSysObj; } } finally { UsbSerializationContext.CurrentDepth--; if (UsbSerializationContext.CurrentDepth <= 0) { Debug.Assert(UsbSerializationContext.CurrentDepth == 0, "Serialization depth cannot be negative"); UsbSerializationContext.SerializedBehaviourSet.Clear(); } } } }
public override void Write(IValueStorage targetObject, in UdonSharpBehaviour sourceObject)
public CleanupService(IValueStorage valueStorage, IOptions <ExpirationConfig> expirationConfig) { _valueStorage = valueStorage; _expirationConfig = expirationConfig.Value; }
public void SetMock(IValueStorage mock) { _realStorage = mock; }