diff --git a/Rpc.sln b/Rpc.sln
index f6fe99d..60c9467 100644
--- a/Rpc.sln
+++ b/Rpc.sln
@@ -11,6 +11,8 @@ Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "BinaryData", "..\sciBASIC#\
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "framework", "framework", "{AAD1FC97-3157-4516-A6B4-2B19D673474E}"
EndProject
+Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "XDRStream", "XDRStream\XDRStream.vbproj", "{806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
BioDeep_database|Any CPU = BioDeep_database|Any CPU
@@ -708,6 +710,204 @@ Global
{487D7C92-D05A-4908-BF81-E6BABA0BF592}.Yilia-Release_x64|x64.Build.0 = Release|x64
{487D7C92-D05A-4908-BF81-E6BABA0BF592}.Yilia-Release_x64|x86.ActiveCfg = Release|x86
{487D7C92-D05A-4908-BF81-E6BABA0BF592}.Yilia-Release_x64|x86.Build.0 = Release|x86
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.BioDeep_database|Any CPU.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.BioDeep_database|Any CPU.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.BioDeep_database|x64.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.BioDeep_database|x64.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.BioDeep_database|x86.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.BioDeep_database|x86.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Biodeep_UNIX_x64|Any CPU.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Biodeep_UNIX_x64|Any CPU.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Biodeep_UNIX_x64|x64.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Biodeep_UNIX_x64|x64.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Biodeep_UNIX_x64|x86.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Biodeep_UNIX_x64|x86.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Biodeep|Any CPU.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Biodeep|Any CPU.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Biodeep|x64.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Biodeep|x64.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Biodeep|x86.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Biodeep|x86.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Biostack|Any CPU.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Biostack|Any CPU.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Biostack|x64.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Biostack|x64.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Biostack|x86.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Biostack|x86.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Biostack-Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Biostack-Debug|Any CPU.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Biostack-Debug|x64.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Biostack-Debug|x64.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Biostack-Debug|x86.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Biostack-Debug|x86.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Debug|x64.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Debug|x86.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.DEMO|Any CPU.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.DEMO|Any CPU.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.DEMO|x64.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.DEMO|x64.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.DEMO|x86.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.DEMO|x86.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Docker|Any CPU.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Docker|Any CPU.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Docker|x64.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Docker|x64.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Docker|x86.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Docker|x86.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.docs|Any CPU.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.docs|Any CPU.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.docs|x64.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.docs|x64.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.docs|x86.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.docs|x86.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.GCModeller(Release_X64)|Any CPU.ActiveCfg = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.GCModeller(Release_X64)|Any CPU.Build.0 = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.GCModeller(Release_X64)|x64.ActiveCfg = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.GCModeller(Release_X64)|x64.Build.0 = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.GCModeller(Release_X64)|x86.ActiveCfg = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.GCModeller(Release_X64)|x86.Build.0 = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.GCModeller(UNIX-Release_X64)|Any CPU.ActiveCfg = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.GCModeller(UNIX-Release_X64)|Any CPU.Build.0 = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.GCModeller(UNIX-Release_X64)|x64.ActiveCfg = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.GCModeller(UNIX-Release_X64)|x64.Build.0 = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.GCModeller(UNIX-Release_X64)|x86.ActiveCfg = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.GCModeller(UNIX-Release_X64)|x86.Build.0 = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.GTA5-game-test|Any CPU.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.GTA5-game-test|Any CPU.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.GTA5-game-test|x64.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.GTA5-game-test|x64.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.GTA5-game-test|x86.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.GTA5-game-test|x86.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.installer_x64|Any CPU.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.installer_x64|Any CPU.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.installer_x64|x64.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.installer_x64|x64.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.installer_x64|x86.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.installer_x64|x86.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.linux-profiler|Any CPU.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.linux-profiler|Any CPU.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.linux-profiler|x64.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.linux-profiler|x64.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.linux-profiler|x86.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.linux-profiler|x86.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.LipidSearch|Any CPU.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.LipidSearch|Any CPU.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.LipidSearch|x64.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.LipidSearch|x64.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.LipidSearch|x86.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.LipidSearch|x86.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.MetaCardio|Any CPU.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.MetaCardio|Any CPU.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.MetaCardio|x64.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.MetaCardio|x64.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.MetaCardio|x86.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.MetaCardio|x86.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.mysqli_X64_release|Any CPU.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.mysqli_X64_release|Any CPU.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.mysqli_X64_release|x64.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.mysqli_X64_release|x64.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.mysqli_X64_release|x86.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.mysqli_X64_release|x86.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.mzkit_UnixDocker|Any CPU.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.mzkit_UnixDocker|Any CPU.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.mzkit_UnixDocker|x64.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.mzkit_UnixDocker|x64.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.mzkit_UnixDocker|x86.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.mzkit_UnixDocker|x86.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.mzkit|Any CPU.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.mzkit|Any CPU.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.mzkit|x64.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.mzkit|x64.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.mzkit|x86.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.mzkit|x86.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.node-debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.node-debug|Any CPU.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.node-debug|x64.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.node-debug|x64.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.node-debug|x86.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.node-debug|x86.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.PlantMAT|Any CPU.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.PlantMAT|Any CPU.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.PlantMAT|x64.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.PlantMAT|x64.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.PlantMAT|x86.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.PlantMAT|x86.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.ProteoWizard.d|Any CPU.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.ProteoWizard.d|Any CPU.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.ProteoWizard.d|x64.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.ProteoWizard.d|x64.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.ProteoWizard.d|x86.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.ProteoWizard.d|x86.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Publish|Any CPU.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Publish|Any CPU.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Publish|x64.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Publish|x64.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Publish|x86.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Publish|x86.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.R-dotnet|Any CPU.ActiveCfg = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.R-dotnet|Any CPU.Build.0 = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.R-dotnet|x64.ActiveCfg = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.R-dotnet|x64.Build.0 = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.R-dotnet|x86.ActiveCfg = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.R-dotnet|x86.Build.0 = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Release|Any CPU.Build.0 = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Release|x64.ActiveCfg = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Release|x64.Build.0 = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Release|x86.ActiveCfg = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Release|x86.Build.0 = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Rsharp_app_release|Any CPU.ActiveCfg = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Rsharp_app_release|Any CPU.Build.0 = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Rsharp_app_release|x64.ActiveCfg = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Rsharp_app_release|x64.Build.0 = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Rsharp_app_release|x86.ActiveCfg = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Rsharp_app_release|x86.Build.0 = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.RsharpDev|Any CPU.ActiveCfg = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.RsharpDev|Any CPU.Build.0 = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.RsharpDev|x64.ActiveCfg = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.RsharpDev|x64.Build.0 = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.RsharpDev|x86.ActiveCfg = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.RsharpDev|x86.Build.0 = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.sciBASIC.NET-test-release|Any CPU.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.sciBASIC.NET-test-release|Any CPU.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.sciBASIC.NET-test-release|x64.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.sciBASIC.NET-test-release|x64.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.sciBASIC.NET-test-release|x86.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.sciBASIC.NET-test-release|x86.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Surveillance-of-infectious-diseases|Any CPU.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Surveillance-of-infectious-diseases|Any CPU.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Surveillance-of-infectious-diseases|x64.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Surveillance-of-infectious-diseases|x64.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Surveillance-of-infectious-diseases|x86.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Surveillance-of-infectious-diseases|x86.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.test|Any CPU.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.test|Any CPU.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.test|x64.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.test|x64.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.test|x86.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.test|x86.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Voyager1|Any CPU.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Voyager1|Any CPU.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Voyager1|x64.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Voyager1|x64.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Voyager1|x86.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Voyager1|x86.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.WebAssembly|Any CPU.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.WebAssembly|Any CPU.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.WebAssembly|x64.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.WebAssembly|x64.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.WebAssembly|x86.ActiveCfg = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.WebAssembly|x86.Build.0 = Debug|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Yilia-Release_x64|Any CPU.ActiveCfg = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Yilia-Release_x64|Any CPU.Build.0 = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Yilia-Release_x64|x64.ActiveCfg = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Yilia-Release_x64|x64.Build.0 = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Yilia-Release_x64|x86.ActiveCfg = Release|Any CPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}.Yilia-Release_x64|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/XDRStream/Attributes/CaseAttribute.vb b/XDRStream/Attributes/CaseAttribute.vb
new file mode 100644
index 0000000..73fd1f0
--- /dev/null
+++ b/XDRStream/Attributes/CaseAttribute.vb
@@ -0,0 +1,63 @@
+#Region "Microsoft.VisualBasic::e82582233ab9370ed4a916d504f35ba8, Data\BinaryData\BinaryData\XDR\Attributes\CaseAttribute.vb"
+
+ ' Author:
+ '
+ ' asuka (amethyst.asuka@gcmodeller.org)
+ ' xie (genetics@smrucc.org)
+ ' xieguigang (xie.guigang@live.com)
+ '
+ ' Copyright (c) 2018 GPL3 Licensed
+ '
+ '
+ ' GNU GENERAL PUBLIC LICENSE (GPL3)
+ '
+ '
+ ' This program is free software: you can redistribute it and/or modify
+ ' it under the terms of the GNU General Public License as published by
+ ' the Free Software Foundation, either version 3 of the License, or
+ ' (at your option) any later version.
+ '
+ ' This program is distributed in the hope that it will be useful,
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ' GNU General Public License for more details.
+ '
+ ' You should have received a copy of the GNU General Public License
+ ' along with this program. If not, see .
+
+
+
+ ' /********************************************************************************/
+
+ ' Summaries:
+
+ ' Class CaseAttribute
+ '
+ ' Constructor: (+1 Overloads) Sub New
+ '
+ '
+ ' /********************************************************************************/
+
+#End Region
+
+Imports System
+
+Namespace Xdr
+
+ Public Class CaseAttribute
+ Inherits Attribute
+
+ Public ReadOnly Value As Object
+
+ Public Sub New(val As Object)
+ Dim vT As Type = val.GetType()
+
+ If vT Is GetType(Integer) OrElse vT.IsEnum Then
+ Value = val
+ Else
+ Throw New InvalidOperationException("required enum type or int")
+ End If
+ End Sub
+ End Class
+End Namespace
+
diff --git a/XDRStream/Attributes/FixAttribute.vb b/XDRStream/Attributes/FixAttribute.vb
new file mode 100644
index 0000000..9a2740b
--- /dev/null
+++ b/XDRStream/Attributes/FixAttribute.vb
@@ -0,0 +1,69 @@
+#Region "Microsoft.VisualBasic::3d125c37a2d81976cafb2e6bb4cd022a, Data\BinaryData\BinaryData\XDR\Attributes\FixAttribute.vb"
+
+ ' Author:
+ '
+ ' asuka (amethyst.asuka@gcmodeller.org)
+ ' xie (genetics@smrucc.org)
+ ' xieguigang (xie.guigang@live.com)
+ '
+ ' Copyright (c) 2018 GPL3 Licensed
+ '
+ '
+ ' GNU GENERAL PUBLIC LICENSE (GPL3)
+ '
+ '
+ ' This program is free software: you can redistribute it and/or modify
+ ' it under the terms of the GNU General Public License as published by
+ ' the Free Software Foundation, either version 3 of the License, or
+ ' (at your option) any later version.
+ '
+ ' This program is distributed in the hope that it will be useful,
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ' GNU General Public License for more details.
+ '
+ ' You should have received a copy of the GNU General Public License
+ ' along with this program. If not, see .
+
+
+
+ ' /********************************************************************************/
+
+ ' Summaries:
+
+ ' Class FixAttribute
+ '
+ ' Properties: Length
+ '
+ ' Constructor: (+1 Overloads) Sub New
+ '
+ '
+ ' /********************************************************************************/
+
+#End Region
+
+Imports System
+
+Namespace Xdr
+
+ Public Class FixAttribute
+ Inherits Attribute
+
+ Private _Length As UInteger
+
+ Public Property Length As UInteger
+ Get
+ Return _Length
+ End Get
+ Private Set(value As UInteger)
+ _Length = value
+ End Set
+ End Property
+
+ Public Sub New(length As UInteger)
+ If length = 0 Then Throw New ArgumentException("length must be greater than zero")
+ Me.Length = length
+ End Sub
+ End Class
+End Namespace
+
diff --git a/XDRStream/Attributes/OptionAttribute.vb b/XDRStream/Attributes/OptionAttribute.vb
new file mode 100644
index 0000000..d18c8ce
--- /dev/null
+++ b/XDRStream/Attributes/OptionAttribute.vb
@@ -0,0 +1,54 @@
+#Region "Microsoft.VisualBasic::681922f83acfe5c665a73aa9e5f05bf3, Data\BinaryData\BinaryData\XDR\Attributes\OptionAttribute.vb"
+
+ ' Author:
+ '
+ ' asuka (amethyst.asuka@gcmodeller.org)
+ ' xie (genetics@smrucc.org)
+ ' xieguigang (xie.guigang@live.com)
+ '
+ ' Copyright (c) 2018 GPL3 Licensed
+ '
+ '
+ ' GNU GENERAL PUBLIC LICENSE (GPL3)
+ '
+ '
+ ' This program is free software: you can redistribute it and/or modify
+ ' it under the terms of the GNU General Public License as published by
+ ' the Free Software Foundation, either version 3 of the License, or
+ ' (at your option) any later version.
+ '
+ ' This program is distributed in the hope that it will be useful,
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ' GNU General Public License for more details.
+ '
+ ' You should have received a copy of the GNU General Public License
+ ' along with this program. If not, see .
+
+
+
+ ' /********************************************************************************/
+
+ ' Summaries:
+
+ ' Class OptionAttribute
+ '
+ ' Constructor: (+1 Overloads) Sub New
+ '
+ '
+ ' /********************************************************************************/
+
+#End Region
+
+Imports System
+
+Namespace Xdr
+
+ Public Class OptionAttribute
+ Inherits Attribute
+
+ Public Sub New()
+ End Sub
+ End Class
+End Namespace
+
diff --git a/XDRStream/Attributes/OrderAttribute.vb b/XDRStream/Attributes/OrderAttribute.vb
new file mode 100644
index 0000000..3a1b960
--- /dev/null
+++ b/XDRStream/Attributes/OrderAttribute.vb
@@ -0,0 +1,68 @@
+#Region "Microsoft.VisualBasic::6d7e61d58408ced9cd1a94f5515eeb60, Data\BinaryData\BinaryData\XDR\Attributes\OrderAttribute.vb"
+
+ ' Author:
+ '
+ ' asuka (amethyst.asuka@gcmodeller.org)
+ ' xie (genetics@smrucc.org)
+ ' xieguigang (xie.guigang@live.com)
+ '
+ ' Copyright (c) 2018 GPL3 Licensed
+ '
+ '
+ ' GNU GENERAL PUBLIC LICENSE (GPL3)
+ '
+ '
+ ' This program is free software: you can redistribute it and/or modify
+ ' it under the terms of the GNU General Public License as published by
+ ' the Free Software Foundation, either version 3 of the License, or
+ ' (at your option) any later version.
+ '
+ ' This program is distributed in the hope that it will be useful,
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ' GNU General Public License for more details.
+ '
+ ' You should have received a copy of the GNU General Public License
+ ' along with this program. If not, see .
+
+
+
+ ' /********************************************************************************/
+
+ ' Summaries:
+
+ ' Class OrderAttribute
+ '
+ ' Properties: Order
+ '
+ ' Constructor: (+1 Overloads) Sub New
+ '
+ '
+ ' /********************************************************************************/
+
+#End Region
+
+Imports System
+
+Namespace Xdr
+
+ Public Class OrderAttribute
+ Inherits Attribute
+
+ Private _Order As UInteger
+
+ Public Property Order As UInteger
+ Get
+ Return _Order
+ End Get
+ Private Set(value As UInteger)
+ _Order = value
+ End Set
+ End Property
+
+ Public Sub New(order As UInteger)
+ Me.Order = order
+ End Sub
+ End Class
+End Namespace
+
diff --git a/XDRStream/Attributes/SwitchAttribute.vb b/XDRStream/Attributes/SwitchAttribute.vb
new file mode 100644
index 0000000..0966232
--- /dev/null
+++ b/XDRStream/Attributes/SwitchAttribute.vb
@@ -0,0 +1,54 @@
+#Region "Microsoft.VisualBasic::043e5bf23dadfd7c723b336c04ab4aca, Data\BinaryData\BinaryData\XDR\Attributes\SwitchAttribute.vb"
+
+ ' Author:
+ '
+ ' asuka (amethyst.asuka@gcmodeller.org)
+ ' xie (genetics@smrucc.org)
+ ' xieguigang (xie.guigang@live.com)
+ '
+ ' Copyright (c) 2018 GPL3 Licensed
+ '
+ '
+ ' GNU GENERAL PUBLIC LICENSE (GPL3)
+ '
+ '
+ ' This program is free software: you can redistribute it and/or modify
+ ' it under the terms of the GNU General Public License as published by
+ ' the Free Software Foundation, either version 3 of the License, or
+ ' (at your option) any later version.
+ '
+ ' This program is distributed in the hope that it will be useful,
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ' GNU General Public License for more details.
+ '
+ ' You should have received a copy of the GNU General Public License
+ ' along with this program. If not, see .
+
+
+
+ ' /********************************************************************************/
+
+ ' Summaries:
+
+ ' Class SwitchAttribute
+ '
+ ' Constructor: (+1 Overloads) Sub New
+ '
+ '
+ ' /********************************************************************************/
+
+#End Region
+
+Imports System
+
+Namespace Xdr
+
+ Public Class SwitchAttribute
+ Inherits Attribute
+
+ Public Sub New()
+ End Sub
+ End Class
+End Namespace
+
diff --git a/XDRStream/Attributes/VarAttribute.vb b/XDRStream/Attributes/VarAttribute.vb
new file mode 100644
index 0000000..0e53014
--- /dev/null
+++ b/XDRStream/Attributes/VarAttribute.vb
@@ -0,0 +1,73 @@
+#Region "Microsoft.VisualBasic::6f93eeec3aac712957ec93b2f9ffe6df, Data\BinaryData\BinaryData\XDR\Attributes\VarAttribute.vb"
+
+ ' Author:
+ '
+ ' asuka (amethyst.asuka@gcmodeller.org)
+ ' xie (genetics@smrucc.org)
+ ' xieguigang (xie.guigang@live.com)
+ '
+ ' Copyright (c) 2018 GPL3 Licensed
+ '
+ '
+ ' GNU GENERAL PUBLIC LICENSE (GPL3)
+ '
+ '
+ ' This program is free software: you can redistribute it and/or modify
+ ' it under the terms of the GNU General Public License as published by
+ ' the Free Software Foundation, either version 3 of the License, or
+ ' (at your option) any later version.
+ '
+ ' This program is distributed in the hope that it will be useful,
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ' GNU General Public License for more details.
+ '
+ ' You should have received a copy of the GNU General Public License
+ ' along with this program. If not, see .
+
+
+
+ ' /********************************************************************************/
+
+ ' Summaries:
+
+ ' Class VarAttribute
+ '
+ ' Properties: MaxLength
+ '
+ ' Constructor: (+2 Overloads) Sub New
+ '
+ '
+ ' /********************************************************************************/
+
+#End Region
+
+Imports System
+
+Namespace Xdr
+
+ Public Class VarAttribute
+ Inherits Attribute
+
+ Private _MaxLength As UInteger
+
+ Public Property MaxLength As UInteger
+ Get
+ Return _MaxLength
+ End Get
+ Private Set(value As UInteger)
+ _MaxLength = value
+ End Set
+ End Property
+
+ Public Sub New()
+ MaxLength = UInteger.MaxValue
+ End Sub
+
+ Public Sub New(maxLength As UInteger)
+ If maxLength = 0 Then Throw New ArgumentException("length must be greater than zero")
+ Me.MaxLength = maxLength
+ End Sub
+ End Class
+End Namespace
+
diff --git a/XDRStream/Delegates.vb b/XDRStream/Delegates.vb
new file mode 100644
index 0000000..83bb174
--- /dev/null
+++ b/XDRStream/Delegates.vb
@@ -0,0 +1,64 @@
+#Region "Microsoft.VisualBasic::f212c520101918e343e9cc664a31306a, Data\BinaryData\BinaryData\XDR\Delegates.vb"
+
+ ' Author:
+ '
+ ' asuka (amethyst.asuka@gcmodeller.org)
+ ' xie (genetics@smrucc.org)
+ ' xieguigang (xie.guigang@live.com)
+ '
+ ' Copyright (c) 2018 GPL3 Licensed
+ '
+ '
+ ' GNU GENERAL PUBLIC LICENSE (GPL3)
+ '
+ '
+ ' This program is free software: you can redistribute it and/or modify
+ ' it under the terms of the GNU General Public License as published by
+ ' the Free Software Foundation, either version 3 of the License, or
+ ' (at your option) any later version.
+ '
+ ' This program is distributed in the hope that it will be useful,
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ' GNU General Public License for more details.
+ '
+ ' You should have received a copy of the GNU General Public License
+ ' along with this program. If not, see .
+
+
+
+ ' /********************************************************************************/
+
+ ' Summaries:
+
+ ' Delegate Function
+ '
+ '
+ ' Delegate Function
+ '
+ '
+ ' Delegate Sub
+ '
+ '
+ ' Delegate Sub
+ '
+ '
+ '
+ '
+ '
+ '
+ '
+ '
+ '
+ ' /********************************************************************************/
+
+#End Region
+
+
+Namespace Xdr
+ Public Delegate Function ReadOneDelegate(Of T)(reader As Reader) As T
+ Public Delegate Function ReadManyDelegate(Of T)(reader As Reader, len As UInteger) As T
+ Public Delegate Sub WriteOneDelegate(Of T)(writer As Writer, item As T)
+ Public Delegate Sub WriteManyDelegate(Of T)(writer As Writer, len As UInteger, item As T)
+End Namespace
+
diff --git a/XDRStream/Emit/BuildRequest.vb b/XDRStream/Emit/BuildRequest.vb
new file mode 100644
index 0000000..498f6c9
--- /dev/null
+++ b/XDRStream/Emit/BuildRequest.vb
@@ -0,0 +1,51 @@
+#Region "Microsoft.VisualBasic::ecdb7d9b305fb129b4e7b0ac7ab18d36, Data\BinaryData\BinaryData\XDR\Emit\BuildRequest.vb"
+
+ ' Author:
+ '
+ ' asuka (amethyst.asuka@gcmodeller.org)
+ ' xie (genetics@smrucc.org)
+ ' xieguigang (xie.guigang@live.com)
+ '
+ ' Copyright (c) 2018 GPL3 Licensed
+ '
+ '
+ ' GNU GENERAL PUBLIC LICENSE (GPL3)
+ '
+ '
+ ' This program is free software: you can redistribute it and/or modify
+ ' it under the terms of the GNU General Public License as published by
+ ' the Free Software Foundation, either version 3 of the License, or
+ ' (at your option) any later version.
+ '
+ ' This program is distributed in the hope that it will be useful,
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ' GNU General Public License for more details.
+ '
+ ' You should have received a copy of the GNU General Public License
+ ' along with this program. If not, see .
+
+
+
+ ' /********************************************************************************/
+
+ ' Summaries:
+
+ ' Class BuildRequest
+ '
+ ' Properties: Method, TargetType
+ '
+ '
+ ' /********************************************************************************/
+
+#End Region
+
+Imports System
+
+Namespace Xdr
+ Friend NotInheritable Class BuildRequest
+ Public Property TargetType As Type
+ Public Property Method As OpaqueType
+ End Class
+End Namespace
+
diff --git a/XDRStream/Emit/DelegateCacheDescription.vb b/XDRStream/Emit/DelegateCacheDescription.vb
new file mode 100644
index 0000000..50ca657
--- /dev/null
+++ b/XDRStream/Emit/DelegateCacheDescription.vb
@@ -0,0 +1,60 @@
+#Region "Microsoft.VisualBasic::d9c9f765057d5f82049889558353172d, Data\BinaryData\BinaryData\XDR\Emit\DelegateCacheDescription.vb"
+
+ ' Author:
+ '
+ ' asuka (amethyst.asuka@gcmodeller.org)
+ ' xie (genetics@smrucc.org)
+ ' xieguigang (xie.guigang@live.com)
+ '
+ ' Copyright (c) 2018 GPL3 Licensed
+ '
+ '
+ ' GNU GENERAL PUBLIC LICENSE (GPL3)
+ '
+ '
+ ' This program is free software: you can redistribute it and/or modify
+ ' it under the terms of the GNU General Public License as published by
+ ' the Free Software Foundation, either version 3 of the License, or
+ ' (at your option) any later version.
+ '
+ ' This program is distributed in the hope that it will be useful,
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ' GNU General Public License for more details.
+ '
+ ' You should have received a copy of the GNU General Public License
+ ' along with this program. If not, see .
+
+
+
+ ' /********************************************************************************/
+
+ ' Summaries:
+
+ ' Class BuildBinderDescription
+ '
+ ' Constructor: (+1 Overloads) Sub New
+ '
+ '
+ ' /********************************************************************************/
+
+#End Region
+
+Imports System
+Imports System.Reflection.Emit
+Imports System.Reflection
+
+Namespace Xdr.Emit
+ Public Class BuildBinderDescription
+ Public ReadOnly Result As Type
+ Public ReadOnly BuildRequest As FieldInfo
+
+ Public Sub New(modBuilder As ModuleBuilder)
+ Dim typeBuilder = modBuilder.DefineType("BuildBinder", TypeAttributes.Public Or TypeAttributes.Class Or TypeAttributes.Abstract Or TypeAttributes.Sealed)
+ Dim fb_request = typeBuilder.DefineField("Request", GetType(Action(Of Type, OpaqueType)), FieldAttributes.Public Or FieldAttributes.Static)
+ Result = typeBuilder.CreateType()
+ BuildRequest = fb_request
+ End Sub
+ End Class
+End Namespace
+
diff --git a/XDRStream/Emit/ErrorStub.vb b/XDRStream/Emit/ErrorStub.vb
new file mode 100644
index 0000000..d91642c
--- /dev/null
+++ b/XDRStream/Emit/ErrorStub.vb
@@ -0,0 +1,71 @@
+#Region "Microsoft.VisualBasic::e6da63e5707615687bc169b000d8cd3d, Data\BinaryData\BinaryData\XDR\Emit\ErrorStub.vb"
+
+ ' Author:
+ '
+ ' asuka (amethyst.asuka@gcmodeller.org)
+ ' xie (genetics@smrucc.org)
+ ' xieguigang (xie.guigang@live.com)
+ '
+ ' Copyright (c) 2018 GPL3 Licensed
+ '
+ '
+ ' GNU GENERAL PUBLIC LICENSE (GPL3)
+ '
+ '
+ ' This program is free software: you can redistribute it and/or modify
+ ' it under the terms of the GNU General Public License as published by
+ ' the Free Software Foundation, either version 3 of the License, or
+ ' (at your option) any later version.
+ '
+ ' This program is distributed in the hope that it will be useful,
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ' GNU General Public License for more details.
+ '
+ ' You should have received a copy of the GNU General Public License
+ ' along with this program. If not, see .
+
+
+
+ ' /********************************************************************************/
+
+ ' Summaries:
+
+ ' Module ErrorStub
+ '
+ ' Function: ReadManyDelegate, ReadOneDelegate, StubDelegate, WriteManyDelegate, WriteOneDelegate
+ '
+ '
+ ' /********************************************************************************/
+
+#End Region
+
+Imports System
+
+Namespace Xdr
+ Friend Module ErrorStub
+ Private Function StubDelegate(ex As Exception, method As String, targetType As Type, genDelegateType As Type) As [Delegate]
+ Dim stubType = GetType(ErrorStubType(Of)).MakeGenericType(targetType)
+ Dim stubInstance = Activator.CreateInstance(stubType, ex)
+ Dim mi = stubType.GetMethod(method)
+ Return [Delegate].CreateDelegate(genDelegateType.MakeGenericType(targetType), stubInstance, mi)
+ End Function
+
+ Friend Function ReadOneDelegate(t As Type, ex As Exception) As [Delegate]
+ Return StubDelegate(ex, "ReadOne", t, GetType(ReadOneDelegate(Of)))
+ End Function
+
+ Friend Function ReadManyDelegate(t As Type, ex As Exception) As [Delegate]
+ Return StubDelegate(ex, "ReadMany", t, GetType(ReadManyDelegate(Of)))
+ End Function
+
+ Friend Function WriteOneDelegate(t As Type, ex As Exception) As [Delegate]
+ Return StubDelegate(ex, "WriteOne", t, GetType(WriteOneDelegate(Of)))
+ End Function
+
+ Friend Function WriteManyDelegate(t As Type, ex As Exception) As [Delegate]
+ Return StubDelegate(ex, "WriteMany", t, GetType(WriteManyDelegate(Of)))
+ End Function
+ End Module
+End Namespace
+
diff --git a/XDRStream/Emit/ErrorStubType.vb b/XDRStream/Emit/ErrorStubType.vb
new file mode 100644
index 0000000..61fd490
--- /dev/null
+++ b/XDRStream/Emit/ErrorStubType.vb
@@ -0,0 +1,74 @@
+#Region "Microsoft.VisualBasic::aca7ad23e0d93dd7158815a5910f7457, Data\BinaryData\BinaryData\XDR\Emit\ErrorStubType.vb"
+
+ ' Author:
+ '
+ ' asuka (amethyst.asuka@gcmodeller.org)
+ ' xie (genetics@smrucc.org)
+ ' xieguigang (xie.guigang@live.com)
+ '
+ ' Copyright (c) 2018 GPL3 Licensed
+ '
+ '
+ ' GNU GENERAL PUBLIC LICENSE (GPL3)
+ '
+ '
+ ' This program is free software: you can redistribute it and/or modify
+ ' it under the terms of the GNU General Public License as published by
+ ' the Free Software Foundation, either version 3 of the License, or
+ ' (at your option) any later version.
+ '
+ ' This program is distributed in the hope that it will be useful,
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ' GNU General Public License for more details.
+ '
+ ' You should have received a copy of the GNU General Public License
+ ' along with this program. If not, see .
+
+
+
+ ' /********************************************************************************/
+
+ ' Summaries:
+
+ ' Class ErrorStubType
+ '
+ ' Constructor: (+1 Overloads) Sub New
+ '
+ ' Function: ReadMany, ReadOne
+ '
+ ' Sub: WriteMany, WriteOne
+ '
+ '
+ ' /********************************************************************************/
+
+#End Region
+
+Imports System
+
+Namespace Xdr
+ Friend NotInheritable Class ErrorStubType(Of T)
+ Public ReadOnly [Error] As Exception
+
+ Public Sub New(ex As Exception)
+ [Error] = ex
+ End Sub
+
+ Public Function ReadOne(reader As Reader) As T
+ Throw [Error]
+ End Function
+
+ Public Function ReadMany(reader As Reader, len As UInteger) As T
+ Throw [Error]
+ End Function
+
+ Public Sub WriteOne(writer As Writer, v As T)
+ Throw [Error]
+ End Sub
+
+ Public Sub WriteMany(writer As Writer, len As UInteger, v As T)
+ Throw [Error]
+ End Sub
+ End Class
+End Namespace
+
diff --git a/XDRStream/Emit/StaticCacheDescription.vb b/XDRStream/Emit/StaticCacheDescription.vb
new file mode 100644
index 0000000..1534b85
--- /dev/null
+++ b/XDRStream/Emit/StaticCacheDescription.vb
@@ -0,0 +1,89 @@
+#Region "Microsoft.VisualBasic::6b4087e1862e5a0af5c252092ad6880a, Data\BinaryData\BinaryData\XDR\Emit\StaticCacheDescription.vb"
+
+ ' Author:
+ '
+ ' asuka (amethyst.asuka@gcmodeller.org)
+ ' xie (genetics@smrucc.org)
+ ' xieguigang (xie.guigang@live.com)
+ '
+ ' Copyright (c) 2018 GPL3 Licensed
+ '
+ '
+ ' GNU GENERAL PUBLIC LICENSE (GPL3)
+ '
+ '
+ ' This program is free software: you can redistribute it and/or modify
+ ' it under the terms of the GNU General Public License as published by
+ ' the Free Software Foundation, either version 3 of the License, or
+ ' (at your option) any later version.
+ '
+ ' This program is distributed in the hope that it will be useful,
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ' GNU General Public License for more details.
+ '
+ ' You should have received a copy of the GNU General Public License
+ ' along with this program. If not, see .
+
+
+
+ ' /********************************************************************************/
+
+ ' Summaries:
+
+ ' Class StaticCacheDescription
+ '
+ ' Constructor: (+1 Overloads) Sub New
+ ' Function: Instance
+ '
+ '
+ ' /********************************************************************************/
+
+#End Region
+
+Imports System
+Imports System.Reflection.Emit
+Imports System.Reflection
+
+Namespace Xdr.Emit
+ Public Class StaticCacheDescription
+ Public ReadOnly Result As Type
+
+ Public Sub New(modBuilder As ModuleBuilder, delegCacheDesc As BuildBinderDescription, name As String, read As Boolean, mType As OpaqueType)
+ Dim typeBuilder = modBuilder.DefineType(name, TypeAttributes.Public Or TypeAttributes.Class Or TypeAttributes.Abstract Or TypeAttributes.Sealed)
+ Dim genTypeParam = typeBuilder.DefineGenericParameters("T")(0)
+ Dim instanceType As Type
+
+ If read Then
+ If mType = OpaqueType.One Then
+ instanceType = GetType(ReadOneDelegate(Of))
+ Else
+ instanceType = GetType(ReadManyDelegate(Of))
+ End If
+ Else
+
+ If mType = OpaqueType.One Then
+ instanceType = GetType(WriteOneDelegate(Of))
+ Else
+ instanceType = GetType(WriteManyDelegate(Of))
+ End If
+ End If
+
+ typeBuilder.DefineField("Instance", instanceType.MakeGenericType(genTypeParam), FieldAttributes.Public Or FieldAttributes.Static)
+ Dim ctor = typeBuilder.DefineConstructor(MethodAttributes.Static, CallingConventions.Standard, New Type(-1) {})
+ Dim il As ILGenerator = ctor.GetILGenerator()
+ il.Emit(OpCodes.Ldsfld, delegCacheDesc.BuildRequest)
+ il.Emit(OpCodes.Ldtoken, genTypeParam)
+ il.Emit(OpCodes.Call, GetType(Type).GetMethod("GetTypeFromHandle"))
+ il.Emit(OpCodes.Ldc_I4_S, mType)
+ il.Emit(OpCodes.Callvirt, GetType(Action(Of Type, OpaqueType)).GetMethod("Invoke"))
+ il.Emit(OpCodes.Ret)
+ Result = typeBuilder.CreateType()
+ End Sub
+
+ Public Function Instance(genType As Type) As FieldInfo
+ Return TypeBuilder.GetField(Result.MakeGenericType(genType), Result.GetField("Instance"))
+ End Function
+ End Class
+End Namespace
+
diff --git a/XDRStream/EmitContexts/EmitContext.vb b/XDRStream/EmitContexts/EmitContext.vb
new file mode 100644
index 0000000..bada711
--- /dev/null
+++ b/XDRStream/EmitContexts/EmitContext.vb
@@ -0,0 +1,113 @@
+#Region "Microsoft.VisualBasic::eba4374986d38a7d2892e1953bc7b70f, Data\BinaryData\BinaryData\XDR\EmitContexts\EmitContext.vb"
+
+ ' Author:
+ '
+ ' asuka (amethyst.asuka@gcmodeller.org)
+ ' xie (genetics@smrucc.org)
+ ' xieguigang (xie.guigang@live.com)
+ '
+ ' Copyright (c) 2018 GPL3 Licensed
+ '
+ '
+ ' GNU GENERAL PUBLIC LICENSE (GPL3)
+ '
+ '
+ ' This program is free software: you can redistribute it and/or modify
+ ' it under the terms of the GNU General Public License as published by
+ ' the Free Software Foundation, either version 3 of the License, or
+ ' (at your option) any later version.
+ '
+ ' This program is distributed in the hope that it will be useful,
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ' GNU General Public License for more details.
+ '
+ ' You should have received a copy of the GNU General Public License
+ ' along with this program. If not, see .
+
+
+
+ ' /********************************************************************************/
+
+ ' Summaries:
+
+ ' Module EmitContext
+ '
+ ' Function: EmitReader, EmitWriter, GetReader, GetWriter
+ '
+ '
+ ' /********************************************************************************/
+
+#End Region
+
+Imports System
+Imports System.Collections.Generic
+
+Namespace Xdr.EmitContexts
+ Public Module EmitContext
+ Private _sync As Object = New Object()
+ Private _readerCache As Dictionary(Of Type, EmitResult) = New Dictionary(Of Type, EmitResult)()
+ Private _writerCache As Dictionary(Of Type, EmitResult) = New Dictionary(Of Type, EmitResult)()
+
+ Public Function GetReader(targetType As Type) As [Delegate]
+ SyncLock _sync
+ Dim result As EmitResult = Nothing
+
+ If Not _readerCache.TryGetValue(targetType, result) Then
+ result = New EmitResult()
+
+ Try
+ result.Method = EmitReader(targetType)
+ Catch ex As Exception
+ result.Error = New InvalidOperationException("can't emit reader", ex)
+ End Try
+
+ _readerCache.Add(targetType, result)
+ End If
+
+ If result.Error IsNot Nothing Then Throw result.Error
+ Return result.Method
+ End SyncLock
+ End Function
+
+ Public Function GetWriter(targetType As Type) As [Delegate]
+ SyncLock _sync
+ Dim result As EmitResult = Nothing
+
+ If Not _writerCache.TryGetValue(targetType, result) Then
+ result = New EmitResult()
+
+ Try
+ result.Method = EmitWriter(targetType)
+ Catch ex As Exception
+ result.Error = New InvalidOperationException("can't emit writer", ex)
+ End Try
+
+ _writerCache.Add(targetType, result)
+ End If
+
+ If result.Error IsNot Nothing Then Throw result.Error
+ Return result.Method
+ End SyncLock
+ End Function
+
+ Public Function EmitReader(targetType As Type) As [Delegate]
+ Dim ordModel = OrderModel.Create(targetType)
+ Dim swModel = SwitchModel.Create(targetType)
+ If swModel IsNot Nothing AndAlso ordModel IsNot Nothing Then Throw New InvalidOperationException("unknown way to convert")
+ If swModel IsNot Nothing Then Return swModel.BuildReader(targetType)
+ If ordModel IsNot Nothing Then Return ordModel.BuildReader(targetType)
+ Return Nothing
+ End Function
+
+ Public Function EmitWriter(targetType As Type) As [Delegate]
+ Dim ordModel = OrderModel.Create(targetType)
+ Dim swModel = SwitchModel.Create(targetType)
+ If swModel IsNot Nothing AndAlso ordModel IsNot Nothing Then Throw New InvalidOperationException("unknown way to convert")
+ If swModel IsNot Nothing Then Return swModel.BuildWriter(targetType)
+ If ordModel IsNot Nothing Then Return ordModel.BuildWriter(targetType)
+ Return Nothing
+ End Function
+ End Module
+End Namespace
+
diff --git a/XDRStream/EmitContexts/EmitResult.vb b/XDRStream/EmitContexts/EmitResult.vb
new file mode 100644
index 0000000..fdd1521
--- /dev/null
+++ b/XDRStream/EmitContexts/EmitResult.vb
@@ -0,0 +1,51 @@
+#Region "Microsoft.VisualBasic::706fbb594e121661e231fb34de656bbe, Data\BinaryData\BinaryData\XDR\EmitContexts\EmitResult.vb"
+
+ ' Author:
+ '
+ ' asuka (amethyst.asuka@gcmodeller.org)
+ ' xie (genetics@smrucc.org)
+ ' xieguigang (xie.guigang@live.com)
+ '
+ ' Copyright (c) 2018 GPL3 Licensed
+ '
+ '
+ ' GNU GENERAL PUBLIC LICENSE (GPL3)
+ '
+ '
+ ' This program is free software: you can redistribute it and/or modify
+ ' it under the terms of the GNU General Public License as published by
+ ' the Free Software Foundation, either version 3 of the License, or
+ ' (at your option) any later version.
+ '
+ ' This program is distributed in the hope that it will be useful,
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ' GNU General Public License for more details.
+ '
+ ' You should have received a copy of the GNU General Public License
+ ' along with this program. If not, see .
+
+
+
+ ' /********************************************************************************/
+
+ ' Summaries:
+
+ ' Class EmitResult
+ '
+ '
+ '
+ '
+ ' /********************************************************************************/
+
+#End Region
+
+Imports System
+
+Namespace Xdr
+ Public Class EmitResult
+ Public Method As [Delegate] = Nothing
+ Public [Error] As Exception = Nothing
+ End Class
+End Namespace
+
diff --git a/XDRStream/EmitContexts/FieldDesc.vb b/XDRStream/EmitContexts/FieldDesc.vb
new file mode 100644
index 0000000..7a032c9
--- /dev/null
+++ b/XDRStream/EmitContexts/FieldDesc.vb
@@ -0,0 +1,151 @@
+#Region "Microsoft.VisualBasic::d37052787037d2d6a3d6bd4ce29511c1, Data\BinaryData\BinaryData\XDR\EmitContexts\FieldDesc.vb"
+
+ ' Author:
+ '
+ ' asuka (amethyst.asuka@gcmodeller.org)
+ ' xie (genetics@smrucc.org)
+ ' xieguigang (xie.guigang@live.com)
+ '
+ ' Copyright (c) 2018 GPL3 Licensed
+ '
+ '
+ ' GNU GENERAL PUBLIC LICENSE (GPL3)
+ '
+ '
+ ' This program is free software: you can redistribute it and/or modify
+ ' it under the terms of the GNU General Public License as published by
+ ' the Free Software Foundation, either version 3 of the License, or
+ ' (at your option) any later version.
+ '
+ ' This program is distributed in the hope that it will be useful,
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ' GNU General Public License for more details.
+ '
+ ' You should have received a copy of the GNU General Public License
+ ' along with this program. If not, see .
+
+
+
+ ' /********************************************************************************/
+
+ ' Summaries:
+
+ ' Class FieldDesc
+ '
+ ' Constructor: (+1 Overloads) Sub New
+ '
+ ' Function: BuildAssign, BuildRead, BuildReadOne, BuildWrite, BuildWriteOne
+ '
+ ' Sub: ExtractAttributes
+ '
+ '
+ ' /********************************************************************************/
+
+#End Region
+
+Imports System
+Imports System.Reflection
+Imports System.Linq.Expressions
+
+Namespace Xdr.EmitContexts
+ Public Class FieldDesc
+ Public ReadOnly FieldType As Type
+ Public ReadOnly MInfo As MemberInfo
+ Protected _isOption As Boolean = False
+ Protected _isMany As Boolean = False
+ Protected _isFix As Boolean = False
+ Protected _len As UInteger = 0
+
+ Public Sub New(mi As MemberInfo)
+ MInfo = mi
+ Dim fi As FieldInfo = TryCast(mi, FieldInfo)
+
+ If fi IsNot Nothing Then
+ FieldType = fi.FieldType
+ ExtractAttributes()
+ Return
+ End If
+
+ Dim pi As PropertyInfo = TryCast(mi, PropertyInfo)
+
+ If pi IsNot Nothing Then
+ FieldType = pi.PropertyType
+ ExtractAttributes()
+ Return
+ End If
+
+ Throw New NotImplementedException("only PropertyInfo or FieldInfo")
+ End Sub
+
+ Private Sub ExtractAttributes()
+ Dim optAttr = MInfo.GetAttr(Of OptionAttribute)()
+
+ If optAttr IsNot Nothing Then
+ If FieldType.IsValueType Then Throw New InvalidOperationException("ValueType not supported Option attribute (use Nullable<> type)")
+ _isOption = True
+ End If
+
+ Dim fixAttr = MInfo.GetAttr(Of FixAttribute)()
+ Dim varAttr = MInfo.GetAttr(Of VarAttribute)()
+ If fixAttr IsNot Nothing AndAlso varAttr IsNot Nothing Then Throw New InvalidOperationException("can not use Fix and Var attributes both")
+
+ If fixAttr IsNot Nothing Then
+ _isMany = True
+ _isFix = True
+ _len = fixAttr.Length
+ End If
+
+ If varAttr IsNot Nothing Then
+ _isMany = True
+ _isFix = False
+ _len = varAttr.MaxLength
+ End If
+
+ If _isOption AndAlso _isMany Then Throw New InvalidOperationException("can not use Fix and Option attributes both or Var and Option attributes both")
+ End Sub
+
+ Friend Function BuildRead(pReader As Expression) As Expression
+ If _isMany Then
+ Return Expression.Call(pReader, GetType(Reader).GetMethod(If(_isFix, "ReadFix", "ReadVar")).MakeGenericMethod(FieldType), Expression.Constant(_len))
+ Else
+ Return Expression.Call(pReader, GetType(Reader).GetMethod(If(_isOption, "ReadOption", "Read")).MakeGenericMethod(FieldType))
+ End If
+ End Function
+
+ Friend Function BuildReadOne(pReader As Expression) As Expression
+ Return Expression.Call(pReader, GetType(Reader).GetMethod("Read").MakeGenericMethod(FieldType))
+ End Function
+
+ Friend Function BuildWriteOne(pWriter As Expression, key As Object) As Expression
+ Dim inTryBody As Expression = Expression.Call(pWriter, GetType(Writer).GetMethod("Write").MakeGenericMethod(FieldType), Expression.Constant(key))
+ Dim exParam = Expression.Parameter(GetType(SystemException), "ex")
+ Dim inCatchBody = Expression.Throw(Expression.[New](GetType(FormatException).GetConstructor(New Type() {GetType(String), GetType(Exception)}), Expression.Constant("can't write '" & MInfo.Name & "' field"), exParam))
+ Return Expression.TryCatch(inTryBody, Expression.Catch(exParam, inCatchBody))
+ End Function
+
+ Friend Function BuildWrite(pWriter As Expression, pItem As Expression) As Expression
+ Dim field As Expression = Expression.PropertyOrField(pItem, MInfo.Name)
+ Dim inTryBody As Expression
+
+ If _isMany Then
+ inTryBody = Expression.Call(pWriter, GetType(Writer).GetMethod(If(_isFix, "WriteFix", "WriteVar")).MakeGenericMethod(FieldType), Expression.Constant(_len), field)
+ Else
+ inTryBody = Expression.Call(pWriter, GetType(Writer).GetMethod(If(_isOption, "WriteOption", "Write")).MakeGenericMethod(FieldType), field)
+ End If
+
+ Dim exParam = Expression.Parameter(GetType(SystemException), "ex")
+ Dim inCatchBody = Expression.Throw(Expression.[New](GetType(FormatException).GetConstructor(New Type() {GetType(String), GetType(Exception)}), Expression.Constant("can't write '" & MInfo.Name & "' field"), exParam))
+ Return Expression.TryCatch(inTryBody, Expression.Catch(exParam, inCatchBody))
+ End Function
+
+ Friend Function BuildAssign(readed As Expression, result As ParameterExpression) As Expression
+ Dim inTryBody = Expression.Assign(Expression.PropertyOrField(result, MInfo.Name), readed)
+ Dim exParam = Expression.Parameter(GetType(SystemException), "ex")
+ Dim inCatchBody = Expression.Throw(Expression.[New](GetType(FormatException).GetConstructor(New Type() {GetType(String), GetType(Exception)}), Expression.Constant("can't read '" & MInfo.Name & "' field"), exParam))
+
+ Return Expression.TryCatch(Expression.Block(GetType(Void), inTryBody), Expression.Catch(exParam, inCatchBody))
+ End Function
+ End Class
+End Namespace
+
diff --git a/XDRStream/EmitContexts/OrderModel.vb b/XDRStream/EmitContexts/OrderModel.vb
new file mode 100644
index 0000000..d36685d
--- /dev/null
+++ b/XDRStream/EmitContexts/OrderModel.vb
@@ -0,0 +1,123 @@
+#Region "Microsoft.VisualBasic::950940959274ac47a33d956210928806, Data\BinaryData\BinaryData\XDR\EmitContexts\OrderModel.vb"
+
+ ' Author:
+ '
+ ' asuka (amethyst.asuka@gcmodeller.org)
+ ' xie (genetics@smrucc.org)
+ ' xieguigang (xie.guigang@live.com)
+ '
+ ' Copyright (c) 2018 GPL3 Licensed
+ '
+ '
+ ' GNU GENERAL PUBLIC LICENSE (GPL3)
+ '
+ '
+ ' This program is free software: you can redistribute it and/or modify
+ ' it under the terms of the GNU General Public License as published by
+ ' the Free Software Foundation, either version 3 of the License, or
+ ' (at your option) any later version.
+ '
+ ' This program is distributed in the hope that it will be useful,
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ' GNU General Public License for more details.
+ '
+ ' You should have received a copy of the GNU General Public License
+ ' along with this program. If not, see .
+
+
+
+ ' /********************************************************************************/
+
+ ' Summaries:
+
+ ' Class OrderModel
+ '
+ ' Properties: Fields
+ '
+ ' Function: BuildReader, BuildWriter, Create
+ '
+ ' Sub: AppendField
+ '
+ '
+ ' /********************************************************************************/
+
+#End Region
+
+Imports System
+Imports System.Linq
+Imports System.Reflection
+Imports System.Collections.Generic
+Imports System.Linq.Expressions
+
+Namespace Xdr.EmitContexts
+ Public Class OrderModel
+ Private _Fields As System.Collections.Generic.List(Of Xdr.EmitContexts.FieldDesc)
+
+ Public Property Fields As List(Of FieldDesc)
+ Get
+ Return _Fields
+ End Get
+ Private Set(value As List(Of FieldDesc))
+ _Fields = value
+ End Set
+ End Property
+
+ Public Function BuildReader(targetType As Type) As [Delegate]
+ Dim pReader = Expression.Parameter(GetType(Reader))
+ Dim variables As List(Of ParameterExpression) = New List(Of ParameterExpression)()
+ Dim body As List(Of Expression) = New List(Of Expression)()
+ Dim resultVar = Expression.Variable(targetType, "result")
+ variables.Add(resultVar)
+ Dim assign = Expression.Assign(resultVar, Expression.[New](targetType))
+ body.Add(assign)
+
+ For Each fieldDesc In Fields
+ body.Add(fieldDesc.BuildAssign(fieldDesc.BuildRead(pReader), resultVar))
+ Next
+
+ body.Add(resultVar)
+ Dim block = Expression.Block(variables, body)
+ Return Expression.Lambda(CType(GetType(ReadOneDelegate(Of)).MakeGenericType(targetType), Type), CType(block, Expression), pReader).Compile()
+ End Function
+
+ Public Function BuildWriter(targetType As Type) As [Delegate]
+ Dim pWriter = Expression.Parameter(GetType(Writer))
+ Dim pItem = Expression.Parameter(targetType)
+ Dim variables As List(Of ParameterExpression) = New List(Of ParameterExpression)()
+ Dim body As List(Of Expression) = New List(Of Expression)()
+
+ For Each fieldDesc In Fields
+ body.Add(fieldDesc.BuildWrite(pWriter, pItem))
+ Next
+
+ Dim block = Expression.Block(variables, body)
+ Return Expression.Lambda(CType(GetType(WriteOneDelegate(Of)).MakeGenericType(targetType), Type), CType(block, Expression), CType(pWriter, ParameterExpression), CType(pItem, ParameterExpression)).Compile()
+ End Function
+
+ Public Shared Function Create(t As Type) As OrderModel
+ Dim fields As SortedList(Of UInteger, FieldDesc) = New SortedList(Of UInteger, FieldDesc)()
+
+ For Each f In t.GetFields().Where(Function(fi) fi.IsPublic AndAlso Not fi.IsStatic)
+ AppendField(fields, f)
+ Next
+
+ For Each p In t.GetProperties().Where(Function(pi) pi.CanWrite AndAlso pi.CanRead)
+ AppendField(fields, p)
+ Next
+
+ If fields.Count = 0 Then Return Nothing
+ Dim result As OrderModel = New OrderModel()
+ result.Fields = fields.Values.ToList()
+ Return result
+ End Function
+
+ Private Shared Sub AppendField(fields As SortedList(Of UInteger, FieldDesc), mi As MemberInfo)
+ Dim fAttr As OrderAttribute = mi.GetAttr(Of OrderAttribute)()
+ If fAttr Is Nothing Then Return
+ If fields.ContainsKey(fAttr.Order) Then Throw New InvalidOperationException("duplicate order " & fAttr.Order)
+ fields.Add(fAttr.Order, New FieldDesc(mi))
+ End Sub
+ End Class
+End Namespace
+
diff --git a/XDRStream/EmitContexts/SwitchModel.vb b/XDRStream/EmitContexts/SwitchModel.vb
new file mode 100644
index 0000000..e0e47af
--- /dev/null
+++ b/XDRStream/EmitContexts/SwitchModel.vb
@@ -0,0 +1,177 @@
+#Region "Microsoft.VisualBasic::d7cbb4b586290172266459ddb63244f0, Data\BinaryData\BinaryData\XDR\EmitContexts\SwitchModel.vb"
+
+ ' Author:
+ '
+ ' asuka (amethyst.asuka@gcmodeller.org)
+ ' xie (genetics@smrucc.org)
+ ' xieguigang (xie.guigang@live.com)
+ '
+ ' Copyright (c) 2018 GPL3 Licensed
+ '
+ '
+ ' GNU GENERAL PUBLIC LICENSE (GPL3)
+ '
+ '
+ ' This program is free software: you can redistribute it and/or modify
+ ' it under the terms of the GNU General Public License as published by
+ ' the Free Software Foundation, either version 3 of the License, or
+ ' (at your option) any later version.
+ '
+ ' This program is distributed in the hope that it will be useful,
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ' GNU General Public License for more details.
+ '
+ ' You should have received a copy of the GNU General Public License
+ ' along with this program. If not, see .
+
+
+
+ ' /********************************************************************************/
+
+ ' Summaries:
+
+ ' Class SwitchModel
+ '
+ ' Properties: Branches, SwitchField
+ '
+ ' Function: BuildReadBranch, BuildReader, BuildWriteBranch, BuildWriter, Create
+ ' ThrowUnexpectedValue
+ '
+ ' Sub: AppendField
+ '
+ '
+ ' /********************************************************************************/
+
+#End Region
+
+Imports System
+Imports System.Linq
+Imports System.Reflection
+Imports System.Collections.Generic
+Imports System.Linq.Expressions
+
+Namespace Xdr.EmitContexts
+ Public Class SwitchModel
+ Private _SwitchField As Xdr.EmitContexts.FieldDesc, _Branches As System.Collections.Generic.Dictionary(Of Object, Xdr.EmitContexts.FieldDesc)
+
+ Public Property SwitchField As FieldDesc
+ Get
+ Return _SwitchField
+ End Get
+ Private Set(value As FieldDesc)
+ _SwitchField = value
+ End Set
+ End Property
+
+ Public Property Branches As Dictionary(Of Object, FieldDesc)
+ Get
+ Return _Branches
+ End Get
+ Private Set(value As Dictionary(Of Object, FieldDesc))
+ _Branches = value
+ End Set
+ End Property
+
+ Public Function BuildWriter(targetType As Type) As [Delegate]
+ Dim pWriter = Expression.Parameter(GetType(Writer))
+ Dim pItem = Expression.Parameter(targetType)
+ Dim variables As List(Of ParameterExpression) = New List(Of ParameterExpression)()
+ Dim body As List(Of Expression) = New List(Of Expression)()
+ Dim [exit] As LabelTarget = Expression.Label()
+ Dim cases As List(Of SwitchCase) = New List(Of SwitchCase)()
+
+ For Each branch In Branches
+ cases.Add(BuildWriteBranch(branch.Key, branch.Value, pWriter, pItem, [exit]))
+ Next
+
+ body.Add(Expression.Switch(Expression.PropertyOrField(pItem, SwitchField.MInfo.Name), Expression.Block(ThrowUnexpectedValue(Expression.PropertyOrField(pItem, SwitchField.MInfo.Name))), cases.ToArray()))
+ body.Add(Expression.Label([exit]))
+ Dim block = Expression.Block(variables, body)
+ Return Expression.Lambda(CType(GetType(WriteOneDelegate(Of)).MakeGenericType(targetType), Type), CType(block, Expression), CType(pWriter, ParameterExpression), CType(pItem, ParameterExpression)).Compile()
+ End Function
+
+ Private Function BuildWriteBranch(key As Object, fieldDesc As FieldDesc, pWriter As Expression, pItem As Expression, [exit] As LabelTarget) As SwitchCase
+ Dim body As List(Of Expression) = New List(Of Expression)()
+ body.Add(SwitchField.BuildWriteOne(pWriter, key))
+ If fieldDesc IsNot Nothing Then body.Add(fieldDesc.BuildWrite(pWriter, pItem))
+ body.Add(Expression.Return([exit]))
+ Return Expression.SwitchCase(Expression.Block(body), Expression.Constant(key))
+ End Function
+
+ Public Function BuildReader(targetType As Type) As [Delegate]
+ Dim pReader = Expression.Parameter(GetType(Reader))
+ Dim variables As List(Of ParameterExpression) = New List(Of ParameterExpression)()
+ Dim body As List(Of Expression) = New List(Of Expression)()
+ Dim resultVar = Expression.Variable(targetType, "result")
+ variables.Add(resultVar)
+ Dim assign = Expression.Assign(resultVar, Expression.[New](targetType))
+ body.Add(assign)
+ body.Add(SwitchField.BuildAssign(SwitchField.BuildReadOne(pReader), resultVar))
+ Dim [exit] As LabelTarget = Expression.Label()
+ Dim cases As List(Of SwitchCase) = New List(Of SwitchCase)()
+
+ For Each branch In Branches
+ cases.Add(BuildReadBranch(branch.Key, branch.Value, resultVar, pReader, [exit]))
+ Next
+
+ body.Add(Expression.Switch(Expression.PropertyOrField(resultVar, SwitchField.MInfo.Name), Expression.Block(ThrowUnexpectedValue(Expression.PropertyOrField(resultVar, SwitchField.MInfo.Name))), cases.ToArray()))
+ body.Add(Expression.Label([exit]))
+ body.Add(resultVar)
+ Dim block = Expression.Block(variables, body)
+ Return Expression.Lambda(CType(GetType(ReadOneDelegate(Of)).MakeGenericType(targetType), Type), CType(block, Expression), pReader).Compile()
+ End Function
+
+ Private Shared Function ThrowUnexpectedValue(value As MemberExpression) As Expression
+ 'throw new FormatException(string.Format("unexpected value: {0}", result.Type));
+
+ Dim strExpr = Expression.Call(GetType(String).GetMethod("Format", New Type() {GetType(String), GetType(Object)}), Expression.Constant("unexpected value: {0}"), Expression.Call(value, GetType(Object).GetMethod("ToString")))
+ Return Expression.Throw(Expression.[New](GetType(FormatException).GetConstructor(New Type() {GetType(String)}), strExpr))
+ End Function
+
+ Private Shared Function BuildReadBranch(key As Object, fieldDesc As FieldDesc, resultVar As ParameterExpression, pReader As Expression, [exit] As LabelTarget) As SwitchCase
+ Dim body As List(Of Expression) = New List(Of Expression)()
+ If fieldDesc IsNot Nothing Then body.Add(fieldDesc.BuildAssign(fieldDesc.BuildRead(pReader), resultVar))
+ body.Add(Expression.Break([exit]))
+ Return Expression.SwitchCase(Expression.Block(body), Expression.Constant(key))
+ End Function
+
+ Public Shared Function Create(t As Type) As SwitchModel
+ Dim model As SwitchModel = New SwitchModel()
+ model.Branches = New Dictionary(Of Object, FieldDesc)()
+
+ For Each f In t.GetFields().Where(Function(fi) fi.IsPublic AndAlso Not fi.IsStatic)
+ AppendField(model, f)
+ Next
+
+ For Each p In t.GetProperties().Where(Function(pi) pi.CanWrite AndAlso pi.CanRead)
+ AppendField(model, p)
+ Next
+
+ If model.SwitchField Is Nothing AndAlso model.Branches.Count = 0 Then Return Nothing
+ If model.SwitchField Is Nothing Then Throw New InvalidOperationException("switch attribute not found")
+ If model.Branches.Count <= 1 Then Throw New InvalidOperationException("requires more than two case attributes")
+ If model.Branches.Values.All(Function(f) f Is Nothing) Then Throw New InvalidOperationException("required no void case attribute")
+ Return model
+ End Function
+
+ Private Shared Sub AppendField(model As SwitchModel, mi As MemberInfo)
+ If mi.GetAttr(Of SwitchAttribute)() IsNot Nothing Then ' switch field
+ If model.SwitchField IsNot Nothing Then Throw New InvalidOperationException("duplicate switch attribute")
+ model.SwitchField = New FieldDesc(mi)
+
+ For Each cAttr In mi.GetAttrs(Of CaseAttribute)()
+ If model.Branches.ContainsKey(cAttr.Value) Then Throw New InvalidOperationException("duplicate case value " & cAttr.Value.ToString())
+ model.Branches.Add(cAttr.Value, Nothing)
+ Next ' case field
+ Else
+
+ For Each cAttr In mi.GetAttrs(Of CaseAttribute)()
+ If model.Branches.ContainsKey(cAttr.Value) Then Throw New InvalidOperationException("duplicate case value " & cAttr.Value.ToString())
+ model.Branches.Add(cAttr.Value, New FieldDesc(mi))
+ Next
+ End If
+ End Sub
+ End Class
+End Namespace
+
diff --git a/XDRStream/EnumHelper.vb b/XDRStream/EnumHelper.vb
new file mode 100644
index 0000000..3d46e9c
--- /dev/null
+++ b/XDRStream/EnumHelper.vb
@@ -0,0 +1,93 @@
+#Region "Microsoft.VisualBasic::4ada7b8a809323e160746d9883d0d5ec, Data\BinaryData\BinaryData\XDR\EnumHelper.vb"
+
+ ' Author:
+ '
+ ' asuka (amethyst.asuka@gcmodeller.org)
+ ' xie (genetics@smrucc.org)
+ ' xieguigang (xie.guigang@live.com)
+ '
+ ' Copyright (c) 2018 GPL3 Licensed
+ '
+ '
+ ' GNU GENERAL PUBLIC LICENSE (GPL3)
+ '
+ '
+ ' This program is free software: you can redistribute it and/or modify
+ ' it under the terms of the GNU General Public License as published by
+ ' the Free Software Foundation, either version 3 of the License, or
+ ' (at your option) any later version.
+ '
+ ' This program is distributed in the hope that it will be useful,
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ' GNU General Public License for more details.
+ '
+ ' You should have received a copy of the GNU General Public License
+ ' along with this program. If not, see .
+
+
+
+ ' /********************************************************************************/
+
+ ' Summaries:
+
+ ' Class EnumHelper
+ '
+ ' Constructor: (+1 Overloads) Sub New
+ ' Function: EnumToInt, IntToEnum
+ '
+ '
+ ' /********************************************************************************/
+
+#End Region
+
+Namespace Xdr
+
+ Public Class EnumHelper(Of T As Structure)
+
+ Private Shared ReadOnly _enumMap As Dictionary(Of T, Integer)
+ Private Shared ReadOnly _intMap As Dictionary(Of Integer, T)
+
+ Shared Sub New()
+ Dim underType As Type = GetType(T).GetEnumUnderlyingType()
+ Dim conv As Func(Of T, Integer)
+
+ If underType Is GetType(Byte) Then
+ conv = Function(item) CByte(CType(item, ValueType))
+ ElseIf underType Is GetType(SByte) Then
+ conv = Function(item) CSByte(CType(item, ValueType))
+ ElseIf underType Is GetType(Short) Then
+ conv = Function(item) CShort(CType(item, ValueType))
+ ElseIf underType Is GetType(UShort) Then
+ conv = Function(item) CUShort(CType(item, ValueType))
+ ElseIf underType Is GetType(Integer) Then
+ conv = Function(item) CType(item, ValueType)
+ Else
+ Throw New NotSupportedException(String.Format("unsupported type {0}", GetType(T).FullName))
+ End If
+
+ _intMap = New Dictionary(Of Integer, T)()
+ _enumMap = New Dictionary(Of T, Integer)()
+
+ For Each item In [Enum].GetValues(GetType(T)).Cast(Of T)()
+ Dim exist As T = Nothing
+ Dim key = conv(item)
+ If Not _intMap.TryGetValue(key, exist) Then _intMap.Add(key, item)
+ If Not _enumMap.TryGetValue(item, key) Then _enumMap.Add(item, conv(item))
+ Next
+ End Sub
+
+ Public Shared Function IntToEnum(val As Integer) As T
+ Dim exist As T = Nothing
+ If _intMap.TryGetValue(val, exist) Then Return exist
+ Throw New InvalidCastException(String.Format("type `{0}' not contain {1}", GetType(T).FullName, val))
+ End Function
+
+ Public Shared Function EnumToInt(item As T) As Integer
+ Dim val As Integer
+ If _enumMap.TryGetValue(item, val) Then Return val
+ Throw New InvalidCastException(String.Format("enum {0} not contain value {1}", GetType(T).FullName, item))
+ End Function
+ End Class
+End Namespace
+
diff --git a/XDRStream/MapException.vb b/XDRStream/MapException.vb
new file mode 100644
index 0000000..386c82d
--- /dev/null
+++ b/XDRStream/MapException.vb
@@ -0,0 +1,88 @@
+#Region "Microsoft.VisualBasic::3be836190f27e2289be3669c639d36b4, Data\BinaryData\BinaryData\XDR\MapException.vb"
+
+ ' Author:
+ '
+ ' asuka (amethyst.asuka@gcmodeller.org)
+ ' xie (genetics@smrucc.org)
+ ' xieguigang (xie.guigang@live.com)
+ '
+ ' Copyright (c) 2018 GPL3 Licensed
+ '
+ '
+ ' GNU GENERAL PUBLIC LICENSE (GPL3)
+ '
+ '
+ ' This program is free software: you can redistribute it and/or modify
+ ' it under the terms of the GNU General Public License as published by
+ ' the Free Software Foundation, either version 3 of the License, or
+ ' (at your option) any later version.
+ '
+ ' This program is distributed in the hope that it will be useful,
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ' GNU General Public License for more details.
+ '
+ ' You should have received a copy of the GNU General Public License
+ ' along with this program. If not, see .
+
+
+
+ ' /********************************************************************************/
+
+ ' Summaries:
+
+ ' Class MapException
+ '
+ ' Constructor: (+3 Overloads) Sub New
+ ' Function: ReadFix, ReadOne, ReadVar, WriteFix, WriteOne
+ ' WriteVar
+ '
+ '
+ ' /********************************************************************************/
+
+#End Region
+
+Imports System
+
+Namespace Xdr
+ Public Class MapException
+ Inherits SystemException
+
+ Public Sub New()
+ MyBase.New()
+ End Sub
+
+ Public Sub New(message As String)
+ MyBase.New(message)
+ End Sub
+
+ Public Sub New(message As String, innerEx As Exception)
+ MyBase.New(message, innerEx)
+ End Sub
+
+ Public Shared Function ReadOne(type As Type, innerEx As Exception) As MapException
+ Return New MapException(String.Format("can't read an instance of `{0}'", type.FullName), innerEx)
+ End Function
+
+ Friend Shared Function ReadVar(type As Type, max As UInteger, innerEx As SystemException) As Exception
+ Return New MapException(String.Format("can't read collection of `{0}' (length <= {1})", type.FullName, max), innerEx)
+ End Function
+
+ Friend Shared Function ReadFix(type As Type, len As UInteger, innerEx As SystemException) As Exception
+ Return New MapException(String.Format("can't read collection of `{0}' (length = {1})", type.FullName, len), innerEx)
+ End Function
+
+ Friend Shared Function WriteOne(type As Type, innerEx As SystemException) As Exception
+ Return New MapException(String.Format("can't write an instance of `{0}'", type.FullName), innerEx)
+ End Function
+
+ Friend Shared Function WriteFix(type As Type, len As UInteger, innerEx As SystemException) As Exception
+ Return New MapException(String.Format("can't write collection of `{0}' (length = {1})", type.FullName, len), innerEx)
+ End Function
+
+ Friend Shared Function WriteVar(type As Type, max As UInteger, innerEx As SystemException) As Exception
+ Return New MapException(String.Format("can't write collection of `{0}' (length <= {1})", type.FullName, max), innerEx)
+ End Function
+ End Class
+End Namespace
+
diff --git a/XDRStream/My Project/Application.Designer.vb b/XDRStream/My Project/Application.Designer.vb
new file mode 100644
index 0000000..537244b
--- /dev/null
+++ b/XDRStream/My Project/Application.Designer.vb
@@ -0,0 +1,13 @@
+'------------------------------------------------------------------------------
+'
+' 此代码由工具生成。
+' 运行时版本:4.0.30319.42000
+'
+' 对此文件的更改可能会导致不正确的行为,并且如果
+' 重新生成代码,这些更改将会丢失。
+'
+'------------------------------------------------------------------------------
+
+Option Strict On
+Option Explicit On
+
diff --git a/XDRStream/My Project/Application.myapp b/XDRStream/My Project/Application.myapp
new file mode 100644
index 0000000..758895d
--- /dev/null
+++ b/XDRStream/My Project/Application.myapp
@@ -0,0 +1,10 @@
+
+
+ false
+ false
+ 0
+ true
+ 0
+ 1
+ true
+
diff --git a/XDRStream/My Project/AssemblyInfo.vb b/XDRStream/My Project/AssemblyInfo.vb
new file mode 100644
index 0000000..5086253
--- /dev/null
+++ b/XDRStream/My Project/AssemblyInfo.vb
@@ -0,0 +1,35 @@
+Imports System
+Imports System.Reflection
+Imports System.Runtime.InteropServices
+
+' 有关程序集的一般信息由以下
+' 控制。更改这些特性值可修改
+' 与程序集关联的信息。
+
+'查看程序集特性的值
+
+
+
+
+
+
+
+
+
+
+'如果此项目向 COM 公开,则下列 GUID 用于 typelib 的 ID
+
+
+' 程序集的版本信息由下列四个值组成:
+'
+' 主版本
+' 次版本
+' 生成号
+' 修订号
+'
+'可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
+'通过使用 "*",如下所示:
+'
+
+
+
diff --git a/XDRStream/My Project/Resources.Designer.vb b/XDRStream/My Project/Resources.Designer.vb
new file mode 100644
index 0000000..adce8ee
--- /dev/null
+++ b/XDRStream/My Project/Resources.Designer.vb
@@ -0,0 +1,63 @@
+'------------------------------------------------------------------------------
+'
+' 此代码由工具生成。
+' 运行时版本:4.0.30319.42000
+'
+' 对此文件的更改可能会导致不正确的行为,并且如果
+' 重新生成代码,这些更改将会丢失。
+'
+'------------------------------------------------------------------------------
+
+Option Strict On
+Option Explicit On
+
+Imports System
+
+Namespace My.Resources
+
+ '此类是由 StronglyTypedResourceBuilder
+ '类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
+ '若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
+ '(以 /str 作为命令选项),或重新生成 VS 项目。
+ '''
+ ''' 一个强类型的资源类,用于查找本地化的字符串等。
+ '''
+ _
+ Friend Module Resources
+
+ Private resourceMan As Global.System.Resources.ResourceManager
+
+ Private resourceCulture As Global.System.Globalization.CultureInfo
+
+ '''
+ ''' 返回此类使用的缓存的 ResourceManager 实例。
+ '''
+ _
+ Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager
+ Get
+ If Object.ReferenceEquals(resourceMan, Nothing) Then
+ Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("XDR.Resources", GetType(Resources).Assembly)
+ resourceMan = temp
+ End If
+ Return resourceMan
+ End Get
+ End Property
+
+ '''
+ ''' 重写当前线程的 CurrentUICulture 属性,对
+ ''' 使用此强类型资源类的所有资源查找执行重写。
+ '''
+ _
+ Friend Property Culture() As Global.System.Globalization.CultureInfo
+ Get
+ Return resourceCulture
+ End Get
+ Set
+ resourceCulture = value
+ End Set
+ End Property
+ End Module
+End Namespace
diff --git a/XDRStream/My Project/Resources.resx b/XDRStream/My Project/Resources.resx
new file mode 100644
index 0000000..af7dbeb
--- /dev/null
+++ b/XDRStream/My Project/Resources.resx
@@ -0,0 +1,117 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/XDRStream/My Project/Settings.Designer.vb b/XDRStream/My Project/Settings.Designer.vb
new file mode 100644
index 0000000..1b3b0b5
--- /dev/null
+++ b/XDRStream/My Project/Settings.Designer.vb
@@ -0,0 +1,73 @@
+'------------------------------------------------------------------------------
+'
+' 此代码由工具生成。
+' 运行时版本:4.0.30319.42000
+'
+' 对此文件的更改可能会导致不正确的行为,并且如果
+' 重新生成代码,这些更改将会丢失。
+'
+'------------------------------------------------------------------------------
+
+Option Strict On
+Option Explicit On
+
+
+Namespace My
+
+ _
+ Partial Friend NotInheritable Class MySettings
+ Inherits Global.System.Configuration.ApplicationSettingsBase
+
+ Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings)
+
+#Region "My.Settings 自动保存功能"
+#If _MyType = "WindowsForms" Then
+ Private Shared addedHandler As Boolean
+
+ Private Shared addedHandlerLockObject As New Object
+
+ _
+ Private Shared Sub AutoSaveSettings(sender As Global.System.Object, e As Global.System.EventArgs)
+ If My.Application.SaveMySettingsOnExit Then
+ My.Settings.Save()
+ End If
+ End Sub
+#End If
+#End Region
+
+ Public Shared ReadOnly Property [Default]() As MySettings
+ Get
+
+#If _MyType = "WindowsForms" Then
+ If Not addedHandler Then
+ SyncLock addedHandlerLockObject
+ If Not addedHandler Then
+ AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings
+ addedHandler = True
+ End If
+ End SyncLock
+ End If
+#End If
+ Return defaultInstance
+ End Get
+ End Property
+ End Class
+End Namespace
+
+Namespace My
+
+ _
+ Friend Module MySettingsProperty
+
+ _
+ Friend ReadOnly Property Settings() As Global.XDR.My.MySettings
+ Get
+ Return Global.XDR.My.MySettings.Default
+ End Get
+ End Property
+ End Module
+End Namespace
diff --git a/XDRStream/My Project/Settings.settings b/XDRStream/My Project/Settings.settings
new file mode 100644
index 0000000..85b890b
--- /dev/null
+++ b/XDRStream/My Project/Settings.settings
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/XDRStream/NamespaceDoc.vb b/XDRStream/NamespaceDoc.vb
new file mode 100644
index 0000000..9d18788
--- /dev/null
+++ b/XDRStream/NamespaceDoc.vb
@@ -0,0 +1,50 @@
+#Region "Microsoft.VisualBasic::0b28834e300186ade27b116682f21ce1, Data\BinaryData\BinaryData\XDR\NamespaceDoc.vb"
+
+ ' Author:
+ '
+ ' asuka (amethyst.asuka@gcmodeller.org)
+ ' xie (genetics@smrucc.org)
+ ' xieguigang (xie.guigang@live.com)
+ '
+ ' Copyright (c) 2018 GPL3 Licensed
+ '
+ '
+ ' GNU GENERAL PUBLIC LICENSE (GPL3)
+ '
+ '
+ ' This program is free software: you can redistribute it and/or modify
+ ' it under the terms of the GNU General Public License as published by
+ ' the Free Software Foundation, either version 3 of the License, or
+ ' (at your option) any later version.
+ '
+ ' This program is distributed in the hope that it will be useful,
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ' GNU General Public License for more details.
+ '
+ ' You should have received a copy of the GNU General Public License
+ ' along with this program. If not, see .
+
+
+
+ ' /********************************************************************************/
+
+ ' Summaries:
+
+ ' Module NamespaceDoc
+ '
+ '
+ '
+ '
+ ' /********************************************************************************/
+
+#End Region
+
+Namespace Xdr
+
+ '''
+ ''' https://github.com/ExM/OncRpc
+ '''
+ Module NamespaceDoc
+ End Module
+End Namespace
diff --git a/XDRStream/OpaqueType.vb b/XDRStream/OpaqueType.vb
new file mode 100644
index 0000000..17d5dc5
--- /dev/null
+++ b/XDRStream/OpaqueType.vb
@@ -0,0 +1,54 @@
+#Region "Microsoft.VisualBasic::c443b173f450c3542b99627efe067598, Data\BinaryData\BinaryData\XDR\OpaqueType.vb"
+
+ ' Author:
+ '
+ ' asuka (amethyst.asuka@gcmodeller.org)
+ ' xie (genetics@smrucc.org)
+ ' xieguigang (xie.guigang@live.com)
+ '
+ ' Copyright (c) 2018 GPL3 Licensed
+ '
+ '
+ ' GNU GENERAL PUBLIC LICENSE (GPL3)
+ '
+ '
+ ' This program is free software: you can redistribute it and/or modify
+ ' it under the terms of the GNU General Public License as published by
+ ' the Free Software Foundation, either version 3 of the License, or
+ ' (at your option) any later version.
+ '
+ ' This program is distributed in the hope that it will be useful,
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ' GNU General Public License for more details.
+ '
+ ' You should have received a copy of the GNU General Public License
+ ' along with this program. If not, see .
+
+
+
+ ' /********************************************************************************/
+
+ ' Summaries:
+
+ ' Enum OpaqueType
+ '
+ '
+ '
+ '
+ '
+ '
+ '
+ ' /********************************************************************************/
+
+#End Region
+
+
+Namespace Xdr
+ Public Enum OpaqueType
+ One = 0
+ Fix = 1
+ Var = 2
+ End Enum
+End Namespace
+
diff --git a/XDRStream/Reading/ReadBuilder.EmitDynReadMapper.vb b/XDRStream/Reading/ReadBuilder.EmitDynReadMapper.vb
new file mode 100644
index 0000000..ea0e6bc
--- /dev/null
+++ b/XDRStream/Reading/ReadBuilder.EmitDynReadMapper.vb
@@ -0,0 +1,100 @@
+#Region "Microsoft.VisualBasic::cab6f19b2cac9246bf0cc15b0992f8fc, Data\BinaryData\BinaryData\XDR\Reading\ReadBuilder.EmitDynReadMapper.vb"
+
+ ' Author:
+ '
+ ' asuka (amethyst.asuka@gcmodeller.org)
+ ' xie (genetics@smrucc.org)
+ ' xieguigang (xie.guigang@live.com)
+ '
+ ' Copyright (c) 2018 GPL3 Licensed
+ '
+ '
+ ' GNU GENERAL PUBLIC LICENSE (GPL3)
+ '
+ '
+ ' This program is free software: you can redistribute it and/or modify
+ ' it under the terms of the GNU General Public License as published by
+ ' the Free Software Foundation, either version 3 of the License, or
+ ' (at your option) any later version.
+ '
+ ' This program is distributed in the hope that it will be useful,
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ' GNU General Public License for more details.
+ '
+ ' You should have received a copy of the GNU General Public License
+ ' along with this program. If not, see .
+
+
+
+ ' /********************************************************************************/
+
+ ' Summaries:
+
+ ' Class ReadBuilder
+ '
+ ' Function: DefineCacheField, EmitDynReadMapper
+ '
+ ' Sub: EmitInitField, EmitOverride_GetCacheType
+ '
+ '
+ ' /********************************************************************************/
+
+#End Region
+
+Imports System
+Imports System.Reflection
+Imports System.Reflection.Emit
+
+Namespace Xdr
+ Public NotInheritable Partial Class ReadBuilder
+ Private Function EmitDynReadMapper() As Type
+ Dim typeBuilder = _modBuilder.DefineType("DynReadMapper", TypeAttributes.NotPublic Or TypeAttributes.Class Or TypeAttributes.Sealed, GetType(ReadMapper))
+ Dim fb_oneCacheType = DefineCacheField(typeBuilder, "_oneCacheType")
+ Dim fb_fixCacheType = DefineCacheField(typeBuilder, "_fixCacheType")
+ Dim fb_varCacheType = DefineCacheField(typeBuilder, "_varCacheType")
+ Dim ctor = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, New Type(-1) {})
+ Dim ilCtor As ILGenerator = ctor.GetILGenerator()
+ ilCtor.Emit(OpCodes.Ldarg_0)
+ ilCtor.Emit(OpCodes.Call, GetType(ReadMapper).GetConstructor(BindingFlags.Instance Or BindingFlags.NonPublic, Nothing, New Type(-1) {}, Nothing))
+ ilCtor.Emit(OpCodes.Ldarg_0)
+ ilCtor.Emit(OpCodes.Ldftn, GetType(ReadMapper).GetMethod("AppendBuildRequest", BindingFlags.NonPublic Or BindingFlags.Instance))
+ ilCtor.Emit(OpCodes.Newobj, GetType(Action(Of Type, OpaqueType)).GetConstructor(New Type() {GetType(Object), GetType(IntPtr)}))
+ ilCtor.Emit(OpCodes.Stsfld, _buildBinderDescription.BuildRequest)
+ EmitInitField(ilCtor, fb_oneCacheType, _oneCacheDescription.Result)
+ EmitInitField(ilCtor, fb_fixCacheType, _fixCacheDescription.Result)
+ EmitInitField(ilCtor, fb_varCacheType, _varCacheDescription.Result)
+
+ ' run init
+ ilCtor.Emit(OpCodes.Ldarg_0)
+ ilCtor.Emit(OpCodes.Call, GetType(ReadMapper).GetMethod("Init", BindingFlags.Instance Or BindingFlags.NonPublic))
+ ilCtor.Emit(OpCodes.Ret)
+ EmitOverride_GetCacheType(typeBuilder, "GetOneCacheType", fb_oneCacheType)
+ EmitOverride_GetCacheType(typeBuilder, "GetFixCacheType", fb_fixCacheType)
+ EmitOverride_GetCacheType(typeBuilder, "GetVarCacheType", fb_varCacheType)
+ Return typeBuilder.CreateType()
+ End Function
+
+ Private Shared Function DefineCacheField(typeBuilder As TypeBuilder, name As String) As FieldBuilder
+ Return typeBuilder.DefineField(name, GetType(Type), FieldAttributes.Private Or FieldAttributes.InitOnly)
+ End Function
+
+ Private Shared Sub EmitInitField(il As ILGenerator, fb As FieldBuilder, type As Type)
+ il.Emit(OpCodes.Ldarg_0)
+ il.Emit(OpCodes.Ldtoken, type)
+ il.Emit(OpCodes.Call, GetType(Type).GetMethod("GetTypeFromHandle"))
+ il.Emit(OpCodes.Stfld, fb)
+ End Sub
+
+ Private Sub EmitOverride_GetCacheType(typeBuilder As TypeBuilder, overrideName As String, fb_cacheType As FieldBuilder)
+ Dim mb = typeBuilder.DefineMethod(overrideName, MethodAttributes.Family Or MethodAttributes.Virtual)
+ mb.SetReturnType(GetType(Type))
+ typeBuilder.DefineMethodOverride(mb, GetType(ReadMapper).GetMethod(overrideName, BindingFlags.NonPublic Or BindingFlags.Instance))
+ Dim il As ILGenerator = mb.GetILGenerator()
+ il.Emit(OpCodes.Ldarg_0)
+ il.Emit(OpCodes.Ldfld, fb_cacheType)
+ il.Emit(OpCodes.Ret)
+ End Sub
+ End Class
+End Namespace
+
diff --git a/XDRStream/Reading/ReadBuilder.EmitDynReader.vb b/XDRStream/Reading/ReadBuilder.EmitDynReader.vb
new file mode 100644
index 0000000..a996007
--- /dev/null
+++ b/XDRStream/Reading/ReadBuilder.EmitDynReader.vb
@@ -0,0 +1,111 @@
+#Region "Microsoft.VisualBasic::e7ca7ca1c9f2cd669436be7e5ed4e188, Data\BinaryData\BinaryData\XDR\Reading\ReadBuilder.EmitDynReader.vb"
+
+ ' Author:
+ '
+ ' asuka (amethyst.asuka@gcmodeller.org)
+ ' xie (genetics@smrucc.org)
+ ' xieguigang (xie.guigang@live.com)
+ '
+ ' Copyright (c) 2018 GPL3 Licensed
+ '
+ '
+ ' GNU GENERAL PUBLIC LICENSE (GPL3)
+ '
+ '
+ ' This program is free software: you can redistribute it and/or modify
+ ' it under the terms of the GNU General Public License as published by
+ ' the Free Software Foundation, either version 3 of the License, or
+ ' (at your option) any later version.
+ '
+ ' This program is distributed in the hope that it will be useful,
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ' GNU General Public License for more details.
+ '
+ ' You should have received a copy of the GNU General Public License
+ ' along with this program. If not, see .
+
+
+
+ ' /********************************************************************************/
+
+ ' Summaries:
+
+ ' Class ReadBuilder
+ '
+ ' Function: EmitDynReader
+ '
+ ' Sub: EmitOverride_ReadTMany, EmitOverride_ReadTOne
+ '
+ '
+ ' /********************************************************************************/
+
+#End Region
+
+Imports System.Reflection
+Imports System.Reflection.Emit
+Imports Microsoft.VisualBasic.Data.IO.Xdr.Emit
+
+Namespace Xdr
+ Public NotInheritable Partial Class ReadBuilder
+ Private Function EmitDynReader() As Type
+ Dim typeBuilder = _modBuilder.DefineType("DynReader", TypeAttributes.NotPublic Or TypeAttributes.Class Or TypeAttributes.Sealed, GetType(Reader))
+ Dim fb_mapperInstance = typeBuilder.DefineField("Mapper", GetType(ReadMapper), FieldAttributes.Public Or FieldAttributes.Static)
+ Dim ctor = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, New Type() {GetType(IByteReader)})
+ Dim ilCtor As ILGenerator = ctor.GetILGenerator()
+ ilCtor.Emit(OpCodes.Ldarg_0)
+ ilCtor.Emit(OpCodes.Ldarg_1) ' reader
+ ilCtor.Emit(OpCodes.Call, GetType(Reader).GetConstructor(BindingFlags.Instance Or BindingFlags.NonPublic, Nothing, New Type() {GetType(IByteReader)}, Nothing))
+ ilCtor.Emit(OpCodes.Ret)
+ EmitOverride_ReadTOne(typeBuilder, fb_mapperInstance)
+ EmitOverride_ReadTMany(typeBuilder, "CacheReadFix", _fixCacheDescription, fb_mapperInstance)
+ EmitOverride_ReadTMany(typeBuilder, "CacheReadVar", _varCacheDescription, fb_mapperInstance)
+ Return typeBuilder.CreateType()
+ End Function
+
+ Private Sub EmitOverride_ReadTOne(typeBuilder As TypeBuilder, mapperInstance As FieldInfo)
+ Dim miDeclaration = GetType(Reader).GetMethod("CacheRead", BindingFlags.NonPublic Or BindingFlags.Instance)
+ Dim mb = typeBuilder.DefineMethod("CacheRead", MethodAttributes.Family Or MethodAttributes.Virtual)
+ Dim genTypeParam = mb.DefineGenericParameters("T")(0)
+ mb.SetReturnType(genTypeParam)
+ typeBuilder.DefineMethodOverride(mb, miDeclaration)
+ Dim fi = TypeBuilder.GetField(_oneCacheDescription.Result.MakeGenericType(genTypeParam), _oneCacheDescription.Result.GetField("Instance"))
+ Dim il As ILGenerator = mb.GetILGenerator()
+ Dim noBuild As Label = il.DefineLabel()
+ il.Emit(OpCodes.Ldsfld, fi)
+ il.Emit(OpCodes.Brtrue, noBuild)
+ il.Emit(OpCodes.Ldsfld, mapperInstance)
+ il.Emit(OpCodes.Call, GetType(ReadMapper).GetMethod("BuildCaches", BindingFlags.Public Or BindingFlags.Instance))
+ il.MarkLabel(noBuild)
+ il.Emit(OpCodes.Ldsfld, fi)
+ il.Emit(OpCodes.Ldarg_0) ' this reader
+ Dim miInvoke = TypeBuilder.GetMethod(GetType(ReadOneDelegate(Of)).MakeGenericType(genTypeParam), GetType(ReadOneDelegate(Of)).GetMethod("Invoke"))
+ il.Emit(OpCodes.Callvirt, miInvoke)
+ il.Emit(OpCodes.Ret)
+ End Sub
+
+ Private Shared Sub EmitOverride_ReadTMany(tb As TypeBuilder, name As String, readManyCacheDesc As StaticCacheDescription, mapperInstance As FieldInfo)
+ Dim miDeclaration = GetType(Reader).GetMethod(name, BindingFlags.NonPublic Or BindingFlags.Instance)
+ Dim mb = tb.DefineMethod(name, MethodAttributes.Family Or MethodAttributes.Virtual)
+ Dim genTypeParam = mb.DefineGenericParameters("T")(0)
+ mb.SetReturnType(genTypeParam)
+ mb.SetParameters(GetType(UInteger))
+ tb.DefineMethodOverride(mb, miDeclaration)
+ Dim fi = readManyCacheDesc.Instance(genTypeParam)
+ Dim il As ILGenerator = mb.GetILGenerator()
+ Dim noBuild As Label = il.DefineLabel()
+ il.Emit(OpCodes.Ldsfld, fi)
+ il.Emit(OpCodes.Brtrue, noBuild)
+ il.Emit(OpCodes.Ldsfld, mapperInstance)
+ il.Emit(OpCodes.Call, GetType(ReadMapper).GetMethod("BuildCaches", BindingFlags.Public Or BindingFlags.Instance))
+ il.MarkLabel(noBuild)
+ il.Emit(OpCodes.Ldsfld, fi)
+ il.Emit(OpCodes.Ldarg_0) ' this reader
+ il.Emit(OpCodes.Ldarg_1) ' len or max
+ Dim miInvoke = TypeBuilder.GetMethod(GetType(ReadManyDelegate(Of)).MakeGenericType(genTypeParam), GetType(ReadManyDelegate(Of)).GetMethod("Invoke"))
+ il.Emit(OpCodes.Callvirt, miInvoke)
+ il.Emit(OpCodes.Ret)
+ End Sub
+ End Class
+End Namespace
+
diff --git a/XDRStream/Reading/ReadBuilder.vb b/XDRStream/Reading/ReadBuilder.vb
new file mode 100644
index 0000000..ddb9981
--- /dev/null
+++ b/XDRStream/Reading/ReadBuilder.vb
@@ -0,0 +1,104 @@
+#Region "Microsoft.VisualBasic::04495aeb2ec95bc163bff7ad36f3acb8, Data\BinaryData\BinaryData\XDR\Reading\ReadBuilder.vb"
+
+ ' Author:
+ '
+ ' asuka (amethyst.asuka@gcmodeller.org)
+ ' xie (genetics@smrucc.org)
+ ' xieguigang (xie.guigang@live.com)
+ '
+ ' Copyright (c) 2018 GPL3 Licensed
+ '
+ '
+ ' GNU GENERAL PUBLIC LICENSE (GPL3)
+ '
+ '
+ ' This program is free software: you can redistribute it and/or modify
+ ' it under the terms of the GNU General Public License as published by
+ ' the Free Software Foundation, either version 3 of the License, or
+ ' (at your option) any later version.
+ '
+ ' This program is distributed in the hope that it will be useful,
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ' GNU General Public License for more details.
+ '
+ ' You should have received a copy of the GNU General Public License
+ ' along with this program. If not, see .
+
+
+
+ ' /********************************************************************************/
+
+ ' Summaries:
+
+ ' Class ReadBuilder
+ '
+ ' Constructor: (+1 Overloads) Sub New
+ ' Function: Create, EmitCreater, Map, MapFix, MapVar
+ '
+ '
+ ' /********************************************************************************/
+
+#End Region
+
+Imports System.Reflection
+Imports System.Reflection.Emit
+Imports Microsoft.VisualBasic.Data.IO.Xdr.Emit
+
+Namespace Xdr
+ Public NotInheritable Partial Class ReadBuilder
+ Private _rm As ReadMapper
+ Private _creater As Func(Of IByteReader, Reader)
+ Private _modBuilder As ModuleBuilder
+ Private _buildBinderDescription As BuildBinderDescription
+ Private _oneCacheDescription As StaticCacheDescription
+ Private _varCacheDescription As StaticCacheDescription
+ Private _fixCacheDescription As StaticCacheDescription
+
+ Public Sub New()
+ Dim name = "DynamicXdrReadMapper"
+ Dim asmName As AssemblyName = New AssemblyName(name)
+ Dim asmBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.RunAndSave)
+ _modBuilder = asmBuilder.DefineDynamicModule(name & ".dll", name & ".dll")
+ _buildBinderDescription = New BuildBinderDescription(_modBuilder)
+ _oneCacheDescription = New StaticCacheDescription(_modBuilder, _buildBinderDescription, "OneCache", True, OpaqueType.One)
+ _fixCacheDescription = New StaticCacheDescription(_modBuilder, _buildBinderDescription, "FixCache", True, OpaqueType.Fix)
+ _varCacheDescription = New StaticCacheDescription(_modBuilder, _buildBinderDescription, "VarCache", True, OpaqueType.Var)
+ Dim dynReadMapperType As Type = EmitDynReadMapper()
+ _rm = CType(Activator.CreateInstance(dynReadMapperType), ReadMapper)
+ Dim dynReaderType As Type = EmitDynReader()
+ Dim mapperInstance = dynReaderType.GetField("Mapper", BindingFlags.Public Or BindingFlags.Static)
+ mapperInstance.SetValue(Nothing, _rm)
+ _creater = EmitCreater(dynReaderType.GetConstructor(New Type() {GetType(IByteReader)}))
+ End Sub
+
+ Private Shared Function EmitCreater(ci As ConstructorInfo) As Func(Of IByteReader, Reader)
+ Dim dm = New DynamicMethod("DynCreateReader", GetType(Reader), New Type() {GetType(IByteReader)}, GetType(ReadBuilder), True)
+ Dim il = dm.GetILGenerator()
+ il.Emit(OpCodes.Ldarg_0)
+ il.Emit(OpCodes.Newobj, ci)
+ il.Emit(OpCodes.Ret)
+ Return CType(dm.CreateDelegate(GetType(Func(Of IByteReader, Reader))), Func(Of IByteReader, Reader))
+ End Function
+
+ Public Function Map(Of T)(reader As ReadOneDelegate(Of T)) As ReadBuilder
+ _rm.AppendMethod(GetType(T), OpaqueType.One, reader)
+ Return Me
+ End Function
+
+ Public Function MapFix(Of T)(reader As ReadManyDelegate(Of T)) As ReadBuilder
+ _rm.AppendMethod(GetType(T), OpaqueType.Fix, reader)
+ Return Me
+ End Function
+
+ Public Function MapVar(Of T)(reader As ReadManyDelegate(Of T)) As ReadBuilder
+ _rm.AppendMethod(GetType(T), OpaqueType.Var, reader)
+ Return Me
+ End Function
+
+ Public Function Create(reader As IByteReader) As Reader
+ Return _creater(reader)
+ End Function
+ End Class
+End Namespace
+
diff --git a/XDRStream/Reading/ReadMapper.vb b/XDRStream/Reading/ReadMapper.vb
new file mode 100644
index 0000000..cb92ef3
--- /dev/null
+++ b/XDRStream/Reading/ReadMapper.vb
@@ -0,0 +1,341 @@
+#Region "Microsoft.VisualBasic::ff85d8c11739908dca1c3faff8baa77c, Data\BinaryData\BinaryData\XDR\Reading\ReadMapper.vb"
+
+ ' Author:
+ '
+ ' asuka (amethyst.asuka@gcmodeller.org)
+ ' xie (genetics@smrucc.org)
+ ' xieguigang (xie.guigang@live.com)
+ '
+ ' Copyright (c) 2018 GPL3 Licensed
+ '
+ '
+ ' GNU GENERAL PUBLIC LICENSE (GPL3)
+ '
+ '
+ ' This program is free software: you can redistribute it and/or modify
+ ' it under the terms of the GNU General Public License as published by
+ ' the Free Software Foundation, either version 3 of the License, or
+ ' (at your option) any later version.
+ '
+ ' This program is distributed in the hope that it will be useful,
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ' GNU General Public License for more details.
+ '
+ ' You should have received a copy of the GNU General Public License
+ ' along with this program. If not, see .
+
+
+
+ ' /********************************************************************************/
+
+ ' Summaries:
+
+ ' Class ReadMapper
+ '
+ ' Constructor: (+1 Overloads) Sub New
+ '
+ ' Function: BuildDelegate, CheckedReadLength, CreateEnumReader, CreateFixArrayReader, CreateFixListReader
+ ' CreateLinkedListReader, CreateNullableReader, CreateVarArrayReader, CreateVarListReader, EnumRead
+ ' GetCacheType, ReadBool, ReadFixArray, ReadFixList, ReadFixOpaque
+ ' ReadLinkedList, ReadNullable, ReadOption, ReadString, ReadVarArray
+ ' ReadVarList, ReadVarOpaque
+ '
+ ' Sub: AppendBuildRequest, AppendMethod, BuildCaches, Init, LockedAppendMethod
+ ' SetFix, SetOne, SetVar
+ '
+ '
+ ' /********************************************************************************/
+
+#End Region
+
+Imports System.Text
+Imports Microsoft.VisualBasic.Data.IO.Xdr.EmitContexts
+
+Namespace Xdr
+ Public MustInherit Class ReadMapper
+ Private _sync As Object = New Object()
+ Private _dependencySync As Object = New Object()
+ Private _dependency As Queue(Of BuildRequest) = New Queue(Of BuildRequest)()
+ Private _builders As Dictionary(Of OpaqueType, Func(Of Type, [Delegate])()) = New Dictionary(Of OpaqueType, Func(Of Type, [Delegate])())()
+
+ Protected Sub New()
+ End Sub
+
+ Protected Sub Init()
+ Call SetOne(Function(r) New Void())
+ SetOne(Function(r) DecodeInt32(r.ByteReader))
+ SetOne(Function(r) DecodeUInt32(r.ByteReader))
+ SetOne(Function(r) DecodeInt64(r.ByteReader))
+ SetOne(Function(r) DecodeUInt64(r.ByteReader))
+ SetOne(Of Single)(Function(r) XdrEncoding.DecodeSingle(r.ByteReader))
+ SetOne(Of Double)(Function(r) XdrEncoding.DecodeDouble(r.ByteReader))
+ Call SetOne(New ReadOneDelegate(Of Boolean)(AddressOf ReadBool))
+ Call SetFix(New ReadManyDelegate(Of Byte())(AddressOf ReadFixOpaque))
+ Call SetVar(New ReadManyDelegate(Of Byte())(AddressOf ReadVarOpaque))
+ Call SetVar(New ReadManyDelegate(Of String)(AddressOf ReadString))
+ _builders.Add(OpaqueType.One, New Func(Of Type, [Delegate])() {AddressOf CreateEnumReader, AddressOf CreateNullableReader, AddressOf CreateLinkedListReader, AddressOf GetReader})
+ _builders.Add(OpaqueType.Fix, New Func(Of Type, [Delegate])() {AddressOf CreateFixArrayReader, AddressOf CreateFixListReader})
+ _builders.Add(OpaqueType.Var, New Func(Of Type, [Delegate])() {AddressOf CreateVarArrayReader, AddressOf CreateVarListReader})
+ End Sub
+
+ Private Shared Function ReadBool(r As Reader) As Boolean
+ Dim val = DecodeUInt32(r.ByteReader)
+ If val = 0 Then Return False
+ If val = 1 Then Return True
+ Throw New InvalidOperationException("unexpected value: " & val.ToString())
+ End Function
+
+ Private Shared Function ReadFixOpaque(r As Reader, len As UInteger) As Byte()
+ Dim result = r.ByteReader.Read(len)
+ Dim tail = len Mod 4UI
+ If tail <> 0 Then r.ByteReader.Read(4UI - tail)
+ Return result
+ End Function
+
+ Private Shared Function ReadVarOpaque(r As Reader, max As UInteger) As Byte()
+ Return ReadFixOpaque(r, CheckedReadLength(r, max))
+ End Function
+
+ Private Shared Function ReadString(r As Reader, max As UInteger) As String
+ Return Encoding.ASCII.GetString(ReadVarOpaque(r, max))
+ End Function
+
+ Private Function BuildDelegate(methodType As OpaqueType, targetType As Type) As [Delegate]
+ Dim wrap As Exception = Nothing
+
+ Try
+
+ For Each build In _builders(methodType)
+ Dim result = build(targetType)
+ If result IsNot Nothing Then Return result
+ Next
+
+ Catch ex As Exception
+ wrap = New InvalidOperationException(String.Format("impossible to create a {0} method type for `{1}'", methodType, targetType.FullName), ex)
+ End Try
+
+ If wrap Is Nothing Then wrap = New NotImplementedException(String.Format("unknown type `{0}' in {1} method type", targetType.FullName, methodType))
+
+ If methodType = OpaqueType.One Then
+ Return ReadOneDelegate(targetType, wrap)
+ Else
+ Return ReadManyDelegate(targetType, wrap)
+ End If
+ End Function
+
+ Protected Sub SetOne(Of T)(method As ReadOneDelegate(Of T))
+ GetOneCacheType().MakeGenericType(GetType(T)).GetField("Instance").SetValue(Nothing, method)
+ End Sub
+
+ Protected Sub SetFix(Of T)(method As ReadManyDelegate(Of T))
+ GetFixCacheType().MakeGenericType(GetType(T)).GetField("Instance").SetValue(Nothing, method)
+ End Sub
+
+ Protected Sub SetVar(Of T)(method As ReadManyDelegate(Of T))
+ GetVarCacheType().MakeGenericType(GetType(T)).GetField("Instance").SetValue(Nothing, method)
+ End Sub
+
+ Private Function GetCacheType(methodType As OpaqueType) As Type
+ Select Case methodType
+ Case OpaqueType.One
+ Return GetOneCacheType()
+ Case OpaqueType.Fix
+ Return GetFixCacheType()
+ Case OpaqueType.Var
+ Return GetVarCacheType()
+ Case Else
+ Throw New NotImplementedException("unknown opaque type")
+ End Select
+ End Function
+
+ Protected MustOverride Function GetOneCacheType() As Type
+ Protected MustOverride Function GetFixCacheType() As Type
+ Protected MustOverride Function GetVarCacheType() As Type
+
+ Public Sub BuildCaches()
+ SyncLock _sync
+
+ While True
+ Dim bReq As BuildRequest = Nothing
+
+ SyncLock _dependencySync
+ If _dependency.Count <> 0 Then bReq = _dependency.Dequeue()
+ End SyncLock
+
+ If bReq Is Nothing Then Return
+ Dim fi = GetCacheType(bReq.Method).MakeGenericType(bReq.TargetType).GetField("Instance")
+ If fi.GetValue(Nothing) Is Nothing Then fi.SetValue(Nothing, BuildDelegate(bReq.Method, bReq.TargetType))
+ End While
+ End SyncLock
+ End Sub
+
+ Friend Sub AppendMethod(targetType As Type, methodType As OpaqueType, method As [Delegate])
+ SyncLock _sync
+ LockedAppendMethod(targetType, methodType, method)
+ End SyncLock
+ End Sub
+
+ Private Sub LockedAppendMethod(targetType As Type, methodType As OpaqueType, method As [Delegate])
+ Dim fi = GetCacheType(methodType).MakeGenericType(targetType).GetField("Instance")
+ If fi.GetValue(Nothing) IsNot Nothing Then Throw New InvalidOperationException("type already mapped")
+ fi.SetValue(Nothing, method)
+ End Sub
+
+ Protected Sub AppendBuildRequest(targetType As Type, methodType As OpaqueType)
+ SyncLock _dependencySync
+ _dependency.Enqueue(New BuildRequest With {
+ .TargetType = targetType,
+ .Method = methodType
+ })
+ End SyncLock
+ End Sub
+
+ Public Shared Function CreateFixArrayReader(collectionType As Type) As [Delegate]
+ Dim itemType As Type = collectionType.ArraySubType()
+ If itemType Is Nothing Then Return Nothing
+ Dim mi = GetType(ReadMapper).GetMethod("ReadFixArray").MakeGenericMethod(itemType)
+ Return [Delegate].CreateDelegate(GetType(ReadManyDelegate(Of)).MakeGenericType(collectionType), mi)
+ End Function
+
+ Public Shared Function ReadFixArray(Of T)(r As Reader, len As UInteger) As T()
+ Dim i As UInteger = 0
+
+ Try
+ Dim result = New T(len - 1) {}
+
+ While i < len
+ result(i) = r.Read(Of T)()
+ i += 1
+ End While
+
+ Return result
+ Catch ex As Exception
+ Throw New FormatException(String.Format("cant't read {0} item", i), ex)
+ End Try
+ End Function
+
+ Public Shared Function CreateLinkedListReader(collectionType As Type) As [Delegate]
+ Dim itemType As Type = collectionType.ListSubType()
+ If itemType Is Nothing Then Return Nothing
+ Dim mi = GetType(ReadMapper).GetMethod("ReadLinkedList").MakeGenericMethod(itemType)
+ Return [Delegate].CreateDelegate(GetType(ReadOneDelegate(Of)).MakeGenericType(collectionType), mi)
+ End Function
+
+ Public Shared Function ReadLinkedList(Of T)(r As Reader) As List(Of T)
+ Dim result As List(Of T) = New List(Of T)()
+
+ While ReadOption(r)
+
+ Try
+ result.Add(r.Read(Of T)())
+ Catch ex As Exception
+ Throw New FormatException(String.Format("cant't read {0} item", result.Count + 1), ex)
+ End Try
+ End While
+
+ Return result
+ End Function
+
+ Public Shared Function CreateFixListReader(collectionType As Type) As [Delegate]
+ Dim itemType As Type = collectionType.ListSubType()
+ If itemType Is Nothing Then Return Nothing
+ Dim mi = GetType(ReadMapper).GetMethod("ReadFixList").MakeGenericMethod(itemType)
+ Return [Delegate].CreateDelegate(GetType(ReadManyDelegate(Of)).MakeGenericType(collectionType), mi)
+ End Function
+
+ Public Shared Function ReadFixList(Of T)(r As Reader, len As UInteger) As List(Of T)
+ Dim i As UInteger = 0
+
+ Try
+ Dim result As List(Of T) = New List(Of T)()
+
+ While i < len
+ result.Add(r.Read(Of T)())
+ i += 1
+ End While
+
+ Return result
+ Catch ex As Exception
+ Throw New FormatException(String.Format("cant't read {0} item", i), ex)
+ End Try
+ End Function
+
+ Public Shared Function CreateEnumReader(targetType As Type) As [Delegate]
+ If Not targetType.IsEnum Then Return Nothing
+ Dim mi = GetType(ReadMapper).GetMethod("EnumRead").MakeGenericMethod(targetType)
+ Return [Delegate].CreateDelegate(GetType(ReadOneDelegate(Of)).MakeGenericType(targetType), mi)
+ End Function
+
+ Public Shared Function EnumRead(Of T As Structure)(reader As Reader) As T
+ Return EnumHelper(Of T).IntToEnum(reader.Read(Of Integer)())
+ End Function
+
+ Public Shared Function CreateNullableReader(targetType As Type) As [Delegate]
+ Dim itemType As Type = targetType.NullableSubType()
+ If itemType Is Nothing Then Return Nothing
+ Dim mi = GetType(ReadMapper).GetMethod("ReadNullable").MakeGenericMethod(itemType)
+ Return [Delegate].CreateDelegate(GetType(ReadOneDelegate(Of)).MakeGenericType(targetType), mi)
+ End Function
+
+ Public Shared Function ReadNullable(Of T As Structure)(reader As Reader) As T?
+ Dim exist = ReadOption(reader)
+
+ Try
+
+ If exist Then
+ Return reader.Read(Of T)()
+ Else
+ Return Nothing
+ End If
+
+ Catch ex As SystemException
+ Throw New FormatException("cant't read 'value'", ex)
+ End Try
+ End Function
+
+ Private Shared Function ReadOption(reader As Reader) As Boolean
+ Try
+ Return reader.Read(Of Boolean)()
+ Catch ex As SystemException
+ Throw New FormatException("cant't read 'option'", ex)
+ End Try
+ End Function
+
+ Public Shared Function CreateVarArrayReader(collectionType As Type) As [Delegate]
+ Dim itemType As Type = collectionType.ArraySubType()
+ If itemType Is Nothing Then Return Nothing
+ Dim mi = GetType(ReadMapper).GetMethod("ReadVarArray").MakeGenericMethod(itemType)
+ Return [Delegate].CreateDelegate(GetType(ReadManyDelegate(Of)).MakeGenericType(collectionType), mi)
+ End Function
+
+ Public Shared Function ReadVarArray(Of T)(r As Reader, max As UInteger) As T()
+ Return ReadFixArray(Of T)(r, CheckedReadLength(r, max))
+ End Function
+
+ Public Shared Function CreateVarListReader(collectionType As Type) As [Delegate]
+ Dim itemType As Type = collectionType.ListSubType()
+ If itemType Is Nothing Then Return Nothing
+ Dim mi = GetType(ReadMapper).GetMethod("ReadVarList").MakeGenericMethod(itemType)
+ Return [Delegate].CreateDelegate(GetType(ReadManyDelegate(Of)).MakeGenericType(collectionType), mi)
+ End Function
+
+ Public Shared Function ReadVarList(Of T)(r As Reader, max As UInteger) As List(Of T)
+ Return ReadFixList(Of T)(r, CheckedReadLength(r, max))
+ End Function
+
+ Private Shared Function CheckedReadLength(r As Reader, max As UInteger) As UInteger
+ Dim len As UInteger
+
+ Try
+ len = DecodeUInt32(r.ByteReader)
+ Catch ex As SystemException
+ Throw New FormatException("cant't read 'length'", ex)
+ End Try
+
+ If len > max Then Throw New FormatException("unexpected length: " & len.ToString())
+ Return len
+ End Function
+ End Class
+End Namespace
+
diff --git a/XDRStream/Reading/Reader.vb b/XDRStream/Reading/Reader.vb
new file mode 100644
index 0000000..df8d095
--- /dev/null
+++ b/XDRStream/Reading/Reader.vb
@@ -0,0 +1,93 @@
+#Region "Microsoft.VisualBasic::3271e9eeeb902e1fdc2ec9be3a8c3df6, Data\BinaryData\BinaryData\XDR\Reading\Reader.vb"
+
+ ' Author:
+ '
+ ' asuka (amethyst.asuka@gcmodeller.org)
+ ' xie (genetics@smrucc.org)
+ ' xieguigang (xie.guigang@live.com)
+ '
+ ' Copyright (c) 2018 GPL3 Licensed
+ '
+ '
+ ' GNU GENERAL PUBLIC LICENSE (GPL3)
+ '
+ '
+ ' This program is free software: you can redistribute it and/or modify
+ ' it under the terms of the GNU General Public License as published by
+ ' the Free Software Foundation, either version 3 of the License, or
+ ' (at your option) any later version.
+ '
+ ' This program is distributed in the hope that it will be useful,
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ' GNU General Public License for more details.
+ '
+ ' You should have received a copy of the GNU General Public License
+ ' along with this program. If not, see .
+
+
+
+ ' /********************************************************************************/
+
+ ' Summaries:
+
+ ' Class Reader
+ '
+ ' Constructor: (+1 Overloads) Sub New
+ ' Function: Read, ReadFix, ReadOption, ReadVar
+ '
+ '
+ ' /********************************************************************************/
+
+#End Region
+
+Imports System
+
+Namespace Xdr
+ Public MustInherit Class Reader
+ Public ReadOnly ByteReader As IByteReader
+
+ Protected Sub New(reader As IByteReader)
+ ByteReader = reader
+ End Sub
+
+ Public Function Read(Of T)() As T
+ Try
+ Return CacheRead(Of T)()
+ Catch ex As SystemException
+ Throw MapException.ReadOne(GetType(T), ex)
+ End Try
+ End Function
+
+ Protected MustOverride Function CacheRead(Of T)() As T
+
+ Public Function ReadFix(Of T)(len As UInteger) As T
+ Try
+ Return CacheReadFix(Of T)(len)
+ Catch ex As SystemException
+ Throw MapException.ReadFix(GetType(T), len, ex)
+ End Try
+ End Function
+
+ Protected MustOverride Function CacheReadFix(Of T)(len As UInteger) As T
+
+ Public Function ReadVar(Of T)(max As UInteger) As T
+ Try
+ Return CacheReadVar(Of T)(max)
+ Catch ex As SystemException
+ Throw MapException.ReadVar(GetType(T), max, ex)
+ End Try
+ End Function
+
+ Protected MustOverride Function CacheReadVar(Of T)(max As UInteger) As T
+
+ Public Function ReadOption(Of T As Class)() As T
+ If Read(Of Boolean)() Then
+ Return Read(Of T)()
+ Else
+ Return Nothing
+ End If
+ End Function
+ End Class
+End Namespace
+
diff --git a/XDRStream/TypeExtensions.vb b/XDRStream/TypeExtensions.vb
new file mode 100644
index 0000000..778959b
--- /dev/null
+++ b/XDRStream/TypeExtensions.vb
@@ -0,0 +1,85 @@
+#Region "Microsoft.VisualBasic::2f151b3ffd00dcc8fdb8a017dd0a15ba, Data\BinaryData\BinaryData\XDR\TypeExtensions.vb"
+
+ ' Author:
+ '
+ ' asuka (amethyst.asuka@gcmodeller.org)
+ ' xie (genetics@smrucc.org)
+ ' xieguigang (xie.guigang@live.com)
+ '
+ ' Copyright (c) 2018 GPL3 Licensed
+ '
+ '
+ ' GNU GENERAL PUBLIC LICENSE (GPL3)
+ '
+ '
+ ' This program is free software: you can redistribute it and/or modify
+ ' it under the terms of the GNU General Public License as published by
+ ' the Free Software Foundation, either version 3 of the License, or
+ ' (at your option) any later version.
+ '
+ ' This program is distributed in the hope that it will be useful,
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ' GNU General Public License for more details.
+ '
+ ' You should have received a copy of the GNU General Public License
+ ' along with this program. If not, see .
+
+
+
+ ' /********************************************************************************/
+
+ ' Summaries:
+
+ ' Module TypeExtensions
+ '
+ ' Function: ArraySubType, GetAttr, GetAttrs, ListSubType, NullableSubType
+ '
+ '
+ ' /********************************************************************************/
+
+#End Region
+
+Imports System
+Imports System.Collections.Generic
+Imports System.Linq
+Imports System.Reflection
+Imports System.Runtime.CompilerServices
+
+Namespace Xdr
+ Public Module TypeExtensions
+
+ Public Function GetAttr(Of T As Attribute)(mi As MemberInfo) As T
+ Return TryCast(mi.GetCustomAttributes(GetType(T), True).FirstOrDefault(), T)
+ End Function
+
+
+ Public Function GetAttrs(Of T As Attribute)(mi As MemberInfo) As IEnumerable(Of T)
+ Return mi.GetCustomAttributes(GetType(T), True).Cast(Of T)()
+ End Function
+
+
+ Public Function NullableSubType(type As Type) As Type
+ If Not type.IsGenericType Then Return Nothing
+ If type.GetGenericTypeDefinition() IsNot GetType(Nullable(Of)) Then Return Nothing
+ Return type.GetGenericArguments()(0)
+ End Function
+
+
+ Public Function ArraySubType(type As Type) As Type
+ If Not type.HasElementType Then Return Nothing
+ Dim itemType As Type = type.GetElementType()
+ If itemType Is Nothing OrElse itemType.MakeArrayType() IsNot type Then Return Nothing
+ Return itemType
+ End Function
+
+
+ Public Function ListSubType(type As Type) As Type
+ If Not type.IsGenericType Then Return Nothing
+ Dim genericType As Type = type.GetGenericTypeDefinition()
+ If genericType IsNot GetType(List(Of)) Then Return Nothing
+ Return type.GetGenericArguments()(0)
+ End Function
+ End Module
+End Namespace
+
diff --git a/XDRStream/Void.vb b/XDRStream/Void.vb
new file mode 100644
index 0000000..cd38ec3
--- /dev/null
+++ b/XDRStream/Void.vb
@@ -0,0 +1,52 @@
+#Region "Microsoft.VisualBasic::2355bf29771a422fab3f38724ab559bd, Data\BinaryData\BinaryData\XDR\Void.vb"
+
+ ' Author:
+ '
+ ' asuka (amethyst.asuka@gcmodeller.org)
+ ' xie (genetics@smrucc.org)
+ ' xieguigang (xie.guigang@live.com)
+ '
+ ' Copyright (c) 2018 GPL3 Licensed
+ '
+ '
+ ' GNU GENERAL PUBLIC LICENSE (GPL3)
+ '
+ '
+ ' This program is free software: you can redistribute it and/or modify
+ ' it under the terms of the GNU General Public License as published by
+ ' the Free Software Foundation, either version 3 of the License, or
+ ' (at your option) any later version.
+ '
+ ' This program is distributed in the hope that it will be useful,
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ' GNU General Public License for more details.
+ '
+ ' You should have received a copy of the GNU General Public License
+ ' along with this program. If not, see .
+
+
+
+ ' /********************************************************************************/
+
+ ' Summaries:
+
+ ' Structure Void
+ '
+ '
+ '
+ '
+ ' /********************************************************************************/
+
+#End Region
+
+
+Namespace Xdr
+ '''
+ ''' Void
+ ''' http://tools.ietf.org/html/rfc4506#section-4.16
+ '''
+ Public Structure Void
+ End Structure
+End Namespace
+
diff --git a/XDRStream/Writing/WriteBuilder.EmitDynWriteMapper.vb b/XDRStream/Writing/WriteBuilder.EmitDynWriteMapper.vb
new file mode 100644
index 0000000..2e5bc51
--- /dev/null
+++ b/XDRStream/Writing/WriteBuilder.EmitDynWriteMapper.vb
@@ -0,0 +1,100 @@
+#Region "Microsoft.VisualBasic::04e4e0fa9494d6e2b4dd89c54241251e, Data\BinaryData\BinaryData\XDR\Writing\WriteBuilder.EmitDynWriteMapper.vb"
+
+ ' Author:
+ '
+ ' asuka (amethyst.asuka@gcmodeller.org)
+ ' xie (genetics@smrucc.org)
+ ' xieguigang (xie.guigang@live.com)
+ '
+ ' Copyright (c) 2018 GPL3 Licensed
+ '
+ '
+ ' GNU GENERAL PUBLIC LICENSE (GPL3)
+ '
+ '
+ ' This program is free software: you can redistribute it and/or modify
+ ' it under the terms of the GNU General Public License as published by
+ ' the Free Software Foundation, either version 3 of the License, or
+ ' (at your option) any later version.
+ '
+ ' This program is distributed in the hope that it will be useful,
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ' GNU General Public License for more details.
+ '
+ ' You should have received a copy of the GNU General Public License
+ ' along with this program. If not, see .
+
+
+
+ ' /********************************************************************************/
+
+ ' Summaries:
+
+ ' Class WriteBuilder
+ '
+ ' Function: DefineCacheField, EmitDynWriteMapper
+ '
+ ' Sub: EmitInitField, EmitOverride_GetCacheType
+ '
+ '
+ ' /********************************************************************************/
+
+#End Region
+
+Imports System
+Imports System.Reflection
+Imports System.Reflection.Emit
+
+Namespace Xdr
+ Public NotInheritable Partial Class WriteBuilder
+ Private Function EmitDynWriteMapper() As Type
+ Dim typeBuilder = _modBuilder.DefineType("DynWriteMapper", TypeAttributes.NotPublic Or TypeAttributes.Class Or TypeAttributes.Sealed, GetType(WriteMapper))
+ Dim fb_oneCacheType = DefineCacheField(typeBuilder, "_oneCacheType")
+ Dim fb_fixCacheType = DefineCacheField(typeBuilder, "_fixCacheType")
+ Dim fb_varCacheType = DefineCacheField(typeBuilder, "_varCacheType")
+ Dim ctor = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, New Type(-1) {})
+ Dim ilCtor As ILGenerator = ctor.GetILGenerator()
+ ilCtor.Emit(OpCodes.Ldarg_0)
+ ilCtor.Emit(OpCodes.Call, GetType(WriteMapper).GetConstructor(BindingFlags.Instance Or BindingFlags.NonPublic, Nothing, New Type(-1) {}, Nothing))
+ ilCtor.Emit(OpCodes.Ldarg_0)
+ ilCtor.Emit(OpCodes.Ldftn, GetType(WriteMapper).GetMethod("AppendBuildRequest", BindingFlags.NonPublic Or BindingFlags.Instance))
+ ilCtor.Emit(OpCodes.Newobj, GetType(Action(Of Type, OpaqueType)).GetConstructor(New Type() {GetType(Object), GetType(IntPtr)}))
+ ilCtor.Emit(OpCodes.Stsfld, _buildBinderDescription.BuildRequest)
+ EmitInitField(ilCtor, fb_oneCacheType, _oneCacheDescription.Result)
+ EmitInitField(ilCtor, fb_fixCacheType, _fixCacheDescription.Result)
+ EmitInitField(ilCtor, fb_varCacheType, _varCacheDescription.Result)
+
+ ' run init
+ ilCtor.Emit(OpCodes.Ldarg_0)
+ ilCtor.Emit(OpCodes.Call, GetType(WriteMapper).GetMethod("Init", BindingFlags.Instance Or BindingFlags.NonPublic))
+ ilCtor.Emit(OpCodes.Ret)
+ EmitOverride_GetCacheType(typeBuilder, "GetOneCacheType", fb_oneCacheType)
+ EmitOverride_GetCacheType(typeBuilder, "GetFixCacheType", fb_fixCacheType)
+ EmitOverride_GetCacheType(typeBuilder, "GetVarCacheType", fb_varCacheType)
+ Return typeBuilder.CreateType()
+ End Function
+
+ Private Shared Function DefineCacheField(typeBuilder As TypeBuilder, name As String) As FieldBuilder
+ Return typeBuilder.DefineField(name, GetType(Type), FieldAttributes.Private Or FieldAttributes.InitOnly)
+ End Function
+
+ Private Shared Sub EmitInitField(il As ILGenerator, fb As FieldBuilder, type As Type)
+ il.Emit(OpCodes.Ldarg_0)
+ il.Emit(OpCodes.Ldtoken, type)
+ il.Emit(OpCodes.Call, GetType(Type).GetMethod("GetTypeFromHandle"))
+ il.Emit(OpCodes.Stfld, fb)
+ End Sub
+
+ Private Sub EmitOverride_GetCacheType(typeBuilder As TypeBuilder, overrideName As String, fb_cacheType As FieldBuilder)
+ Dim mb = typeBuilder.DefineMethod(overrideName, MethodAttributes.Family Or MethodAttributes.Virtual)
+ mb.SetReturnType(GetType(Type))
+ typeBuilder.DefineMethodOverride(mb, GetType(WriteMapper).GetMethod(overrideName, BindingFlags.NonPublic Or BindingFlags.Instance))
+ Dim il As ILGenerator = mb.GetILGenerator()
+ il.Emit(OpCodes.Ldarg_0)
+ il.Emit(OpCodes.Ldfld, fb_cacheType)
+ il.Emit(OpCodes.Ret)
+ End Sub
+ End Class
+End Namespace
+
diff --git a/XDRStream/Writing/WriteBuilder.EmitDynWriter.vb b/XDRStream/Writing/WriteBuilder.EmitDynWriter.vb
new file mode 100644
index 0000000..1a734af
--- /dev/null
+++ b/XDRStream/Writing/WriteBuilder.EmitDynWriter.vb
@@ -0,0 +1,114 @@
+#Region "Microsoft.VisualBasic::af1a372ac5207d90b3e37baaaa9079b6, Data\BinaryData\BinaryData\XDR\Writing\WriteBuilder.EmitDynWriter.vb"
+
+ ' Author:
+ '
+ ' asuka (amethyst.asuka@gcmodeller.org)
+ ' xie (genetics@smrucc.org)
+ ' xieguigang (xie.guigang@live.com)
+ '
+ ' Copyright (c) 2018 GPL3 Licensed
+ '
+ '
+ ' GNU GENERAL PUBLIC LICENSE (GPL3)
+ '
+ '
+ ' This program is free software: you can redistribute it and/or modify
+ ' it under the terms of the GNU General Public License as published by
+ ' the Free Software Foundation, either version 3 of the License, or
+ ' (at your option) any later version.
+ '
+ ' This program is distributed in the hope that it will be useful,
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ' GNU General Public License for more details.
+ '
+ ' You should have received a copy of the GNU General Public License
+ ' along with this program. If not, see .
+
+
+
+ ' /********************************************************************************/
+
+ ' Summaries:
+
+ ' Class WriteBuilder
+ '
+ ' Function: EmitDynWriter
+ '
+ ' Sub: EmitOverride_WriteTMany, EmitOverride_WriteTOne
+ '
+ '
+ ' /********************************************************************************/
+
+#End Region
+
+Imports System.Reflection
+Imports System.Reflection.Emit
+Imports Microsoft.VisualBasic.Data.IO.Xdr.Emit
+
+Namespace Xdr
+ Partial Public NotInheritable Class WriteBuilder
+ Private Function EmitDynWriter() As Type
+ Dim typeBuilder = _modBuilder.DefineType("DynWriter", TypeAttributes.NotPublic Or TypeAttributes.Class Or TypeAttributes.Sealed, GetType(Writer))
+ Dim fb_mapperInstance = typeBuilder.DefineField("Mapper", GetType(WriteMapper), FieldAttributes.Public Or FieldAttributes.Static)
+ Dim ctor = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, New Type() {GetType(IByteWriter)})
+ Dim ilCtor As ILGenerator = ctor.GetILGenerator()
+ ilCtor.Emit(OpCodes.Ldarg_0)
+ ilCtor.Emit(OpCodes.Ldarg_1) ' reader
+ ilCtor.Emit(OpCodes.Call, GetType(Writer).GetConstructor(BindingFlags.Instance Or BindingFlags.NonPublic, Nothing, New Type() {GetType(IByteWriter)}, Nothing))
+ ilCtor.Emit(OpCodes.Ret)
+ EmitOverride_WriteTOne(typeBuilder, fb_mapperInstance)
+ EmitOverride_WriteTMany(typeBuilder, "CacheWriteFix", _fixCacheDescription, fb_mapperInstance)
+ EmitOverride_WriteTMany(typeBuilder, "CacheWriteVar", _varCacheDescription, fb_mapperInstance)
+ Return typeBuilder.CreateType()
+ End Function
+
+ Private Sub EmitOverride_WriteTOne(typeBuilder As TypeBuilder, mapperInstance As FieldInfo)
+ Dim miDeclaration = GetType(Writer).GetMethod("CacheWrite", BindingFlags.NonPublic Or BindingFlags.Instance)
+ Dim mb = typeBuilder.DefineMethod("CacheWrite", MethodAttributes.Family Or MethodAttributes.Virtual)
+ Dim genTypeParam = mb.DefineGenericParameters("T")(0)
+ mb.SetReturnType(Nothing)
+ mb.SetParameters(genTypeParam)
+ typeBuilder.DefineMethodOverride(mb, miDeclaration)
+ Dim fi = TypeBuilder.GetField(_oneCacheDescription.Result.MakeGenericType(genTypeParam), _oneCacheDescription.Result.GetField("Instance"))
+ Dim il As ILGenerator = mb.GetILGenerator()
+ Dim noBuild As Label = il.DefineLabel()
+ il.Emit(OpCodes.Ldsfld, fi)
+ il.Emit(OpCodes.Brtrue, noBuild)
+ il.Emit(OpCodes.Ldsfld, mapperInstance)
+ il.Emit(OpCodes.Call, GetType(WriteMapper).GetMethod("BuildCaches", BindingFlags.Public Or BindingFlags.Instance))
+ il.MarkLabel(noBuild)
+ il.Emit(OpCodes.Ldsfld, fi)
+ il.Emit(OpCodes.Ldarg_0) ' this writer
+ il.Emit(OpCodes.Ldarg_1) ' item
+ Dim miInvoke = TypeBuilder.GetMethod(GetType(WriteOneDelegate(Of)).MakeGenericType(genTypeParam), GetType(WriteOneDelegate(Of)).GetMethod("Invoke"))
+ il.Emit(OpCodes.Callvirt, miInvoke)
+ il.Emit(OpCodes.Ret)
+ End Sub
+
+ Private Shared Sub EmitOverride_WriteTMany(tb As TypeBuilder, name As String, manyCacheDesc As StaticCacheDescription, mapperInstance As FieldInfo)
+ Dim miDeclaration = GetType(Writer).GetMethod(name, BindingFlags.NonPublic Or BindingFlags.Instance)
+ Dim mb = tb.DefineMethod(name, MethodAttributes.Family Or MethodAttributes.Virtual)
+ Dim genTypeParam = mb.DefineGenericParameters("T")(0)
+ mb.SetReturnType(Nothing)
+ mb.SetParameters(GetType(UInteger), genTypeParam)
+ tb.DefineMethodOverride(mb, miDeclaration)
+ Dim fi = manyCacheDesc.Instance(genTypeParam)
+ Dim il As ILGenerator = mb.GetILGenerator()
+ Dim noBuild As Label = il.DefineLabel()
+ il.Emit(OpCodes.Ldsfld, fi)
+ il.Emit(OpCodes.Brtrue, noBuild)
+ il.Emit(OpCodes.Ldsfld, mapperInstance)
+ il.Emit(OpCodes.Call, GetType(WriteMapper).GetMethod("BuildCaches", BindingFlags.Public Or BindingFlags.Instance))
+ il.MarkLabel(noBuild)
+ il.Emit(OpCodes.Ldsfld, fi)
+ il.Emit(OpCodes.Ldarg_0) ' this writer
+ il.Emit(OpCodes.Ldarg_1) ' len or max
+ il.Emit(OpCodes.Ldarg_2) ' item
+ Dim miInvoke = TypeBuilder.GetMethod(GetType(WriteManyDelegate(Of)).MakeGenericType(genTypeParam), GetType(WriteManyDelegate(Of)).GetMethod("Invoke"))
+ il.Emit(OpCodes.Callvirt, miInvoke)
+ il.Emit(OpCodes.Ret)
+ End Sub
+ End Class
+End Namespace
+
diff --git a/XDRStream/Writing/WriteBuilder.vb b/XDRStream/Writing/WriteBuilder.vb
new file mode 100644
index 0000000..342df99
--- /dev/null
+++ b/XDRStream/Writing/WriteBuilder.vb
@@ -0,0 +1,104 @@
+#Region "Microsoft.VisualBasic::e686ed45971518f5d34a3e3fd2cb38b7, Data\BinaryData\BinaryData\XDR\Writing\WriteBuilder.vb"
+
+ ' Author:
+ '
+ ' asuka (amethyst.asuka@gcmodeller.org)
+ ' xie (genetics@smrucc.org)
+ ' xieguigang (xie.guigang@live.com)
+ '
+ ' Copyright (c) 2018 GPL3 Licensed
+ '
+ '
+ ' GNU GENERAL PUBLIC LICENSE (GPL3)
+ '
+ '
+ ' This program is free software: you can redistribute it and/or modify
+ ' it under the terms of the GNU General Public License as published by
+ ' the Free Software Foundation, either version 3 of the License, or
+ ' (at your option) any later version.
+ '
+ ' This program is distributed in the hope that it will be useful,
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ' GNU General Public License for more details.
+ '
+ ' You should have received a copy of the GNU General Public License
+ ' along with this program. If not, see .
+
+
+
+ ' /********************************************************************************/
+
+ ' Summaries:
+
+ ' Class WriteBuilder
+ '
+ ' Constructor: (+1 Overloads) Sub New
+ ' Function: Create, EmitCreater, Map, MapFix, MapVar
+ '
+ '
+ ' /********************************************************************************/
+
+#End Region
+
+Imports System.Reflection
+Imports System.Reflection.Emit
+Imports Microsoft.VisualBasic.Data.IO.Xdr.Emit
+
+Namespace Xdr
+ Public NotInheritable Partial Class WriteBuilder
+ Private _wm As WriteMapper
+ Private _creater As Func(Of IByteWriter, Writer)
+ Private _modBuilder As ModuleBuilder
+ Private _buildBinderDescription As BuildBinderDescription
+ Private _oneCacheDescription As StaticCacheDescription
+ Private _varCacheDescription As StaticCacheDescription
+ Private _fixCacheDescription As StaticCacheDescription
+
+ Public Sub New()
+ Dim name = "DynamicXdrWriteMapper"
+ Dim asmName As AssemblyName = New AssemblyName(name)
+ Dim asmBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.RunAndSave)
+ _modBuilder = asmBuilder.DefineDynamicModule(name & ".dll", name & ".dll")
+ _buildBinderDescription = New BuildBinderDescription(_modBuilder)
+ _oneCacheDescription = New StaticCacheDescription(_modBuilder, _buildBinderDescription, "OneCache", False, OpaqueType.One)
+ _fixCacheDescription = New StaticCacheDescription(_modBuilder, _buildBinderDescription, "FixCache", False, OpaqueType.Fix)
+ _varCacheDescription = New StaticCacheDescription(_modBuilder, _buildBinderDescription, "VarCache", False, OpaqueType.Var)
+ Dim dynWriteMapperType As Type = EmitDynWriteMapper()
+ _wm = CType(Activator.CreateInstance(dynWriteMapperType), WriteMapper)
+ Dim dynWriterType As Type = EmitDynWriter()
+ Dim mapperInstance = dynWriterType.GetField("Mapper", BindingFlags.Public Or BindingFlags.Static)
+ mapperInstance.SetValue(Nothing, _wm)
+ _creater = EmitCreater(dynWriterType.GetConstructor(New Type() {GetType(IByteWriter)}))
+ End Sub
+
+ Private Shared Function EmitCreater(ci As ConstructorInfo) As Func(Of IByteWriter, Writer)
+ Dim dm = New DynamicMethod("DynCreateWriter", GetType(Writer), New Type() {GetType(IByteWriter)}, GetType(WriteBuilder), True)
+ Dim il = dm.GetILGenerator()
+ il.Emit(OpCodes.Ldarg_0)
+ il.Emit(OpCodes.Newobj, ci)
+ il.Emit(OpCodes.Ret)
+ Return CType(dm.CreateDelegate(GetType(Func(Of IByteWriter, Writer))), Func(Of IByteWriter, Writer))
+ End Function
+
+ Public Function Map(Of T)(writer As WriteOneDelegate(Of T)) As WriteBuilder
+ _wm.AppendMethod(GetType(T), OpaqueType.One, writer)
+ Return Me
+ End Function
+
+ Public Function MapFix(Of T)(writer As WriteManyDelegate(Of T)) As WriteBuilder
+ _wm.AppendMethod(GetType(T), OpaqueType.Fix, writer)
+ Return Me
+ End Function
+
+ Public Function MapVar(Of T)(writer As WriteManyDelegate(Of T)) As WriteBuilder
+ _wm.AppendMethod(GetType(T), OpaqueType.Var, writer)
+ Return Me
+ End Function
+
+ Public Function Create(writer As IByteWriter) As Writer
+ Return _creater(writer)
+ End Function
+ End Class
+End Namespace
+
diff --git a/XDRStream/Writing/WriteMapper.vb b/XDRStream/Writing/WriteMapper.vb
new file mode 100644
index 0000000..91b092e
--- /dev/null
+++ b/XDRStream/Writing/WriteMapper.vb
@@ -0,0 +1,377 @@
+#Region "Microsoft.VisualBasic::313d875a366955af6a1292fd1c1e144c, Data\BinaryData\BinaryData\XDR\Writing\WriteMapper.vb"
+
+ ' Author:
+ '
+ ' asuka (amethyst.asuka@gcmodeller.org)
+ ' xie (genetics@smrucc.org)
+ ' xieguigang (xie.guigang@live.com)
+ '
+ ' Copyright (c) 2018 GPL3 Licensed
+ '
+ '
+ ' GNU GENERAL PUBLIC LICENSE (GPL3)
+ '
+ '
+ ' This program is free software: you can redistribute it and/or modify
+ ' it under the terms of the GNU General Public License as published by
+ ' the Free Software Foundation, either version 3 of the License, or
+ ' (at your option) any later version.
+ '
+ ' This program is distributed in the hope that it will be useful,
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ' GNU General Public License for more details.
+ '
+ ' You should have received a copy of the GNU General Public License
+ ' along with this program. If not, see .
+
+
+
+ ' /********************************************************************************/
+
+ ' Summaries:
+
+ ' Class WriteMapper
+ '
+ ' Constructor: (+1 Overloads) Sub New
+ '
+ ' Function: BuildDelegate, CreateEnumWriter, CreateFixArrayWriter, CreateFixListWriter, CreateLinkedListWriter
+ ' CreateNullableWriter, CreateVarArrayWriter, CreateVarListWriter, GetCacheType
+ '
+ ' Sub: AppendBuildRequest, AppendMethod, BuildCaches, EnumWriter, Init
+ ' LockedAppendMethod, NoCheckWriteFixOpaque, SetFix, SetOne, SetVar
+ ' WriteBool, WriteFixArray, WriteFixList, WriteFixOpaque, WriteLinkedList
+ ' WriteNullable, WriteOption, WriteString, WriteVarArray, WriteVarList
+ ' WriteVarOpaque
+ '
+ '
+ ' /********************************************************************************/
+
+#End Region
+
+Imports System.Text
+Imports Microsoft.VisualBasic.Data.IO.Xdr.EmitContexts
+
+Namespace Xdr
+ Public MustInherit Class WriteMapper
+ Private _sync As Object = New Object()
+ Private _dependencySync As Object = New Object()
+ Private _dependency As Queue(Of BuildRequest) = New Queue(Of BuildRequest)()
+ Private _builders As Dictionary(Of OpaqueType, Func(Of Type, [Delegate])()) = New Dictionary(Of OpaqueType, Func(Of Type, [Delegate])())()
+
+ Protected Sub New()
+ End Sub
+
+ Protected Sub Init()
+ SetOne(Of Void)(Sub(w, i)
+ End Sub)
+ SetOne(Of Integer)(Sub(w, i) EncodeInt32(i, w.ByteWriter))
+ SetOne(Of UInteger)(Sub(w, i) EncodeUInt32(i, w.ByteWriter))
+ SetOne(Of Long)(Sub(w, i) EncodeInt64(i, w.ByteWriter))
+ SetOne(Of ULong)(Sub(w, i) EncodeUInt64(i, w.ByteWriter))
+ SetOne(Of Single)(Sub(w, i) XdrEncoding.EncodeSingle(i, w.ByteWriter))
+ SetOne(Of Double)(Sub(w, i) XdrEncoding.EncodeDouble(i, w.ByteWriter))
+ Call SetOne(New WriteOneDelegate(Of Boolean)(AddressOf WriteBool))
+ Call SetFix(New WriteManyDelegate(Of Byte())(AddressOf WriteFixOpaque))
+ Call SetVar(New WriteManyDelegate(Of Byte())(AddressOf WriteVarOpaque))
+ Call SetVar(New WriteManyDelegate(Of String)(AddressOf WriteString))
+ _builders.Add(OpaqueType.One, New Func(Of Type, [Delegate])() {AddressOf CreateEnumWriter, AddressOf CreateNullableWriter, AddressOf CreateLinkedListWriter, AddressOf GetWriter})
+ _builders.Add(OpaqueType.Fix, New Func(Of Type, [Delegate])() {AddressOf CreateFixArrayWriter, AddressOf CreateFixListWriter})
+ _builders.Add(OpaqueType.Var, New Func(Of Type, [Delegate])() {AddressOf CreateVarArrayWriter, AddressOf CreateVarListWriter})
+ End Sub
+
+ Private Shared Sub WriteBool(w As Writer, v As Boolean)
+ w.Write(If(v, 1, 0))
+ End Sub
+
+ Private Shared _tails As Byte()() = New Byte()() {Nothing, New Byte() {&H00}, New Byte() {&H00, &H00}, New Byte() {&H00, &H00, &H00}}
+
+ Private Shared Sub WriteFixOpaque(w As Writer, len As UInteger, v As Byte())
+ If v.LongLength <> len Then Throw New FormatException("unexpected length: " & v.LongLength.ToString())
+ NoCheckWriteFixOpaque(w, len, v)
+ End Sub
+
+ Private Shared Sub WriteVarOpaque(w As Writer, max As UInteger, v As Byte())
+ Dim len As UInteger = v.LongLength
+ If len > max Then Throw New FormatException("unexpected length: " & len.ToString())
+
+ Try
+ w.Write(len)
+ Catch ex As SystemException
+ Throw New FormatException("can't write length", ex)
+ End Try
+
+ NoCheckWriteFixOpaque(w, len, v)
+ End Sub
+
+ Private Shared Sub NoCheckWriteFixOpaque(w As Writer, len As UInteger, v As Byte())
+ Try
+ w.ByteWriter.Write(v)
+ Dim tail = len Mod 4UI
+ If tail <> 0 Then w.ByteWriter.Write(_tails(4UI - tail))
+ Catch ex As SystemException
+ Throw New FormatException("can't write byte array", ex)
+ End Try
+ End Sub
+
+ Private Shared Sub WriteString(w As Writer, max As UInteger, v As String)
+ WriteVarOpaque(w, max, Encoding.ASCII.GetBytes(v))
+ End Sub
+
+ Private Function BuildDelegate(methodType As OpaqueType, targetType As Type) As [Delegate]
+ Dim wrap As Exception = Nothing
+
+ Try
+
+ For Each build In _builders(methodType)
+ Dim result = build(targetType)
+ If result IsNot Nothing Then Return result
+ Next
+
+ Catch ex As Exception
+ wrap = New InvalidOperationException(String.Format("impossible to create a {0} method type for `{1}'", methodType, targetType.FullName), ex)
+ End Try
+
+ If wrap Is Nothing Then wrap = New NotImplementedException(String.Format("unknown type `{0}' in {1} method type", targetType.FullName, methodType))
+
+ If methodType = OpaqueType.One Then
+ Return WriteOneDelegate(targetType, wrap)
+ Else
+ Return WriteManyDelegate(targetType, wrap)
+ End If
+ End Function
+
+ Protected Sub SetOne(Of T)(method As WriteOneDelegate(Of T))
+ GetOneCacheType().MakeGenericType(GetType(T)).GetField("Instance").SetValue(Nothing, method)
+ End Sub
+
+ Protected Sub SetFix(Of T)(method As WriteManyDelegate(Of T))
+ GetFixCacheType().MakeGenericType(GetType(T)).GetField("Instance").SetValue(Nothing, method)
+ End Sub
+
+ Protected Sub SetVar(Of T)(method As WriteManyDelegate(Of T))
+ GetVarCacheType().MakeGenericType(GetType(T)).GetField("Instance").SetValue(Nothing, method)
+ End Sub
+
+ Private Function GetCacheType(methodType As OpaqueType) As Type
+ Select Case methodType
+ Case OpaqueType.One
+ Return GetOneCacheType()
+ Case OpaqueType.Fix
+ Return GetFixCacheType()
+ Case OpaqueType.Var
+ Return GetVarCacheType()
+ Case Else
+ Throw New NotImplementedException("unknown opaque type")
+ End Select
+ End Function
+
+ Protected MustOverride Function GetOneCacheType() As Type
+ Protected MustOverride Function GetFixCacheType() As Type
+ Protected MustOverride Function GetVarCacheType() As Type
+
+ Public Sub BuildCaches()
+ SyncLock _sync
+
+ While True
+ Dim bReq As BuildRequest = Nothing
+
+ SyncLock _dependencySync
+ If _dependency.Count <> 0 Then bReq = _dependency.Dequeue()
+ End SyncLock
+
+ If bReq Is Nothing Then Return
+ Dim fi = GetCacheType(bReq.Method).MakeGenericType(bReq.TargetType).GetField("Instance")
+ If fi.GetValue(Nothing) Is Nothing Then fi.SetValue(Nothing, BuildDelegate(bReq.Method, bReq.TargetType))
+ End While
+ End SyncLock
+ End Sub
+
+ Friend Sub AppendMethod(targetType As Type, methodType As OpaqueType, method As [Delegate])
+ SyncLock _sync
+ LockedAppendMethod(targetType, methodType, method)
+ End SyncLock
+ End Sub
+
+ Private Sub LockedAppendMethod(targetType As Type, methodType As OpaqueType, method As [Delegate])
+ Dim fi = GetCacheType(methodType).MakeGenericType(targetType).GetField("Instance")
+ If fi.GetValue(Nothing) IsNot Nothing Then Throw New InvalidOperationException("type already mapped")
+ fi.SetValue(Nothing, method)
+ End Sub
+
+ Protected Sub AppendBuildRequest(targetType As Type, methodType As OpaqueType)
+ SyncLock _dependencySync
+ _dependency.Enqueue(New BuildRequest With {
+ .TargetType = targetType,
+ .Method = methodType
+ })
+ End SyncLock
+ End Sub
+
+ Public Shared Function CreateFixArrayWriter(collectionType As Type) As [Delegate]
+ Dim itemType As Type = collectionType.ArraySubType()
+ If itemType Is Nothing Then Return Nothing
+ Dim mi = GetType(WriteMapper).GetMethod("WriteFixArray").MakeGenericMethod(itemType)
+ Return [Delegate].CreateDelegate(GetType(WriteManyDelegate(Of)).MakeGenericType(collectionType), mi)
+ End Function
+
+ Public Shared Sub WriteFixArray(Of T)(w As Writer, len As UInteger, val As T())
+ If val.LongLength <> len Then Throw New FormatException("unexpected length: " & val.LongLength.ToString())
+ Dim i As UInteger = 0
+
+ Try
+
+ While i < len
+ w.Write(val(i))
+ i += 1
+ End While
+
+ Catch ex As SystemException
+ Throw New FormatException(String.Format("can't write {0} item", i), ex)
+ End Try
+ End Sub
+
+ Public Shared Function CreateLinkedListWriter(collectionType As Type) As [Delegate]
+ Dim itemType As Type = collectionType.ListSubType()
+ If itemType Is Nothing Then Return Nothing
+ Dim mi = GetType(WriteMapper).GetMethod("WriteLinkedList").MakeGenericMethod(itemType)
+ Return [Delegate].CreateDelegate(GetType(WriteOneDelegate(Of)).MakeGenericType(collectionType), mi)
+ End Function
+
+ Public Shared Sub WriteLinkedList(Of T)(w As Writer, val As List(Of T))
+ For i = 0 To val.Count - 1
+ WriteOption(w, True)
+
+ Try
+ w.Write(val(i))
+ Catch ex As SystemException
+ Throw New FormatException(String.Format("can't write {0} item", i), ex)
+ End Try
+ Next
+
+ WriteOption(w, False)
+ End Sub
+
+ Public Shared Function CreateFixListWriter(collectionType As Type) As [Delegate]
+ Dim itemType As Type = collectionType.ListSubType()
+ If itemType Is Nothing Then Return Nothing
+ Dim mi = GetType(WriteMapper).GetMethod("WriteFixList").MakeGenericMethod(itemType)
+ Return [Delegate].CreateDelegate(GetType(WriteManyDelegate(Of)).MakeGenericType(collectionType), mi)
+ End Function
+
+ Public Shared Sub WriteFixList(Of T)(w As Writer, len As UInteger, val As List(Of T))
+ If val.Count <> len Then Throw New FormatException("unexpected length: " & val.Count.ToString())
+ Dim i = 0
+
+ Try
+
+ While i < val.Count
+ w.Write(val(i))
+ i += 1
+ End While
+
+ Catch ex As SystemException
+ Throw New FormatException(String.Format("can't write {0} item", i), ex)
+ End Try
+ End Sub
+
+ Public Shared Function CreateEnumWriter(targetType As Type) As [Delegate]
+ If Not targetType.IsEnum Then Return Nothing
+ Dim mi = GetType(WriteMapper).GetMethod("EnumWriter").MakeGenericMethod(targetType)
+ Return [Delegate].CreateDelegate(GetType(WriteOneDelegate(Of)).MakeGenericType(targetType), mi)
+ End Function
+
+ Public Shared Sub EnumWriter(Of T As Structure)(writer As Writer, val As T)
+ writer.Write(EnumHelper(Of T).EnumToInt(val))
+ End Sub
+
+ Public Shared Function CreateNullableWriter(targetType As Type) As [Delegate]
+ Dim itemType As Type = targetType.NullableSubType()
+ If itemType Is Nothing Then Return Nothing
+ Dim mi = GetType(WriteMapper).GetMethod("WriteNullable").MakeGenericMethod(itemType)
+ Return [Delegate].CreateDelegate(GetType(WriteOneDelegate(Of)).MakeGenericType(targetType), mi)
+ End Function
+
+ Public Shared Sub WriteNullable(Of T As Structure)(writer As Writer, val As T?)
+ WriteOption(writer, val.HasValue)
+ If Not val.HasValue Then Return
+
+ Try
+ writer.Write(val.Value)
+ Catch ex As SystemException
+ Throw New FormatException("can't write value", ex)
+ End Try
+ End Sub
+
+ Private Shared Sub WriteOption(writer As Writer, val As Boolean)
+ Try
+ writer.Write(val)
+ Catch ex As SystemException
+ Throw New FormatException("can't write option", ex)
+ End Try
+ End Sub
+
+ Public Shared Function CreateVarArrayWriter(collectionType As Type) As [Delegate]
+ Dim itemType As Type = collectionType.ArraySubType()
+ If itemType Is Nothing Then Return Nothing
+ Dim mi = GetType(WriteMapper).GetMethod("WriteVarArray").MakeGenericMethod(itemType)
+ Return [Delegate].CreateDelegate(GetType(WriteManyDelegate(Of)).MakeGenericType(collectionType), mi)
+ End Function
+
+ Public Shared Sub WriteVarArray(Of T)(w As Writer, max As UInteger, val As T())
+ Dim len As UInteger = val.LongLength
+ If len > max Then Throw New FormatException("unexpected length: " & len.ToString())
+
+ Try
+ w.Write(len)
+ Catch ex As SystemException
+ Throw New FormatException("can't write length", ex)
+ End Try
+
+ Dim i As UInteger = 0
+
+ Try
+
+ While i < len
+ w.Write(val(i))
+ i += 1
+ End While
+
+ Catch ex As SystemException
+ Throw New FormatException(String.Format("can't write {0} item", i), ex)
+ End Try
+ End Sub
+
+ Public Shared Function CreateVarListWriter(collectionType As Type) As [Delegate]
+ Dim itemType As Type = collectionType.ListSubType()
+ If itemType Is Nothing Then Return Nothing
+ Dim mi = GetType(WriteMapper).GetMethod("WriteVarList").MakeGenericMethod(itemType)
+ Return [Delegate].CreateDelegate(GetType(WriteManyDelegate(Of)).MakeGenericType(collectionType), mi)
+ End Function
+
+ Public Shared Sub WriteVarList(Of T)(w As Writer, max As UInteger, val As List(Of T))
+ Dim len = val.Count
+ If len > max Then Throw New FormatException("unexpected length: " & len.ToString())
+
+ Try
+ w.Write(Of UInteger)(len)
+ Catch ex As SystemException
+ Throw New FormatException("can't write length", ex)
+ End Try
+
+ Dim i = 0
+
+ Try
+
+ While i < len
+ w.Write(val(i))
+ i += 1
+ End While
+
+ Catch ex As SystemException
+ Throw New FormatException(String.Format("can't write {0} item", i), ex)
+ End Try
+ End Sub
+ End Class
+End Namespace
+
diff --git a/XDRStream/Writing/Writer.vb b/XDRStream/Writing/Writer.vb
new file mode 100644
index 0000000..71a4a14
--- /dev/null
+++ b/XDRStream/Writing/Writer.vb
@@ -0,0 +1,94 @@
+#Region "Microsoft.VisualBasic::e8ea3985ba52d2f47bc6f5004d9aa066, Data\BinaryData\BinaryData\XDR\Writing\Writer.vb"
+
+ ' Author:
+ '
+ ' asuka (amethyst.asuka@gcmodeller.org)
+ ' xie (genetics@smrucc.org)
+ ' xieguigang (xie.guigang@live.com)
+ '
+ ' Copyright (c) 2018 GPL3 Licensed
+ '
+ '
+ ' GNU GENERAL PUBLIC LICENSE (GPL3)
+ '
+ '
+ ' This program is free software: you can redistribute it and/or modify
+ ' it under the terms of the GNU General Public License as published by
+ ' the Free Software Foundation, either version 3 of the License, or
+ ' (at your option) any later version.
+ '
+ ' This program is distributed in the hope that it will be useful,
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ' GNU General Public License for more details.
+ '
+ ' You should have received a copy of the GNU General Public License
+ ' along with this program. If not, see .
+
+
+
+ ' /********************************************************************************/
+
+ ' Summaries:
+
+ ' Class Writer
+ '
+ ' Constructor: (+1 Overloads) Sub New
+ ' Sub: Write, WriteFix, WriteOption, WriteVar
+ '
+ '
+ ' /********************************************************************************/
+
+#End Region
+
+Imports System
+
+Namespace Xdr
+ Public MustInherit Class Writer
+ Public ReadOnly ByteWriter As IByteWriter
+
+ Protected Sub New(writer As IByteWriter)
+ ByteWriter = writer
+ End Sub
+
+ Public Sub Write(Of T)(item As T)
+ Try
+ CacheWrite(item)
+ Catch ex As SystemException
+ Throw MapException.WriteOne(GetType(T), ex)
+ End Try
+ End Sub
+
+ Protected MustOverride Sub CacheWrite(Of T)(item As T)
+
+ Public Sub WriteFix(Of T)(len As UInteger, item As T)
+ Try
+ CacheWriteFix(len, item)
+ Catch ex As SystemException
+ Throw MapException.WriteFix(GetType(T), len, ex)
+ End Try
+ End Sub
+
+ Protected MustOverride Sub CacheWriteFix(Of T)(len As UInteger, item As T)
+
+ Public Sub WriteVar(Of T)(max As UInteger, item As T)
+ Try
+ CacheWriteVar(max, item)
+ Catch ex As SystemException
+ Throw MapException.WriteVar(GetType(T), max, ex)
+ End Try
+ End Sub
+
+ Protected MustOverride Sub CacheWriteVar(Of T)(max As UInteger, item As T)
+
+ Public Sub WriteOption(Of T As Class)(item As T)
+ If item Is Nothing Then
+ Write(False)
+ Else
+ Write(True)
+ Write(item)
+ End If
+ End Sub
+ End Class
+End Namespace
+
diff --git a/XDRStream/XDRStream.vbproj b/XDRStream/XDRStream.vbproj
new file mode 100644
index 0000000..11768ab
--- /dev/null
+++ b/XDRStream/XDRStream.vbproj
@@ -0,0 +1,137 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {806818F5-D50A-4BFF-ACA3-CFF60D3FC61E}
+ Library
+ XDR
+ XDRStream
+ 512
+ Windows
+ v4.8
+ true
+
+
+ true
+ full
+ true
+ true
+ bin\Debug\
+ XDRStream.xml
+ 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022
+
+
+ pdbonly
+ false
+ true
+ true
+ bin\Release\
+ XDRStream.xml
+ 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022
+
+
+ On
+
+
+ Binary
+
+
+ Off
+
+
+ On
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ True
+ Application.myapp
+ True
+
+
+ True
+ True
+ Resources.resx
+
+
+ True
+ Settings.settings
+ True
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VbMyResourcesResXFileCodeGenerator
+ Resources.Designer.vb
+ My.Resources
+ Designer
+
+
+
+
+ MyApplicationCodeGenerator
+ Application.Designer.vb
+
+
+ SettingsSingleFileGenerator
+ My
+ Settings.Designer.vb
+
+
+
+
\ No newline at end of file