/// <summary> /// Initializes a new instance of the TypeSerializationInfo class for /// legacy serialization mechanisms. For internal use only. /// </summary> /// <param name="legacyType"></param> internal TypeSerializationInfo(LegacySerializationType legacyType) { deferredInitializationAction = () => { switch (legacyType) { case LegacySerializationType.Version: this.serializeMethod = SerializeVersionSerializable; this.deserializeMethod = DeserializeVersionSerializable; break; case LegacySerializationType.Custom: this.serializeMethod = SerializeCustomSerializable; this.deserializeMethod = DeserializeCustomSerializable; break; case LegacySerializationType.Unknown: this.serializeMethod = SerializeUnknownType; this.deserializeMethod = DeserializeUnknownType; break; } this.compareMethod = object.Equals; }; }
public CustomType(Type type, byte code, SerializeMethod serializeFunction, DeserializeMethod deserializeFunction) { this.Type = type; this.Code = code; this.SerializeFunction = serializeFunction; this.DeserializeFunction = deserializeFunction; }
public static void RegisterTypes(this PhotonClient client) { Type typeFromHandle = typeof(Vector3); byte code = 86; SerializeMethod Serialize1 = new SerializeMethod(JFAFAPNBFLC); DeserializeMethod DeSerialize1 = new DeserializeMethod(IKFICLDHAOI); PhotonPeer.RegisterType(typeFromHandle, code, Serialize1, DeSerialize1); Type typeFromHandle2 = typeof(Quaternion); byte code2 = 81; SerializeMethod Serialize2 = new SerializeMethod(FECGOFBPKPP); DeserializeMethod DeSerialize2 = new DeserializeMethod(KCFONHKNDJH); PhotonPeer.RegisterType(typeFromHandle2, code2, Serialize2, DeSerialize2); byte b = 100; Type typeFromHandle3 = typeof(Vector2); SerializeMethod Serialize3 = new SerializeMethod(KMIBNBFAHEN); DeserializeMethod DeSerialize3 = new DeserializeMethod(HHBPLJKDKPI); GCJHKDFNJEA(typeFromHandle3, ref b, Serialize3, DeSerialize3); Type typeFromHandle4 = typeof(Vector4); SerializeMethod Serialize4 = new SerializeMethod(DFMLPAEPHJD); DeserializeMethod DeSerialize4 = new DeserializeMethod(GPJDPFFENPL); GCJHKDFNJEA(typeFromHandle4, ref b, Serialize4, DeSerialize4); }
internal CustomType(Type type, int typeId, SerializeMethod encodeFunc, DeserializeMethod decodeFunc) { Type = type; TypeId = typeId; SerializeMethod = encodeFunc; DeserializeMethod = decodeFunc; }
public SerializableTypeInfo(Type type, byte id, SerializeMethod serializeFunction, DeserializeMethod deserializeFunction) { this.Type = type; this.Id = id; this.SerializeFunction = serializeFunction; this.DeserializeFunction = deserializeFunction; }
private IEnumerator Logout() { Protocol.TypeDict.Remove(typeof(LogoutType)); Protocol.CodeDict.Remove(102); #if STEAM SerializeMethod serializeMethod = new SerializeMethod(AADBLALKGMG.LDCIBGFMECI); DeserializeMethod deserializeMethod = new DeserializeMethod(AADBLALKGMG.JDJKKLNPMNA); #elif OCULUS SerializeMethod serializeMethod = new SerializeMethod(AADBLALKGMG.LDCIBGFMECI); DeserializeMethod deserializeMethod = new DeserializeMethod(AADBLALKGMG.JDJKKLNPMNA); #endif PhotonPeer.RegisterType(typeof(LogoutType), (byte)102, new SerializeMethod(SerializeThisFunction), deserializeMethod); PhotonView photonView = PhotonView.Get(VRC_EventLog.Instance.Replicator); for (int i = 0; i < 10; i++) { try { if (Targets[0] != null) { photonView.RpcSecure("ProcessEvent", Targets[0], true, new object[] { #if STEAM new VRC_EventLog.INGKOGDACII() #elif OCULUS new VRC_EventLog.INGKOGDACII() #endif }); } }
public PropertyConverter(PropertyInfo propertyInfo, IJsonConverter valueConverter) { var instance = Expression.Parameter(Typeof <TObject> .Raw, "instance"); var converter = Expression.Constant(valueConverter, valueConverter.GetType()); Deserialize = BuildDeserializeMethod(instance, propertyInfo, converter); Read = BuildReadMethod(instance, propertyInfo, converter); Serialize = BuildSerializeMethod(instance, propertyInfo, converter); Write = BuildWriteMethod(instance, propertyInfo, converter); }
public static void SendCustomEvent(int photonId, SerializeMethod method) { void Clear() { if (originalSerializeMethod == null || originalDeserializeMethod == null) { object instance = typeDictInfo.GetValue(null); object customTypeInfo = typeDictItemInfo.GetValue(instance, new object[] { logoutType }); if (originalSerializeMethod == null) { originalSerializeMethod = (SerializeMethod)serializeMethodInfo.GetValue(customTypeInfo); } if (originalDeserializeMethod == null) { originalDeserializeMethod = (DeserializeMethod)deserializeMethodInfo.GetValue(customTypeInfo); } } TypeDictRemove(logoutType); CodeDictRemove(102); } void RegisterCustom() { PhotonPeer.RegisterType(logoutType, (byte)102, method, originalDeserializeMethod); } void Send() { PhotonView photonView = PhotonView.Get(VRC_EventLog.Instance.Replicator); object target = PhotonPlayerWrappers.GetById(photonId); if (target != null) { RpcSecure(photonView, "ProcessEvent", target, true, new object[] { Activator.CreateInstance(logoutType) }); } } void RegisterOriginal() { PhotonPeer.RegisterType(logoutType, 102, originalSerializeMethod, originalDeserializeMethod); } Clear(); RegisterCustom(); Send(); Clear(); RegisterOriginal(); }
/// <summary> /// <para>Binary-serializes an object and deserializes it into another object.</para> /// </summary> /// <typeparam name="T">The Object type.</typeparam> /// <param name="original"> /// <para>The original instance to serialize.</para> /// </param> /// <param name="method"> /// <para>The method to deserialize the object with.</para> /// </param> /// <returns> /// <para>The deserialized object of type <typeparam name="T"/>; /// never <see langword="null"/>.</para> /// </returns> /// <exception cref="ArgumentNullException"> /// <para>The argument <paramref name="original"/> is <see langword="null"/>.</para> /// <para>-or-</para> /// <para>The argument <paramref name="method"/> is <see langword="null"/>.</para> /// </exception> public static T PerformBinaryRoundTrip <T>(T original, DeserializeMethod <T> method) where T : IVersionSerializable { using (MemoryStream stream = new MemoryStream()) { Serializer.Serialize <T>(stream, original); SaveToFile(stream.ToArray(), ".bin"); stream.Position = 0; using (CompactBinaryReader reader = new CompactBinaryReader(stream)) { return(method(reader)); } } }
void InitializeLegacySerializable() { if (this.versionSerializable == true) { this.serializeMethod = SerializeVersionSerializable; this.deserializeMethod = DeserializeVersionSerializable; } else if (this.type.GetInterface(typeof(ICustomSerializable).Name) != null) { this.serializeMethod = SerializeCustomSerializable; this.deserializeMethod = DeserializeCustomSerializable; } else { this.serializeMethod = SerializeUnknownType; this.deserializeMethod = DeserializeUnknownType; } this.compareMethod = object.Equals; }
/// <summary>registers a custom serializable type using type, a character and 2 methods for serialization and deserilialization</summary> public void RegisterCustomType(Type t, char c, SerializeMethod s, DeserializeMethod d) { if (usedCodes.Contains(c)) { Debug.LogWarningFormat("Failed registering serializable type with code {0}:: code is already used", c); return; } if (SerializedTypes.Contains(t)) { Debug.LogWarningFormat("Failed registering serializable type {0}:: type is already registered", t); return; } if (!PhotonPeer.RegisterType(t, (byte)c, s, d)) { Debug.LogWarningFormat("Failed registering serializable type with code {0}:: check photon requirements for serialization", c); return; } usedCodes.Add(c); SerializedTypes.Add(t); }
public StorageMgr(string dataFileName, DeserializeMethod ds) { Deserializer = ds; m_datafileMgr = dataFileName; ProcessAttributes(); }
public static bool TryRegisterType(Type type, byte typeCode, SerializeMethod serializeFunction, DeserializeMethod deserializeFunction) { bool flag = Protocol.CodeDict.ContainsKey(typeCode) || Protocol.TypeDict.ContainsKey(type); bool result; if (flag) { result = false; } else { CustomType value = new CustomType(type, typeCode, serializeFunction, deserializeFunction); Protocol.CodeDict.Add(typeCode, value); Protocol.TypeDict.Add(type, value); result = true; } return(result); }
/// <summary> /// Does not support deserializing of anonymous types /// Type should be covered by preceeding resolvers in complex/standard resolver. /// </summary> private object DeserializeByTypeName(ArraySegment <byte> typeName, ref MessagePackReader byteSequence, MessagePackSerializerOptions options) { // try get type with assembly name, throw if not found Type type; if (!this.typeCache.TryGetValue(typeName, out type)) { var buffer = new byte[typeName.Count]; Buffer.BlockCopy(typeName.Array, typeName.Offset, buffer, 0, buffer.Length); var str = StringEncoding.UTF8.GetString(buffer); type = this.BindToType(str); if (type == null) { if (IsMscorlib && str.Contains("System.Private.CoreLib")) { str = str.Replace("System.Private.CoreLib", "mscorlib"); type = Type.GetType(str, true); // throw } else if (!IsMscorlib && str.Contains("mscorlib")) { str = str.Replace("mscorlib", "System.Private.CoreLib"); type = Type.GetType(str, true); // throw } else { type = Type.GetType(str, true); // re-throw } } this.typeCache.TryAdd(buffer, type); } KeyValuePair <object, DeserializeMethod> formatterAndDelegate; if (!this.deserializers.TryGetValue(type, out formatterAndDelegate)) { lock (this.deserializers) { if (!this.deserializers.TryGetValue(type, out formatterAndDelegate)) { TypeInfo ti = type.GetTypeInfo(); IFormatterResolver resolver = options.Resolver; var formatter = resolver.GetFormatterDynamic(type); if (formatter == null) { throw new FormatterNotRegisteredException(type.FullName + " is not registered in this resolver. resolver:" + resolver.GetType().Name); } Type formatterType = typeof(IMessagePackFormatter <>).MakeGenericType(type); ParameterExpression param0 = Expression.Parameter(typeof(object), "formatter"); ParameterExpression param1 = Expression.Parameter(typeof(MessagePackReader).MakeByRefType(), "reader"); ParameterExpression param2 = Expression.Parameter(typeof(MessagePackSerializerOptions), "options"); MethodInfo deserializeMethodInfo = formatterType.GetRuntimeMethod("Deserialize", new[] { typeof(MessagePackReader).MakeByRefType(), typeof(MessagePackSerializerOptions) }); MethodCallExpression deserialize = Expression.Call( Expression.Convert(param0, formatterType), deserializeMethodInfo, param1, param2); Expression body = deserialize; if (ti.IsValueType) { body = Expression.Convert(deserialize, typeof(object)); } DeserializeMethod lambda = Expression.Lambda <DeserializeMethod>(body, param0, param1, param2).Compile(); formatterAndDelegate = new KeyValuePair <object, DeserializeMethod>(formatter, lambda); this.deserializers.TryAdd(type, formatterAndDelegate); } } } return(formatterAndDelegate.Value(formatterAndDelegate.Key, ref byteSequence, options)); }
/// <summary>registers a custom serializable type using type, a character and 2 methods for serialization and deserilialization</summary> public static void RegisterCustomSerializable(Type type, char charCode, SerializeMethod serialize, DeserializeMethod deserialize) { serialization.RegisterCustomType(type, charCode, serialize, deserialize); }
internal static bool TryRegisterType(Type type, byte typeCode, SerializeMethod serializeFunction, DeserializeMethod deserializeFunction) { if (CodeDict.ContainsKey(typeCode) || TypeDict.ContainsKey(type)) { return(false); } CustomType customType = new CustomType(type, typeCode, serializeFunction, deserializeFunction); CodeDict.Add(typeCode, customType); TypeDict.Add(type, customType); return(true); }
private static void GCJHKDFNJEA(Type GMLMGAFFKEL, ref byte JGJGAENECKO, SerializeMethod HNDHEEONDNN, DeserializeMethod EBMBMGANEJJ) { byte code; JGJGAENECKO = Convert.ToByte((code = JGJGAENECKO) + 1); if (PhotonPeer.RegisterType(GMLMGAFFKEL, code, HNDHEEONDNN, EBMBMGANEJJ) && !ILHFIJHBPKK.Contains(GMLMGAFFKEL)) { ILHFIJHBPKK.Add(GMLMGAFFKEL); } }
/// <summary> /// 注册自定义类型的序列化 /// </summary> /// <returns><c>true</c>, if type was registered, <c>false</c> otherwise.</returns> /// <param name="type">类型</param> /// <param name="typeId">类型 Id</param> /// <param name="serializeMethod">序列化方法</param> /// <param name="deserializeMethod">反序列化方法</param> public static bool RegisterType(Type type, int typeId, SerializeMethod serializeMethod, DeserializeMethod deserializeMethod) { if (type == null) { throw new ArgumentNullException(nameof(type)); } if (serializeMethod == null) { throw new ArgumentNullException(nameof(serializeMethod)); } if (deserializeMethod == null) { throw new ArgumentNullException(nameof(deserializeMethod)); } if (typeDict.ContainsKey(type) || typeIdDict.ContainsKey(typeId)) { return(false); } var customType = new CustomType(type, typeId, serializeMethod, deserializeMethod); typeDict.Add(type, customType); typeIdDict.Add(typeId, customType); return(true); }
} // 0x00000001806C6830-0x00000001806C6930 // Methods public static bool TryRegisterType(Type type, byte typeCode, SerializeMethod serializeFunction, DeserializeMethod deserializeFunction) => default; // 0x00000001806C6660-0x00000001806C6830
public static void RegisterType(Type type, byte id, SerializeMethod serializeFunction, DeserializeMethod deserializeFunction) { if (TypeDict.ContainsKey(type) || IdDict.ContainsKey(id)) { throw new Exception("Type Already Registed :" + type + "/" + id); } SerializableTypeInfo customType = new SerializableTypeInfo(type, id, serializeFunction, deserializeFunction); TypeDict.Add(type, customType); IdDict.Add(id, customType); }
void CreateDeserializationMethod(List <PropertySerializationInfo> properties) { const string HasNameTableLabel = "_hasNameTable"; const string endLabel = "exitFunction"; const string SkipPropertyLabel = "_skipProperty"; const string BaseSucceededLabel = "_baseSucceeded"; const string SkipLegacyDeserialize = "_skipLegacyDeserialize"; int version = 0; PropertySerializationInfo.GenerateArgs args = new PropertySerializationInfo.GenerateArgs(); args.il = new DynamicMethodHelper( "Deserialize_" + type.Name, null, new Type[] { typeof(object), typeof(int), typeof(TypeSerializationArgs) }, this.type ); args.instanceArg = 0; args.versionArg = 1; args.dataArg = 2; args.streamVar = "_reader"; args.headerVar = "_header"; args.il.DeclareLocal(args.streamVar, typeof(IPrimitiveReader)); args.il.GetField(args.dataArg, typeof(TypeSerializationArgs).GetField("Reader")); args.il.PopLocal(args.streamVar); args.il.DeclareLocal(args.headerVar, typeof(TypeSerializationHeader)); args.il.GetField(args.dataArg, typeof(TypeSerializationArgs).GetField("Header")); args.il.PopLocal(args.headerVar); // Handle legacy deserialization if ((this.LegacyVersion > 0) && (this.MinVersion <= this.LegacyVersion)) { MethodInfo method = this.Type.GetMethod( "Deserialize", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] { typeof(IPrimitiveReader), typeof(int) }, null ); if (method == null) { throw new ApplicationException(string.Format( "Class {0} specified a legacy version but could not find the Deserialize method", this.Type.Name )); } // // if (dataVersion > legacyVersion) // goto SkipLegacyDeserialize // // call instance.Deserialize(reader, version) // goto endLabel // // :SkipLegacyDeserialize // args.il.PushArg(args.versionArg); args.il.PushInt(this.LegacyVersion); args.il.GotoIfGreater(SkipLegacyDeserialize); args.il.PushArg(args.instanceArg); args.il.PushLocal(args.streamVar); args.il.PushArg(args.versionArg); args.il.CallMethod(method); args.il.Goto(endLabel); args.il.MarkLabel(SkipLegacyDeserialize); } // TypeNameTable _typeNameTable = dataArg.NameTable; // if (_typeNameType == null) // _typeNameType = new TypeNameTable(); // dataArg.NameTable = _typeNameType; args.nameTableVar = "_typeNameTable"; args.il.DeclareLocal(args.nameTableVar, typeof(TypeNameTable)); args.il.GetField(args.dataArg, typeof(TypeSerializationArgs).GetField("NameTable")); args.il.PopLocal(args.nameTableVar); args.il.PushLocal(args.nameTableVar); args.il.GotoIfTrue(HasNameTableLabel); args.il.NewObject(args.nameTableVar); args.il.SetField(args.dataArg, args.nameTableVar, typeof(TypeSerializationArgs).GetField("NameTable")); args.il.BeginCallMethod(args.nameTableVar, "Deserialize", new Type[] { typeof(IPrimitiveReader), typeof(TypeSerializationHeader) }); args.il.PushLocal(args.streamVar); args.il.PushLocal(args.headerVar); args.il.CallMethod(); args.il.BeginCallMethod(args.nameTableVar, "GetSerializationInfo", new Type[] { typeof(SerializationInfo), typeof(int) }); args.il.GetField(args.dataArg, typeof(TypeSerializationArgs).GetField("SerializationInfo")); args.il.PushInt(this.CurrentVersion); args.il.CallMethod(); args.il.MarkLabel(HasNameTableLabel); // If the type automatically serializes its base class // then read it now. This must be done after the derived class // has a chance to load the name table if (this.serializableBaseType != null) { FieldInfo fi = typeof(TypeSerializationArgs).GetField("IsBaseClass"); args.il.PushArg(args.dataArg); args.il.PushBool(true); args.il.SetField(fi); // Set IsBaseClass field to ensure proper type mapping args.il.PushArgAsRef(args.instanceArg); args.il.PushArg(args.dataArg); args.il.CallMethod(PropertySerializationInfo.GetTypeMethod(this.serializableBaseType, PropertySerializationInfo.TypeMethodType.Deserialize)); args.il.GotoIfTrue(BaseSucceededLabel); args.il.PushArg(args.dataArg); args.il.PushBool(false); args.il.SetField(typeof(TypeSerializationArgs).GetField("Succeeded")); args.il.Goto(endLabel); args.il.MarkLabel(BaseSucceededLabel); // Clear IsBaseClass flag args.il.PushArg(args.dataArg); args.il.PushBool(false); args.il.SetField(fi); } // Create calls to deserialize each member foreach (PropertySerializationInfo propInfo in properties) { // If we hit a higher version property then put in // an "if" statement to exit if the serialized version // is lower than the next batch of properties if (propInfo.Version > version) { // push versionParam // push propInfo.Version // branch_if_less_than endLabel ; versionParam < propInfo.Version args.il.PushArg(args.versionArg); args.il.PushInt(propInfo.Version); args.il.GotoIfLess(endLabel); version = propInfo.Version; } args.il.BeginScope(); // If this property is marked obsolete, do not deserialize // it if the data min version is equal to or greater than // the version it was made obsolete in. if (propInfo.ObsoleteVersion > 0) { const string NoHeaderLabel = "_checkObsoleteNoHeader"; const string NotObsoleteLabel = "_notObsolete"; args.il.PushLocal(args.headerVar); args.il.GotoIfFalse(NoHeaderLabel); args.il.CallMethod(args.headerVar, typeof(TypeSerializationHeader).GetProperty("DataMinVersion").GetGetMethod()); args.il.PushInt(propInfo.ObsoleteVersion); args.il.GotoIfGreaterOrEqual(SkipPropertyLabel); args.il.Goto(NotObsoleteLabel); args.il.MarkLabel(NoHeaderLabel); args.il.PushArg(args.versionArg); args.il.PushInt(propInfo.ObsoleteVersion); args.il.GotoIfGreaterOrEqual(SkipPropertyLabel); args.il.MarkLabel(NotObsoleteLabel); } propInfo.GenerateReadIL(args); args.il.MarkLabel(SkipPropertyLabel); args.il.EndScope(); } // :endFunction args.il.MarkLabel(endLabel); args.il.Return(); this.autoDeserializeMethod = (AutoDeserializeMethod)args.il.Compile(typeof(AutoDeserializeMethod)); this.deserializeMethod = DeserializeAutoSerializable; }
public static bool RegisterType(Type customType, byte code, SerializeMethod serializeMethod, DeserializeMethod constructor) { return(Protocol.TryRegisterType(customType, code, serializeMethod, constructor)); }
} // Dummy constructor public CustomType(Type type, byte code, SerializeMethod serializeFunction, DeserializeMethod deserializeFunction) { } // 0x00000001806ACFB0-0x00000001806AD020
public object ProxyDeserialize(IJsonDict source) { return(DeserializeMethod.Invoke(this, new object[] { source })); }
public bool RegisterSerializableType(Type customType, byte code, SerializeMethod serializeMethod, DeserializeMethod constructor) { return(PhotonPeer.RegisterType(customType, code, serializeMethod, constructor)); }