internal CustomType(Type type, int typeId, SerializeMethod encodeFunc, DeserializeMethod decodeFunc) { Type = type; TypeId = typeId; SerializeMethod = encodeFunc; DeserializeMethod = decodeFunc; }
/// <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 SerializableTypeInfo(Type type, byte id, SerializeMethod serializeFunction, DeserializeMethod deserializeFunction) { this.Type = type; this.Id = id; this.SerializeFunction = serializeFunction; this.DeserializeFunction = deserializeFunction; }
public CustomType(Type type, byte code, SerializeMethod serializeFunction, DeserializeMethod deserializeFunction) { this.Type = type; this.Code = code; 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 }); } }
/// <summary> /// Reads an object of the specified Type from an existing data Stream. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="stream"></param> /// <param name="method"></param> /// <returns></returns> public static T ReadObject <T>(Stream stream, SerializeMethod method = SerializeMethod.Unknown) { using (Serializer formatter = Serializer.Create(stream, method)) { return(formatter.ReadObject <T>()); } }
/// <summary> /// Saves an object to the specified data stream. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="obj"></param> /// <param name="stream"></param> /// <param name="method"></param> public static void WriteObject <T>(T obj, Stream stream, SerializeMethod method = SerializeMethod.Unknown) { using (Serializer formatter = Serializer.Create(stream, method)) { formatter.WriteObject(obj); } }
/// <summary> /// Reads an object of the specified Type from an existing data file. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="file"></param> /// <param name="method"></param> /// <returns></returns> public static T ReadObject <T>(string file, SerializeMethod method = SerializeMethod.Unknown) { using (FileStream str = File.OpenRead(file)) { return(Serializer.ReadObject <T>(str, method)); } }
/// <summary> /// Creates a new <see cref="Serializer"/> using the specified stream for I/O. /// </summary> /// <param name="stream">The stream to use.</param> /// <param name="method"> /// The serialization method to prefer. If <see cref="SerializeMethod.Unknown"/> is specified, if the stream /// is read- and seekable, auto-detection is used. Otherwise, the <see cref="DefaultMethod">default serialization method</see> is used. /// </param> /// <returns>A newly created <see cref="Serializer"/> meeting the specified criteria.</returns> public static Serializer Create(Stream stream, SerializeMethod method = SerializeMethod.Unknown) { if (method == SerializeMethod.Unknown) { if (stream.CanRead && stream.CanSeek && stream.Length > 0) { if (XmlSerializer.IsXmlStream(stream)) { method = SerializeMethod.Xml; } else { method = SerializeMethod.Binary; } } else { method = defaultMethod; } } if (method == SerializeMethod.Xml) { return(new XmlSerializer(stream)); } else { return(new BinarySerializer(stream)); } }
public ISerializedRecord Serialize(SerializeMethod method) { var accountFields = SerializedAccount.DEFAULT_FIELDS; var recordFields = SerializedRecord.DEFAULT_FIELDS; return(Serialize(method, accountFields, recordFields)); }
internal static void InitDefaultMethod() { if (DualityApp.ExecEnvironment == DualityApp.ExecutionEnvironment.Editor) { defaultMethod = SerializeMethod.Xml; } else { defaultMethod = SerializeMethod.Binary; } if (Directory.Exists(DualityApp.DataDirectory)) { foreach (string anyResource in Directory.EnumerateFiles(DualityApp.DataDirectory, "*" + Resource.FileExt, SearchOption.AllDirectories)) { using (FileStream stream = File.OpenRead(anyResource)) { try { defaultMethod = XmlSerializer.IsXmlStream(stream) ? SerializeMethod.Xml : SerializeMethod.Binary; break; } catch (Exception) {} } } } }
public ISerializedAccount Serialize(SerializeMethod method, DirectDebitConfiguration config) { var accountFields = config.BankAccount.GetProperties(); return(Serialize(method, accountFields)); }
public void BenchmarkDeserializeMethod <T>(SerializeMethod method, string json) { Stopwatch timed = new Stopwatch(); timed.Start(); object value = null; for (int x = 0; x < Iterations; x++) { switch (method) { case SerializeMethod.JsonNet: value = DeserializeJsonNet <T>(json); break; case SerializeMethod.JavaScriptSerializer: value = DeserializeWebExtensions <T>(json); break; case SerializeMethod.DataContractJsonSerializer: value = DeserializeDataContract <T>(json); break; } } timed.Stop(); Console.WriteLine("Deserialize method: {0}", method); Console.WriteLine("{0} ms", timed.ElapsedMilliseconds); Console.WriteLine(value); Console.WriteLine(); }
private T Deserialize <T>(SerializeMethod method, object json) { switch (method) { case SerializeMethod.JsonNet: return(DeserializeJsonNet <T>((string)json, false)); case SerializeMethod.JsonNetWithIsoConverter: return(DeserializeJsonNet <T>((string)json, true)); case SerializeMethod.JsonNetBinary: return(DeserializeJsonNetBinary <T>((byte[])json)); case SerializeMethod.BinaryFormatter: return(DeserializeBinaryFormatter <T>((byte[])json)); case SerializeMethod.JavaScriptSerializer: return(DeserializeWebExtensions <T>((string)json)); case SerializeMethod.DataContractSerializer: return(DeserializeDataContract <T>((string)json)); case SerializeMethod.DataContractJsonSerializer: return(DeserializeDataContractJson <T>((string)json)); default: throw new ArgumentOutOfRangeException("method"); } }
public static void RegisterSerializationTarget(SerializeMethod _nSerializeMethod, UnserializeMethod _nUnserializeMethod) { int iTargetId = s_mThrottledSerializeTargets.Count + 1; s_mThrottledSerializeTargets.Add((byte)iTargetId, new TSerializationMethods(_nSerializeMethod, _nUnserializeMethod)); }
internal static void WriteList <U> ( this StreamWriter writer, SerializeMethod <U> serializer, string fieldName, ICollection <U> elements, IPEndPoint endPoint, string serviceName ) { bool firstElement = true; WriteAnchor(writer, fieldName); writer.Write(openingBracket); foreach (var element in elements) { if (firstElement == true) { firstElement = false; } else { writer.Write(JSONSpanSerializer.comma); } serializer(writer, element, endPoint, serviceName); } writer.Write(closingBracket); }
/// <summary> /// 根据用户指定的方式构造序列化对象 /// </summary> /// <param name="mode">序列化方式</param> /// <returns>序列化对象</returns> public static ISerializer GetSerializer(SerializeMethod mode) { ISerializer Serializer; switch (mode) { case SerializeMethod.Bin: Serializer = new BinSerializer(); break; case SerializeMethod.Base64: Serializer = new Base64Serializer(); break; case SerializeMethod.NameValue: Serializer = new NameValueSerializer(); break; case SerializeMethod.Xml: Serializer = new XMLSerializer(); break; default: Serializer = new BinSerializer(); break; } ///默认设置编码为utf-8 Serializer.EncodName = "utf-8"; return(Serializer); }
private void TestWriteRead <T>(T writeObj, SerializeMethod format, Func <T, T, bool> checkEqual = null) { if (checkEqual == null) { checkEqual = (a, b) => object.Equals(a, b); } T readObj; using (MemoryStream stream = new MemoryStream()) { // Write using (Serializer formatterWrite = Serializer.Create(stream, format)) { formatterWrite.WriteObject(writeObj); } // Read stream.Position = 0; using (Serializer formatterRead = Serializer.Create(stream)) { readObj = formatterRead.ReadObject <T>(); } } Assert.IsTrue(checkEqual(writeObj, readObj), "Failed single WriteRead of Type {0} with Value {1}", typeof(T), writeObj); }
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); }
public void BenchmarkSerializeMethod(SerializeMethod method, object value) { Stopwatch timed = new Stopwatch(); timed.Start(); string json = null; for (int x = 0; x < Iterations; x++) { switch (method) { case SerializeMethod.JsonNet: json = JsonConvert.SerializeObject(value); break; case SerializeMethod.JavaScriptSerializer: json = SerializeWebExtensions(value); break; case SerializeMethod.DataContractJsonSerializer: json = SerializeDataContract(value); break; } } timed.Stop(); Console.WriteLine("Serialize method: {0}", method); Console.WriteLine("{0} ms", timed.ElapsedMilliseconds); Console.WriteLine(json); Console.WriteLine(); }
// Token: 0x06005379 RID: 21369 RVA: 0x001CCB54 File Offset: 0x001CAF54 internal static void Register() { Debug.Log("Registering Custom Photon Objets"); Type typeFromHandle = typeof(ApiAvatar); byte code = 66; if (PhotonCustomTypes.f__mg0 == null) { PhotonCustomTypes.f__mg0 = new SerializeMethod(PhotonCustomTypes.SerializeApiAvatar); } SerializeMethod serializeMethod = PhotonCustomTypes.f__mg0; if (PhotonCustomTypes.f__mg1 == null) { PhotonCustomTypes.f__mg1 = new DeserializeMethod(PhotonCustomTypes.DeserializeApiAvatar); } PhotonPeer.RegisterType(typeFromHandle, code, serializeMethod, PhotonCustomTypes.f__mg1); Type typeFromHandle2 = typeof(ApiWorld); byte code2 = 87; if (PhotonCustomTypes.f__mg2 == null) { PhotonCustomTypes.f__mg2 = new SerializeMethod(PhotonCustomTypes.SerializeApiWorld); } SerializeMethod serializeMethod2 = PhotonCustomTypes.f__mg2; if (PhotonCustomTypes.f__mg3 == null) { PhotonCustomTypes.f__mg3 = new DeserializeMethod(PhotonCustomTypes.DeserializeApiWorld); } PhotonPeer.RegisterType(typeFromHandle2, code2, serializeMethod2, PhotonCustomTypes.f__mg3); }
public ISerializedAccount Serialize(SerializeMethod method, string[] accountFields) { var account = new SerializedAccount(); if (Number.Length <= 8) { account.Number = Number.PadLeft(8, '0'); } if (Number.Length == 9) { account.Number = Number.Substring(1, 8); } if (Number.Length == 10 && Bank == DirectDebitAlbany.Bank.Natwest) { account.Number = Number.Substring(2, 8); } if (Number.Length == 10 && Bank == DirectDebitAlbany.Bank.Coop) { account.Number = Number.Substring(0, 8); } account.SortCode = SortCode; account.Name = Name.Format(method, 18); account.Line = Sugar.ComposeLine <SerializedAccount>( method, accountFields, account); return(account); }
/// <summary> Add a base type to SUCC serialization. It is recommended that you call this method in a static constructor. </summary> public static void AddBaseType <T>(SerializeMethod <T> serializeMethod, ParseMethod <T> parseMethod) { AddBaseType ( typeof(T), (object obj) => serializeMethod((T)obj), (string text) => parseMethod.Invoke(text) ); }
private void CreateReferenceFile <T>(string name, T writeObj, SerializeMethod format) { string filePath = TestHelper.GetEmbeddedResourcePath(GetReferenceResourceName(name, format), ".dat"); using (FileStream stream = File.Open(filePath, FileMode.Create)) using (Serializer formatter = Serializer.Create(stream, format)) { formatter.WriteObject(writeObj); } }
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); } }
private static void AddBaseType(Type type, SerializeMethod serializeMethod, ParseMethod parseMethod) { if (IsBaseType(type)) { throw new Exception($"Type {type} is already a supported base type. You cannot re-add it."); } BaseSerializeMethods.Add(type, serializeMethod); BaseParseMethods.Add(type, parseMethod); }
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(); }
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); }
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); }
public static string Format(this String str, SerializeMethod method, int length) { if (method == SerializeMethod.FixedWidth) { return(str.FixedWidth(length)); } if (method == SerializeMethod.CSV) { return(str.Truncate(length)); } throw new ArgumentOutOfRangeException("method", method, "Unknown SerializeMethod"); }
public ISerializedAccount Serialize(SerializeMethod method) { return Serialize(method, SerializedAccount.DEFAULT_FIELDS); }
public ISerializedAccount Serialize(SerializeMethod method, string[] accountFields) { var account = new SerializedAccount(); if (Number.Length <= 8) account.Number = Number.PadLeft(8, '0'); if (Number.Length == 9) account.Number = Number.Substring(1, 8); if (Number.Length == 10 && Bank == DirectDebitAlbany.Bank.Natwest) account.Number = Number.Substring(2, 8); if (Number.Length == 10 && Bank == DirectDebitAlbany.Bank.Coop) account.Number = Number.Substring(0, 8); account.SortCode = SortCode; account.Name = Name.Format(method, 18); account.Line = Sugar.ComposeLine<SerializedAccount>( method, accountFields, account); return account; }
public ISerializedRecord Serialize(SerializeMethod method, string[] accountFields, string[] recordFields) { var record = new SerializedRecord(); record.TransCode = BankValidation.TransCode[this.TransCode]; record.Amount = Amount.Format(method, 11, 2); record.Reference = Reference.Format(method, 18); record.Originator = Originator.Serialize(method, accountFields); record.Destination = Destination.Serialize(method, accountFields); record.Line = Sugar.ComposeLine<SerializedRecord>(method, recordFields, record); return record; }
public void GetSerializerTest() { SerializeMethod mode = SerializeMethod.Base64; ISerializer actual; actual = SerializeFactory.GetSerializer(mode); Assert.IsTrue(actual is Base64Serializer); mode = SerializeMethod.Bin; actual = SerializeFactory.GetSerializer(mode); Assert.IsTrue(actual is BinSerializer); mode = SerializeMethod.NameValue; actual = SerializeFactory.GetSerializer(mode); Assert.IsTrue(actual is NameValueSerializer); mode = SerializeMethod.Soap; actual = SerializeFactory.GetSerializer(mode); Assert.IsTrue(actual is SoapSerializer); mode = SerializeMethod.Xml; actual = SerializeFactory.GetSerializer(mode); Assert.IsTrue(actual is XMLSerializer); mode = new SerializeMethod(); actual = SerializeFactory.GetSerializer(mode); Assert.IsTrue(actual is BinSerializer); }
public ISerializedAccount Serialize(SerializeMethod method, DirectDebitConfiguration config) { var accountFields = config.BankAccount.GetProperties(); return Serialize(method, accountFields); }
public TSerializationMethods(SerializeMethod _nSerializeMethod, UnserializeMethod _nUnserializeMethod) { nSerializeMethod = _nSerializeMethod; nUnserializeMethod = _nUnserializeMethod; }
public ISerializedRecord Serialize(SerializeMethod method) { var accountFields = SerializedAccount.DEFAULT_FIELDS; var recordFields = SerializedRecord.DEFAULT_FIELDS; return Serialize(method, accountFields, recordFields); }