public static void Test <T, TCreate>(RuntimeTypeModel model, bool compile = false, params Type[] extraTypes) where TCreate : T, new() where T : ICallbackTest { model.Add(typeof(TCreate), true); if (extraTypes != null) { for (int i = 0; i < extraTypes.Length; i++) { model.Add(extraTypes[i], true); } } model.AutoCompile = false; Test <T, TCreate>(model, "Runtime"); if (compile) { string name = typeof(TCreate).FullName + "Ser"; model.Compile(name, name + ".dll"); PEVerify.AssertValid(name + ".dll"); } model.CompileInPlace(); Test <T, TCreate>(model, "CompileInPlace"); if (compile) { Test <T, TCreate>(model.Compile(), "Compile"); // <===== lots of private members etc } }
void ExecuteAllModes(RuntimeTypeModel model, [CallerMemberName] string caller = null, bool standalone = false) { Execute(model, "Runtime"); Execute(model, "CompileInPlace"); if (standalone) { Execute(model.Compile(), "Compile"); model.Compile(caller, caller + ".dll"); PEVerify.AssertValid(caller + ".dll"); } }
public static void Main() { WriteHeading(".NET version"); Console.WriteLine(Environment.Version); RuntimeTypeModel orderModel = TypeModel.Create(); orderModel.Add(typeof(OrderHeader), true); orderModel.Add(typeof(OrderDetail), true); orderModel.Compile("OrderSerializer", "OrderSerializer.dll"); RuntimeTypeModel model = BuildMeta(); SampleDto.Customer cust1 = new SampleDto.Customer(); CustomerStruct cust2 = new CustomerStruct(); cust2.Id = cust1.Id = 123; cust2.Name = cust1.Name = "Fred"; #if !FX11 cust1.HasValue = cust2.HasValue = true; cust1.HowMuch = cust2.HowMuch = 0.123; #endif WriteCustomer(model, "Runtime - class", cust1); WriteCustomer(model, "Runtime - struct", cust2); #if FEAT_COMPILER && !FX11 model.CompileInPlace(); WriteCustomer(model, "InPlace- class", cust1); WriteCustomer(model, "InPlace - struct", cust2); #endif #if FEAT_COMPILER TypeModel compiled = model.Compile("CustomerModel", "CustomerModel.dll"); //PEVerify.Verify("CustomerModel.dll"); compiled = model.Compile("CustomerModel", "CustomerModel.dll"); WriteCustomer(compiled, "Compiled - class", cust2); WriteCustomer(compiled, "Compiled - struct", cust2); /* * CustomerModel serializer = new CustomerModel(); * using (MemoryStream ms = new MemoryStream()) * { * Customer cust = new Customer(); * cust.Id = 123; * cust.Name = "Fred"; * serializer.Serialize(ms, cust); * ms.Position = 0; * Customer clone = (Customer)serializer.Deserialize(ms, null, typeof(Customer)); * Console.WriteLine(clone.Id); * Console.WriteLine(clone.Name); * } */ #endif }
private static void SetUp() { protobufModel = TypeModel.Create(); AddTypeToModel <CallStackItem>(protobufModel); AddTypeToModel <List <CallStackItem> >(protobufModel); compiledModel = protobufModel.Compile(); }
//[MenuItem("Tools/Runtime SaveLoad/Persistent Classes/Build Type Model")] private static void BuildTypeModel() { //Removal of RTSLTypeModel.dll created by previous version of RTE File.Delete(Path.GetFullPath(RTSLPath.UserRoot + "/" + RTSLPath.TypeModel + ".dll")); EditorUtility.DisplayProgressBar("Build", "Building Type Model...", 0.66f); RuntimeTypeModel model = ProtobufSerializer.CreateTypeModel(); model.Compile(new RuntimeTypeModel.CompilerOptions() { OutputPath = TypeModelDll, TypeName = RTSLPath.TypeModel }); string srcPath = Application.dataPath.Remove(Application.dataPath.LastIndexOf("Assets")) + TypeModelDll; string dstPath = Path.GetFullPath(RTSLPath.UserRoot + "/" + TypeModelDll); Debug.LogFormat("Done! Move {0} to {1} ...", srcPath, dstPath); StringBuilder sb = new StringBuilder(); foreach (BuildTarget target in Enum.GetValues(typeof(BuildTarget))) { sb.AppendFormat(LinkFileAssemblyName, target); } File.WriteAllText(Path.GetFullPath(RTSLPath.UserRoot + "/link.xml"), string.Format(LinkFileTemplate, sb.ToString())); File.Delete(dstPath); File.Move(srcPath, dstPath); EditorPrefs.SetInt("RTSL_UpdateTypeModelImportSettings", 2); AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport); }
public static void TestModel(RuntimeTypeModel model, object value, string hex) { byte[] raw; using (MemoryStream ms = new MemoryStream()) { model.Serialize(ms, value); raw = ms.ToArray(); } Assert.Equal(hex, GetHex(raw)); model.CompileInPlace(); using (MemoryStream ms = new MemoryStream()) { model.Serialize(ms, value); raw = ms.ToArray(); } Assert.Equal(hex, GetHex(raw)); TypeModel compiled = model.Compile("compiled", "compiled.dll"); PEVerify.Verify("compiled.dll"); using (MemoryStream ms = new MemoryStream()) { compiled.Serialize(ms, value); raw = ms.ToArray(); } Assert.Equal(hex, GetHex(raw)); }
private static void BuildTypeModel() { RuntimeTypeModel model = TypeModelCreator.Create(); string dllName = RTSLPath.TypeModelDll; model.Compile(new RuntimeTypeModel.CompilerOptions() { OutputPath = dllName, TypeName = "RTSLTypeModel" }); string srcPath = Application.dataPath.Remove(Application.dataPath.LastIndexOf("Assets")) + dllName; string dstPath = Application.dataPath + RTSLPath.UserRoot + "/" + dllName; Debug.LogFormat("Done! Move {0} to {1} ...", srcPath, dstPath); File.Delete(dstPath); File.Move(srcPath, dstPath); AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); PluginImporter importer = AssetImporter.GetAtPath("Assets" + RTSLPath.UserRoot + "/" + dllName) as PluginImporter; importer.SetCompatibleWithAnyPlatform(true); importer.SetExcludeEditorFromAnyPlatform(true); importer.SaveAndReimport(); }
/// <summary> /// /// </summary> /// <returns></returns> public ProtoBuf.Meta.TypeModel Compile() { foreach (var type in _typeModel.Types) { var typeDescription = _typeModel.GetTypeDescription(type); Add(typeDescription); } return(_runtimeTypeModel.Compile()); }
void CompilePre(string name, int size) { Console.WriteLine("\n----------Compile Serializer DLL----------"); Type[] types = coreLib.GetTypes(); RuntimeTypeModel tm = TypeModel.Create(); int c = 0; int i = 0; foreach (var t in types) { if (t.Name.EndsWith("_ValidateInfo")) { continue; } tm.Add(t, true); i++; if (i > size) { string fn = name + c.ToString() + ".dll"; tm.Compile(name.Replace("-", "_") + c.ToString(), fn); File.Move(Globals.Instance.curBase + fn, dllPath + fn); c++; tm = TypeModel.Create(); i = 0; } } if (i > 0) { string fn = name + c.ToString() + ".dll"; tm.Compile(name.Replace("-", "_") + c.ToString(), fn); File.Move(Globals.Instance.curBase + fn, dllPath + fn); } }
internal static TypeModel CompileAndVerify(this RuntimeTypeModel model, [CallerMemberName] string name = null, int exitCode = 0, bool deleteOnSuccess = true) { var path = Path.ChangeExtension(name, "dll"); if (File.Exists(path)) { File.Delete(path); } var compiled = model.Compile(name, path); Verify(path, exitCode, deleteOnSuccess); return(compiled); }
internal static void CompileAndCache <T>(this RuntimeTypeModel model) { TypeModel compileModel; if (compiledModels.TryGetValue(typeof(T), out compileModel)) { return; } var cModel = model.Compile(); if (compiledModels.TryGetValue(typeof(T), out compileModel)) { return; } compiledModels.TryAdd(typeof(T), cModel); }
public static void CompileModel(RuntimeTypeModel model) { model.Compile(UniBufSerializer.TYPE_MODEL_NAME, LibraryFullName); if (!Directory.Exists(UNI_BUF_FOLDER)) { Directory.CreateDirectory(UNI_BUF_FOLDER); } if (File.Exists(LibraryPath)) { File.Delete(LibraryPath); } File.Move(LibraryFullName, LibraryPath); AssetDatabase.ImportAsset(LibraryPath); }
private void PrepareSerializer <T>(RuntimeTypeModel model) { model.CompileInPlace(); try { if (_targetType != typeof(TypeMetaData)) { model.Compile(); } } catch (InvalidOperationException ex) { throw new SerializationException( string.Format( "The model {0} could not be serialized, this could be because private members in the type (or down its graph) are decorated with the 'DataMember attribute', check inner exception for more details.", _targetType.FullName), ex); } }
private static void __CJNetFrameworkSerialzetionToolCompile() { RuntimeTypeModel rtCSProtocolSerializeTypSet = TypeModel.Create(); List <Type> CSProtocolSerializeTypSet = JsonSerializtionFactory.CreateSpecializationSerializeTypeSet(); foreach (Type typeItem in CSProtocolSerializeTypSet) { rtCSProtocolSerializeTypSet.Add(typeItem, true); } rtCSProtocolSerializeTypSet.Compile("CJNet_SerializeTool", "CJNet_SerializeTool.dll"); //RuntimeTypeModel rtMiddlewareProtocolSerializeTypSet = TypeModel.Create(); //List<Type> MiddlewareSerializeTypSet = Middleware.Middleware.JsonSerializtionFactory.CreateSpecializationSerializeTypeSet(); //foreach (Type typeItem in MiddlewareSerializeTypSet) //{ // rtMiddlewareProtocolSerializeTypSet.Add(typeItem, true); //} //rtMiddlewareProtocolSerializeTypSet.Compile("CJNet_MiddlewareProtocolSerializeTool", "CJNet_MiddlewareProtocolSerializeTool.dll"); }
public async Task SetupAsync() { RuntimeTypeModel rtModel = RuntimeTypeModel.Create(); rtModel.Add(typeof(TestStructSmall1)); rtModel.Add(typeof(TestStructSmall2)); rtModel.Add(typeof(TestStructLarge1)); rtModel.Add(typeof(TestClassSmall)); rtModel.Add(typeof(TestClassLarge)); rtModel.RegisterParallelServices <TestClassSmall>(); rtModel.RegisterParallelServices <TestClassLarge>(); model = rtModel.Compile(); tmpFilesRoot = Path.Combine(Path.GetTempPath(), "slStreamBenchmarks"); if (!Directory.Exists(tmpFilesRoot)) { Directory.CreateDirectory(tmpFilesRoot); } tmpFilename_baseline = Path.Combine(tmpFilesRoot, $"tmp_PB_PS_baseline_{typeof(T).Name}.dat"); tmpFilename_parallel = Path.Combine(tmpFilesRoot, $"tmp_PB_PS_parallel_{typeof(T).Name}.dat"); objArr = GetRandInstanceArr(BlockSize, TotBlocks); ms_baseline = new MemoryStream(); ms_parallel = new MemoryStream(); // generate binary files and memstreams to work with Write_Baseline(null, usingMemoryStream: true); await WriteAsync_Parallel(1, null, usingMemoryStream : true); Write_Baseline(null, usingMemoryStream: false); await WriteAsync_Parallel(1, null, usingMemoryStream : false); var File_size_baseline = new FileInfo(tmpFilename_baseline).Length; var File_size_parallel = new FileInfo(tmpFilename_parallel).Length; var Mem_size_padded = objArr.Sum(f => f.GetSize()) + objArr.Length * IntPtr.Size; var Mem_size_padded_SingleItem = objArr.First().GetSize(); Console.WriteLine($"{nameof(T)}: {typeof(T)}"); Console.WriteLine($"Memory size (padded) = {Mem_size_padded / ((double)1024 * 1024):f2} MB"); Console.WriteLine($"Memory size (padded) for 1 item = {Mem_size_padded_SingleItem / (double)1024:f2} KB"); Console.WriteLine($"Baseline file length (no framing data) = {File_size_baseline / ((double)1024 * 1024):f2} MB"); Console.WriteLine($"File length (with framing data) = {File_size_parallel / ((double)1024 * 1024):f2} MB"); }
private static void BuildTypeModel() { EditorUtility.DisplayProgressBar("Build", "Building Type Model...", 0.66f); RuntimeTypeModel model = TypeModelCreator.Create(); model.Compile(new RuntimeTypeModel.CompilerOptions() { OutputPath = RTSLPath.TypeModelDll, TypeName = "RTSLTypeModel" }); string srcPath = Application.dataPath.Remove(Application.dataPath.LastIndexOf("Assets")) + RTSLPath.TypeModelDll; string dstPath = Application.dataPath + RTSLPath.UserRoot + "/" + RTSLPath.TypeModelDll; Debug.LogFormat("Done! Move {0} to {1} ...", srcPath, dstPath); File.Delete(dstPath); File.Move(srcPath, dstPath); EditorPrefs.SetBool("RTSL_UpdateTypeModelImportSettings", true); AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport); }
private static void BuildMyProtoModel() { RuntimeTypeModel typeModel = GetModel(); //typeModel.Compile("MyProtoModel", "MyProtoModel.dll"); RuntimeTypeModel.CompilerOptions co = new RuntimeTypeModel.CompilerOptions(); co.TypeName = "MyProtoModel"; #pragma warning disable CS0618 // Type or member is obsolete co.OutputPath = "MyProtoModel.dll"; #pragma warning restore CS0618 // Type or member is obsolete typeModel.Compile(co); if (!Directory.Exists("Assets/Plugins")) { Directory.CreateDirectory("Assets/Plugins"); } File.Copy("MyProtoModel.dll", "Assets/Plugins/MyProtoModel.dll"); AssetDatabase.Refresh(); }
public static void Main(string[] args) { RuntimeTypeModel model = TypeModel.Create(); //RuntimeTypeModel.Default; // Add new derived models // Console.WriteLine("1"); // model[typeof(Model)].AddSubType(100, typeof(WorldModel)); Console.WriteLine("1"); model[typeof(NetworkPlayerData)].AddSubType(100, typeof(NetworkSorPlayerData)); // There seems to be a bug in protobuf-net, // if I don't do those deepclones they doesn't get registered... if (model.CanSerialize(typeof(InternalState))) { InternalState state = new InternalState(); model.DeepClone(state); Console.WriteLine("deep cloned InternalState"); } Console.WriteLine("compiling.."); model.Compile(SerializationConstants.StateSerializerName, SerializationConstants.StateDllName); }
public static void Main(string[] args) { RuntimeTypeModel model = TypeModel.Create(); // There seems to be a bug in protobuf-net, // if I don't do those deepclones they doesn't get registered... if (model.CanSerialize(typeof(Character))) { Character state = new Character(); model.DeepClone(state); Console.WriteLine("deep cloned Character"); } // There seems to be a bug in protobuf-net, // if I don't do those deepclones they doesn't get registered... if (model.CanSerialize(typeof(HUD))) { HUD state = new HUD(); model.DeepClone(state); Console.WriteLine("deep cloned HUD"); } Console.WriteLine("compiling.."); model.Compile(SerializationConstants.StorageSerializerName, SerializationConstants.StorageDllName); }
internal static TypeModel CompileAndVerify(this RuntimeTypeModel model, [CallerMemberName] string name = null, int exitCode = 0, bool deleteOnSuccess = true) { return(model.Compile()); }
public static TypeModel Compile(this RuntimeTypeModel model, string x, string y) { return(model.Compile()); }
public static TypeModel Compile(this RuntimeTypeModel model, string x, string y) { return(model.Compile()); // use an in-memory compile instead }