private void Given_Sig(SerializedType ret, params Argument_v1 [] args) { ssig = new SerializedSignature { ReturnValue = new Argument_v1 { Type = ret } }; }
private object Get(string command, string key, bool keyIsChecked, uint hash) { if (!keyIsChecked) { checkKey(key); } object value = serverPool.Execute <object>(hash, null, delegate(MSocket socket) { CheckDB(socket, hash); using (RedisCommand cmd = new RedisCommand(socket, 2, command)) { cmd.WriteKey(keyPrefix + key); } string result = socket.ReadResponse(); if (!string.IsNullOrEmpty(result) && result[0] == '$') { int len = 0; if (int.TryParse(result.Substring(1), out len) && len > 0) { byte[] bytes = socket.ReadLineBytes(); if (bytes.Length > 0) { byte[] data = new byte[bytes.Length - 1]; SerializedType st = (SerializedType)bytes[0]; Array.Copy(bytes, 1, data, 0, data.Length); bytes = null; return(Serializer.DeSerialize(data, st)); } } } return(null); }); return(value); }
public static object DeSerialize(byte[] bytes, SerializedType type) { switch (type) { case SerializedType.String: return(Encoding.UTF8.GetString(bytes)); case SerializedType.Datetime: return(new DateTime(BitConverter.ToInt64(bytes, 0))); case SerializedType.Bool: return(bytes[0] == 1); case SerializedType.Byte: return(bytes[0]); case SerializedType.Short: return(BitConverter.ToInt16(bytes, 0)); case SerializedType.UShort: return(BitConverter.ToUInt16(bytes, 0)); case SerializedType.Int: return(BitConverter.ToInt32(bytes, 0)); case SerializedType.UInt: return(BitConverter.ToUInt32(bytes, 0)); case SerializedType.Long: return(BitConverter.ToInt64(bytes, 0)); case SerializedType.ULong: return(BitConverter.ToUInt64(bytes, 0)); case SerializedType.Float: return(BitConverter.ToSingle(bytes, 0)); case SerializedType.Double: return(BitConverter.ToDouble(bytes, 0)); case SerializedType.Object: using (MemoryStream ms = new MemoryStream(bytes)) { return(new BinaryFormatter().Deserialize(ms)); } case SerializedType.CompressedByteArray: return(DeSerialize(decompress(bytes), SerializedType.ByteArray)); case SerializedType.CompressedString: return(DeSerialize(decompress(bytes), SerializedType.String)); case SerializedType.CompressedObject: return(DeSerialize(decompress(bytes), SerializedType.Object)); case SerializedType.ByteArray: default: return(bytes); } }
public void SetUp() { using (var stream = TestDataHelper.OpenResource("Text.list_of_values.vdf")) { data = KVSerializer.Deserialize <SerializedType>(stream); } }
// do not use directly in migration function static SerializedProperty FindBase(SerializedObject material, SerializedType type) { var propertyBase = material.FindProperty("m_SavedProperties"); switch (type) { case SerializedType.Boolean: case SerializedType.Integer: case SerializedType.Float: propertyBase = propertyBase.FindPropertyRelative("m_Floats"); break; case SerializedType.Color: case SerializedType.Vector: propertyBase = propertyBase.FindPropertyRelative("m_Colors"); break; case SerializedType.Texture: propertyBase = propertyBase.FindPropertyRelative("m_TexEnvs"); break; default: throw new ArgumentException($"Unknown SerializedType {type}"); } return(propertyBase); }
// do not use directly in migration function static bool TryFindProperty(SerializedObject material, string propertyName, SerializedType type, out SerializedProperty property, out int indexOf, out SerializedProperty propertyBase) { propertyBase = FindBase(material, type); property = null; int maxSearch = propertyBase.arraySize; indexOf = 0; for (; indexOf < maxSearch; ++indexOf) { property = propertyBase.GetArrayElementAtIndex(indexOf); if (property.FindPropertyRelative("first").stringValue == propertyName) { break; } } if (indexOf == maxSearch) { return(false); } property = property.FindPropertyRelative("second"); return(true); }
public Argument_v1(string name, SerializedType type, SerializedKind kind, bool outParameter) { Name = name; Type = type; Kind = kind; OutParameter = outParameter; }
public DerivedType(System.Type baseType, System.Type derivedType) { if (derivedType.IsSubclassOf(baseType)) { _baseType = new SerializedType(baseType); _typeValue = new SerializedType(derivedType); } }
private static Argument_v1 Arg(string name, SerializedType sType) { return(new Argument_v1 { Name = name, Type = sType, }); }
public void AddDecoratorDrawerHandler(SerializedType drawerReference) { if (decoratorDrawerHandlers == null) { decoratorDrawerHandlers = new List <SerializedType>(); } decoratorDrawerHandlers.Add(drawerReference); }
static SerializedProperty FindBase(SerializedObject material, SerializedType type) { if (!TryFindBase(material, type, out var propertyBase)) { throw new ArgumentException($"Unknown SerializedType {type}"); } return(propertyBase); }
private static MemberPointer_v1 NearPtr(SerializedType type) { return(new MemberPointer_v1 { Size = 2, MemberType = type, }); }
public void AddPropertyDrawerHandler(SerializedType drawerReference) { if (propertyDrawerHandlers == null) { propertyDrawerHandlers = new List <SerializedType>(); } propertyDrawerHandlers.Add(drawerReference); }
public void AddCollectionDrawerHandler(SerializedType drawerReference) { if (collectionDrawerHandlers == null) { collectionDrawerHandlers = new List <SerializedType>(); } collectionDrawerHandlers.Add(drawerReference); }
public void AddTargetTypeDrawerHandler(SerializedType drawerReference) { if (targetTypeDrawerHandlers == null) { targetTypeDrawerHandlers = new List <SerializedType>(); } targetTypeDrawerHandlers.Add(drawerReference); }
private Argument_v1 StackArg(SerializedType type, string name) { return(new Argument_v1( name, type, new StackVariable_v1(), false)); }
private void Given_Sig(SerializedType ret, params Argument_v1 [] args) { ssig = new SerializedSignature { ReturnValue = new Argument_v1 { Type = ret } }; }
public override ParameterReference GetParameter(string paramName, SerializedType holdType) { if (ParametrizedProperties.TryGetValue(paramName, out var property)) { return(property.Parameter); } return(null); }
public static BaseTypeConverter ForSerializedType(SerializedType type) { if (type == SerializedType.Null) { return(NullConverter); } return(_converters.First(x => x.Value.Type == type).Value); }
public static BaseTypeConverter ForSerializedType(SerializedType type) { if (Converters.TryGetValue(type, out BaseTypeConverter converter)) { return(converter); } throw new SerializationException($"Unable to find find a converter for type {type}"); }
public T Deserialize <T>(byte[] bytes) { var stream = new DeserializationStream(bytes); SerializedType deserializedType = stream.ReadSerializedType(); if (deserializedType == SerializedType.Null) { return(default);
public object GetValue(SerializedType serializedType) { if (_cachedValue != null) { return(_cachedValue); } return(GetValue(_value, serializedType)); }
public void SetString(string value) { stringValue = value; values = null; objectValue = null; type = SerializedType.String; }
private void ResetReference() { m_SceneGuid = m_GameObjectGuid = null; m_SerializedComponentType = new SerializedType(null); m_ComponentIndex = 0; m_AssetObject = null; m_ReferencedObject = null; m_Prefab = null; }
public void Update(UnityEngine.Object newObject) { ResetInitialization(); ResetReference(); if (newObject == null) { SaveProperties(); return; } SceneObjectGUIDComponent guidComponent = null; Component component = null; GameObject go = null; if (newObject is Component) { component = newObject as Component; go = component.gameObject; guidComponent = go.GetComponent <SceneObjectGUIDComponent>(); m_SerializedComponentType = new SerializedType(component.GetType()); m_ComponentIndex = Array.IndexOf(go.GetComponents(component.GetType()), component); } else if (newObject is GameObject) { go = newObject as GameObject; if (PrefabUtility.IsPartOfPrefabAsset(go)) { m_Prefab = go; SaveProperties(); return; } guidComponent = go.GetComponent <SceneObjectGUIDComponent>(); } else { m_ReferencedObject = m_AssetObject = newObject; SaveProperties(); return; } if (guidComponent == null) { guidComponent = go.AddComponent <SceneObjectGUIDComponent>(); Undo.RegisterCreatedObjectUndo(guidComponent, "Created GUID component"); } m_GameObjectGuid = guidComponent.id; m_SceneGuid = GetSceneId(go); if (string.IsNullOrEmpty(m_SceneGuid)) { Debug.LogError("The scene needs to be saved"); return; } SaveProperties(); }
protected bool IsReal(SerializedType sType) { var prim = sType as PrimitiveType_v1; if (prim == null) { return(false); } return(prim.Domain == Domain.Real); }
private void AddNewParam(SerializedType type) { string typename = KnownType.GetDisplayedName(type.Type); string paramName = StringUtils.MakeUnique($"New {typename}", Parameters.Select(p => p.Name)); Parameters.Add ( new Parameter(type, paramName) ); }
private void AddNewParam(SerializedType type, List <Framework.Parameter> list) { string typename = KnownType.GetDisplayedName(type.Type); string paramName = StringUtils.MakeUnique($"New {typename}", list.Select(p => p.Name)); list.Add ( new Framework.Parameter(type, paramName) ); }
private SerializedType Qualify(SerializedType t, Qualifier q) { if (q == Qualifier.None) { return(t); } return(new QualifiedType_v1 { DataType = t, Qualifier = q }); }
private Argument_v1 FpuArg(SerializedType type, string name) { return(new Argument_v1( name, type, new Register_v1 { Name = name }, false)); }
private Argument_v1 FpuArg(SerializedType type, string name) { return(new Argument_v1( name, type, new FpuStackVariable_v1 { ByteSize = 8 }, false)); }
protected override void OnGUISafe(Rect position, SerializedProperty property, GUIContent label) { var refAttribute = Attribute; var refProperty = property.FindPropertyRelative("classReference"); //validate serialized data if (refAttribute == null || refAttribute.AssemblyType == null) { EditorGUI.PropertyField(position, property, label); return; } var refType = !string.IsNullOrEmpty(refProperty.stringValue) ? Type.GetType(refProperty.stringValue) : null; var refTypes = new List <Type>(); var refLabels = new List <string>() { "<None>" }; var index = -1; //get stored types if possible or create new item if (!filteredTypes.TryGetValue(refAttribute.AssemblyType, out refTypes)) { refTypes = filteredTypes[refAttribute.AssemblyType] = refAttribute.GetFilteredTypes(); } else { refTypes = filteredTypes[refAttribute.AssemblyType]; } //create labels from filtered types for (int i = 0; i < refTypes.Count; i++) { var menuType = refTypes[i]; var menuLabel = FormatGroupedTypeName(menuType, refAttribute.Grouping); if (menuType == refType) { index = i; } refLabels.Add(menuLabel); } //draw the reference property label = EditorGUI.BeginProperty(position, label, property); label = property.name != "data" ? label : GUIContent.none; //draw the proper label field position = EditorGUI.PrefixLabel(position, label); index = EditorGUI.Popup(position, index + 1, refLabels.ToArray()); //get the correct class reference, index = 0 is reserved to <None> type refProperty.stringValue = index >= 1 ? SerializedType.GetClassReference(refTypes[index - 1]) : ""; EditorGUI.EndProperty(); }
public static object DeSerialize(byte[] bytes, SerializedType type) { switch (type) { case SerializedType.String: return Encoding.UTF8.GetString(bytes); case SerializedType.Datetime: return new DateTime(BitConverter.ToInt64(bytes, 0)); case SerializedType.Bool: return bytes[0] == 1; case SerializedType.Byte: return bytes[0]; case SerializedType.Short: return BitConverter.ToInt16(bytes, 0); case SerializedType.UShort: return BitConverter.ToUInt16(bytes, 0); case SerializedType.Int: return BitConverter.ToInt32(bytes, 0); case SerializedType.UInt: return BitConverter.ToUInt32(bytes, 0); case SerializedType.Long: return BitConverter.ToInt64(bytes, 0); case SerializedType.ULong: return BitConverter.ToUInt64(bytes, 0); case SerializedType.Float: return BitConverter.ToSingle(bytes, 0); case SerializedType.Double: return BitConverter.ToDouble(bytes, 0); case SerializedType.Object: using (MemoryStream ms = new MemoryStream(bytes)) { return new BinaryFormatter().Deserialize(ms); } case SerializedType.CompressedByteArray: return DeSerialize(decompress(bytes), SerializedType.ByteArray); case SerializedType.CompressedString: return DeSerialize(decompress(bytes), SerializedType.String); case SerializedType.CompressedObject: return DeSerialize(decompress(bytes), SerializedType.Object); case SerializedType.ByteArray: default: return bytes; } }
private Argument_v1 FpuArg(SerializedType type, string name) { return new Argument_v1( name, type, new Register_v1 { Name = name }, false); }
private Argument_v1 RegArg(SerializedType type, string regName) { return new Argument_v1 { Type = type, Kind = new Register_v1 { Name = regName }, Name = regName }; }
protected bool IsReal(SerializedType sType) { var prim = sType as PrimitiveType_v1; if (prim == null) return false; return prim.Domain == Domain.Real; }
public object Deserialize(EndianAwareBinaryReader reader, SerializedType serializedType, int? length = null) { int? effectiveLength = null; if (length != null) effectiveLength = length.Value; else if (TypeNode.FieldLengthBinding != null) { object lengthValue = TypeNode.FieldLengthBinding.GetValue(this); effectiveLength = Convert.ToInt32(lengthValue); } else if (TypeNode.FieldCountBinding != null) { object countValue = TypeNode.FieldCountBinding.GetValue(this); effectiveLength = Convert.ToInt32(countValue); } else if (serializedType == SerializedType.ByteArray || serializedType == SerializedType.SizedString || serializedType == SerializedType.NullTerminatedString) { // try to get bounded length from limiter var baseStream = (StreamLimiter) reader.BaseStream; checked { effectiveLength = (int) (baseStream.AvailableForReading); } } object value; switch (serializedType) { case SerializedType.Int1: value = reader.ReadSByte(); break; case SerializedType.UInt1: value = reader.ReadByte(); break; case SerializedType.Int2: value = reader.ReadInt16(); break; case SerializedType.UInt2: value = reader.ReadUInt16(); break; case SerializedType.Int4: value = reader.ReadInt32(); break; case SerializedType.UInt4: value = reader.ReadUInt32(); break; case SerializedType.Int8: value = reader.ReadInt64(); break; case SerializedType.UInt8: value = reader.ReadUInt64(); break; case SerializedType.Float4: value = reader.ReadSingle(); break; case SerializedType.Float8: value = reader.ReadDouble(); break; case SerializedType.ByteArray: { Debug.Assert(effectiveLength != null, "effectiveLength != null"); value = reader.ReadBytes(effectiveLength.Value); break; } case SerializedType.NullTerminatedString: { Debug.Assert(effectiveLength != null, "effectiveLength != null"); byte[] data = ReadNullTerminatedString(reader, effectiveLength.Value).ToArray(); value = Encoding.GetString(data, 0, data.Length); break; } case SerializedType.SizedString: { Debug.Assert(effectiveLength != null, "effectiveLength != null"); byte[] data = reader.ReadBytes(effectiveLength.Value); value = Encoding.GetString(data, 0, data.Length).TrimEnd('\0'); break; } case SerializedType.LengthPrefixedString: { value = reader.ReadString(); break; } default: throw new NotSupportedException(); } return value; }
public void Serialize(EndianAwareBinaryWriter writer, object value, SerializedType serializedType, int? length = null) { if (value == null) { /* In the special case of sized strings, don't allow nulls */ if (serializedType == SerializedType.SizedString) value = string.Empty; else return; } int? constLength = null; long? maxLength = null; var typeParent = TypeNode.Parent as TypeNode; if (length != null) constLength = length.Value; else if (TypeNode.FieldLengthBinding != null && TypeNode.FieldLengthBinding.IsConst) { constLength = Convert.ToInt32(TypeNode.FieldLengthBinding.ConstValue); } else if (typeParent != null && typeParent.ItemLengthBinding != null && typeParent.ItemLengthBinding.IsConst) { constLength = Convert.ToInt32(typeParent.ItemLengthBinding.ConstValue); } else if (TypeNode.FieldCountBinding != null && TypeNode.FieldCountBinding.IsConst) { constLength = Convert.ToInt32(TypeNode.FieldCountBinding.ConstValue); } else if (serializedType == SerializedType.ByteArray || serializedType == SerializedType.SizedString || serializedType == SerializedType.NullTerminatedString) { // try to get bounded length from limiter var baseStream = (StreamLimiter) writer.BaseStream; maxLength = baseStream.AvailableForWriting; } switch (serializedType) { case SerializedType.Int1: writer.Write(Convert.ToSByte(value)); break; case SerializedType.UInt1: writer.Write(Convert.ToByte(value)); break; case SerializedType.Int2: writer.Write(Convert.ToInt16(value)); break; case SerializedType.UInt2: writer.Write(Convert.ToUInt16(value)); break; case SerializedType.Int4: writer.Write(Convert.ToInt32(value)); break; case SerializedType.UInt4: writer.Write(Convert.ToUInt32(value)); break; case SerializedType.Int8: writer.Write(Convert.ToInt64(value)); break; case SerializedType.UInt8: writer.Write(Convert.ToUInt64(value)); break; case SerializedType.Float4: writer.Write(Convert.ToSingle(value)); break; case SerializedType.Float8: writer.Write(Convert.ToDouble(value)); break; case SerializedType.ByteArray: { var data = (byte[]) value; writer.Write(data, 0, data.Length); break; } case SerializedType.NullTerminatedString: { byte[] data = Encoding.GetBytes(value.ToString()); if (constLength != null) Array.Resize(ref data, constLength.Value - 1); if(maxLength != null && data.Length > maxLength) Array.Resize(ref data, (int)maxLength.Value - 1); writer.Write(data); writer.Write((byte) 0); break; } case SerializedType.SizedString: { byte[] data = Encoding.GetBytes(value.ToString()); if (constLength != null) Array.Resize(ref data, constLength.Value); if (maxLength != null && data.Length > maxLength) Array.Resize(ref data, (int)maxLength.Value); writer.Write(data); break; } case SerializedType.LengthPrefixedString: { if(constLength != null) throw new NotSupportedException("Length-prefixed strings cannot have a const length."); writer.Write(value.ToString()); break; } default: throw new NotSupportedException(); } }
public void Serialize(Stream stream, object value, SerializedType serializedType, int? length = null) { var writer = new EndianAwareBinaryWriter(stream, Endianness); Serialize(writer, value, serializedType, length); }
public GlobalDataItem_v2 ModifyUserGlobal(Address address, SerializedType dataType, string name) { GlobalDataItem_v2 gbl; if (!User.Globals.TryGetValue(address, out gbl)) { gbl = new GlobalDataItem_v2() { Address = address.ToString(), }; User.Globals.Add(address, gbl); } gbl.Name = name; gbl.DataType = dataType; this.ImageMap.RemoveItem(address); var tlDeser = CreateTypeLibraryDeserializer(); var dt = dataType.Accept(tlDeser); var size = GetDataSize(address, dt); var item = new ImageMapItem { Address = address, Size = size, Name = name, DataType = dt, }; if (size != 0) this.ImageMap.AddItemWithSize(address, item); else this.ImageMap.AddItem(address, item); return gbl; }
private Argument_v1 StackArg(SerializedType type, string name) { return new Argument_v1( name, type, new StackVariable_v1(), false); }
public static byte[] Serialize(object value, out SerializedType type, uint compressionThreshold) { byte[] bytes; if (value is byte[]) { bytes = (byte[])value; type = SerializedType.ByteArray; if (bytes.Length > compressionThreshold) { bytes = compress(bytes); type = SerializedType.CompressedByteArray; } } else if (value is string) { bytes = Encoding.UTF8.GetBytes((string)value); type = SerializedType.String; if (bytes.Length > compressionThreshold) { bytes = compress(bytes); type = SerializedType.CompressedString; } } else if (value is DateTime) { bytes = BitConverter.GetBytes(((DateTime)value).Ticks); type = SerializedType.Datetime; } else if (value is bool) { bytes = new byte[] { (byte)((bool)value ? 1 : 0) }; type = SerializedType.Bool; } else if (value is byte) { bytes = new byte[] { (byte)value }; type = SerializedType.Byte; } else if (value is short) { bytes = BitConverter.GetBytes((short)value); type = SerializedType.Short; } else if (value is ushort) { bytes = BitConverter.GetBytes((ushort)value); type = SerializedType.UShort; } else if (value is int) { bytes = BitConverter.GetBytes((int)value); type = SerializedType.Int; } else if (value is uint) { bytes = BitConverter.GetBytes((uint)value); type = SerializedType.UInt; } else if (value is long) { bytes = BitConverter.GetBytes((long)value); type = SerializedType.Long; } else if (value is ulong) { bytes = BitConverter.GetBytes((ulong)value); type = SerializedType.ULong; } else if (value is float) { bytes = BitConverter.GetBytes((float)value); type = SerializedType.Float; } else if (value is double) { bytes = BitConverter.GetBytes((double)value); type = SerializedType.Double; } else { //Object using (MemoryStream ms = new MemoryStream()) { new BinaryFormatter().Serialize(ms, value); bytes = ms.ToArray(); type = SerializedType.Object; if (bytes.Length > compressionThreshold) { bytes = compress(bytes); type = SerializedType.CompressedObject; } } } return bytes; }
private Argument_v1 FpuArg(SerializedType type, string name) { return new Argument_v1( name, type, new FpuStackVariable_v1 { ByteSize = 8 }, false); }
private static Argument_v1 Arg(string name, SerializedType sType) { return new Argument_v1 { Name = name, Type = sType, }; }
public object Deserialize(StreamLimiter stream, SerializedType serializedType, int? length = null) { var reader = new EndianAwareBinaryReader(stream, Endianness); return Deserialize(reader, serializedType, length); }
private Argument_v1 Arg(string argName, SerializedType sType) { return new Argument_v1(argName, sType, null, false); }
private PointerType_v1 Ptr(SerializedType sType) { return new PointerType_v1 { DataType = sType, PointerSize = 4 }; }