From bf34494ae14035e785f36b6a24454eb04be8ea73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6llner?= Date: Wed, 4 Sep 2019 22:29:23 +0200 Subject: [PATCH 01/22] Initial skeleton for MSBuild integration --- Capnp.Net.sln | 6 + .../AssemblyAttributes.cs | 4 + .../Capnpc.Csharp.MsBuild.Generation.csproj | 79 +++++++ .../Capnpc.Csharp.MsBuild.Generation.nuspec | 30 +++ .../CodeBehindWriter.cs | 49 +++++ .../FeatureCodeBehindGenerator.cs | 39 ++++ .../FeatureFileCodeBehindGenerator.cs | 78 +++++++ .../FilePathGenerator.cs | 31 +++ .../FileSystemHelper.cs | 204 ++++++++++++++++++ .../GenerateCapnpFileCodeBehindTask.cs | 112 ++++++++++ .../Helper/LogExtensions.cs | 22 ++ .../ICapnpCsharpGenerator.cs | 9 + .../TestFileGeneratorResult.cs | 42 ++++ .../TestGenerationError.cs | 6 + .../TestGeneratorResult.cs | 11 + .../CpsExtension.DesignTime.targets | 15 ++ .../Buildsystem/Rules/FeatureFileType.xaml | 34 +++ .../Buildsystem/Rules/ProjectItemsSchema.xaml | 18 ++ .../Capnpc.Csharp.MsBuild.Generation.props | 77 +++++++ .../Capnpc.Csharp.MsBuild.Generation.targets | 145 +++++++++++++ .../Capnpc.Csharp.MsBuild.Generation.tasks | 3 + .../Capnpc.Csharp.MsBuild.Generation.props | 5 + Licenses/SpecFlow-LICENSE-NewBSD.txt | 31 +++ 23 files changed, 1050 insertions(+) create mode 100644 Capnpc.Csharp.MsBuild.Generation/AssemblyAttributes.cs create mode 100644 Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.csproj create mode 100644 Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.nuspec create mode 100644 Capnpc.Csharp.MsBuild.Generation/CodeBehindWriter.cs create mode 100644 Capnpc.Csharp.MsBuild.Generation/FeatureCodeBehindGenerator.cs create mode 100644 Capnpc.Csharp.MsBuild.Generation/FeatureFileCodeBehindGenerator.cs create mode 100644 Capnpc.Csharp.MsBuild.Generation/FilePathGenerator.cs create mode 100644 Capnpc.Csharp.MsBuild.Generation/FileSystemHelper.cs create mode 100644 Capnpc.Csharp.MsBuild.Generation/GenerateCapnpFileCodeBehindTask.cs create mode 100644 Capnpc.Csharp.MsBuild.Generation/Helper/LogExtensions.cs create mode 100644 Capnpc.Csharp.MsBuild.Generation/ICapnpCsharpGenerator.cs create mode 100644 Capnpc.Csharp.MsBuild.Generation/TestFileGeneratorResult.cs create mode 100644 Capnpc.Csharp.MsBuild.Generation/TestGenerationError.cs create mode 100644 Capnpc.Csharp.MsBuild.Generation/TestGeneratorResult.cs create mode 100644 Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/CpsExtension.DesignTime.targets create mode 100644 Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/FeatureFileType.xaml create mode 100644 Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/ProjectItemsSchema.xaml create mode 100644 Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.props create mode 100644 Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.targets create mode 100644 Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.tasks create mode 100644 Capnpc.Csharp.MsBuild.Generation/buildMultiTargeting/Capnpc.Csharp.MsBuild.Generation.props create mode 100644 Licenses/SpecFlow-LICENSE-NewBSD.txt diff --git a/Capnp.Net.sln b/Capnp.Net.sln index 41f5968..8e20bf5 100644 --- a/Capnp.Net.sln +++ b/Capnp.Net.sln @@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Capnp.Net.Runtime.Tests.Cor EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "capnpc-csharp.tests", "capnpc-csharp.tests\capnpc-csharp.tests.csproj", "{B77AC567-E232-4072-85C3-8689566BF3D4}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Capnpc.Csharp.MsBuild.Generation", "Capnpc.Csharp.MsBuild.Generation\Capnpc.Csharp.MsBuild.Generation.csproj", "{1EFC1F20-C7BB-4F44-8BF9-DBB123AACCF4}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -39,6 +41,10 @@ Global {B77AC567-E232-4072-85C3-8689566BF3D4}.Debug|Any CPU.Build.0 = Debug|Any CPU {B77AC567-E232-4072-85C3-8689566BF3D4}.Release|Any CPU.ActiveCfg = Release|Any CPU {B77AC567-E232-4072-85C3-8689566BF3D4}.Release|Any CPU.Build.0 = Release|Any CPU + {1EFC1F20-C7BB-4F44-8BF9-DBB123AACCF4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1EFC1F20-C7BB-4F44-8BF9-DBB123AACCF4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1EFC1F20-C7BB-4F44-8BF9-DBB123AACCF4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1EFC1F20-C7BB-4F44-8BF9-DBB123AACCF4}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Capnpc.Csharp.MsBuild.Generation/AssemblyAttributes.cs b/Capnpc.Csharp.MsBuild.Generation/AssemblyAttributes.cs new file mode 100644 index 0000000..ff364dc --- /dev/null +++ b/Capnpc.Csharp.MsBuild.Generation/AssemblyAttributes.cs @@ -0,0 +1,4 @@ + +using System.Runtime.CompilerServices; +using System.Security; + diff --git a/Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.csproj b/Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.csproj new file mode 100644 index 0000000..bb09bb6 --- /dev/null +++ b/Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.csproj @@ -0,0 +1,79 @@ + + + netstandard2.0;netcoreapp2.1 + false + $(MSBuildThisFileDirectory)Capnpc.Csharp.MsBuild.Generation.nuspec + true + + + true + true + + true + true + $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb + + + + + + + + + + + + + + All + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Microsoft.Build + + + Microsoft.Build.Framework + + + Microsoft.Build.Utilities.Core + + + + + + + MSBuild:Compile + + + MSBuild:Compile + + + + \ No newline at end of file diff --git a/Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.nuspec b/Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.nuspec new file mode 100644 index 0000000..35629ed --- /dev/null +++ b/Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.nuspec @@ -0,0 +1,30 @@ + + + + Capnpc.Csharp.Generation + 1.0.0 + Capnpc.Csharp.MsBuild.Generation + Christian Köllner and contributors + Christian Köllner + Package to enable the .capnp -> .cs file generation during build time + Package to enable the .capnp -> .cs file generation during build time + en-US + https://github.com/c80k/capnproto-dotnetcore + false + MIT + capnproto csharp msbuild + Christian Köllner and contributors + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Capnpc.Csharp.MsBuild.Generation/CodeBehindWriter.cs b/Capnpc.Csharp.MsBuild.Generation/CodeBehindWriter.cs new file mode 100644 index 0000000..f147ee7 --- /dev/null +++ b/Capnpc.Csharp.MsBuild.Generation/CodeBehindWriter.cs @@ -0,0 +1,49 @@ +using System; +using System.IO; +using Microsoft.Build.Utilities; + +namespace Capnpc.Csharp.MsBuild.Generation +{ + public class CodeBehindWriter + { + public CodeBehindWriter(TaskLoggingHelper log) + { + Log = log; + } + + public TaskLoggingHelper Log { get; } + + public string WriteCodeBehindFile(string outputPath, string featureFile, TestFileGeneratorResult testFileGeneratorResult) //todo needs unit tests + { + //if (string.IsNullOrEmpty(testFileGeneratorResult.Filename)) + //{ + // Log?.LogWithNameTag(Log.LogError, $"{featureFile} has no generated filename"); + // return null; + //} + + //string directoryPath = Path.GetDirectoryName(outputPath) ?? throw new InvalidOperationException(); + //Log?.LogWithNameTag(Log.LogMessage, directoryPath); + + //Log?.LogWithNameTag(Log.LogMessage, $"Writing data to {outputPath}; path = {directoryPath}; generatedFilename = {testFileGeneratorResult.Filename}"); + + //if (File.Exists(outputPath)) + //{ + // if (!FileSystemHelper.FileCompareContent(outputPath, testFileGeneratorResult.GeneratedTestCode)) + // { + // File.WriteAllText(outputPath, testFileGeneratorResult.GeneratedTestCode); + // } + //} + //else + //{ + // if (!Directory.Exists(directoryPath)) + // { + // Directory.CreateDirectory(directoryPath); + // } + + // File.WriteAllText(outputPath, testFileGeneratorResult.GeneratedTestCode); + //} + + return outputPath; + } + } +} diff --git a/Capnpc.Csharp.MsBuild.Generation/FeatureCodeBehindGenerator.cs b/Capnpc.Csharp.MsBuild.Generation/FeatureCodeBehindGenerator.cs new file mode 100644 index 0000000..1f6d631 --- /dev/null +++ b/Capnpc.Csharp.MsBuild.Generation/FeatureCodeBehindGenerator.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.IO; + +namespace Capnpc.Csharp.MsBuild.Generation +{ + public class FeatureCodeBehindGenerator : IDisposable + { + //private SpecFlowProject _specFlowProject; + //private ITestGenerator _testGenerator; + + public void InitializeProject(string projectPath, string rootNamespace, IEnumerable generatorPlugins) + { + //_specFlowProject = MsBuildProjectReader.LoadSpecFlowProjectFromMsBuild(Path.GetFullPath(projectPath), rootNamespace); + + //var projectSettings = _specFlowProject.ProjectSettings; + + //var testGeneratorFactory = new TestGeneratorFactory(); + + //_testGenerator = testGeneratorFactory.CreateGenerator(projectSettings, generatorPlugins); + } + + + public TestFileGeneratorResult GenerateCodeBehindFile(string featureFile) + { + //var featureFileInput = new FeatureFileInput(featureFile); + //var generatedFeatureFileName = Path.GetFileName(_testGenerator.GetTestFullPath(featureFileInput)); + + //var testGeneratorResult = _testGenerator.GenerateTestFile(featureFileInput, new GenerationSettings()); + + return new TestFileGeneratorResult(null, null); + } + + public void Dispose() + { + //_testGenerator?.Dispose(); + } + } +} \ No newline at end of file diff --git a/Capnpc.Csharp.MsBuild.Generation/FeatureFileCodeBehindGenerator.cs b/Capnpc.Csharp.MsBuild.Generation/FeatureFileCodeBehindGenerator.cs new file mode 100644 index 0000000..eeb369f --- /dev/null +++ b/Capnpc.Csharp.MsBuild.Generation/FeatureFileCodeBehindGenerator.cs @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Build.Utilities; + +namespace Capnpc.Csharp.MsBuild.Generation +{ + public class FeatureFileCodeBehindGenerator : ICapnpCsharpGenerator + { + private readonly FilePathGenerator _filePathGenerator; + + public FeatureFileCodeBehindGenerator(TaskLoggingHelper log) + { + Log = log ?? throw new ArgumentNullException(nameof(log)); + _filePathGenerator = new FilePathGenerator(); + } + + public TaskLoggingHelper Log { get; } + + public IEnumerable GenerateFilesForProject( + string projectPath, + string rootNamespace, + List CapnpFiles, + List generatorPlugins, + string projectFolder, + string outputPath) + { + using (var featureCodeBehindGenerator = new FeatureCodeBehindGenerator()) + { + featureCodeBehindGenerator.InitializeProject(projectPath, rootNamespace, generatorPlugins); + + var codeBehindWriter = new CodeBehindWriter(null); + + if (CapnpFiles == null) + { + yield break; + } + + foreach (var featureFile in CapnpFiles) + { + var featureFileItemSpec = featureFile; + var generatorResult = featureCodeBehindGenerator.GenerateCodeBehindFile(featureFileItemSpec); + + if (!generatorResult.Success) + { + foreach (var error in generatorResult.Errors) + { + //Log.LogError( + // null, + // null, + // null, + // featureFile, + // error.Line, + // error.LinePosition, + // 0, + // 0, + // error.Message); + } + continue; + } + + var targetFilePath = _filePathGenerator.GenerateFilePath( + projectFolder, + outputPath, + featureFile, + generatorResult.Filename); + + var resultedFile = codeBehindWriter.WriteCodeBehindFile(targetFilePath, featureFile, generatorResult); + + yield return FileSystemHelper.GetRelativePath(resultedFile, projectFolder); + } + } + + } + } +} diff --git a/Capnpc.Csharp.MsBuild.Generation/FilePathGenerator.cs b/Capnpc.Csharp.MsBuild.Generation/FilePathGenerator.cs new file mode 100644 index 0000000..c1e71a1 --- /dev/null +++ b/Capnpc.Csharp.MsBuild.Generation/FilePathGenerator.cs @@ -0,0 +1,31 @@ +using System; +using System.IO; + +namespace Capnpc.Csharp.MsBuild.Generation +{ + public class FilePathGenerator + { + public string GenerateFilePath(string projectFolder, string relativeOutputPath, string featureFileName, string generatedCodeBehindFileName) + { + if (projectFolder is null) + { + throw new ArgumentNullException(nameof(projectFolder)); + } + + if (featureFileName is null) + { + throw new ArgumentNullException(nameof(featureFileName)); + } + + if (generatedCodeBehindFileName is null) + { + throw new ArgumentNullException(nameof(generatedCodeBehindFileName)); + } + + string featureFileFullPath = Path.GetFullPath(Path.Combine(projectFolder, relativeOutputPath ?? "", featureFileName)); + string featureFileDirPath = Path.GetDirectoryName(featureFileFullPath); + + return Path.Combine(featureFileDirPath, generatedCodeBehindFileName); + } + } +} diff --git a/Capnpc.Csharp.MsBuild.Generation/FileSystemHelper.cs b/Capnpc.Csharp.MsBuild.Generation/FileSystemHelper.cs new file mode 100644 index 0000000..14cfd41 --- /dev/null +++ b/Capnpc.Csharp.MsBuild.Generation/FileSystemHelper.cs @@ -0,0 +1,204 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Text; + +namespace Capnpc.Csharp.MsBuild.Generation +{ + public static class FileSystemHelper + { + public static void CopyFileToFolder(string filePath, string folderName) + { + File.Copy(filePath, Path.Combine(folderName, Path.GetFileName(filePath))); + } + + public static string GetRelativePath(string path, string basePath) + { + path = Path.GetFullPath(path); + basePath = Path.GetFullPath(basePath); + if (String.Equals(path, basePath, StringComparison.OrdinalIgnoreCase)) + return "."; // the "this folder" + + if (path.StartsWith(basePath + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase)) + return path.Substring(basePath.Length + 1); + + //handle different drives + string pathRoot = Path.GetPathRoot(path); + if (!String.Equals(pathRoot, Path.GetPathRoot(basePath), StringComparison.OrdinalIgnoreCase)) + return path; + + //handle ".." pathes + string[] pathParts = path.Substring(pathRoot.Length).Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); + string[] basePathParts = basePath.Substring(pathRoot.Length).Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); + + int commonFolderCount = 0; + while (commonFolderCount < pathParts.Length && commonFolderCount < basePathParts.Length && + String.Equals(pathParts[commonFolderCount], basePathParts[commonFolderCount], StringComparison.OrdinalIgnoreCase)) + commonFolderCount++; + + StringBuilder result = new StringBuilder(); + for (int i = 0; i < basePathParts.Length - commonFolderCount; i++) + { + result.Append(".."); + result.Append(Path.DirectorySeparatorChar); + } + + if (pathParts.Length - commonFolderCount == 0) + return result.ToString().TrimEnd(Path.DirectorySeparatorChar); + + result.Append(String.Join(Path.DirectorySeparatorChar.ToString(), pathParts, commonFolderCount, pathParts.Length - commonFolderCount)); + return result.ToString(); + } + + // This method accepts two strings the represent two files to + // compare. A return value of true indicates that the contents of the files + // are the same. A return value of any other value indicates that the + // files are not the same. + public static bool FileCompare(string filePath1, string filePath2) + { + int file1byte; + int file2byte; + + // Determine if the same file was referenced two times. + if (String.Equals(filePath1, filePath2, StringComparison.CurrentCultureIgnoreCase)) + { + // Return true to indicate that the files are the same. + return true; + } + + // Open the two files. + using (FileStream fs1 = new FileStream(filePath1, FileMode.Open, FileAccess.Read)) + using (FileStream fs2 = new FileStream(filePath2, FileMode.Open, FileAccess.Read)) + { + // Check the file sizes. If they are not the same, the files + // are not the same. + if (fs1.Length != fs2.Length) + { + // Return false to indicate files are different + return false; + } + + // Read and compare a byte from each file until either a + // non-matching set of bytes is found or until the end of + // file1 is reached. + do + { + // Read one byte from each file. + file1byte = fs1.ReadByte(); + file2byte = fs2.ReadByte(); + } while ((file1byte == file2byte) && (file1byte != -1)); + } + + // Return the success of the comparison. "file1byte" is + // equal to "file2byte" at this point only if the files are + // the same. + return ((file1byte - file2byte) == 0); + } + + public static void CopyDirectory(string sourcePath, string destPath, bool cleanDestination = true) + { + if (cleanDestination) + EnsureEmptyFolder(destPath); + else + { + if (!Directory.Exists(destPath)) + { + Directory.CreateDirectory(destPath); + } + } + + foreach (string file in Directory.GetFiles(sourcePath)) + { + var fileName = Path.GetFileName(file); + Debug.Assert(fileName != null); + string dest = Path.Combine(destPath, fileName); + File.Copy(file, dest, true); + File.SetAttributes(dest, File.GetAttributes(dest) & (~FileAttributes.ReadOnly)); + } + + foreach (string folder in Directory.GetDirectories(sourcePath)) + { + var folderName = Path.GetFileName(folder); + Debug.Assert(folderName != null); + string dest = Path.Combine(destPath, folderName); + CopyDirectory(folder, dest); + } + } + + public static void EnsureEmptyFolder(string folderName) + { + folderName = Path.GetFullPath(folderName); + + if (!Directory.Exists(folderName)) + { + Directory.CreateDirectory(folderName); + return; + } + + DeleteFolderContent(folderName); + } + + public static void EnsureFolderOfFile(string filePath) + { + string directory = Path.GetDirectoryName(filePath); + if (directory != null && !Directory.Exists(directory)) + Directory.CreateDirectory(directory); + } + + + private static void Retry(int number, Action action) + { + try + { + action(); + } + catch (UnauthorizedAccessException) + { + var i = number - 1; + + if (i == 0) + throw; + + Retry(i, action); + } + } + + public static void DeleteFolderContent(string folderName) + { + foreach (string file in Directory.GetFiles(folderName)) + { + try + { + Retry(5, () => File.Delete(file)); + } + catch (Exception ex) + { + throw new Exception("Unable to delete file: " + file, ex); + } + } + + foreach (string folder in Directory.GetDirectories(folderName)) + { + try + { + Retry(5, () => Directory.Delete(folder, true)); + } + catch (Exception ex) + { + throw new Exception("Unable to delete folder: " + folder, ex); + } + } + } + + public static void DeleteFolder(string path) + { + if (!Directory.Exists(path)) + return; + + DeleteFolderContent(path); + + Retry(5, () => Directory.Delete(path, true)); + } + } +} diff --git a/Capnpc.Csharp.MsBuild.Generation/GenerateCapnpFileCodeBehindTask.cs b/Capnpc.Csharp.MsBuild.Generation/GenerateCapnpFileCodeBehindTask.cs new file mode 100644 index 0000000..ee69aa8 --- /dev/null +++ b/Capnpc.Csharp.MsBuild.Generation/GenerateCapnpFileCodeBehindTask.cs @@ -0,0 +1,112 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Resources; +using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; + +namespace Capnpc.Csharp.MsBuild.Generation +{ + public class GenerateCapnpFileCodeBehindTask : Task + { + public GenerateCapnpFileCodeBehindTask() + { + CodeBehindGenerator = new FeatureFileCodeBehindGenerator(Log); + } + + public ICapnpCsharpGenerator CodeBehindGenerator { get; set; } + + [Required] + public string ProjectPath { get; set; } + + public string RootNamespace { get; set; } + + public string ProjectFolder => Path.GetDirectoryName(ProjectPath); + public string OutputPath { get; set; } + + public ITaskItem[] CapnpFiles { get; set; } + + public ITaskItem[] GeneratorPlugins { get; set; } + + [Output] + public ITaskItem[] GeneratedFiles { get; private set; } + + public override bool Execute() + { + try + { + try + { + var currentProcess = Process.GetCurrentProcess(); + + Log.LogWithNameTag(Log.LogMessage, $"process: {currentProcess.ProcessName}, pid: {currentProcess.Id}, CD: {Environment.CurrentDirectory}"); + + foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) + { + Log.LogWithNameTag(Log.LogMessage, " " + assembly.FullName); + } + } + catch (Exception e) + { + Log.LogWithNameTag(Log.LogMessage, $"Error when dumping process info: {e}"); + } + + AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; + + var generator = CodeBehindGenerator ?? new FeatureFileCodeBehindGenerator(Log); + + Log.LogWithNameTag(Log.LogMessage, "Starting GenerateFeatureFileCodeBehind"); + + var generatorPlugins = GeneratorPlugins?.Select(gp => gp.ItemSpec).ToList() ?? new List(); + + var capnpFiles = CapnpFiles?.Select(i => i.ItemSpec).ToList() ?? new List(); + + var generatedFiles = generator.GenerateFilesForProject( + ProjectPath, + RootNamespace, + capnpFiles, + generatorPlugins, + ProjectFolder, + OutputPath); + + GeneratedFiles = generatedFiles.Select(file => new TaskItem { ItemSpec = file }).ToArray(); + + return !Log.HasLoggedErrors; + } + catch (Exception e) + { + if (e.InnerException != null) + { + if (e.InnerException is FileLoadException fle) + { + Log?.LogWithNameTag(Log.LogError, $"FileLoadException Filename: {fle.FileName}"); + Log?.LogWithNameTag(Log.LogError, $"FileLoadException FusionLog: {fle.FusionLog}"); + Log?.LogWithNameTag(Log.LogError, $"FileLoadException Message: {fle.Message}"); + } + + Log?.LogWithNameTag(Log.LogError, e.InnerException.ToString()); + } + + Log?.LogWithNameTag(Log.LogError, e.ToString()); + return false; + } + finally + { + AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve; + } + } + + private System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) + { + Log.LogWithNameTag(Log.LogMessage, args.Name); + + + return null; + } + + } + + +} \ No newline at end of file diff --git a/Capnpc.Csharp.MsBuild.Generation/Helper/LogExtensions.cs b/Capnpc.Csharp.MsBuild.Generation/Helper/LogExtensions.cs new file mode 100644 index 0000000..1343a80 --- /dev/null +++ b/Capnpc.Csharp.MsBuild.Generation/Helper/LogExtensions.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Build.Utilities; + +namespace Capnpc.Csharp.MsBuild.Generation +{ + public static class LogExtensions + { + public static void LogWithNameTag( + this TaskLoggingHelper loggingHelper, + Action loggingMethod, + string message, + params object[] messageArgs) + { + string fullMessage = $"[SpecFlow] {message}"; + loggingMethod?.Invoke(fullMessage, messageArgs); + } + } +} diff --git a/Capnpc.Csharp.MsBuild.Generation/ICapnpCsharpGenerator.cs b/Capnpc.Csharp.MsBuild.Generation/ICapnpCsharpGenerator.cs new file mode 100644 index 0000000..5368331 --- /dev/null +++ b/Capnpc.Csharp.MsBuild.Generation/ICapnpCsharpGenerator.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace Capnpc.Csharp.MsBuild.Generation +{ + public interface ICapnpCsharpGenerator + { + IEnumerable GenerateFilesForProject(string projectPath, string rootNamespace, List CapnpFiles, List generatorPlugins, string projectFolder, string outputPath); + } +} \ No newline at end of file diff --git a/Capnpc.Csharp.MsBuild.Generation/TestFileGeneratorResult.cs b/Capnpc.Csharp.MsBuild.Generation/TestFileGeneratorResult.cs new file mode 100644 index 0000000..5eb0160 --- /dev/null +++ b/Capnpc.Csharp.MsBuild.Generation/TestFileGeneratorResult.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Capnpc.Csharp.MsBuild.Generation +{ + public class TestFileGeneratorResult + { + public TestFileGeneratorResult(TestGeneratorResult generatorResult, string fileName) + { + if (generatorResult == null) + { + throw new ArgumentNullException(nameof(generatorResult)); + } + + Filename = fileName ?? throw new ArgumentNullException(nameof(fileName)); + + Errors = generatorResult.Errors; + IsUpToDate = generatorResult.IsUpToDate; + GeneratedTestCode = generatorResult.GeneratedTestCode; + } + + /// + /// The errors, if any. + /// + public IEnumerable Errors { get; } + + /// + /// The generated file was up-to-date. + /// + public bool IsUpToDate { get; } + + /// + /// The generated test code. + /// + public string GeneratedTestCode { get; } + + public bool Success => Errors == null || !Errors.Any(); + + public string Filename { get; } + } +} \ No newline at end of file diff --git a/Capnpc.Csharp.MsBuild.Generation/TestGenerationError.cs b/Capnpc.Csharp.MsBuild.Generation/TestGenerationError.cs new file mode 100644 index 0000000..1bf834c --- /dev/null +++ b/Capnpc.Csharp.MsBuild.Generation/TestGenerationError.cs @@ -0,0 +1,6 @@ +namespace Capnpc.Csharp.MsBuild.Generation +{ + public class TestGenerationError + { + } +} \ No newline at end of file diff --git a/Capnpc.Csharp.MsBuild.Generation/TestGeneratorResult.cs b/Capnpc.Csharp.MsBuild.Generation/TestGeneratorResult.cs new file mode 100644 index 0000000..35b34e3 --- /dev/null +++ b/Capnpc.Csharp.MsBuild.Generation/TestGeneratorResult.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; + +namespace Capnpc.Csharp.MsBuild.Generation +{ + public class TestGeneratorResult + { + public IEnumerable Errors { get; internal set; } + public bool IsUpToDate { get; internal set; } + public string GeneratedTestCode { get; internal set; } + } +} \ No newline at end of file diff --git a/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/CpsExtension.DesignTime.targets b/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/CpsExtension.DesignTime.targets new file mode 100644 index 0000000..b23690f --- /dev/null +++ b/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/CpsExtension.DesignTime.targets @@ -0,0 +1,15 @@ + + + + + $(MSBuildThisFileDirectory)Rules\ + + + + + + + File;BrowseObject + + + \ No newline at end of file diff --git a/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/FeatureFileType.xaml b/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/FeatureFileType.xaml new file mode 100644 index 0000000..0864f1e --- /dev/null +++ b/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/FeatureFileType.xaml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/ProjectItemsSchema.xaml b/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/ProjectItemsSchema.xaml new file mode 100644 index 0000000..47300db --- /dev/null +++ b/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/ProjectItemsSchema.xaml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + diff --git a/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.props b/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.props new file mode 100644 index 0000000..e51a8aa --- /dev/null +++ b/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.props @@ -0,0 +1,77 @@ + + + + $(MSBuildThisFileDirectory)CPS\Buildsystem\CpsExtension.DesignTime.targets + + + + + + + false + $(CapnpcCsharp_UseHostCompilerIfAvailable) + + + + + false + false + + false + true + false + + <_SpecFlowPropsImported Condition="'$(_SpecFlowPropsImported)'==''">true + + + + + + + false + + + true + $(CapnpcCsharp_EnableDefaultCompileItems) + + $(DefaultItemExcludes);**/*.feature + + + + + %(RelativeDir)%(Filename).capnp(DefaultLanguageSourceExtension) + $(UsingMicrosoftNETSdk) + + + + + + + + + + + + + + + <_CapnpcCsharp_TaskFolder Condition=" '$(MSBuildRuntimeType)' == 'Core' And '$(_CapnpcCsharp_TaskFolder)' == ''">netcoreapp2.0 + <_CapnpcCsharp_TaskFolder Condition=" '$(MSBuildRuntimeType)' != 'Core' And '$(_CapnpcCsharp_TaskFolder)' == ''">net471 + <_CapnpcCsharp_TaskAssembly Condition=" '$(_CapnpcCsharp_TaskAssembly)' == '' ">..\tasks\$(_CapnpcCsharp_TaskFolder)\Capnpc.Csharp.MsBuild.Generation.dll + + + + + diff --git a/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.targets b/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.targets new file mode 100644 index 0000000..a61cde4 --- /dev/null +++ b/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.targets @@ -0,0 +1,145 @@ + + + + + + false + true + + + <_CapnpcCsharp_EnableDefaultCompileItems Condition="'$(CapnpcCsharp_EnableDefaultCompileItems)' == '' And '$(UsingMicrosoftNETSdk)' == 'true'">true + <_CapnpcCsharp_EnableDefaultCompileItems Condition="'$(CapnpcCsharp_EnableDefaultCompileItems)' == 'true' And '$(UsingMicrosoftNETSdk)' == 'true'">true + + + + + BeforeUpdateCapnpFilesInProject; + UpdateCapnpFilesInProject; + IncludeCodeBehindFilesInProject; + AfterUpdateCapnpFilesInProject; + $(BuildDependsOn) + + + CleanCapnpFilesInProject; + $(CleanDependsOn) + + + SwitchToForceGenerate; + $(RebuildDependsOn) + + + + + + + + + + + + + + + + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.tasks b/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.tasks new file mode 100644 index 0000000..9e4e977 --- /dev/null +++ b/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.tasks @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/Capnpc.Csharp.MsBuild.Generation/buildMultiTargeting/Capnpc.Csharp.MsBuild.Generation.props b/Capnpc.Csharp.MsBuild.Generation/buildMultiTargeting/Capnpc.Csharp.MsBuild.Generation.props new file mode 100644 index 0000000..f3c49ea --- /dev/null +++ b/Capnpc.Csharp.MsBuild.Generation/buildMultiTargeting/Capnpc.Csharp.MsBuild.Generation.props @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/Licenses/SpecFlow-LICENSE-NewBSD.txt b/Licenses/SpecFlow-LICENSE-NewBSD.txt new file mode 100644 index 0000000..665e1cd --- /dev/null +++ b/Licenses/SpecFlow-LICENSE-NewBSD.txt @@ -0,0 +1,31 @@ +SpecFlow Licence (New BSD License) + +Copyright (c) 2009, TechTalk + +Disclaimer: + * The initial codebase of Specflow was written by TechTalk employees. + No 3rd party code was included. + * No code of customer projects was used to create this project. + * TechTalk had the full rights to publish the initial codebase. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the SpecFlow project nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL TECHTALK OR CONTRIBUTORS BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. From 6b81abb0f0f67fd2287de6175b20252f62fb4af7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6llner?= Date: Thu, 5 Sep 2019 21:59:25 +0200 Subject: [PATCH 02/22] MSBuild integration WIP --- ...nerator.cs => CapnpCodeBehindGenerator.cs} | 10 +- ...tor.cs => CapnpFileCodeBehindGenerator.cs} | 28 ++-- .../Capnpc.Csharp.MsBuild.Generation.csproj | 4 +- .../Capnpc.Csharp.MsBuild.Generation.nuspec | 4 +- .../CodeBehindWriter.cs | 38 ++--- .../FilePathGenerator.cs | 8 +- .../FileSystemHelper.cs | 142 +++--------------- .../GenerateCapnpFileCodeBehindTask.cs | 18 +-- .../ICapnpCsharpGenerator.cs | 4 +- .../TestFileGeneratorResult.cs | 6 +- .../CpsExtension.DesignTime.targets | 2 +- ...eatureFileType.xaml => CapnpFileType.xaml} | 6 +- .../Buildsystem/Rules/ProjectItemsSchema.xaml | 12 +- .../Capnpc.Csharp.MsBuild.Generation.props | 12 +- .../Capnpc.Csharp.MsBuild.Generation.targets | 34 ++--- .../Capnpc.Csharp.MsBuild.Generation.tasks | 2 +- 16 files changed, 107 insertions(+), 223 deletions(-) rename Capnpc.Csharp.MsBuild.Generation/{FeatureCodeBehindGenerator.cs => CapnpCodeBehindGenerator.cs} (79%) rename Capnpc.Csharp.MsBuild.Generation/{FeatureFileCodeBehindGenerator.cs => CapnpFileCodeBehindGenerator.cs} (66%) rename Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/{FeatureFileType.xaml => CapnpFileType.xaml} (92%) diff --git a/Capnpc.Csharp.MsBuild.Generation/FeatureCodeBehindGenerator.cs b/Capnpc.Csharp.MsBuild.Generation/CapnpCodeBehindGenerator.cs similarity index 79% rename from Capnpc.Csharp.MsBuild.Generation/FeatureCodeBehindGenerator.cs rename to Capnpc.Csharp.MsBuild.Generation/CapnpCodeBehindGenerator.cs index 1f6d631..97ab0ba 100644 --- a/Capnpc.Csharp.MsBuild.Generation/FeatureCodeBehindGenerator.cs +++ b/Capnpc.Csharp.MsBuild.Generation/CapnpCodeBehindGenerator.cs @@ -4,12 +4,12 @@ using System.IO; namespace Capnpc.Csharp.MsBuild.Generation { - public class FeatureCodeBehindGenerator : IDisposable + public class CapnpCodeBehindGenerator : IDisposable { //private SpecFlowProject _specFlowProject; //private ITestGenerator _testGenerator; - public void InitializeProject(string projectPath, string rootNamespace, IEnumerable generatorPlugins) + public void InitializeProject(string projectPath) { //_specFlowProject = MsBuildProjectReader.LoadSpecFlowProjectFromMsBuild(Path.GetFullPath(projectPath), rootNamespace); @@ -21,14 +21,16 @@ namespace Capnpc.Csharp.MsBuild.Generation } - public TestFileGeneratorResult GenerateCodeBehindFile(string featureFile) + public TestFileGeneratorResult GenerateCodeBehindFile(string capnpFile) { //var featureFileInput = new FeatureFileInput(featureFile); //var generatedFeatureFileName = Path.GetFileName(_testGenerator.GetTestFullPath(featureFileInput)); //var testGeneratorResult = _testGenerator.GenerateTestFile(featureFileInput, new GenerationSettings()); - return new TestFileGeneratorResult(null, null); + return new TestFileGeneratorResult( + new TestGeneratorResult() { GeneratedTestCode = "//dummy" }, + capnpFile + ".cs"); } public void Dispose() diff --git a/Capnpc.Csharp.MsBuild.Generation/FeatureFileCodeBehindGenerator.cs b/Capnpc.Csharp.MsBuild.Generation/CapnpFileCodeBehindGenerator.cs similarity index 66% rename from Capnpc.Csharp.MsBuild.Generation/FeatureFileCodeBehindGenerator.cs rename to Capnpc.Csharp.MsBuild.Generation/CapnpFileCodeBehindGenerator.cs index eeb369f..ff6d30e 100644 --- a/Capnpc.Csharp.MsBuild.Generation/FeatureFileCodeBehindGenerator.cs +++ b/Capnpc.Csharp.MsBuild.Generation/CapnpFileCodeBehindGenerator.cs @@ -7,11 +7,11 @@ using Microsoft.Build.Utilities; namespace Capnpc.Csharp.MsBuild.Generation { - public class FeatureFileCodeBehindGenerator : ICapnpCsharpGenerator + public class CapnpFileCodeBehindGenerator : ICapnpcCsharpGenerator { private readonly FilePathGenerator _filePathGenerator; - public FeatureFileCodeBehindGenerator(TaskLoggingHelper log) + public CapnpFileCodeBehindGenerator(TaskLoggingHelper log) { Log = log ?? throw new ArgumentNullException(nameof(log)); _filePathGenerator = new FilePathGenerator(); @@ -21,27 +21,24 @@ namespace Capnpc.Csharp.MsBuild.Generation public IEnumerable GenerateFilesForProject( string projectPath, - string rootNamespace, - List CapnpFiles, - List generatorPlugins, - string projectFolder, - string outputPath) + List capnpFiles, + string projectFolder) { - using (var featureCodeBehindGenerator = new FeatureCodeBehindGenerator()) + using (var capnpCodeBehindGenerator = new CapnpCodeBehindGenerator()) { - featureCodeBehindGenerator.InitializeProject(projectPath, rootNamespace, generatorPlugins); + capnpCodeBehindGenerator.InitializeProject(projectPath); var codeBehindWriter = new CodeBehindWriter(null); - if (CapnpFiles == null) + if (capnpFiles == null) { yield break; } - foreach (var featureFile in CapnpFiles) + foreach (var capnpFile in capnpFiles) { - var featureFileItemSpec = featureFile; - var generatorResult = featureCodeBehindGenerator.GenerateCodeBehindFile(featureFileItemSpec); + var capnpFileItemSpec = capnpFile; + var generatorResult = capnpCodeBehindGenerator.GenerateCodeBehindFile(capnpFileItemSpec); if (!generatorResult.Success) { @@ -63,11 +60,10 @@ namespace Capnpc.Csharp.MsBuild.Generation var targetFilePath = _filePathGenerator.GenerateFilePath( projectFolder, - outputPath, - featureFile, + capnpFile, generatorResult.Filename); - var resultedFile = codeBehindWriter.WriteCodeBehindFile(targetFilePath, featureFile, generatorResult); + var resultedFile = codeBehindWriter.WriteCodeBehindFile(targetFilePath, capnpFile, generatorResult); yield return FileSystemHelper.GetRelativePath(resultedFile, projectFolder); } diff --git a/Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.csproj b/Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.csproj index bb09bb6..67c482c 100644 --- a/Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.csproj +++ b/Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.csproj @@ -1,6 +1,6 @@  - netstandard2.0;netcoreapp2.1 + net471;netcoreapp2.1 false $(MSBuildThisFileDirectory)Capnpc.Csharp.MsBuild.Generation.nuspec true @@ -68,7 +68,7 @@ - + MSBuild:Compile diff --git a/Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.nuspec b/Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.nuspec index 35629ed..887d527 100644 --- a/Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.nuspec +++ b/Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.nuspec @@ -1,7 +1,7 @@ - Capnpc.Csharp.Generation + Capnpc.Csharp.MsBuild.Generation 1.0.0 Capnpc.Csharp.MsBuild.Generation Christian Köllner and contributors @@ -20,7 +20,7 @@ - + diff --git a/Capnpc.Csharp.MsBuild.Generation/CodeBehindWriter.cs b/Capnpc.Csharp.MsBuild.Generation/CodeBehindWriter.cs index f147ee7..f581de3 100644 --- a/Capnpc.Csharp.MsBuild.Generation/CodeBehindWriter.cs +++ b/Capnpc.Csharp.MsBuild.Generation/CodeBehindWriter.cs @@ -13,7 +13,7 @@ namespace Capnpc.Csharp.MsBuild.Generation public TaskLoggingHelper Log { get; } - public string WriteCodeBehindFile(string outputPath, string featureFile, TestFileGeneratorResult testFileGeneratorResult) //todo needs unit tests + public string WriteCodeBehindFile(string outputPath, string capnpFile, TestFileGeneratorResult testFileGeneratorResult) { //if (string.IsNullOrEmpty(testFileGeneratorResult.Filename)) //{ @@ -21,27 +21,27 @@ namespace Capnpc.Csharp.MsBuild.Generation // return null; //} - //string directoryPath = Path.GetDirectoryName(outputPath) ?? throw new InvalidOperationException(); - //Log?.LogWithNameTag(Log.LogMessage, directoryPath); + string directoryPath = Path.GetDirectoryName(outputPath) ?? throw new InvalidOperationException(); + Log?.LogWithNameTag(Log.LogMessage, directoryPath); - //Log?.LogWithNameTag(Log.LogMessage, $"Writing data to {outputPath}; path = {directoryPath}; generatedFilename = {testFileGeneratorResult.Filename}"); + Log?.LogWithNameTag(Log.LogMessage, $"Writing data to {outputPath}; path = {directoryPath}; generatedFilename = {testFileGeneratorResult.Filename}"); - //if (File.Exists(outputPath)) - //{ - // if (!FileSystemHelper.FileCompareContent(outputPath, testFileGeneratorResult.GeneratedTestCode)) - // { - // File.WriteAllText(outputPath, testFileGeneratorResult.GeneratedTestCode); - // } - //} - //else - //{ - // if (!Directory.Exists(directoryPath)) - // { - // Directory.CreateDirectory(directoryPath); - // } + if (File.Exists(outputPath)) + { + if (!FileSystemHelper.FileCompareContent(outputPath, testFileGeneratorResult.GeneratedCode)) + { + File.WriteAllText(outputPath, testFileGeneratorResult.GeneratedCode); + } + } + else + { + if (!Directory.Exists(directoryPath)) + { + Directory.CreateDirectory(directoryPath); + } - // File.WriteAllText(outputPath, testFileGeneratorResult.GeneratedTestCode); - //} + File.WriteAllText(outputPath, testFileGeneratorResult.GeneratedCode); + } return outputPath; } diff --git a/Capnpc.Csharp.MsBuild.Generation/FilePathGenerator.cs b/Capnpc.Csharp.MsBuild.Generation/FilePathGenerator.cs index c1e71a1..4ac982d 100644 --- a/Capnpc.Csharp.MsBuild.Generation/FilePathGenerator.cs +++ b/Capnpc.Csharp.MsBuild.Generation/FilePathGenerator.cs @@ -5,16 +5,16 @@ namespace Capnpc.Csharp.MsBuild.Generation { public class FilePathGenerator { - public string GenerateFilePath(string projectFolder, string relativeOutputPath, string featureFileName, string generatedCodeBehindFileName) + public string GenerateFilePath(string projectFolder, string capnpFileName, string generatedCodeBehindFileName) { if (projectFolder is null) { throw new ArgumentNullException(nameof(projectFolder)); } - if (featureFileName is null) + if (capnpFileName is null) { - throw new ArgumentNullException(nameof(featureFileName)); + throw new ArgumentNullException(nameof(capnpFileName)); } if (generatedCodeBehindFileName is null) @@ -22,7 +22,7 @@ namespace Capnpc.Csharp.MsBuild.Generation throw new ArgumentNullException(nameof(generatedCodeBehindFileName)); } - string featureFileFullPath = Path.GetFullPath(Path.Combine(projectFolder, relativeOutputPath ?? "", featureFileName)); + string featureFileFullPath = Path.GetFullPath(Path.Combine(projectFolder, capnpFileName)); string featureFileDirPath = Path.GetDirectoryName(featureFileFullPath); return Path.Combine(featureFileDirPath, generatedCodeBehindFileName); diff --git a/Capnpc.Csharp.MsBuild.Generation/FileSystemHelper.cs b/Capnpc.Csharp.MsBuild.Generation/FileSystemHelper.cs index 14cfd41..d27428f 100644 --- a/Capnpc.Csharp.MsBuild.Generation/FileSystemHelper.cs +++ b/Capnpc.Csharp.MsBuild.Generation/FileSystemHelper.cs @@ -69,136 +69,44 @@ namespace Capnpc.Csharp.MsBuild.Generation // Open the two files. using (FileStream fs1 = new FileStream(filePath1, FileMode.Open, FileAccess.Read)) - using (FileStream fs2 = new FileStream(filePath2, FileMode.Open, FileAccess.Read)) { - // Check the file sizes. If they are not the same, the files - // are not the same. - if (fs1.Length != fs2.Length) + using (FileStream fs2 = new FileStream(filePath2, FileMode.Open, FileAccess.Read)) { - // Return false to indicate files are different - return false; + // Check the file sizes. If they are not the same, the files + // are not the same. + if (fs1.Length != fs2.Length) + { + // Return false to indicate files are different + return false; + } + + // Read and compare a byte from each file until either a + // non-matching set of bytes is found or until the end of + // file1 is reached. + do + { + // Read one byte from each file. + file1byte = fs1.ReadByte(); + file2byte = fs2.ReadByte(); + } while ((file1byte == file2byte) && (file1byte != -1)); } - - // Read and compare a byte from each file until either a - // non-matching set of bytes is found or until the end of - // file1 is reached. - do - { - // Read one byte from each file. - file1byte = fs1.ReadByte(); - file2byte = fs2.ReadByte(); - } while ((file1byte == file2byte) && (file1byte != -1)); } - // Return the success of the comparison. "file1byte" is // equal to "file2byte" at this point only if the files are // the same. return ((file1byte - file2byte) == 0); } - public static void CopyDirectory(string sourcePath, string destPath, bool cleanDestination = true) + // This method accepts two strings the represent two files to + // compare. A return value of true indicates that the contents of the files + // are the same. A return value of any other value indicates that the + // files are not the same. + public static bool FileCompareContent(string filePath1, string fileContent) { - if (cleanDestination) - EnsureEmptyFolder(destPath); - else - { - if (!Directory.Exists(destPath)) - { - Directory.CreateDirectory(destPath); - } - } + var currentFileContent = File.ReadAllText(filePath1); - foreach (string file in Directory.GetFiles(sourcePath)) - { - var fileName = Path.GetFileName(file); - Debug.Assert(fileName != null); - string dest = Path.Combine(destPath, fileName); - File.Copy(file, dest, true); - File.SetAttributes(dest, File.GetAttributes(dest) & (~FileAttributes.ReadOnly)); - } + return string.CompareOrdinal(currentFileContent, fileContent) == 0; - foreach (string folder in Directory.GetDirectories(sourcePath)) - { - var folderName = Path.GetFileName(folder); - Debug.Assert(folderName != null); - string dest = Path.Combine(destPath, folderName); - CopyDirectory(folder, dest); - } - } - - public static void EnsureEmptyFolder(string folderName) - { - folderName = Path.GetFullPath(folderName); - - if (!Directory.Exists(folderName)) - { - Directory.CreateDirectory(folderName); - return; - } - - DeleteFolderContent(folderName); - } - - public static void EnsureFolderOfFile(string filePath) - { - string directory = Path.GetDirectoryName(filePath); - if (directory != null && !Directory.Exists(directory)) - Directory.CreateDirectory(directory); - } - - - private static void Retry(int number, Action action) - { - try - { - action(); - } - catch (UnauthorizedAccessException) - { - var i = number - 1; - - if (i == 0) - throw; - - Retry(i, action); - } - } - - public static void DeleteFolderContent(string folderName) - { - foreach (string file in Directory.GetFiles(folderName)) - { - try - { - Retry(5, () => File.Delete(file)); - } - catch (Exception ex) - { - throw new Exception("Unable to delete file: " + file, ex); - } - } - - foreach (string folder in Directory.GetDirectories(folderName)) - { - try - { - Retry(5, () => Directory.Delete(folder, true)); - } - catch (Exception ex) - { - throw new Exception("Unable to delete folder: " + folder, ex); - } - } - } - - public static void DeleteFolder(string path) - { - if (!Directory.Exists(path)) - return; - - DeleteFolderContent(path); - - Retry(5, () => Directory.Delete(path, true)); } } } diff --git a/Capnpc.Csharp.MsBuild.Generation/GenerateCapnpFileCodeBehindTask.cs b/Capnpc.Csharp.MsBuild.Generation/GenerateCapnpFileCodeBehindTask.cs index ee69aa8..c120448 100644 --- a/Capnpc.Csharp.MsBuild.Generation/GenerateCapnpFileCodeBehindTask.cs +++ b/Capnpc.Csharp.MsBuild.Generation/GenerateCapnpFileCodeBehindTask.cs @@ -13,23 +13,18 @@ namespace Capnpc.Csharp.MsBuild.Generation { public GenerateCapnpFileCodeBehindTask() { - CodeBehindGenerator = new FeatureFileCodeBehindGenerator(Log); + CodeBehindGenerator = new CapnpFileCodeBehindGenerator(Log); } - public ICapnpCsharpGenerator CodeBehindGenerator { get; set; } + public ICapnpcCsharpGenerator CodeBehindGenerator { get; set; } [Required] public string ProjectPath { get; set; } - public string RootNamespace { get; set; } - public string ProjectFolder => Path.GetDirectoryName(ProjectPath); - public string OutputPath { get; set; } public ITaskItem[] CapnpFiles { get; set; } - public ITaskItem[] GeneratorPlugins { get; set; } - [Output] public ITaskItem[] GeneratedFiles { get; private set; } @@ -55,21 +50,16 @@ namespace Capnpc.Csharp.MsBuild.Generation AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; - var generator = CodeBehindGenerator ?? new FeatureFileCodeBehindGenerator(Log); + var generator = CodeBehindGenerator ?? new CapnpFileCodeBehindGenerator(Log); Log.LogWithNameTag(Log.LogMessage, "Starting GenerateFeatureFileCodeBehind"); - var generatorPlugins = GeneratorPlugins?.Select(gp => gp.ItemSpec).ToList() ?? new List(); - var capnpFiles = CapnpFiles?.Select(i => i.ItemSpec).ToList() ?? new List(); var generatedFiles = generator.GenerateFilesForProject( ProjectPath, - RootNamespace, capnpFiles, - generatorPlugins, - ProjectFolder, - OutputPath); + ProjectFolder); GeneratedFiles = generatedFiles.Select(file => new TaskItem { ItemSpec = file }).ToArray(); diff --git a/Capnpc.Csharp.MsBuild.Generation/ICapnpCsharpGenerator.cs b/Capnpc.Csharp.MsBuild.Generation/ICapnpCsharpGenerator.cs index 5368331..4213d8d 100644 --- a/Capnpc.Csharp.MsBuild.Generation/ICapnpCsharpGenerator.cs +++ b/Capnpc.Csharp.MsBuild.Generation/ICapnpCsharpGenerator.cs @@ -2,8 +2,8 @@ namespace Capnpc.Csharp.MsBuild.Generation { - public interface ICapnpCsharpGenerator + public interface ICapnpcCsharpGenerator { - IEnumerable GenerateFilesForProject(string projectPath, string rootNamespace, List CapnpFiles, List generatorPlugins, string projectFolder, string outputPath); + IEnumerable GenerateFilesForProject(string projectPath, List capnpFiles, string projectFolder); } } \ No newline at end of file diff --git a/Capnpc.Csharp.MsBuild.Generation/TestFileGeneratorResult.cs b/Capnpc.Csharp.MsBuild.Generation/TestFileGeneratorResult.cs index 5eb0160..36ab361 100644 --- a/Capnpc.Csharp.MsBuild.Generation/TestFileGeneratorResult.cs +++ b/Capnpc.Csharp.MsBuild.Generation/TestFileGeneratorResult.cs @@ -17,7 +17,7 @@ namespace Capnpc.Csharp.MsBuild.Generation Errors = generatorResult.Errors; IsUpToDate = generatorResult.IsUpToDate; - GeneratedTestCode = generatorResult.GeneratedTestCode; + GeneratedCode = generatorResult.GeneratedTestCode; } /// @@ -31,9 +31,9 @@ namespace Capnpc.Csharp.MsBuild.Generation public bool IsUpToDate { get; } /// - /// The generated test code. + /// The generated code. /// - public string GeneratedTestCode { get; } + public string GeneratedCode { get; } public bool Success => Errors == null || !Errors.Any(); diff --git a/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/CpsExtension.DesignTime.targets b/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/CpsExtension.DesignTime.targets index b23690f..4f6883c 100644 --- a/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/CpsExtension.DesignTime.targets +++ b/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/CpsExtension.DesignTime.targets @@ -8,7 +8,7 @@ - + File;BrowseObject diff --git a/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/FeatureFileType.xaml b/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/CapnpFileType.xaml similarity index 92% rename from Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/FeatureFileType.xaml rename to Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/CapnpFileType.xaml index 0864f1e..51e0ab0 100644 --- a/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/FeatureFileType.xaml +++ b/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/CapnpFileType.xaml @@ -2,10 +2,10 @@ diff --git a/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/ProjectItemsSchema.xaml b/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/ProjectItemsSchema.xaml index 47300db..1cf7ddb 100644 --- a/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/ProjectItemsSchema.xaml +++ b/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/ProjectItemsSchema.xaml @@ -4,15 +4,15 @@ xmlns="http://schemas.microsoft.com/build/2009/properties"> - - + - + - + + \ No newline at end of file diff --git a/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.props b/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.props index e51a8aa..fe7e57a 100644 --- a/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.props +++ b/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.props @@ -21,7 +21,7 @@ true false - <_SpecFlowPropsImported Condition="'$(_SpecFlowPropsImported)'==''">true + <_CapnpcCsharpPropsImported Condition="'$(_CapnpcCsharpPropsImported)'==''">true true - $(CapnpcCsharp_EnableDefaultCompileItems) + $(CapnpcCsharp_EnableDefaultCompileItems) - $(DefaultItemExcludes);**/*.feature + $(DefaultItemExcludes);**/*.capnp - %(RelativeDir)%(Filename).capnp(DefaultLanguageSourceExtension) + %(RelativeDir)%(Filename).capnp.cs $(UsingMicrosoftNETSdk) @@ -54,7 +54,7 @@ - after deletion of a feature file - after pulling latest changes from version control with above changes --> - + - - + CapnpFiles="@(CapnpFiles)" > - - + + - + + diff --git a/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.tasks b/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.tasks index 9e4e977..b20fdae 100644 --- a/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.tasks +++ b/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.tasks @@ -1,3 +1,3 @@  - + \ No newline at end of file From 107d10e3f43d260655b0f33f9b549e450fefb637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6llner?= Date: Fri, 6 Sep 2019 19:25:54 +0200 Subject: [PATCH 03/22] Factoring out capnpc-csharp into separate assembly --- Capnp.Net.sln | 6 + .../CapnpC.CSharp.Generator.csproj | 15 + CapnpC.CSharp.Generator/CapnpCompilation.cs | 49 + .../CodeGen/CodeGenerator.cs | 190 ++ .../CodeGen/CommonSnippetGen.cs | 91 + .../CodeGen/DomainClassSnippetGen.cs | 970 ++++++++++ CapnpC.CSharp.Generator/CodeGen/GenNames.cs | 600 +++++++ .../CodeGen/GeneratorOptions.cs | 38 + .../CodeGen/InterfaceSnippetGen.cs | 843 +++++++++ CapnpC.CSharp.Generator/CodeGen/Name.cs | 33 + .../CodeGen/ReaderSnippetGen.cs | 713 ++++++++ .../CodeGen/SerializerStateWorder.cs | 10 + .../CodeGen/SkeletonWorder.cs | 12 + .../CodeGen/SyntaxHelpers.cs | 126 ++ .../CodeGen/WriterSnippetGen.cs | 403 +++++ .../FileGenerationResult.cs | 52 + CapnpC.CSharp.Generator/GenerationResult.cs | 44 + CapnpC.CSharp.Generator/Model/AbstractType.cs | 45 + CapnpC.CSharp.Generator/Model/Annotation.cs | 23 + CapnpC.CSharp.Generator/Model/Constant.cs | 23 + .../Model/DefinitionManager.cs | 67 + CapnpC.CSharp.Generator/Model/Enumerant.cs | 14 + CapnpC.CSharp.Generator/Model/Field.cs | 52 + CapnpC.CSharp.Generator/Model/GenFile.cs | 25 + .../Model/GenericParameter.cs | 26 + .../Model/HasGenericParameters.cs | 19 + CapnpC.CSharp.Generator/Model/IDefinition.cs | 11 + .../Model/IHasGenericParameters.cs | 9 + .../Model/IHasNestedDefinitions.cs | 18 + .../Model/IdentifierRenamer.cs | 22 + .../Model/InvalidSchemaException.cs | 11 + CapnpC.CSharp.Generator/Model/Method.cs | 16 + CapnpC.CSharp.Generator/Model/SchemaModel.cs | 783 ++++++++ CapnpC.CSharp.Generator/Model/SpecialName.cs | 9 + CapnpC.CSharp.Generator/Model/Type.cs | 201 +++ CapnpC.CSharp.Generator/Model/TypeCategory.cs | 8 + .../Model/TypeDefinition.cs | 89 + CapnpC.CSharp.Generator/Model/TypeTag.cs | 36 + CapnpC.CSharp.Generator/Model/Types.cs | 56 + CapnpC.CSharp.Generator/Model/Value.cs | 300 ++++ .../Schema/SchemaSerialization.cs | 1575 +++++++++++++++++ .../Schema/schema-with-offsets.capnp | 235 +++ .../CapnpFileCodeBehindGenerator.cs | 6 +- .../GenerateCapnpFileCodeBehindTask.cs | 8 +- .../ICapnpCsharpGenerator.cs | 2 +- .../CPS/Buildsystem/Rules/CapnpFileType.xaml | 11 +- 46 files changed, 7890 insertions(+), 5 deletions(-) create mode 100644 CapnpC.CSharp.Generator/CapnpC.CSharp.Generator.csproj create mode 100644 CapnpC.CSharp.Generator/CapnpCompilation.cs create mode 100644 CapnpC.CSharp.Generator/CodeGen/CodeGenerator.cs create mode 100644 CapnpC.CSharp.Generator/CodeGen/CommonSnippetGen.cs create mode 100644 CapnpC.CSharp.Generator/CodeGen/DomainClassSnippetGen.cs create mode 100644 CapnpC.CSharp.Generator/CodeGen/GenNames.cs create mode 100644 CapnpC.CSharp.Generator/CodeGen/GeneratorOptions.cs create mode 100644 CapnpC.CSharp.Generator/CodeGen/InterfaceSnippetGen.cs create mode 100644 CapnpC.CSharp.Generator/CodeGen/Name.cs create mode 100644 CapnpC.CSharp.Generator/CodeGen/ReaderSnippetGen.cs create mode 100644 CapnpC.CSharp.Generator/CodeGen/SerializerStateWorder.cs create mode 100644 CapnpC.CSharp.Generator/CodeGen/SkeletonWorder.cs create mode 100644 CapnpC.CSharp.Generator/CodeGen/SyntaxHelpers.cs create mode 100644 CapnpC.CSharp.Generator/CodeGen/WriterSnippetGen.cs create mode 100644 CapnpC.CSharp.Generator/FileGenerationResult.cs create mode 100644 CapnpC.CSharp.Generator/GenerationResult.cs create mode 100644 CapnpC.CSharp.Generator/Model/AbstractType.cs create mode 100644 CapnpC.CSharp.Generator/Model/Annotation.cs create mode 100644 CapnpC.CSharp.Generator/Model/Constant.cs create mode 100644 CapnpC.CSharp.Generator/Model/DefinitionManager.cs create mode 100644 CapnpC.CSharp.Generator/Model/Enumerant.cs create mode 100644 CapnpC.CSharp.Generator/Model/Field.cs create mode 100644 CapnpC.CSharp.Generator/Model/GenFile.cs create mode 100644 CapnpC.CSharp.Generator/Model/GenericParameter.cs create mode 100644 CapnpC.CSharp.Generator/Model/HasGenericParameters.cs create mode 100644 CapnpC.CSharp.Generator/Model/IDefinition.cs create mode 100644 CapnpC.CSharp.Generator/Model/IHasGenericParameters.cs create mode 100644 CapnpC.CSharp.Generator/Model/IHasNestedDefinitions.cs create mode 100644 CapnpC.CSharp.Generator/Model/IdentifierRenamer.cs create mode 100644 CapnpC.CSharp.Generator/Model/InvalidSchemaException.cs create mode 100644 CapnpC.CSharp.Generator/Model/Method.cs create mode 100644 CapnpC.CSharp.Generator/Model/SchemaModel.cs create mode 100644 CapnpC.CSharp.Generator/Model/SpecialName.cs create mode 100644 CapnpC.CSharp.Generator/Model/Type.cs create mode 100644 CapnpC.CSharp.Generator/Model/TypeCategory.cs create mode 100644 CapnpC.CSharp.Generator/Model/TypeDefinition.cs create mode 100644 CapnpC.CSharp.Generator/Model/TypeTag.cs create mode 100644 CapnpC.CSharp.Generator/Model/Types.cs create mode 100644 CapnpC.CSharp.Generator/Model/Value.cs create mode 100644 CapnpC.CSharp.Generator/Schema/SchemaSerialization.cs create mode 100644 CapnpC.CSharp.Generator/Schema/schema-with-offsets.capnp diff --git a/Capnp.Net.sln b/Capnp.Net.sln index 8e20bf5..15732e6 100644 --- a/Capnp.Net.sln +++ b/Capnp.Net.sln @@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "capnpc-csharp.tests", "capn EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Capnpc.Csharp.MsBuild.Generation", "Capnpc.Csharp.MsBuild.Generation\Capnpc.Csharp.MsBuild.Generation.csproj", "{1EFC1F20-C7BB-4F44-8BF9-DBB123AACCF4}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CapnpC.CSharp.Generator", "CapnpC.CSharp.Generator\CapnpC.CSharp.Generator.csproj", "{C3A3BB49-356E-4762-A190-76D877BE18F7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -45,6 +47,10 @@ Global {1EFC1F20-C7BB-4F44-8BF9-DBB123AACCF4}.Debug|Any CPU.Build.0 = Debug|Any CPU {1EFC1F20-C7BB-4F44-8BF9-DBB123AACCF4}.Release|Any CPU.ActiveCfg = Release|Any CPU {1EFC1F20-C7BB-4F44-8BF9-DBB123AACCF4}.Release|Any CPU.Build.0 = Release|Any CPU + {C3A3BB49-356E-4762-A190-76D877BE18F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C3A3BB49-356E-4762-A190-76D877BE18F7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C3A3BB49-356E-4762-A190-76D877BE18F7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C3A3BB49-356E-4762-A190-76D877BE18F7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CapnpC.CSharp.Generator/CapnpC.CSharp.Generator.csproj b/CapnpC.CSharp.Generator/CapnpC.CSharp.Generator.csproj new file mode 100644 index 0000000..53233fd --- /dev/null +++ b/CapnpC.CSharp.Generator/CapnpC.CSharp.Generator.csproj @@ -0,0 +1,15 @@ + + + + netcoreapp2.1 + + + + + + + + + + + diff --git a/CapnpC.CSharp.Generator/CapnpCompilation.cs b/CapnpC.CSharp.Generator/CapnpCompilation.cs new file mode 100644 index 0000000..9f1a0a4 --- /dev/null +++ b/CapnpC.CSharp.Generator/CapnpCompilation.cs @@ -0,0 +1,49 @@ +using Capnp; +using System; +using System.Diagnostics; +using System.IO; + +namespace CapnpC.CSharp.Generator +{ + /// + /// Provides methods for controlling both the C# code generator backend and the frontend "capnpc" + /// + public static class CapnpCompilation + { + /// + /// Generates C# code from given input stream + /// + /// input stream containing the binary code generation request, which the frontend capnpc emits + /// generation result + /// if is null + public static GenerationResult GenerateFromStream(Stream input) + { + if (input == null) + throw new ArgumentNullException(nameof(input)); + + try + { + WireFrame segments; + + using (input) + { + segments = Framing.ReadSegments(input); + } + + var dec = DeserializerState.CreateRoot(segments); + var reader = Schema.CodeGeneratorRequest.Reader.Create(dec); + var model = Model.SchemaModel.Create(reader); + var codeGen = new CodeGen.CodeGenerator(model, new CodeGen.GeneratorOptions()); + return new GenerationResult(codeGen.Generate()); + } + catch (Exception exception) + { + return new GenerationResult(exception); + } + } + + public static GenerationResult InvokeCapnpcAndGenerate() + { + } + } +} diff --git a/CapnpC.CSharp.Generator/CodeGen/CodeGenerator.cs b/CapnpC.CSharp.Generator/CodeGen/CodeGenerator.cs new file mode 100644 index 0000000..c983ccc --- /dev/null +++ b/CapnpC.CSharp.Generator/CodeGen/CodeGenerator.cs @@ -0,0 +1,190 @@ +namespace CapnpC.CSharp.Generator.CodeGen +{ + using System; + using System.Collections.Generic; + using System.IO; + using System.Linq; + using CapnpC.CSharp.Generator.Model; + using Microsoft.CodeAnalysis; + using Microsoft.CodeAnalysis.CSharp; + using Microsoft.CodeAnalysis.CSharp.Syntax; + using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; + using static SyntaxHelpers; + + class CodeGenerator + { + readonly SchemaModel _model; + readonly GenNames _names; + readonly CommonSnippetGen _commonGen; + readonly DomainClassSnippetGen _domClassGen; + readonly ReaderSnippetGen _readerGen; + readonly WriterSnippetGen _writerGen; + readonly InterfaceSnippetGen _interfaceGen; + + public CodeGenerator(SchemaModel model, GeneratorOptions options) + { + _model = model; + _names = new GenNames(options); + _commonGen = new CommonSnippetGen(_names); + _domClassGen = new DomainClassSnippetGen(_names); + _readerGen = new ReaderSnippetGen(_names); + _writerGen = new WriterSnippetGen(_names); + _interfaceGen = new InterfaceSnippetGen(_names); + } + + internal GenNames GetNames() => _names; + + IEnumerable TransformEnum(TypeDefinition def) + { + yield return _commonGen.MakeEnum(def); + } + + IEnumerable MakeTypeParameters(TypeDefinition def) + { + foreach (string name in def.GenericParameters) + { + yield return TypeParameter(_names.GetGenericTypeParameter(name).Identifier); + } + } + + IEnumerable MakeTypeParameterConstraints(TypeDefinition def) + { + foreach (string name in def.GenericParameters) + { + yield return TypeParameterConstraintClause( + _names.GetGenericTypeParameter(name).IdentifierName) + .AddConstraints(ClassOrStructConstraint(SyntaxKind.ClassConstraint)); + } + } + + IEnumerable TransformStruct(TypeDefinition def) + { + var topDecl = ClassDeclaration(_names.MakeTypeName(def).Identifier) + .AddModifiers(Public) + .AddBaseListTypes(SimpleBaseType(Type())); + + if (def.GenericParameters.Count > 0) + { + topDecl = topDecl + .AddTypeParameterListParameters(MakeTypeParameters(def).ToArray()) + .AddConstraintClauses(MakeTypeParameterConstraints(def).ToArray()); + } + + if (def.UnionInfo != null) + { + topDecl = topDecl.AddMembers(_commonGen.MakeUnionSelectorEnum(def)); + } + + topDecl = topDecl.AddMembers(_domClassGen.MakeDomainClassMembers(def)); + topDecl = topDecl.AddMembers(_readerGen.MakeReaderStruct(def)); + topDecl = topDecl.AddMembers(_writerGen.MakeWriterStruct(def)); + + foreach (var nestedGroup in def.NestedGroups) + { + topDecl = topDecl.AddMembers(Transform(nestedGroup).ToArray()); + } + + foreach (var nestedDef in def.NestedTypes) + { + topDecl = topDecl.AddMembers(Transform(nestedDef).ToArray()); + } + + yield return topDecl; + } + + IEnumerable TransformInterface(TypeDefinition def) + { + yield return _interfaceGen.MakeInterface(def); + yield return _interfaceGen.MakeProxy(def); + yield return _interfaceGen.MakeSkeleton(def); + + if (_interfaceGen.RequiresPipeliningSupport(def)) + { + yield return _interfaceGen.MakePipeliningSupport(def); + } + + if (def.NestedTypes.Any()) + { + var ns = ClassDeclaration( + _names.MakeTypeName(def, NameUsage.Namespace).ToString()) + .AddModifiers(Public, Static); + + if (def.GenericParameters.Count > 0) + { + ns = ns + .AddTypeParameterListParameters(MakeTypeParameters(def).ToArray()) + .AddConstraintClauses(MakeTypeParameterConstraints(def).ToArray()); + } + + foreach (var nestedDef in def.NestedTypes) + { + ns = ns.AddMembers(Transform(nestedDef).ToArray()); + } + + yield return ns; + } + } + + IEnumerable Transform(TypeDefinition def) + { + switch (def.Tag) + { + case TypeTag.Enum: + return TransformEnum(def); + + case TypeTag.Group: + case TypeTag.Struct: + return TransformStruct(def); + + case TypeTag.Interface: + return TransformInterface(def); + + default: + throw new NotSupportedException($"Cannot declare type of kind {def.Tag} here"); + } + } + + internal string Transform(GenFile file) + { + NameSyntax topNamespace = GenNames.NamespaceName(file.Namespace) ?? _names.TopNamespace; + + var ns = NamespaceDeclaration(topNamespace); + + foreach (var def in file.NestedTypes) + { + ns = ns.AddMembers(Transform(def).ToArray()); + } + + var cu = CompilationUnit().AddUsings( + UsingDirective(ParseName("Capnp")), + UsingDirective(ParseName("Capnp.Rpc")), + UsingDirective(ParseName("System")), + UsingDirective(ParseName("System.Collections.Generic")), + UsingDirective(ParseName("System.Threading")), + UsingDirective(ParseName("System.Threading.Tasks"))); + + cu = cu.AddMembers(ns); + + return cu.NormalizeWhitespace().ToFullString(); + } + + public IReadOnlyList Generate() + { + var result = new List(); + + foreach (var file in _model.FilesToGenerate) + { + try + { + result.Add(new FileGenerationResult(file.Name, Transform(file))); + } + catch (System.Exception exception) + { + result.Add(new FileGenerationResult(file.Name, exception)); + } + } + + return result; + } + } +} diff --git a/CapnpC.CSharp.Generator/CodeGen/CommonSnippetGen.cs b/CapnpC.CSharp.Generator/CodeGen/CommonSnippetGen.cs new file mode 100644 index 0000000..d89b873 --- /dev/null +++ b/CapnpC.CSharp.Generator/CodeGen/CommonSnippetGen.cs @@ -0,0 +1,91 @@ +using System.Collections.Generic; +using System.Linq; +using CapnpC.CSharp.Generator.Model; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; +using static CapnpC.CSharp.Generator.CodeGen.SyntaxHelpers; + +namespace CapnpC.CSharp.Generator.CodeGen +{ + class CommonSnippetGen + { + readonly GenNames _names; + + public CommonSnippetGen(GenNames names) + { + _names = names; + } + + public EnumDeclarationSyntax MakeUnionSelectorEnum(TypeDefinition def) + { + var whichEnum = EnumDeclaration(_names.UnionDiscriminatorEnum.ToString()) + .AddModifiers(Public) + .AddBaseListTypes(SimpleBaseType(Type())); + + var discFields = def.Fields.Where(f => f.DiscValue.HasValue); + + foreach (var discField in discFields) + { + whichEnum = whichEnum.AddMembers( + EnumMemberDeclaration(_names.GetCodeIdentifier(discField).Identifier) + .WithEqualsValue( + EqualsValueClause(LiteralExpression( + SyntaxKind.NumericLiteralExpression, + Literal(discField.DiscValue.Value))))); + } + + var ndecl = EnumMemberDeclaration(_names.UnionDiscriminatorUndefined.ToString()).WithEqualsValue( + EqualsValueClause( + LiteralExpression( + SyntaxKind.NumericLiteralExpression, + Literal(Schema.Field.Reader.NoDiscriminant)))); + + whichEnum = whichEnum.AddMembers(ndecl); + + return whichEnum; + } + + public EnumDeclarationSyntax MakeEnum(TypeDefinition def) + { + var decl = EnumDeclaration(def.Name) + .AddModifiers(Public) + .AddBaseListTypes(SimpleBaseType(Type())); + + foreach (var enumerant in def.Enumerants.OrderBy(e => e.CodeOrder)) + { + var mdecl = EnumMemberDeclaration(enumerant.Literal); + + if (enumerant.Ordinal.HasValue) + { + mdecl = mdecl.WithEqualsValue( + EqualsValueClause( + LiteralExpression( + SyntaxKind.NumericLiteralExpression, + Literal(enumerant.Ordinal.Value)))); + } + + decl = decl.AddMembers(mdecl); + } + + return decl; + } + + public static IEnumerable MakeCommaSeparatedList(IEnumerable expressions) + { + bool first = true; + + foreach (var expr in expressions) + { + if (first) + first = false; + else + yield return Token(SyntaxKind.CommaToken); + + yield return expr; + } + } + + } +} diff --git a/CapnpC.CSharp.Generator/CodeGen/DomainClassSnippetGen.cs b/CapnpC.CSharp.Generator/CodeGen/DomainClassSnippetGen.cs new file mode 100644 index 0000000..fb41086 --- /dev/null +++ b/CapnpC.CSharp.Generator/CodeGen/DomainClassSnippetGen.cs @@ -0,0 +1,970 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using CapnpC.CSharp.Generator.Model; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; +using static CapnpC.CSharp.Generator.CodeGen.SyntaxHelpers; + +namespace CapnpC.CSharp.Generator.CodeGen +{ + class DomainClassSnippetGen + { + readonly GenNames _names; + + public DomainClassSnippetGen(GenNames names) + { + _names = names; + } + + MemberDeclarationSyntax MakeUnionField(Field field) + { + var type = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.DomainClassNullable); + + switch (field.Type.Tag) + { + case TypeTag.Void: + return null; + + default: + return PropertyDeclaration(type, + _names.GetCodeIdentifier(field).Identifier) + .AddModifiers(Public).AddAccessorListAccessors( + AccessorDeclaration(SyntaxKind.GetAccessorDeclaration) + .WithExpressionBody( + ArrowExpressionClause( + ConditionalExpression( + BinaryExpression( + SyntaxKind.EqualsExpression, + _names.UnionDiscriminatorField.IdentifierName, + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + _names.UnionDiscriminatorEnum.IdentifierName, + _names.GetCodeIdentifier(field).IdentifierName)), + CastExpression(type, + _names.UnionContentField.IdentifierName), + LiteralExpression( + SyntaxKind.NullLiteralExpression)))) + .WithSemicolonToken( + Token(SyntaxKind.SemicolonToken)), + AccessorDeclaration( + SyntaxKind.SetAccessorDeclaration) + .WithBody( + Block( + ExpressionStatement( + AssignmentExpression( + SyntaxKind.SimpleAssignmentExpression, + _names.UnionDiscriminatorField.IdentifierName, + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + _names.UnionDiscriminatorEnum.IdentifierName, + _names.GetCodeIdentifier(field).IdentifierName))), + ExpressionStatement( + AssignmentExpression( + SyntaxKind.SimpleAssignmentExpression, + _names.UnionContentField.IdentifierName, + IdentifierName("value")))))); + } + } + + MemberDeclarationSyntax MakeStructField(Field field) + { + if (field.Type.Tag == TypeTag.Void) + { + return null; + } + + var prop = PropertyDeclaration(_names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.DomainClass), + _names.GetCodeIdentifier(field).Identifier) + .AddModifiers(Public).AddAccessorListAccessors( + AccessorDeclaration(SyntaxKind.GetAccessorDeclaration) + .WithSemicolonToken(Token(SyntaxKind.SemicolonToken)), + AccessorDeclaration(SyntaxKind.SetAccessorDeclaration) + .WithSemicolonToken(Token(SyntaxKind.SemicolonToken))); + + if (field.DefaultValueIsExplicit && field.Type.IsValueType) + { + prop = prop.WithInitializer( + EqualsValueClause(MakeDefaultValue(field))) + .WithSemicolonToken(Token(SyntaxKind.SemicolonToken)); + } + + return prop; + } + + MemberDeclarationSyntax MakeUnionDiscriminatorField() + { + return FieldDeclaration( + VariableDeclaration(_names.UnionDiscriminatorEnum.IdentifierName) + .AddVariables( + VariableDeclarator(_names.UnionDiscriminatorField.Identifier) + .WithInitializer( + EqualsValueClause( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + _names.UnionDiscriminatorEnum.IdentifierName, + _names.UnionDiscriminatorUndefined.IdentifierName))))) + .AddModifiers(Private); + } + + MemberDeclarationSyntax MakeUnionContentField() + { + return FieldDeclaration( + VariableDeclaration(SyntaxHelpers.Type()) + .WithVariables( + SingletonSeparatedList( + VariableDeclarator(_names.UnionContentField.Identifier)))) + .AddModifiers(Private); + } + + IEnumerable MakeInitializerAssignments(Value structValue, TypeDefinition scope) + { + foreach (var fieldValue in structValue.Fields) + { + var valueExpr = MakeValue(fieldValue.Item2, scope); + if (valueExpr == null) + continue; + + yield return AssignmentExpression( + SyntaxKind.SimpleAssignmentExpression, + _names.GetCodeIdentifier(fieldValue.Item1).IdentifierName, + valueExpr); + } + } + + ExpressionSyntax MakeValue(Value value, TypeDefinition scope) + { + switch (value.Type.Tag) + { + case TypeTag.AnyEnum: + return LiteralExpression( + SyntaxKind.NumericLiteralExpression, Literal((ushort)value.ScalarValue)); + + case TypeTag.Bool: + + if ((bool)value.ScalarValue) + return LiteralExpression(SyntaxKind.TrueLiteralExpression); + else + return LiteralExpression(SyntaxKind.FalseLiteralExpression); + + case TypeTag.Data: + return ArrayCreationExpression(ArrayType( + PredefinedType(Token(SyntaxKind.ByteKeyword))) + .WithRankSpecifiers( + SingletonList( + ArrayRankSpecifier( + SingletonSeparatedList( + OmittedArraySizeExpression()))))) + .WithInitializer( + InitializerExpression( + SyntaxKind.ArrayInitializerExpression) + .AddExpressions(value.Items.Select(v => MakeValue(v, scope)).ToArray())); + + case TypeTag.Enum: + return MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, + _names.MakeTypeSyntax(value.Type, scope, TypeUsage.NotRelevant), + IdentifierName(value.GetEnumerant().Literal)); + + case TypeTag.F32: + switch ((float)value.ScalarValue) + { + case float.NaN: + return MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName("float"), + IdentifierName(nameof(float.NaN))); + + case float.NegativeInfinity: + return MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName("float"), + IdentifierName(nameof(float.NegativeInfinity))); + + case float.PositiveInfinity: + return MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName("float"), + IdentifierName(nameof(float.PositiveInfinity))); + + default: + return LiteralExpression(SyntaxKind.NumericLiteralExpression, + Literal((float)value.ScalarValue)); + } + + case TypeTag.F64: + switch ((double)value.ScalarValue) + { + case double.NaN: + return MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName("double"), + IdentifierName(nameof(double.NaN))); + + case double.NegativeInfinity: + return MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName("double"), + IdentifierName(nameof(double.NegativeInfinity))); + + case double.PositiveInfinity: + return MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName("double"), + IdentifierName(nameof(double.PositiveInfinity))); + + default: + return LiteralExpression(SyntaxKind.NumericLiteralExpression, + Literal((double)value.ScalarValue)); + } + + case TypeTag.S8: + return LiteralExpression(SyntaxKind.NumericLiteralExpression, + Literal((sbyte)value.ScalarValue)); + + case TypeTag.S16: + return LiteralExpression(SyntaxKind.NumericLiteralExpression, + Literal((short)value.ScalarValue)); + + case TypeTag.S32: + return LiteralExpression(SyntaxKind.NumericLiteralExpression, + Literal((int)value.ScalarValue)); + + case TypeTag.S64: + return LiteralExpression(SyntaxKind.NumericLiteralExpression, + Literal((long)value.ScalarValue)); + + case TypeTag.U8: + return LiteralExpression(SyntaxKind.NumericLiteralExpression, + Literal((byte)value.ScalarValue)); + + case TypeTag.U16: + return LiteralExpression(SyntaxKind.NumericLiteralExpression, + Literal((ushort)value.ScalarValue)); + + case TypeTag.U32: + return LiteralExpression(SyntaxKind.NumericLiteralExpression, + Literal((uint)value.ScalarValue)); + + case TypeTag.U64: + return LiteralExpression(SyntaxKind.NumericLiteralExpression, + Literal((ulong)value.ScalarValue)); + + case TypeTag.Text: + value.Decode(); + return value.ScalarValue == null ? + LiteralExpression(SyntaxKind.NullLiteralExpression) : + LiteralExpression(SyntaxKind.StringLiteralExpression, + Literal((string)value.ScalarValue)); + + case TypeTag.Group: + case TypeTag.Struct: + value.Decode(); + + return ObjectCreationExpression( + _names.MakeTypeSyntax(value.Type, scope, TypeUsage.DomainClass)) + .WithArgumentList(ArgumentList()) + .WithInitializer( + InitializerExpression( + SyntaxKind.ObjectInitializerExpression) + .AddExpressions(MakeInitializerAssignments(value, scope).ToArray())); + + case TypeTag.ListPointer: + // TBD + return LiteralExpression(SyntaxKind.NullLiteralExpression); + + case TypeTag.List when value.Type.ElementType.Tag == TypeTag.Void: + value.Decode(); + + return LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal((int)value.VoidListCount)); + + case TypeTag.List: + value.Decode(); + + return ArrayCreationExpression(ArrayType( + _names.MakeTypeSyntax(value.Type.ElementType, scope, TypeUsage.DomainClass)) + .WithRankSpecifiers( + SingletonList( + ArrayRankSpecifier( + SingletonSeparatedList( + OmittedArraySizeExpression()))))) + .WithInitializer( + InitializerExpression( + SyntaxKind.ArrayInitializerExpression) + .AddExpressions(value.Items.Select(v => MakeValue(v, scope)).ToArray())); + + case TypeTag.AnyPointer: + case TypeTag.CapabilityPointer: + // TBD + return null; + + case TypeTag.Interface: + return null; + + default: + throw new NotImplementedException(); + } + } + + ExpressionSyntax MakeDefaultValue(Field field) + { + if (field.DefaultValueIsExplicit) + { + return MakeValue(field.DefaultValue, field.DeclaringType); + } + else + { + switch (field.Type.Tag) + { + case TypeTag.AnyEnum: + case TypeTag.S16: + case TypeTag.S32: + case TypeTag.S64: + case TypeTag.S8: + case TypeTag.U16: + case TypeTag.U32: + case TypeTag.U64: + case TypeTag.U8: + return LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0)); + + case TypeTag.AnyPointer: + case TypeTag.CapabilityPointer: + case TypeTag.Data: + case TypeTag.Group: + case TypeTag.Interface: + case TypeTag.List: + case TypeTag.ListPointer: + case TypeTag.Struct: + case TypeTag.StructPointer: + case TypeTag.Text: + return LiteralExpression(SyntaxKind.NullLiteralExpression); + + case TypeTag.Bool: + return LiteralExpression(SyntaxKind.FalseLiteralExpression); + + case TypeTag.Enum: + return MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.NotRelevant), + _names.UnionDiscriminatorUndefined.IdentifierName); + + case TypeTag.F32: + return LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0.0f)); + + case TypeTag.F64: + return LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0.0)); + + default: + throw new NotImplementedException(); + } + } + } + + IEnumerable MakeUnionDiscriminatorSetter(TypeDefinition def) + { + var unionFields = def.Fields.Where(f => f.DiscValue.HasValue); + + foreach (var unionField in unionFields) + { + var section = SwitchSection() + .WithLabels( + SingletonList( + CaseSwitchLabel(MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + _names.UnionDiscriminatorEnum.IdentifierName, + _names.GetCodeIdentifier(unionField).IdentifierName)))); + + if (unionField.Type.Tag != TypeTag.Void) + { + section = section.AddStatements( + ExpressionStatement( + AssignmentExpression( + SyntaxKind.SimpleAssignmentExpression, + _names.UnionContentField.IdentifierName, + MakeDefaultValue(unionField)))); + } + + section = section.AddStatements(BreakStatement()); + + yield return section; + } + } + + MemberDeclarationSyntax MakeUnionDiscriminatorProperty(TypeDefinition def) + { + return PropertyDeclaration(_names.UnionDiscriminatorEnum.IdentifierName, + _names.UnionDiscriminatorProp.Identifier) + .AddModifiers(Public).AddAccessorListAccessors( + AccessorDeclaration(SyntaxKind.GetAccessorDeclaration) + .WithExpressionBody( + ArrowExpressionClause(_names.UnionDiscriminatorField.IdentifierName)) + .WithSemicolonToken(Token(SyntaxKind.SemicolonToken)), + AccessorDeclaration(SyntaxKind.SetAccessorDeclaration) + .WithBody( + Block( + IfStatement( + BinaryExpression( + SyntaxKind.EqualsExpression, + IdentifierName("value"), + _names.UnionDiscriminatorField.IdentifierName), + ReturnStatement()), + ExpressionStatement( + AssignmentExpression( + SyntaxKind.SimpleAssignmentExpression, + _names.UnionDiscriminatorField.IdentifierName, + IdentifierName("value"))), + SwitchStatement(IdentifierName("value")) + .WithOpenParenToken( + Token(SyntaxKind.OpenParenToken)) + .WithCloseParenToken( + Token(SyntaxKind.CloseParenToken)) + .AddSections(MakeUnionDiscriminatorSetter(def).ToArray())))); + } + + MemberDeclarationSyntax MakeField(Field field) + { + if (field.DiscValue.HasValue) + return MakeUnionField(field); + else + return MakeStructField(field); + } + + ExpressionSyntax MakeListSerializeParticle(Model.Type type, ExpressionSyntax writer, ExpressionSyntax domain) + { + string s = $"_s{type.GetRank().Item1}"; + string v = $"_v{type.GetRank().Item1}"; + + switch (type.ElementType?.Tag) + { + case TypeTag.List: + case TypeTag.ListPointer: + case TypeTag.Struct: + case TypeTag.Group: + case TypeTag.StructPointer: + case TypeTag.Data: + + return InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + writer, + IdentifierName(nameof(Capnp.ListOfPrimitivesSerializer.Init)))) + .AddArgumentListArguments( + Argument(domain), + Argument( + ParenthesizedLambdaExpression( + MakeComplexSerializeParticle( + type.ElementType, + IdentifierName(s), + IdentifierName(v))) + .AddParameterListParameters( + Parameter(Identifier(s)), + Parameter(Identifier(v))))); + + default: + return InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + writer, + IdentifierName(nameof(Capnp.ListOfPrimitivesSerializer.Init)))) + .AddArgumentListArguments(Argument(domain)); + } + } + + ExpressionSyntax MakeComplexSerializeParticle(Model.Type type, ExpressionSyntax writer, ExpressionSyntax domain) + { + switch (type.Tag) + { + case TypeTag.Data: + case TypeTag.List: + return MakeListSerializeParticle(type, writer, domain); + + case TypeTag.Struct: + case TypeTag.Group: + return ConditionalAccessExpression(domain, + InvocationExpression(MemberBindingExpression(_names.SerializeMethod.IdentifierName)) + .AddArgumentListArguments(Argument(writer))); + + default: + throw new NotImplementedException(); + } + } + + StatementSyntax MakeSerializeMethodFieldAssignment(Field field) + { + var writerProp = MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + _names.WriterParameter.IdentifierName, + _names.GetCodeIdentifier(field).IdentifierName); + + switch (field.Type.Tag) + { + case TypeTag.Bool: + case TypeTag.Enum: + case TypeTag.F32: + case TypeTag.F64: + case TypeTag.S16: + case TypeTag.S32: + case TypeTag.S64: + case TypeTag.S8: + case TypeTag.U16: + case TypeTag.U32: + case TypeTag.U64: + case TypeTag.U8: + case TypeTag.AnyEnum: + case TypeTag.List when field.Type.Tag == TypeTag.Void: + if (field.DiscValue.HasValue) + { + return ExpressionStatement( + AssignmentExpression( + SyntaxKind.SimpleAssignmentExpression, + writerProp, + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + _names.GetCodeIdentifier(field).IdentifierName, + IdentifierName(nameof(Nullable.Value))))); + } + else + { + return ExpressionStatement( + AssignmentExpression( + SyntaxKind.SimpleAssignmentExpression, + writerProp, + _names.GetCodeIdentifier(field).IdentifierName)); + } + + case TypeTag.AnyPointer: + case TypeTag.ListPointer: + case TypeTag.StructPointer: + return ExpressionStatement( + InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + _names.WriterParameter.IdentifierName, + _names.GetCodeIdentifier(field).IdentifierName), + IdentifierName(nameof(Capnp.DynamicSerializerState.SetObject)))) + .AddArgumentListArguments( + Argument(_names.GetCodeIdentifier(field).IdentifierName))); + + case TypeTag.CapabilityPointer: + case TypeTag.Interface: + return ExpressionStatement( + AssignmentExpression( + SyntaxKind.SimpleAssignmentExpression, + writerProp, + _names.GetCodeIdentifier(field).IdentifierName)); + + case TypeTag.Text: + return ExpressionStatement( + AssignmentExpression( + SyntaxKind.SimpleAssignmentExpression, + writerProp, + _names.GetCodeIdentifier(field).IdentifierName)); + + case TypeTag.Data: + case TypeTag.List: + case TypeTag.Struct: + case TypeTag.Group: + return ExpressionStatement( + MakeComplexSerializeParticle( + field.Type, + writerProp, + _names.GetCodeIdentifier(field).IdentifierName)); + + case TypeTag.Void: + return null; + + default: + throw new NotImplementedException(); + } + } + + StatementSyntax MakeApplyDefaultsMethodFieldAssignment(Field field) + { + var lhs = _names.GetCodeIdentifier(field).IdentifierName; + var rhs = MakeDefaultValue(field); + + if (rhs == null) + { + return null; + } + + return ExpressionStatement( + AssignmentExpression( + SyntaxKind.SimpleAssignmentExpression, + lhs, + BinaryExpression(SyntaxKind.CoalesceExpression, + lhs, rhs))); + } + + ExpressionSyntax MakeInnerStructListConversion(ExpressionSyntax context, TypeSyntax elementType) + { + return InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + context, + IdentifierName(nameof(Capnp.ReadOnlyListExtensions.ToReadOnlyList)))) + .AddArgumentListArguments(Argument( + SimpleLambdaExpression(Parameter(Identifier("_")), + InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName(nameof(Capnp.CapnpSerializable)), + GenericName(nameof(Capnp.CapnpSerializable.Create)) + .AddTypeArgumentListArguments(elementType))) + .AddArgumentListArguments(Argument(IdentifierName("_")))))); + } + + ExpressionSyntax MakeStructListConversion(ExpressionSyntax context, TypeSyntax elementType, int rank) + { + if (rank == 1) + { + return MakeInnerStructListConversion(context, elementType); + } + + string lambdaVarName = $"_{rank}"; + + return InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + context, + IdentifierName(nameof(Capnp.ReadOnlyListExtensions.ToReadOnlyList)))) + .AddArgumentListArguments(Argument( + SimpleLambdaExpression( + Parameter(Identifier(lambdaVarName)), + MakeStructListConversion(IdentifierName(lambdaVarName), elementType, rank - 1)))); + } + + ExpressionSyntax MakeAnyListConversion(ExpressionSyntax context) + { + return InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + context, + IdentifierName(nameof(Capnp.ReadOnlyListExtensions.ToReadOnlyList)))) + .AddArgumentListArguments(Argument( + SimpleLambdaExpression( + Parameter(Identifier("_")), + CastExpression(Type(), IdentifierName("_"))))); + } + + ExpressionSyntax MakeDeserializeMethodRightHandSide(Field field) + { + switch (field.Type.Tag) + { + case TypeTag.Struct: + case TypeTag.Group: + case TypeTag.StructPointer: + case TypeTag.AnyPointer: + return InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName(nameof(Capnp.CapnpSerializable)), + GenericName(nameof(Capnp.CapnpSerializable.Create)) + .AddTypeArgumentListArguments( + _names.MakeTypeSyntax( + field.Type, + field.DeclaringType, + TypeUsage.DomainClass)))) + .AddArgumentListArguments(Argument(MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + _names.ReaderParameter.IdentifierName, + _names.GetCodeIdentifier(field).IdentifierName))); + + case TypeTag.Void: + return null; + + case TypeTag.List: + (var rank, var elementType) = field.Type.GetRank(); + if (elementType.Tag != TypeTag.Struct) + break; + + return MakeStructListConversion( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + _names.ReaderParameter.IdentifierName, + _names.GetCodeIdentifier(field).IdentifierName), + _names.MakeTypeSyntax(elementType, field.DeclaringType, TypeUsage.DomainClass), + rank); + + case TypeTag.ListPointer: + return MakeAnyListConversion( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + _names.ReaderParameter.IdentifierName, + _names.GetCodeIdentifier(field).IdentifierName)); + } + + return MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + _names.ReaderParameter.IdentifierName, + _names.GetCodeIdentifier(field).IdentifierName); + } + + IEnumerable MakeSerializeMethodSwitchSections(TypeDefinition def) + { + var unionFields = def.Fields.Where(f => f.DiscValue.HasValue); + + foreach (var unionField in unionFields) + { + var section = SwitchSection() + .AddLabels( + CaseSwitchLabel(MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + _names.UnionDiscriminatorEnum.IdentifierName, + _names.GetCodeIdentifier(unionField).IdentifierName))); + + if (unionField.Type.Tag != TypeTag.Void) + { + ExpressionSyntax right = _names.GetCodeIdentifier(unionField).IdentifierName; + + var syntax = _names.MakeTypeSyntax(unionField.Type, unionField.DeclaringType, TypeUsage.DomainClassNullable); + + if (syntax is NullableTypeSyntax) + { + right = MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + right, + IdentifierName(nameof(Nullable.Value))); + } + + section = section.AddStatements(MakeSerializeMethodFieldAssignment(unionField)); + } + + section = section.AddStatements(BreakStatement()); + + yield return section; + } + } + + IEnumerable MakeDeserializeMethodSwitchSections(TypeDefinition def) + { + var unionFields = def.Fields.Where(f => f.DiscValue.HasValue); + + foreach (var unionField in unionFields) + { + var section = SwitchSection() + .AddLabels( + CaseSwitchLabel(MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + _names.UnionDiscriminatorEnum.IdentifierName, + _names.GetCodeIdentifier(unionField).IdentifierName))); + + switch (unionField.Type.Tag) + { + case TypeTag.Void: + section = section.AddStatements( + ExpressionStatement(AssignmentExpression( + SyntaxKind.SimpleAssignmentExpression, + _names.UnionDiscriminatorProp.IdentifierName, + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + _names.ReaderParameter.IdentifierName, + _names.UnionDiscriminatorProp.IdentifierName)))); + break; + + default: + section = section.AddStatements( + ExpressionStatement(AssignmentExpression( + SyntaxKind.SimpleAssignmentExpression, + _names.GetCodeIdentifier(unionField).IdentifierName, + MakeDeserializeMethodRightHandSide(unionField)))); + break; + + } + + section = section.AddStatements(BreakStatement()); + + yield return section; + } + } + + IEnumerable MakeSerializeStatements(TypeDefinition def) + { + if (def.UnionInfo != null) + { + yield return ExpressionStatement(AssignmentExpression( + SyntaxKind.SimpleAssignmentExpression, + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + _names.WriterParameter.IdentifierName, + _names.UnionDiscriminatorProp.IdentifierName), + _names.UnionDiscriminatorProp.IdentifierName)); + + yield return SwitchStatement(_names.UnionDiscriminatorProp.IdentifierName) + .WithOpenParenToken(Token(SyntaxKind.OpenParenToken)) + .WithCloseParenToken(Token(SyntaxKind.CloseParenToken)) + .AddSections(MakeSerializeMethodSwitchSections(def).ToArray()); + } + + var nondiscFields = def.Fields.Where(f => !f.DiscValue.HasValue && f.Type.Tag != TypeTag.Void); + + foreach (var field in nondiscFields) + { + var asmt = MakeSerializeMethodFieldAssignment(field); + + if (asmt != null) + { + yield return asmt; + } + } + } + + IEnumerable MakeApplyDefaultsStatements(TypeDefinition def) + { + var relevantFields = def.Fields.Where( + f => !f.DiscValue.HasValue && + f.Type.Tag != TypeTag.Void && + f.DefaultValueIsExplicit && + !f.Type.IsValueType); + + foreach (var field in relevantFields) + { + var asmt = MakeApplyDefaultsMethodFieldAssignment(field); + + if (asmt != null) + { + yield return asmt; + } + } + } + + MemberDeclarationSyntax MakeSerializeMethod(TypeDefinition def) + { + return MethodDeclaration(PredefinedType( + Token(SyntaxKind.VoidKeyword)), + _names.SerializeMethod.Identifier) + .AddModifiers(Public) + .AddParameterListParameters( + Parameter(_names.WriterParameter.Identifier) + .WithType(_names.WriterStruct.IdentifierName)) + .AddBodyStatements(MakeSerializeStatements(def).ToArray()); + } + + MemberDeclarationSyntax MakeSerializeInterfaceMethod() + { + return MethodDeclaration(PredefinedType(Token(SyntaxKind.VoidKeyword)), + Identifier(nameof(Capnp.ICapnpSerializable.Serialize))) + .WithExplicitInterfaceSpecifier( + ExplicitInterfaceSpecifier(IdentifierName(nameof(Capnp.ICapnpSerializable)))) + .AddParameterListParameters( + Parameter(_names.AnonymousParameter.Identifier) + .WithType(Type())) + .AddBodyStatements( + ExpressionStatement( + InvocationExpression(_names.SerializeMethod.IdentifierName) + .AddArgumentListArguments( + Argument( + InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + _names.AnonymousParameter.IdentifierName, + GenericName(Identifier(nameof(Capnp.SerializerState.Rewrap))) + .AddTypeArgumentListArguments(_names.WriterStruct.IdentifierName))))))); + } + + MemberDeclarationSyntax MakeApplyDefaultsMethod(TypeDefinition def) + { + return MethodDeclaration(PredefinedType( + Token(SyntaxKind.VoidKeyword)), + _names.ApplyDefaultsMethod.Identifier) + .AddModifiers(Public) + .AddBodyStatements(MakeApplyDefaultsStatements(def).ToArray()); + } + + IEnumerable MakeDeserializeStatements(TypeDefinition def) + { + var relevantFields = def.Fields.Where( + f => !f.DiscValue.HasValue && + f.Type.Tag != TypeTag.Void); + + foreach (var field in relevantFields) + { + var rhs = MakeDeserializeMethodRightHandSide(field); + + if (rhs != null) + { + yield return ExpressionStatement(AssignmentExpression( + SyntaxKind.SimpleAssignmentExpression, + _names.GetCodeIdentifier(field).IdentifierName, + rhs)); + } + } + } + + MemberDeclarationSyntax MakeDeserializeMethod(TypeDefinition def) + { + var stmts = new List(); + + stmts.Add(LocalDeclarationStatement( + VariableDeclaration(IdentifierName("var")) + .AddVariables( + VariableDeclarator(_names.ReaderParameter.Identifier) + .WithInitializer( + EqualsValueClause( + InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + _names.ReaderStruct.IdentifierName, + _names.ReaderCreateMethod.IdentifierName)) + .AddArgumentListArguments( + Argument(_names.AnonymousParameter.IdentifierName))))))); + + + if (def.UnionInfo != null) + { + stmts.Add(SwitchStatement( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + _names.ReaderParameter.IdentifierName, + _names.UnionDiscriminatorProp.IdentifierName)) + .WithOpenParenToken(Token(SyntaxKind.OpenParenToken)) + .WithCloseParenToken(Token(SyntaxKind.CloseParenToken)) + .AddSections(MakeDeserializeMethodSwitchSections(def).ToArray())); + } + + stmts.AddRange(MakeDeserializeStatements(def)); + stmts.Add(ExpressionStatement(InvocationExpression( + _names.ApplyDefaultsMethod.IdentifierName))); + + return MethodDeclaration(PredefinedType(Token(SyntaxKind.VoidKeyword)), + Identifier(nameof(Capnp.ICapnpSerializable.Deserialize))) + .WithExplicitInterfaceSpecifier( + ExplicitInterfaceSpecifier(IdentifierName(nameof(Capnp.ICapnpSerializable)))) + .AddParameterListParameters( + Parameter(_names.AnonymousParameter.Identifier) + .WithType(Type())) + .AddBodyStatements(stmts.ToArray()); + } + + IEnumerable EnumerateDomainClassMembers(TypeDefinition def) + { + yield return MakeDeserializeMethod(def); + + if (def.UnionInfo != null) + { + yield return MakeUnionDiscriminatorField(); + yield return MakeUnionContentField(); + yield return MakeUnionDiscriminatorProperty(def); + } + + yield return MakeSerializeMethod(def); + yield return MakeSerializeInterfaceMethod(); + yield return MakeApplyDefaultsMethod(def); + + foreach (var field in def.Fields) + { + var decl = MakeField(field); + + if (decl != null) + yield return decl; + } + } + + public MemberDeclarationSyntax[] MakeDomainClassMembers(TypeDefinition def) + { + return EnumerateDomainClassMembers(def).ToArray(); + } + } +} diff --git a/CapnpC.CSharp.Generator/CodeGen/GenNames.cs b/CapnpC.CSharp.Generator/CodeGen/GenNames.cs new file mode 100644 index 0000000..b9282ab --- /dev/null +++ b/CapnpC.CSharp.Generator/CodeGen/GenNames.cs @@ -0,0 +1,600 @@ +using CapnpC.CSharp.Generator.Model; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using System; +using System.Collections.Generic; +using System.Linq; +using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; + +namespace CapnpC.CSharp.Generator.CodeGen +{ + enum NameUsage + { + Default, + Interface, + Proxy, + Skeleton, + Namespace + } + + enum TypeUsage + { + NotRelevant, + DomainClass, + DomainClassNullable, + Reader, + Writer + } + + class GenNames + { + readonly Dictionary _fieldNameMap = new Dictionary(); + + public NameSyntax TopNamespace { get; set; } + public Name ReaderStruct { get; } + public Name ReaderParameter { get; } + public Name WriterParameter { get; } + public Name WriterStruct { get; } + public Name ReaderCreateMethod { get; } + public Name ReaderContextField { get; } + public Name ContextParameter { get; } + public Name GroupReaderContextArg { get; } + public Name GroupWriterContextArg { get; } + public Name UnionDiscriminatorEnum { get; } + public Name UnionDiscriminatorProp { get; } + public Name UnionDiscriminatorUndefined { get; } + public Name UnionDiscriminatorField { get; } + public Name UnionContentField { get; } + public Name AnonymousParameter { get; } + public Name CancellationTokenParameter { get; } + public Name ParamsLocal { get; } + public Name DeserializerLocal { get; } + public Name SerializerLocal { get; } + public Name ResultLocal { get; } + public Name SerializeMethod { get; } + public Name ApplyDefaultsMethod { get; } + public Name InstLocalName { get; } + public string ParamsStructFormat { get; } + public string ResultStructFormat { get; } + public string PropertyNamedLikeTypeRenameFormat { get; } + public string GenericTypeParameterFormat { get; } + public Name PipeliningExtensionsClassName { get; } + public string MemberAccessPathNameFormat { get; } + public Name TaskParameter { get; } + public Name EagerMethod { get; } + + public GenNames(GeneratorOptions options) + { + TopNamespace = new Name(options.TopNamespaceName).IdentifierName; + ReaderStruct = new Name(options.ReaderStructName); + WriterStruct = new Name(options.WriterStructName); + ReaderParameter = new Name(options.ReaderParameterName); + WriterParameter = new Name(options.WriterParameterName); + ReaderCreateMethod = new Name(options.ReaderCreateMethodName); + ReaderContextField = new Name(options.ReaderContextFieldName); + ContextParameter = new Name(options.ContextParameterName); + GroupReaderContextArg = new Name(options.GroupReaderContextArgName); + GroupWriterContextArg = new Name(options.GroupWriterContextArgName); + UnionDiscriminatorEnum = new Name(options.UnionDisciminatorEnumName); + UnionDiscriminatorProp = new Name(options.UnionDiscriminatorPropName); + UnionDiscriminatorUndefined = new Name(options.UnionDisciminatorUndefinedName); + UnionDiscriminatorField = new Name(options.UnionDiscriminatorFieldName); + UnionContentField = new Name(options.UnionContentFieldName); + SerializeMethod = new Name(options.SerializeMethodName); + ApplyDefaultsMethod = new Name(options.ApplyDefaultsMethodName); + AnonymousParameter = new Name(options.AnonymousParameterName); + CancellationTokenParameter = new Name(options.CancellationTokenParameterName); + ParamsLocal = new Name(options.ParamsLocalName); + DeserializerLocal = new Name(options.DeserializerLocalName); + SerializerLocal = new Name(options.SerializerLocalName); + ResultLocal = new Name(options.ResultLocalName); + InstLocalName = new Name(options.InstLocalName); + ParamsStructFormat = options.ParamsStructFormat; + ResultStructFormat = options.ResultStructFormat; + PropertyNamedLikeTypeRenameFormat = options.PropertyNamedLikeTypeRenameFormat; + GenericTypeParameterFormat = options.GenericTypeParameterFormat; + PipeliningExtensionsClassName = new Name(options.PipeliningExtensionsClassName); + MemberAccessPathNameFormat = options.MemberAccessPathNameFormat; + TaskParameter = new Name(options.TaskParameterName); + EagerMethod = new Name(options.EagerMethodName); + } + + public Name MakeTypeName(TypeDefinition def, NameUsage usage = NameUsage.Default) + { + if (def.Tag == TypeTag.Group) + { + return new Name(SyntaxHelpers.MakeAllLower(def.Name)); + } + else + { + string name; + + switch (usage) + { + case NameUsage.Default: + if (def.Tag == TypeTag.Interface) + goto case NameUsage.Interface; + + switch (def.SpecialName) + { + case SpecialName.NothingSpecial: + name = def.Name; + break; + + case SpecialName.MethodParamsStruct: + name = MakeParamsStructName(def.UsingMethod); + break; + + case SpecialName.MethodResultStruct: + name = MakeResultStructName(def.UsingMethod); + break; + + default: + throw new NotImplementedException(); + } + break; + + case NameUsage.Namespace: + name = def.Name; + break; + + case NameUsage.Interface: + name = "I" + def.Name; + break; + + case NameUsage.Proxy: + name = def.Name + "Proxy"; + break; + + case NameUsage.Skeleton: + name = def.Name + "Skeleton"; + break; + + default: + throw new NotImplementedException(); + } + + return new Name(name); + } + } + + public SimpleNameSyntax MakeGenericTypeName(TypeDefinition def, NameUsage usage = NameUsage.Default) + { + var name = MakeTypeName(def, usage); + + if (def.GenericParameters.Count > 0) + { + return GenericName(name.Identifier) + .AddTypeArgumentListArguments(def + .GenericParameters + .Select(p => GetGenericTypeParameter(p).IdentifierName).ToArray()); + } + else + { + return name.IdentifierName; + } + } + + TypeSyntax ResolveGenericParameter(GenericParameter p, Model.Type boundType, TypeDefinition def) + { + var type = boundType.ResolveGenericParameter(p); + return MakeTypeSyntax(type, def, TypeUsage.DomainClass); + } + + public SimpleNameSyntax MakeGenericTypeName(TypeDefinition def, Model.Type boundType, NameUsage usage = NameUsage.Default) + { + var name = MakeTypeName(def, usage); + + if (def.GenericParameters.Count > 0) + { + return GenericName(name.Identifier) + .AddTypeArgumentListArguments(def + .GetLocalTypeParameters() + .Select(p => ResolveGenericParameter(p, boundType, def)).ToArray()); + } + else + { + return name.IdentifierName; + } + } + + public SimpleNameSyntax MakeGenericTypeNameForAttribute(TypeDefinition def, NameUsage usage) + { + var name = MakeTypeName(def, usage); + + if (def.GenericParameters.Count > 0) + { + return GenericName(name.Identifier).AddTypeArgumentListArguments(); + } + else + { + return name.IdentifierName; + } + } + + public static NameSyntax NamespaceName(string[] @namespace) + { + NameSyntax ident = null; + if (@namespace != null) + { + ident = IdentifierName(SyntaxHelpers.MakeCamel(@namespace[0])); + foreach (string name in @namespace.Skip(1)) + { + var temp = IdentifierName(SyntaxHelpers.MakeCamel(name)); + ident = QualifiedName(ident, temp); + } + } + return ident; + } + + NameSyntax GetNamespaceFor(TypeDefinition def) => NamespaceName(def?.File?.Namespace); + + internal NameSyntax GetQName(Model.Type type, TypeDefinition scope) + { + // FIXME: With the help of the 'scope' parameter we will be able to generate abbreviated + // qualified names. Unfortunately the commented approach is too naive. It will fail if + // there are multiple objects with identical name up the hierarchy. We will need a more + // sophisticated algorithm. + + var scopeSet = new HashSet(); + //while (scope != null) + //{ + // scopeSet.Add(scope); + // scope = scope.DeclaringElement as TypeDefinition; + //} + + if (type.Definition != null) + { + var stack = new Stack(); + + var def = type.Definition; + stack.Push(MakeGenericTypeName(def, type, NameUsage.Default)); + + while (def.DeclaringElement is TypeDefinition pdef && !scopeSet.Contains(pdef)) + { + stack.Push(MakeGenericTypeName(pdef, type, NameUsage.Namespace)); + def = pdef; + } + + var qtype = + GetNamespaceFor(type.Definition) + ?? GetNamespaceFor(scope) + ?? TopNamespace; + + foreach (var name in stack) + { + qtype = QualifiedName(qtype, name); + } + + return qtype; + } + else + { + return GetGenericTypeParameter(type.Parameter.Name).IdentifierName; + } + } + + public TypeSyntax MakeListSerializerSyntax(Model.Type elementType, TypeDefinition scope) + { + switch (elementType.Tag) + { + case TypeTag.AnyPointer: + case TypeTag.StructPointer: + case TypeTag.ListPointer: + return SyntaxHelpers.Type>(); + + case TypeTag.CapabilityPointer: + return SyntaxHelpers.Type>(); + + case TypeTag.Data: + return SyntaxHelpers.Type>>(); + + case TypeTag.Enum: + return GenericName("ListOfPrimitivesSerializer") + .AddTypeArgumentListArguments(MakeTypeSyntax(elementType, scope, TypeUsage.Writer)); + + case TypeTag.Group: + case TypeTag.Struct: + return GenericName("ListOfStructsSerializer") + .AddTypeArgumentListArguments(MakeTypeSyntax(elementType, scope, TypeUsage.Writer)); + + case TypeTag.Interface: + return GenericName("ListOfCapsSerializer") + .AddTypeArgumentListArguments(MakeTypeSyntax(elementType, scope, TypeUsage.Writer)); + + case TypeTag.List: + return GenericName("ListOfPointersSerializer") + .AddTypeArgumentListArguments(MakeTypeSyntax(elementType, scope, TypeUsage.Writer)); + + case TypeTag.Text: + return SyntaxHelpers.Type(); + + case TypeTag.Void: + return SyntaxHelpers.Type(); + + case TypeTag.Bool: + return SyntaxHelpers.Type(); + + case TypeTag.F32: + return SyntaxHelpers.Type>(); + + case TypeTag.F64: + return SyntaxHelpers.Type>(); + + case TypeTag.S8: + return SyntaxHelpers.Type>(); + + case TypeTag.U8: + return SyntaxHelpers.Type>(); + + case TypeTag.S16: + return SyntaxHelpers.Type>(); + + case TypeTag.U16: + case TypeTag.AnyEnum: + return SyntaxHelpers.Type>(); + + case TypeTag.S32: + return SyntaxHelpers.Type>(); + + case TypeTag.U32: + return SyntaxHelpers.Type>(); + + case TypeTag.S64: + return SyntaxHelpers.Type>(); + + case TypeTag.U64: + return SyntaxHelpers.Type>(); + + default: + throw new NotImplementedException("Unexpected type tag, don't know how to deal with this"); + } + } + + TypeSyntax MaybeNullableValueType(TypeSyntax typeSyntax, TypeUsage usage) + { + switch (usage) + { + case TypeUsage.DomainClassNullable: + return NullableType(typeSyntax); + + default: + return typeSyntax; + } + } + + public TypeSyntax MakeTypeSyntax(Model.Type type, TypeDefinition scope, TypeUsage usage) + { + switch (type.Tag) + { + case TypeTag.AnyEnum: + return MaybeNullableValueType(SyntaxHelpers.Type(), usage); + + case TypeTag.CapabilityPointer: + if (type.Parameter != null) + { + return GetQName(type, scope); + } + else + { + return SyntaxHelpers.Type(); + } + + case TypeTag.AnyPointer: + case TypeTag.StructPointer: + switch (usage) + { + case TypeUsage.Reader: + return SyntaxHelpers.Type(); + + case TypeUsage.Writer: + return SyntaxHelpers.Type(); + + case TypeUsage.DomainClass: + case TypeUsage.DomainClassNullable: + if (type.Parameter != null) + { + return GetQName(type, scope); + } + else + { + return SyntaxHelpers.Type(); + } + + default: + throw new NotImplementedException(); + } + + case TypeTag.Bool: + return MaybeNullableValueType(SyntaxHelpers.Type(), usage); + + case TypeTag.Data: + switch (usage) + { + case TypeUsage.Reader: + case TypeUsage.DomainClass: + case TypeUsage.DomainClassNullable: + return SyntaxHelpers.Type>(); + + case TypeUsage.Writer: + return SyntaxHelpers.Type>(); + + default: + throw new NotImplementedException(); + } + + case TypeTag.Enum: + return MaybeNullableValueType(GetQName(type, scope), usage); + + case TypeTag.Interface: + return GetQName(type, scope); + + case TypeTag.Struct: + case TypeTag.Group: + switch (usage) + { + case TypeUsage.Writer: + return QualifiedName(GetQName(type, scope), WriterStruct.IdentifierName); + + case TypeUsage.Reader: + return QualifiedName(GetQName(type, scope), ReaderStruct.IdentifierName); + + case TypeUsage.DomainClass: + case TypeUsage.DomainClassNullable: + return GetQName(type, scope); + + default: + throw new NotImplementedException(); + } + + case TypeTag.F32: + return MaybeNullableValueType(SyntaxHelpers.Type(), usage); + + case TypeTag.F64: + return MaybeNullableValueType(SyntaxHelpers.Type(), usage); + + case TypeTag.List when type.ElementType.Tag == TypeTag.Void && usage != TypeUsage.Writer: + return MaybeNullableValueType(SyntaxHelpers.Type(), usage); + + case TypeTag.List: + switch (usage) + { + case TypeUsage.Writer: + return MakeListSerializerSyntax(type.ElementType, scope); + + case TypeUsage.Reader: + return GenericName(Identifier("IReadOnlyList")) + .AddTypeArgumentListArguments(MakeTypeSyntax(type.ElementType, scope, TypeUsage.Reader)); + + case TypeUsage.DomainClass: + case TypeUsage.DomainClassNullable: + return GenericName(Identifier("IReadOnlyList")) + .AddTypeArgumentListArguments(MakeTypeSyntax(type.ElementType, scope, TypeUsage.DomainClass)); + + default: + throw new NotImplementedException(); + } + + case TypeTag.ListPointer: + switch (usage) + { + case TypeUsage.Writer: + return SyntaxHelpers.Type(); + + case TypeUsage.Reader: + return SyntaxHelpers.Type>(); + + case TypeUsage.DomainClass: + case TypeUsage.DomainClassNullable: + return SyntaxHelpers.Type>(); + + default: + throw new NotImplementedException(); + } + + case TypeTag.S16: + return MaybeNullableValueType(SyntaxHelpers.Type(), usage); + + case TypeTag.S32: + return MaybeNullableValueType(SyntaxHelpers.Type(), usage); + + case TypeTag.S64: + return MaybeNullableValueType(SyntaxHelpers.Type(), usage); + + case TypeTag.S8: + return MaybeNullableValueType(SyntaxHelpers.Type(), usage); + + case TypeTag.Text: + return SyntaxHelpers.Type(); + + case TypeTag.U16: + return MaybeNullableValueType(SyntaxHelpers.Type(), usage); + + case TypeTag.U32: + return MaybeNullableValueType(SyntaxHelpers.Type(), usage); + + case TypeTag.U64: + return MaybeNullableValueType(SyntaxHelpers.Type(), usage); + + case TypeTag.U8: + return MaybeNullableValueType(SyntaxHelpers.Type(), usage); + + case TypeTag.Void: + return PredefinedType(Token(SyntaxKind.VoidKeyword)); + + default: + throw new NotImplementedException("Unexpected type tag, don't know how to deal with this"); + } + } + + public string MakeParamsStructName(Method method) + { + return string.Format(ParamsStructFormat, method.Name); + } + + public string MakeResultStructName(Method method) + { + return string.Format(ResultStructFormat, method.Name); + } + + public Name GetCodeIdentifier(Method method) + { + return new Name(SyntaxHelpers.MakeCamel(method.Name)); + } + + public Name GetCodeIdentifier(Field field) + { + if (_fieldNameMap.TryGetValue(field, out var name)) + { + return name; + } + + var def = field.DeclaringType; + + if (def == null) + { + // Method parameters are internally represented with the same class "Field". + // They do not have a declaring type. Anyway, they don't suffer from the field-name-equals-nested-type-name problem. + return new Name(SyntaxHelpers.MakeCamel(field.Name)); + } + + var typeNames = new HashSet(def.NestedTypes.Select(t => MakeTypeName(t))); + typeNames.Add(MakeTypeName(def)); + + foreach (var member in def.Fields) + { + var memberName = new Name(SyntaxHelpers.MakeCamel(member.Name)); + + while (typeNames.Contains(memberName)) + { + memberName = new Name(string.Format(PropertyNamedLikeTypeRenameFormat, memberName.ToString())); + } + + _fieldNameMap.Add(member, memberName); + } + + return _fieldNameMap[field]; + } + + public Name GetGenericTypeParameter(string name) + { + return new Name(string.Format(GenericTypeParameterFormat, name)); + } + + public Name MakePipeliningSupportExtensionMethodName(IReadOnlyList path) + { + if (path.Count == 1 && path[0].Offset == 0) + return EagerMethod; + else + return new Name(string.Join("_", path.Select(f => GetCodeIdentifier(f).ToString()))); + } + + public Name MakeMemberAccessPathFieldName(Method method, IReadOnlyList path) + { + return new Name(string.Format(MemberAccessPathNameFormat, + method.Name, + MakePipeliningSupportExtensionMethodName(path))); + } + } +} diff --git a/CapnpC.CSharp.Generator/CodeGen/GeneratorOptions.cs b/CapnpC.CSharp.Generator/CodeGen/GeneratorOptions.cs new file mode 100644 index 0000000..e534f2b --- /dev/null +++ b/CapnpC.CSharp.Generator/CodeGen/GeneratorOptions.cs @@ -0,0 +1,38 @@ +namespace CapnpC.CSharp.Generator.CodeGen +{ + class GeneratorOptions + { + public string TopNamespaceName { get; set; } = "CapnpGen"; + public string ReaderStructName { get; set; } = "READER"; + public string WriterStructName { get; set; } = "WRITER"; + public string ReaderParameterName { get; set; } = "reader"; + public string WriterParameterName { get; set; } = "writer"; + public string ReaderCreateMethodName { get; set; } = "create"; + public string ReaderContextFieldName { get; set; } = "ctx"; + public string ContextParameterName { get; set; } = "ctx"; + public string GroupReaderContextArgName { get; set; } = "ctx"; + public string GroupWriterContextArgName { get; set; } = "ctx"; + public string UnionDisciminatorEnumName { get; set; } = "WHICH"; + public string UnionDiscriminatorPropName { get; set; } = "which"; + public string UnionDiscriminatorFieldName { get; set; } = "_which"; + public string UnionDisciminatorUndefinedName { get; set; } = "undefined"; + public string UnionContentFieldName { get; set; } = "_content"; + public string SerializeMethodName { get; set; } = "serialize"; + public string ApplyDefaultsMethodName { get; set; } = "applyDefaults"; + public string AnonymousParameterName { get; set; } = "arg_"; + public string CancellationTokenParameterName { get; set; } = "cancellationToken_"; + public string ParamsLocalName { get; set; } = "in_"; + public string DeserializerLocalName { get; set; } = "d_"; + public string SerializerLocalName { get; set; } = "s_"; + public string ResultLocalName { get; set; } = "r_"; + public string ParamsStructFormat { get; set; } = "Params_{0}"; + public string ResultStructFormat { get; set; } = "Result_{0}"; + public string PropertyNamedLikeTypeRenameFormat { get; set; } = "The{0}"; + public string InstLocalName { get; set; } = "inst"; + public string GenericTypeParameterFormat { get; set; } = "T{0}"; + public string PipeliningExtensionsClassName { get; set; } = "PipeliningSupportExtensions"; + public string MemberAccessPathNameFormat { get; set; } = "Path_{0}_{1}"; + public string TaskParameterName { get; set; } = "task"; + public string EagerMethodName { get; set; } = "Eager"; + } +} diff --git a/CapnpC.CSharp.Generator/CodeGen/InterfaceSnippetGen.cs b/CapnpC.CSharp.Generator/CodeGen/InterfaceSnippetGen.cs new file mode 100644 index 0000000..11d6d36 --- /dev/null +++ b/CapnpC.CSharp.Generator/CodeGen/InterfaceSnippetGen.cs @@ -0,0 +1,843 @@ +using CapnpC.CSharp.Generator.Model; +using System; +using System.Collections.Generic; +using System.Linq; +using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; +using static CapnpC.CSharp.Generator.CodeGen.SyntaxHelpers; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using System.Threading.Tasks; +using System.Threading; +using Microsoft.CodeAnalysis.CSharp; + +namespace CapnpC.CSharp.Generator.CodeGen +{ + class InterfaceSnippetGen + { + readonly GenNames _names; + + public InterfaceSnippetGen(GenNames names) + { + _names = names; + } + + TypeSyntax TransformReturnType(Method method) + { + switch (method.Results.Count) + { + case 0: + return IdentifierName(nameof(Task)); + + case 1: + return GenericName(nameof(Task)).AddTypeArgumentListArguments( + _names.MakeTypeSyntax(method.Results[0].Type, method.DeclaringInterface, TypeUsage.DomainClass)); + + default: + return GenericName(nameof(Task)).AddTypeArgumentListArguments( + TupleType(SeparatedList( + method.Results.Select( + f => TupleElement(_names.MakeTypeSyntax(f.Type, method.DeclaringInterface, TypeUsage.DomainClass)))))); + } + } + + ParameterSyntax[] TransformParameters(Method method) + { + var list = new List(); + + if (method.Params.Count > 0) + { + var arg0 = method.Params[0]; + + if (arg0.Name == null) + { + list.Add(Parameter(_names.AnonymousParameter.Identifier) + .WithType(_names.MakeTypeSyntax(arg0.Type, method.DeclaringInterface, TypeUsage.DomainClass))); + } + else + { + foreach (var arg in method.Params) + { + list.Add(Parameter(Identifier(arg.Name)) + .WithType(_names.MakeTypeSyntax(arg.Type, method.DeclaringInterface, TypeUsage.DomainClass))); + } + } + } + + list.Add(Parameter(_names.CancellationTokenParameter.Identifier) + .WithType(IdentifierName(nameof(CancellationToken))) + .WithDefault(EqualsValueClause(LiteralExpression( + SyntaxKind.DefaultLiteralExpression, + Token(SyntaxKind.DefaultKeyword))))); + + return list.ToArray(); + } + + IEnumerable MakeTypeParameters(TypeDefinition def) + { + foreach (string name in def.GenericParameters) + { + yield return TypeParameter(_names.GetGenericTypeParameter(name).Identifier); + } + } + + IEnumerable MakeTypeParameterConstraints(TypeDefinition def) + { + foreach (string name in def.GenericParameters) + { + yield return TypeParameterConstraintClause( + _names.GetGenericTypeParameter(name).IdentifierName) + .AddConstraints(ClassOrStructConstraint(SyntaxKind.ClassConstraint)); + } + } + + public MemberDeclarationSyntax MakeInterface(TypeDefinition type) + { + var ifaceDecl = InterfaceDeclaration(_names.MakeTypeName(type, NameUsage.Interface).Identifier) + .AddModifiers(Public) + .AddAttributeLists( + AttributeList() + .AddAttributes( + Attribute(IdentifierName("Proxy")) + .AddArgumentListArguments( + AttributeArgument( + TypeOfExpression(_names.MakeGenericTypeNameForAttribute(type, NameUsage.Proxy)))), + Attribute(IdentifierName("Skeleton")) + .AddArgumentListArguments( + AttributeArgument( + TypeOfExpression(_names.MakeGenericTypeNameForAttribute(type, NameUsage.Skeleton)))))); + + if (type.GenericParameters.Count > 0) + { + ifaceDecl = ifaceDecl.AddTypeParameterListParameters(MakeTypeParameters(type).ToArray()); + } + + if (type.Superclasses.Count == 0) + { + ifaceDecl = ifaceDecl.AddBaseListTypes(SimpleBaseType(IdentifierName(nameof(IDisposable)))); + } + else + { + foreach (var superClass in type.Superclasses) + { + ifaceDecl = ifaceDecl.AddBaseListTypes( + SimpleBaseType(_names.MakeTypeSyntax( + superClass, type, + TypeUsage.NotRelevant))); + } + } + + foreach (var method in type.Methods) + { + var methodDecl = MethodDeclaration( + TransformReturnType(method), + _names.GetCodeIdentifier(method).Identifier) + .AddParameterListParameters(TransformParameters(method)) + .WithSemicolonToken(Token(SyntaxKind.SemicolonToken)); + + if (method.GenericParameters.Count > 0) + { + methodDecl = methodDecl + .AddTypeParameterListParameters(MakeTypeParameters(method).ToArray()) + .AddConstraintClauses(MakeTypeParameterConstraints(method).ToArray()); + + } + + ifaceDecl = ifaceDecl.AddMembers(methodDecl); + } + + return ifaceDecl; + } + + bool IsSubjectToPipelining(Model.Type type, HashSet visited) + { + if (!visited.Add(type)) + return false; + + switch (type.Tag) + { + case TypeTag.AnyPointer: + case TypeTag.CapabilityPointer: + case TypeTag.Interface: + case TypeTag.ListPointer: + case TypeTag.StructPointer: + return true; + + case TypeTag.List: + return IsSubjectToPipelining(type.ElementType, visited); + + case TypeTag.Struct: + return type.Fields.Any(f => IsSubjectToPipelining(f.Type, visited)); + + default: + return false; + } + } + + bool IsSubjectToPipelining(Method method) + { + return method.Results.Any(r => IsSubjectToPipelining(r.Type, new HashSet())); + } + + IEnumerable MakeProxyCallInitializerAssignments(Method method) + { + foreach (var methodParam in method.Params) + { + yield return AssignmentExpression( + SyntaxKind.SimpleAssignmentExpression, + _names.GetCodeIdentifier(methodParam).IdentifierName, + IdentifierName(methodParam.Name)); + } + } + + IEnumerable MakeProxyReturnResultTupleElements(Method method) + { + foreach (var item in method.ResultStruct.Fields) + { + yield return Argument(MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + _names.ResultLocal.IdentifierName, + _names.GetCodeIdentifier(item).IdentifierName)); + } + } + + StatementSyntax MakeProxyReturnResult(Method method) + { + if (method.ResultStruct.Definition.SpecialName == SpecialName.MethodResultStruct) + { + if (method.ResultStruct.Fields.Count == 0) + { + return ReturnStatement(); + } + else + { + return ReturnStatement(TupleExpression() + .AddArguments(MakeProxyReturnResultTupleElements(method).ToArray())); + } + + } + else + { + return ReturnStatement(_names.ResultLocal.IdentifierName); + } + } + + StatementSyntax MakeProxyCreateResult(Method method) + { + var resultType = method.ResultStruct; + var domainType = _names.MakeTypeSyntax(resultType, method.DeclaringInterface, TypeUsage.DomainClass); + + var createDomain = InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName(nameof(Capnp.CapnpSerializable)), + GenericName(nameof(Capnp.CapnpSerializable.Create)) + .AddTypeArgumentListArguments(domainType))) + .AddArgumentListArguments( + Argument(_names.DeserializerLocal.IdentifierName)); + + return LocalDeclarationStatement( + VariableDeclaration( + IdentifierName("var")) + .WithVariables( + SingletonSeparatedList( + VariableDeclarator( + _names.ResultLocal.Identifier) + .WithInitializer( + EqualsValueClause(createDomain))))); + } + + IEnumerable MakeTypeParameters(Method method) + { + foreach (string name in method.GenericParameters) + { + yield return TypeParameter(_names.GetGenericTypeParameter(name).Identifier); + } + } + + IEnumerable MakeTypeParameterConstraints(Method method) + { + foreach (string name in method.GenericParameters) + { + yield return TypeParameterConstraintClause( + _names.GetGenericTypeParameter(name).IdentifierName) + .AddConstraints(ClassOrStructConstraint(SyntaxKind.ClassConstraint)); + } + } + + public MemberDeclarationSyntax MakeProxy(TypeDefinition type) + { + var classDecl = ClassDeclaration(_names.MakeTypeName(type, NameUsage.Proxy).Identifier) + .AddModifiers(Public) + .AddBaseListTypes( + SimpleBaseType(Type()), + SimpleBaseType(_names.MakeGenericTypeName(type, NameUsage.Interface))); + + if (type.GenericParameters.Count > 0) + { + classDecl = classDecl + .AddTypeParameterListParameters(MakeTypeParameters(type).ToArray()) + .AddConstraintClauses(MakeTypeParameterConstraints(type).ToArray()); + } + + var allMethods = + from c in Types.FromDefinition(type).AllImplementedClasses + from m in c.Definition.Methods + select m; + + foreach (var method in allMethods) + { + var bodyStmts = new List(); + + bodyStmts.Add(LocalDeclarationStatement( + VariableDeclaration( + IdentifierName("var")) + .WithVariables( + SingletonSeparatedList( + VariableDeclarator( + _names.ParamsLocal.Identifier) + .WithInitializer( + EqualsValueClause( + InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName(nameof(Capnp.SerializerState)), + GenericName( + Identifier(nameof(Capnp.SerializerState.CreateForRpc))) + .WithTypeArgumentList( + TypeArgumentList( + SingletonSeparatedList( + _names.MakeTypeSyntax( + method.ParamsStruct, + method.ParamsStruct.Definition, + TypeUsage.Writer)))))))))))); + + if (method.ParamsStruct.Definition.SpecialName == SpecialName.MethodParamsStruct) + { + bodyStmts.Add(LocalDeclarationStatement( + VariableDeclaration( + IdentifierName("var")) + .WithVariables( + SingletonSeparatedList( + VariableDeclarator( + _names.AnonymousParameter.Identifier) + .WithInitializer( + EqualsValueClause( + ObjectCreationExpression( + _names.MakeTypeSyntax( + method.ParamsStruct, + method.ParamsStruct.Definition, + TypeUsage.DomainClass)) + .WithArgumentList( + ArgumentList()) + .WithInitializer( + InitializerExpression( + SyntaxKind.ObjectInitializerExpression, + SeparatedList( + CommonSnippetGen.MakeCommaSeparatedList( + MakeProxyCallInitializerAssignments(method)).ToArray()))))))))); + } + + bodyStmts.Add(ExpressionStatement( + InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + _names.AnonymousParameter.IdentifierName, + _names.SerializeMethod.IdentifierName)) + .AddArgumentListArguments( + Argument(_names.ParamsLocal.IdentifierName)))); + + var call = InvocationExpression(IdentifierName(nameof(Capnp.Rpc.BareProxy.Call))) + .AddArgumentListArguments( + Argument( + LiteralExpression(SyntaxKind.NumericLiteralExpression, + Literal(method.DeclaringInterface.Id))), + Argument( + LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(method.Id))), + Argument( + InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + _names.ParamsLocal.IdentifierName, + GenericName(nameof(Capnp.SerializerState.Rewrap)) + .AddTypeArgumentListArguments(Type()))) + .AddArgumentListArguments()), + Argument( + LiteralExpression(SyntaxKind.FalseLiteralExpression)), + Argument( + _names.CancellationTokenParameter.IdentifierName)); + + MethodDeclarationSyntax methodDecl; + + if (IsSubjectToPipelining(method)) + { + methodDecl = MethodDeclaration( + TransformReturnType(method), + _names.GetCodeIdentifier(method).Identifier) + .AddParameterListParameters(TransformParameters(method)) + .AddModifiers(Public); + + var pipelineAwareCall = InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName(nameof(Capnp.Rpc.Impatient)), + IdentifierName(nameof(Capnp.Rpc.Impatient.MakePipelineAware)))) + .AddArgumentListArguments( + Argument(call), + Argument(SimpleLambdaExpression( + Parameter(_names.DeserializerLocal.Identifier), + Block( + MakeProxyCreateResult(method), + MakeProxyReturnResult(method))))); + + bodyStmts.Add(ReturnStatement(pipelineAwareCall)); + } + else + { + methodDecl = MethodDeclaration( + TransformReturnType(method), + _names.GetCodeIdentifier(method).Identifier) + .AddParameterListParameters(TransformParameters(method)) + .AddModifiers(Public, Token(SyntaxKind.AsyncKeyword)); + + var whenReturned = MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + call, + IdentifierName(nameof(Capnp.Rpc.IPromisedAnswer.WhenReturned))); + + var assignAwaited = LocalDeclarationStatement( + VariableDeclaration( + IdentifierName("var")) + .AddVariables( + VariableDeclarator( + _names.DeserializerLocal.Identifier) + .WithInitializer( + EqualsValueClause( + AwaitExpression(whenReturned))))); + + bodyStmts.Add(assignAwaited); + bodyStmts.Add(MakeProxyCreateResult(method)); + bodyStmts.Add(MakeProxyReturnResult(method)); + } + + if (method.GenericParameters.Count > 0) + { + methodDecl = methodDecl + .AddTypeParameterListParameters(MakeTypeParameters(method).ToArray()) + .AddConstraintClauses(MakeTypeParameterConstraints(method).ToArray()); + } + + methodDecl = methodDecl.AddBodyStatements(bodyStmts.ToArray()); + + classDecl = classDecl.AddMembers(methodDecl); + } + + return classDecl; + } + + IEnumerable MakeSkeletonSetMethodTableArguments(TypeDefinition def) + { + foreach (var method in def.Methods) + { + if (method.GenericParameters.Count > 0) + { + yield return Argument( + GenericName(_names.GetCodeIdentifier(method).ToString()) + .AddTypeArgumentListArguments( + Enumerable.Repeat( + Type(), + method.GenericParameters.Count).ToArray())); + } + else + { + yield return Argument(_names.GetCodeIdentifier(method).IdentifierName); + } + } + } + + IEnumerable MakeSkeletonMethodResultStructInitializer(Method method) + { + foreach (var arg in method.Results) + { + yield return AssignmentExpression( + SyntaxKind.SimpleAssignmentExpression, + _names.GetCodeIdentifier(arg).IdentifierName, + IdentifierName(arg.Name)); + } + } + + IEnumerable MakeSkeletonMethodCallArgs(Method method) + { + foreach (var arg in method.ParamsStruct.Fields) + { + yield return Argument( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + _names.ParamsLocal.IdentifierName, + _names.GetCodeIdentifier(arg).IdentifierName)); + } + } + + StatementSyntax MakeSkeletonMethodSerializerLocalDeclaration(Method method) + { + return LocalDeclarationStatement( + VariableDeclaration( + IdentifierName("var")) + .WithVariables( + SingletonSeparatedList( + VariableDeclarator( + _names.SerializerLocal.Identifier) + .WithInitializer( + EqualsValueClause( + InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName(nameof(Capnp.SerializerState)), + GenericName( + Identifier(nameof(Capnp.SerializerState.CreateForRpc))) + .WithTypeArgumentList( + TypeArgumentList( + SingletonSeparatedList( + _names.MakeTypeSyntax( + method.ResultStruct, + method.ResultStruct.Definition, + TypeUsage.Writer))))))))))); + + } + + CSharpSyntaxNode MakeMaybeTailCallLambdaBody(Method method) + { + var block = Block( + MakeSkeletonMethodSerializerLocalDeclaration(method)); + + if (method.ResultStruct.Definition.SpecialName == SpecialName.MethodResultStruct) + { + block = block.AddStatements( + LocalDeclarationStatement( + VariableDeclaration( + IdentifierName("var")) + .AddVariables( + VariableDeclarator(_names.ResultLocal.Identifier) + .WithInitializer(EqualsValueClause(ObjectCreationExpression( + _names.MakeTypeSyntax( + method.ResultStruct, + method.ResultStruct.Definition, + TypeUsage.DomainClass)) + .WithInitializer( + InitializerExpression(SyntaxKind.ObjectInitializerExpression) + .AddExpressions( + MakeSkeletonMethodResultStructInitializer(method).ToArray()))))))); + } + + if (method.Results.Count > 0) + { + block = block.AddStatements( + ExpressionStatement( + InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + _names.ResultLocal.IdentifierName, + _names.SerializeMethod.IdentifierName)) + .AddArgumentListArguments( + Argument(_names.SerializerLocal.IdentifierName)))); + } + + block = block.AddStatements( + ReturnStatement(_names.SerializerLocal.IdentifierName)); + + return block; + } + + IEnumerable MakeSkeletonMethodBody(Method method) + { + var call = InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName(SkeletonWorder.ImplName), + _names.GetCodeIdentifier(method).IdentifierName)); + + if (method.Params.Count > 0) + { + var paramsType = method.ParamsStruct; + var domainType = _names.MakeTypeSyntax(paramsType, method.ParamsStruct.Definition, TypeUsage.DomainClass); + + var createDomain = InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName(nameof(Capnp.CapnpSerializable)), + GenericName(nameof(Capnp.CapnpSerializable.Create)) + .AddTypeArgumentListArguments(domainType))) + .AddArgumentListArguments( + Argument(_names.DeserializerLocal.IdentifierName)); + + if (method.ParamsStruct.Definition.SpecialName == SpecialName.MethodParamsStruct) + { + yield return LocalDeclarationStatement( + VariableDeclaration( + IdentifierName("var")) + .AddVariables( + VariableDeclarator(_names.ParamsLocal.Identifier) + .WithInitializer(EqualsValueClause(createDomain)))); + + call = call.AddArgumentListArguments( + MakeSkeletonMethodCallArgs(method).ToArray()); + } + else + { + call = call.AddArgumentListArguments( + Argument(createDomain)); + } + } + + call = call.AddArgumentListArguments( + Argument( + _names.CancellationTokenParameter.IdentifierName)); + + if (method.Results.Count == 0) + { + var awaitCall = AwaitExpression(call); + yield return ExpressionStatement(awaitCall); + yield return MakeSkeletonMethodSerializerLocalDeclaration(method); + yield return ReturnStatement(_names.SerializerLocal.IdentifierName); + } + else + { + ExpressionSyntax lambdaArg; + + if (method.ResultStruct.Definition.SpecialName == SpecialName.MethodResultStruct) + { + if (method.Results.Count == 1) + { + lambdaArg = SimpleLambdaExpression( + Parameter(Identifier(method.Results.Single().Name)), + MakeMaybeTailCallLambdaBody(method)); + } + else + { + lambdaArg = ParenthesizedLambdaExpression( + MakeMaybeTailCallLambdaBody(method)) + .AddParameterListParameters( + method.Results.Select(arg => Parameter(Identifier(arg.Name))).ToArray()); + } + } + else + { + lambdaArg = SimpleLambdaExpression( + Parameter(_names.ResultLocal.Identifier), + MakeMaybeTailCallLambdaBody(method)); + + } + + var maybeTailCall = InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName(nameof(Capnp.Rpc.Impatient)), + IdentifierName(nameof(Capnp.Rpc.Impatient.MaybeTailCall)))) + .AddArgumentListArguments( + Argument(call), + Argument(lambdaArg)); + + yield return ReturnStatement(maybeTailCall); + } + } + + IEnumerable MakeSkeletonMethods(TypeDefinition def) + { + foreach (var method in def.Methods) + { + var methodDecl = MethodDeclaration( + Type>(), + _names.GetCodeIdentifier(method).Identifier) + .AddParameterListParameters( + Parameter(_names.DeserializerLocal.Identifier) + .WithType(Type()), + Parameter(_names.CancellationTokenParameter.Identifier) + .WithType(Type())) + .AddBodyStatements( + MakeSkeletonMethodBody(method).ToArray()); + + if (method.Results.Count == 0) + { + methodDecl = methodDecl.AddModifiers(Async); + } + + if (method.GenericParameters.Count > 0) + { + methodDecl = methodDecl + .AddTypeParameterListParameters(MakeTypeParameters(method).ToArray()) + .AddConstraintClauses(MakeTypeParameterConstraints(method).ToArray()); + } + + yield return methodDecl; + } + } + + public MemberDeclarationSyntax MakeSkeleton(TypeDefinition type) + { + var name = _names.MakeTypeName(type, NameUsage.Skeleton).Identifier; + var classDecl = ClassDeclaration(name) + .AddModifiers(Public) + .AddBaseListTypes( + SimpleBaseType( + GenericName(nameof(Capnp.Rpc.Skeleton)) + .AddTypeArgumentListArguments( + _names.MakeGenericTypeName(type, NameUsage.Interface)))) + .AddMembers( + // C'tor + ConstructorDeclaration(name) + .AddModifiers(Public) + .AddBodyStatements( + ExpressionStatement( + InvocationExpression( + IdentifierName(SkeletonWorder.SetMethodTableName)) + .AddArgumentListArguments( + MakeSkeletonSetMethodTableArguments(type).ToArray()))), + // InterfaceId + PropertyDeclaration(Type(), nameof(Capnp.Rpc.Skeleton.InterfaceId)) + .AddModifiers(Public, Override) + .WithExpressionBody( + ArrowExpressionClause( + ValueOf(type.Id))) + .WithSemicolonToken( + Token(SyntaxKind.SemicolonToken))); + + if (type.GenericParameters.Count > 0) + { + classDecl = classDecl + .AddTypeParameterListParameters(MakeTypeParameters(type).ToArray()) + .AddConstraintClauses(MakeTypeParameterConstraints(type).ToArray()); + } + + classDecl = classDecl.AddMembers(MakeSkeletonMethods(type).ToArray()); + + return classDecl; + } + + public bool RequiresPipeliningSupport(TypeDefinition type) + { + return type.Methods.Any(m => ExpandPipeliningPaths(m).Any()); + } + + IEnumerable> ExpandPipeliningPaths(Method method) + { + var stack = new Stack>(); + foreach (var field in method.ResultStruct.Fields) + { + stack.Push(new List() { field }); + } + + while (stack.Count > 0) + { + var path = stack.Pop(); + var last = path[path.Count - 1]; + + switch (last.Type.Tag) + { + case TypeTag.Interface: + case TypeTag.CapabilityPointer: + yield return path; + break; + + case TypeTag.Struct: + foreach (var field in last.Type.Fields) + { + if (path.Contains(field)) + { + // Recursive structs protection + continue; + } + + var copy = new List(); + copy.AddRange(path); + copy.Add(field); + stack.Push(copy); + } + break; + } + } + } + + readonly HashSet<(string, string)> _existingExtensionMethods = new HashSet<(string, string)>(); + + public MemberDeclarationSyntax MakePipeliningSupport(TypeDefinition type) + { + var classDecl = ClassDeclaration(_names.PipeliningExtensionsClassName.Identifier) + .AddModifiers(Public, Static, Partial); + + foreach (var method in type.Methods) + { + foreach (var path in ExpandPipeliningPaths(method)) + { + var accessPath = _names.MakeMemberAccessPathFieldName(method, path); + var methodName = _names.MakePipeliningSupportExtensionMethodName(path); + var capType = path[path.Count - 1].Type; + var capTypeSyntax = _names.MakeTypeSyntax(capType, null, TypeUsage.DomainClass); + + if (!_existingExtensionMethods.Add((capTypeSyntax.ToString(), methodName.ToString()))) + { + continue; + } + + var pathDecl = FieldDeclaration( + VariableDeclaration( + IdentifierName(nameof(Capnp.Rpc.MemberAccessPath))) + .AddVariables( + VariableDeclarator( + accessPath.Identifier) + .WithInitializer( + EqualsValueClause( + ObjectCreationExpression( + IdentifierName(nameof(Capnp.Rpc.MemberAccessPath))) + .AddArgumentListArguments( + path.Select( + f => Argument( + LiteralExpression(SyntaxKind.NumericLiteralExpression, + Literal(f.Offset)))).ToArray()))))) + .AddModifiers(Static, Readonly); + + + var methodDecl = MethodDeclaration( + capTypeSyntax, + methodName.Identifier) + .AddModifiers(Public, Static) + .AddParameterListParameters( + Parameter( + _names.TaskParameter.Identifier) + .AddModifiers(This) + .WithType(TransformReturnType(method))) + .AddBodyStatements( + ReturnStatement( + CastExpression( + capTypeSyntax, + InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName(nameof(Capnp.Rpc.CapabilityReflection)), + GenericName( + Identifier(nameof(Capnp.Rpc.CapabilityReflection.CreateProxy))) + .AddTypeArgumentListArguments( + capTypeSyntax))) + .AddArgumentListArguments( + Argument( + InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName(nameof(Capnp.Rpc.Impatient)), + IdentifierName(nameof(Capnp.Rpc.Impatient.GetAnswer)))) + .AddArgumentListArguments( + Argument( + _names.TaskParameter.IdentifierName)), + IdentifierName(nameof(Capnp.Rpc.IPromisedAnswer.Access)))) + .AddArgumentListArguments( + Argument( + accessPath.IdentifierName))))))); + + classDecl = classDecl.AddMembers(pathDecl, methodDecl); + } + } + + return classDecl; + } + } +} diff --git a/CapnpC.CSharp.Generator/CodeGen/Name.cs b/CapnpC.CSharp.Generator/CodeGen/Name.cs new file mode 100644 index 0000000..5b8e877 --- /dev/null +++ b/CapnpC.CSharp.Generator/CodeGen/Name.cs @@ -0,0 +1,33 @@ +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using System; + +namespace CapnpC.CSharp.Generator.CodeGen +{ + class Name + { + readonly string _name; + + public Name(string name) + { + _name = name ?? throw new ArgumentNullException(nameof(name)); + IdentifierName = SyntaxFactory.IdentifierName(_name); + Identifier = SyntaxFactory.Identifier(_name); + VariableDeclarator = SyntaxFactory.VariableDeclarator(_name); + } + + public IdentifierNameSyntax IdentifierName { get; } + public SyntaxToken Identifier { get; } + public VariableDeclaratorSyntax VariableDeclarator { get; } + + public override string ToString() => _name; + + public override bool Equals(object obj) + { + return obj is Name other && _name == other._name; + } + + public override int GetHashCode() => _name.GetHashCode(); + } +} diff --git a/CapnpC.CSharp.Generator/CodeGen/ReaderSnippetGen.cs b/CapnpC.CSharp.Generator/CodeGen/ReaderSnippetGen.cs new file mode 100644 index 0000000..869acf1 --- /dev/null +++ b/CapnpC.CSharp.Generator/CodeGen/ReaderSnippetGen.cs @@ -0,0 +1,713 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using CapnpC.CSharp.Generator.Model; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; +using static CapnpC.CSharp.Generator.CodeGen.SyntaxHelpers; + +namespace CapnpC.CSharp.Generator.CodeGen +{ + class ReaderSnippetGen + { + readonly GenNames _names; + + public ReaderSnippetGen(GenNames names) + { + _names = names; + } + + MemberDeclarationSyntax MakeReaderImplicitConversionOperator1() + { + return ConversionOperatorDeclaration( + Token(SyntaxKind.ImplicitKeyword), + IdentifierName(nameof(Capnp.DeserializerState))) + .WithModifiers( + TokenList( + new[]{ + Token(SyntaxKind.PublicKeyword), + Token(SyntaxKind.StaticKeyword)})) + .WithParameterList( + ParameterList( + SingletonSeparatedList( + Parameter(_names.ReaderParameter.Identifier) + .WithType(_names.ReaderStruct.IdentifierName)))) + .WithExpressionBody( + ArrowExpressionClause( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + _names.ReaderParameter.IdentifierName, + _names.ReaderContextField.IdentifierName))) + .WithSemicolonToken( + Token(SyntaxKind.SemicolonToken)); + } + + MemberDeclarationSyntax MakeReaderImplicitConversionOperator2() + { + return ConversionOperatorDeclaration( + Token(SyntaxKind.ImplicitKeyword), + _names.ReaderStruct.IdentifierName) + .WithModifiers( + TokenList( + new[] { + Token(SyntaxKind.PublicKeyword), + Token(SyntaxKind.StaticKeyword) })) + .WithParameterList( + ParameterList( + SingletonSeparatedList( + Parameter(_names.ReaderContextField.Identifier) + .WithType(Type())))) + .WithExpressionBody( + ArrowExpressionClause( + ObjectCreationExpression(_names.ReaderStruct.IdentifierName) + .WithArgumentList( + ArgumentList( + SingletonSeparatedList( + Argument(_names.ReaderContextField.IdentifierName)))))) + .WithSemicolonToken( + Token(SyntaxKind.SemicolonToken)); + } + + MemberDeclarationSyntax MakeReaderCreateMethod() + { + return MethodDeclaration(_names.ReaderStruct.IdentifierName, _names.ReaderCreateMethod.Identifier) + .AddModifiers(Public, Static) + .WithParameterList( + ParameterList( + SingletonSeparatedList( + Parameter(_names.ContextParameter.Identifier) + .WithType( + Type())))) + .WithExpressionBody( + ArrowExpressionClause( + ObjectCreationExpression(_names.ReaderStruct.IdentifierName) + .AddArgumentListArguments(Argument(_names.ContextParameter.IdentifierName)))) + .WithSemicolonToken(Token(SyntaxKind.SemicolonToken)); + } + + IEnumerable MakeReaderStructMembers() + { + yield return FieldDeclaration( + VariableDeclaration( + Type()) + .AddVariables(_names.ReaderContextField.VariableDeclarator)) + .AddModifiers(Readonly); + + yield return ConstructorDeclaration(_names.ReaderStruct.Identifier) + .AddModifiers(Public) + .WithParameterList( + ParameterList( + SingletonSeparatedList( + Parameter(_names.ContextParameter.Identifier) + .WithType(Type())))) + .WithBody( + Block( + SingletonList( + ExpressionStatement( + AssignmentExpression( + SyntaxKind.SimpleAssignmentExpression, + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + ThisExpression(), + _names.ReaderContextField.IdentifierName), + _names.ContextParameter.IdentifierName))))); + + yield return MakeReaderCreateMethod(); + yield return MakeReaderImplicitConversionOperator1(); + yield return MakeReaderImplicitConversionOperator2(); + } + + IEnumerable MakeGroupReaderStructMembers() + { + yield return FieldDeclaration( + VariableDeclaration( + Type()) + .AddVariables(_names.ReaderContextField.VariableDeclarator)) + .AddModifiers(Readonly); + + yield return ConstructorDeclaration(_names.ReaderStruct.Identifier) + .AddModifiers(Public) + .WithParameterList( + ParameterList( + SingletonSeparatedList(Parameter(_names.GroupReaderContextArg.Identifier) + .WithType(Type())))) + .WithBody( + Block( + SingletonList( + ExpressionStatement( + AssignmentExpression( + SyntaxKind.SimpleAssignmentExpression, + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + ThisExpression(), + _names.ReaderContextField.IdentifierName), + _names.GroupReaderContextArg.IdentifierName))))); + + yield return MakeReaderCreateMethod(); + yield return MakeReaderImplicitConversionOperator1(); + yield return MakeReaderImplicitConversionOperator2(); + } + + PropertyDeclarationSyntax MakeReaderProperty(TypeSyntax type, string name, ExpressionSyntax right, bool cond) + { + if (cond) + { + right = ConditionalExpression( + BinaryExpression( + SyntaxKind.EqualsExpression, + _names.UnionDiscriminatorProp.IdentifierName, + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + _names.UnionDiscriminatorEnum.IdentifierName, + IdentifierName(name))), + right, + LiteralExpression( + SyntaxKind.DefaultLiteralExpression, + Token(SyntaxKind.DefaultKeyword))); + } + + return PropertyDeclaration(type, name) + .AddModifiers(Public) + .WithExpressionBody(ArrowExpressionClause(right)) + .WithSemicolonToken(Token(SyntaxKind.SemicolonToken)); + } + + static Func MakeCastFunc(TypeSyntax type) => + x => CastExpression(type, x); + + static Func MakeListCastFunc(string castName, Field field) + { + // Insight: List may have complex default values (e.g. [true, false, false, true] as a + // valid default value for a list of bools. This does not yet fit the author's mindset. + + //if (field.DefaultValueIsExplicit) + //{ + // return x => InvocationExpression( + // MemberAccessExpression( + // SyntaxKind.SimpleMemberAccessExpression, + // x, + // IdentifierName(castName)) + // ) + // .AddArgumentListArguments( + // Argument(ValueOf(field.DefaultValue))); + //} + //else + + { + return x => InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + x, + IdentifierName(castName)) + ); + } + } + + static Func MakeListCastFuncWithCons( + string castName, ExpressionSyntax cons) + { + return x => InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + x, + IdentifierName(castName)) + ).AddArgumentListArguments(Argument(cons)); + } + + static Func MakeGenericListCastFunc(string castName, TypeSyntax genericArgument) + { + return x => InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + x, + GenericName(castName).AddTypeArgumentListArguments(genericArgument)) + ); + } + + PropertyDeclarationSyntax MakeReadProperty(TypeSyntax type, string name, SimpleNameSyntax readName, + object indexOrBitOffset, ExpressionSyntax secondArg, + Func cast, bool cond) + { + var right = InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + _names.ReaderContextField.IdentifierName, + readName)) + .AddArgumentListArguments( + Argument(ValueOf(indexOrBitOffset))); + + if (secondArg != null) + { + right = right.AddArgumentListArguments(Argument(secondArg)); + } + + ExpressionSyntax expr = right; + + if (cast != null) + { + expr = cast(expr); + } + + return MakeReaderProperty(type, name, expr, cond); + } + + PropertyDeclarationSyntax MakeReadProperty(TypeSyntax type, string name, string readName, + object indexOrBitOffset, ExpressionSyntax secondArg, + Func cast, bool cond) + { + return MakeReadProperty(type, name, IdentifierName(readName), indexOrBitOffset, secondArg, cast, cond); + } + + PropertyDeclarationSyntax MakeReadPrimitiveProperty(Field field, string readName) + { + return MakeReadProperty(Type(), _names.GetCodeIdentifier(field).ToString(), readName, field.BitOffset.Value, + ValueOf(field.DefaultValue.ScalarValue), null, field.DiscValue.HasValue); + } + + PropertyDeclarationSyntax MakeReadEnumProperty(Field field) + { + var typeSyntax = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Reader); + return MakeReadProperty(typeSyntax, + _names.GetCodeIdentifier(field).ToString(), + nameof(Capnp.SerializerExtensions.ReadDataUShort), field.BitOffset.Value, + ValueOf(field.DefaultValue.ScalarValue), + x => CastExpression(typeSyntax, x), + field.DiscValue.HasValue); + } + + PropertyDeclarationSyntax MakeReadTextProperty(Field field) + { + return MakeReadProperty(Type(), _names.GetCodeIdentifier(field).ToString(), + nameof(Capnp.DeserializerState.ReadText), (int)field.Offset, + ValueOf(field.DefaultValue.ScalarValue), null, field.DiscValue.HasValue); + } + + MemberAccessExpressionSyntax MakeReaderCreator(TypeSyntax qtype) + { + return MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + qtype, + _names.ReaderCreateMethod.IdentifierName); + } + + PropertyDeclarationSyntax MakeReadStructProperty(Field field) + { + var qtype = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Reader); + var creator = MakeReaderCreator(qtype); + + return MakeReadProperty(qtype, _names.GetCodeIdentifier(field).ToString(), + nameof(Capnp.DeserializerState.ReadStruct), (int)field.Offset, + creator, null, field.DiscValue.HasValue); + } + + PropertyDeclarationSyntax MakeReadGroupProperty(Field field) + { + var type = QualifiedName( + _names.MakeTypeName(field.Type.Definition).IdentifierName, + _names.ReaderStruct.IdentifierName); + + var right = ObjectCreationExpression(type) + .WithArgumentList( + ArgumentList( + SingletonSeparatedList( + Argument(_names.ReaderContextField.IdentifierName)))); + + return MakeReaderProperty(type, _names.GetCodeIdentifier(field).ToString(), right, field.DiscValue.HasValue); + } + + void MakeReadListPropertyImpl(Model.Type elementType, TypeDefinition scope, ExpressionSyntax context, int depth, + out TypeSyntax listType, out ExpressionSyntax impl) + { + var elementTypeSyntax = _names.MakeTypeSyntax(elementType, scope, TypeUsage.Reader); + listType = GenericName("IReadOnlyList").AddTypeArgumentListArguments(elementTypeSyntax); + + if (elementType.Tag == TypeTag.Interface || + elementType.Tag == TypeTag.CapabilityPointer) + { + if (depth == 0) + { + impl = InvocationExpression(MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + _names.ReaderContextField.IdentifierName, + GenericName(nameof(Capnp.DeserializerState.ReadCapList)) + .AddTypeArgumentListArguments(elementTypeSyntax) + )).AddArgumentListArguments(Argument(context)); + } + else + { + impl = InvocationExpression( + MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, + context, + GenericName(nameof(Capnp.DeserializerState.RequireCapList)) + .AddTypeArgumentListArguments(elementTypeSyntax) + )); + } + + return; + } + + if (depth == 0) + { + context = InvocationExpression(MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + _names.ReaderContextField.IdentifierName, + IdentifierName(nameof(Capnp.DeserializerState.ReadList)))) + .AddArgumentListArguments(Argument(context)); + } + else + { + context = InvocationExpression( + MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, + context, + IdentifierName(nameof(Capnp.DeserializerState.RequireList)) + )); + } + + string lambdaParamName = "_" + depth; + var lambdaParam = Parameter(Identifier(lambdaParamName)); + var lambdaArg = IdentifierName(lambdaParamName); + string castFuncName; + + switch (elementType.Tag) + { + case TypeTag.List: + { + + MakeReadListPropertyImpl( + elementType.ElementType, + scope, + lambdaArg, + depth + 1, + out var innerListType, + out var innerImpl); + + listType = GenericName("IReadOnlyList").AddTypeArgumentListArguments(innerListType); + + impl = InvocationExpression( + MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, + context, + IdentifierName(nameof(Capnp.ListDeserializer.Cast)))) + .AddArgumentListArguments( + Argument(SimpleLambdaExpression(lambdaParam, innerImpl))); + + return; + } + + case TypeTag.ListPointer: + { + listType = Type>(); + + context = InvocationExpression(MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + context, + IdentifierName(nameof(Capnp.DeserializerState.RequireList)) + )).AddArgumentListArguments(Argument(lambdaArg)); + + impl = InvocationExpression( + MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, + context, + IdentifierName(nameof(Capnp.ReadOnlyListExtensions.LazyListSelect)))) + .AddArgumentListArguments( + Argument(SimpleLambdaExpression(lambdaParam, context))); + + return; + } + + case TypeTag.Struct: + { + impl = InvocationExpression( + MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, + context, + IdentifierName(nameof(Capnp.ListDeserializer.Cast)))) + .AddArgumentListArguments( + Argument(MakeReaderCreator(elementTypeSyntax))); + + return; + } + + case TypeTag.Enum: + { + var cons = SimpleLambdaExpression( + lambdaParam, + CastExpression(elementTypeSyntax, lambdaArg)); + + impl = InvocationExpression( + MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, + context, + IdentifierName(nameof(Capnp.ListDeserializer.CastEnums)))) + .AddArgumentListArguments( + Argument(cons)); + + return; + } + + case TypeTag.AnyPointer: + case TypeTag.StructPointer: + { + listType = Type>(); + impl = context; + return; + } + + case TypeTag.Void: + { + listType = Type(); + impl = MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + context, + IdentifierName(nameof(Capnp.ListDeserializer.Count))); + return; + } + + case TypeTag.Data: + castFuncName = nameof(Capnp.ListDeserializer.CastData); + break; + + case TypeTag.Text: + castFuncName = nameof(Capnp.ListDeserializer.CastText2); + break; + + case TypeTag.Bool: + castFuncName = nameof(Capnp.ListDeserializer.CastBool); + break; + + case TypeTag.F32: + castFuncName = nameof(Capnp.ListDeserializer.CastFloat); + break; + + case TypeTag.F64: + castFuncName = nameof(Capnp.ListDeserializer.CastDouble); + break; + + case TypeTag.S8: + castFuncName = nameof(Capnp.ListDeserializer.CastSByte); + break; + + case TypeTag.U8: + castFuncName = nameof(Capnp.ListDeserializer.CastByte); + break; + + case TypeTag.S16: + castFuncName = nameof(Capnp.ListDeserializer.CastShort); + break; + + case TypeTag.U16: + case TypeTag.AnyEnum: + castFuncName = nameof(Capnp.ListDeserializer.CastUShort); + break; + + case TypeTag.S32: + castFuncName = nameof(Capnp.ListDeserializer.CastInt); + break; + + case TypeTag.U32: + castFuncName = nameof(Capnp.ListDeserializer.CastUInt); + break; + + case TypeTag.S64: + castFuncName = nameof(Capnp.ListDeserializer.CastLong); + break; + + case TypeTag.U64: + castFuncName = nameof(Capnp.ListDeserializer.CastULong); + break; + + default: + throw new NotImplementedException("Unexpected type tag, don't know how to deal with this"); + } + + impl = InvocationExpression(MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + context, + IdentifierName(castFuncName))); + } + + PropertyDeclarationSyntax MakeReadListProperty(Field field) + { + var elementType = field.Type.ElementType; + var context = ValueOf((int)field.Offset); + MakeReadListPropertyImpl(elementType, field.DeclaringType, context, 0, out var listType, out var impl); + return MakeReaderProperty(listType, _names.GetCodeIdentifier(field).ToString(), impl, field.DiscValue.HasValue); + } + + PropertyDeclarationSyntax MakeReadAnyListProperty(Field field) + { + var type = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Reader); + + return MakeReadProperty(type, _names.GetCodeIdentifier(field).ToString(), + nameof(Capnp.DeserializerState.ReadList), + (int)field.Offset, null, x => CastExpression(type, x), field.DiscValue.HasValue); + } + + PropertyDeclarationSyntax MakeReadCapProperty(Field field) + { + var type = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Reader); + var readName = GenericName(nameof(Capnp.DeserializerState.ReadCap)) + .AddTypeArgumentListArguments(type); + + return MakeReadProperty(type, _names.GetCodeIdentifier(field).ToString(), + readName, + (int)field.Offset, null, null, field.DiscValue.HasValue); + } + + PropertyDeclarationSyntax MakeReadAnyCapProperty(Field field) + { + var type = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Reader); + + return MakeReadProperty(type, _names.GetCodeIdentifier(field).ToString(), + nameof(Capnp.DeserializerState.ReadCap), + (int)field.Offset, null, null, field.DiscValue.HasValue); + } + + PropertyDeclarationSyntax MakeReadDataProperty(Field field) + { + var context = InvocationExpression(MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + _names.ReaderContextField.IdentifierName, + IdentifierName(nameof(Capnp.DeserializerState.ReadList)))) + .AddArgumentListArguments(Argument(ValueOf((int)field.Offset))); + var impl = InvocationExpression(MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + context, + IdentifierName(nameof(Capnp.ListDeserializer.CastByte)))); + + return MakeReaderProperty( + _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Reader), + _names.GetCodeIdentifier(field).ToString(), impl, field.DiscValue.HasValue); + } + + PropertyDeclarationSyntax MakeReadAnyPointerProperty(Field field) + { + var type = IdentifierName(nameof(Capnp.DeserializerState)); + + return MakeReadProperty(type, _names.GetCodeIdentifier(field).ToString(), + nameof(Capnp.DeserializerState.StructReadPointer), + (int)field.Offset, null, null, field.DiscValue.HasValue); + } + + PropertyDeclarationSyntax MakeReaderUnionSelector(TypeDefinition def) + { + var type = _names.UnionDiscriminatorEnum.IdentifierName; + return MakeReadProperty( + type, + _names.UnionDiscriminatorProp.ToString(), + nameof(Capnp.SerializerExtensions.ReadDataUShort), + def.UnionInfo.TagOffset, + ValueOf(default(ushort)), + MakeCastFunc(type), false); + } + + PropertyDeclarationSyntax MakeReaderFieldProperty(Field field) + { + switch (field.Type.Tag) + { + case TypeTag.Bool: + return MakeReadPrimitiveProperty(field, + nameof(Capnp.SerializerExtensions.ReadDataBool)); + + case TypeTag.S8: + return MakeReadPrimitiveProperty(field, + nameof(Capnp.SerializerExtensions.ReadDataSByte)); + + case TypeTag.U8: + return MakeReadPrimitiveProperty(field, + nameof(Capnp.SerializerExtensions.ReadDataByte)); + + case TypeTag.S16: + return MakeReadPrimitiveProperty(field, + nameof(Capnp.SerializerExtensions.ReadDataShort)); + + case TypeTag.U16: + return MakeReadPrimitiveProperty(field, + nameof(Capnp.SerializerExtensions.ReadDataUShort)); + + case TypeTag.S32: + return MakeReadPrimitiveProperty(field, + nameof(Capnp.SerializerExtensions.ReadDataInt)); + + case TypeTag.U32: + return MakeReadPrimitiveProperty(field, + nameof(Capnp.SerializerExtensions.ReadDataUInt)); + + case TypeTag.S64: + return MakeReadPrimitiveProperty(field, + nameof(Capnp.SerializerExtensions.ReadDataLong)); + + case TypeTag.U64: + return MakeReadPrimitiveProperty(field, + nameof(Capnp.SerializerExtensions.ReadDataULong)); + + case TypeTag.F32: + return MakeReadPrimitiveProperty(field, + nameof(Capnp.SerializerExtensions.ReadDataFloat)); + + case TypeTag.F64: + return MakeReadPrimitiveProperty(field, + nameof(Capnp.SerializerExtensions.ReadDataDouble)); + + case TypeTag.Enum: + return MakeReadEnumProperty(field); + + case TypeTag.Text: + return MakeReadTextProperty(field); + + case TypeTag.Struct: + return MakeReadStructProperty(field); + + case TypeTag.Group: + return MakeReadGroupProperty(field); + + case TypeTag.List: + return MakeReadListProperty(field); + + case TypeTag.Interface: + return MakeReadCapProperty(field); + + case TypeTag.CapabilityPointer: + return MakeReadAnyCapProperty(field); + + case TypeTag.ListPointer: + return MakeReadAnyListProperty(field); + + case TypeTag.AnyPointer: + case TypeTag.StructPointer: + return MakeReadAnyPointerProperty(field); + + case TypeTag.Data: + return MakeReadDataProperty(field); + + default: + return null; + } + } + + public StructDeclarationSyntax MakeReaderStruct(TypeDefinition def) + { + var readerDecl = StructDeclaration(_names.ReaderStruct.ToString()).AddModifiers(Public); + + var members = def.Tag == TypeTag.Group ? + MakeGroupReaderStructMembers() : + MakeReaderStructMembers(); + + readerDecl = readerDecl.AddMembers(members.ToArray()); + + if (def.UnionInfo != null) + { + readerDecl = readerDecl.AddMembers(MakeReaderUnionSelector(def)); + } + + foreach (var field in def.Fields) + { + var propDecl = MakeReaderFieldProperty(field); + + if (propDecl != null) + { + readerDecl = readerDecl.AddMembers(propDecl); + } + } + + return readerDecl; + } + } +} diff --git a/CapnpC.CSharp.Generator/CodeGen/SerializerStateWorder.cs b/CapnpC.CSharp.Generator/CodeGen/SerializerStateWorder.cs new file mode 100644 index 0000000..29cb72a --- /dev/null +++ b/CapnpC.CSharp.Generator/CodeGen/SerializerStateWorder.cs @@ -0,0 +1,10 @@ +using Capnp; + +namespace CapnpC.CSharp.Generator.CodeGen +{ + class SerializerStateWorder: SerializerState + { + public const string LinkName = nameof(SerializerStateWorder.Link); + public const string SetStructName = nameof(SerializerStateWorder.SetStruct); + } +} diff --git a/CapnpC.CSharp.Generator/CodeGen/SkeletonWorder.cs b/CapnpC.CSharp.Generator/CodeGen/SkeletonWorder.cs new file mode 100644 index 0000000..703ee3b --- /dev/null +++ b/CapnpC.CSharp.Generator/CodeGen/SkeletonWorder.cs @@ -0,0 +1,12 @@ +using System; + +namespace CapnpC.CSharp.Generator.CodeGen +{ + class SkeletonWorder : Capnp.Rpc.Skeleton + { + public override ulong InterfaceId => throw new NotImplementedException(); + + public const string SetMethodTableName = nameof(SkeletonWorder.SetMethodTable); + public const string ImplName = nameof(SkeletonWorder.Impl); + } +} diff --git a/CapnpC.CSharp.Generator/CodeGen/SyntaxHelpers.cs b/CapnpC.CSharp.Generator/CodeGen/SyntaxHelpers.cs new file mode 100644 index 0000000..56f258e --- /dev/null +++ b/CapnpC.CSharp.Generator/CodeGen/SyntaxHelpers.cs @@ -0,0 +1,126 @@ +using System; +using System.Linq; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; + +namespace CapnpC.CSharp.Generator.CodeGen +{ + static class SyntaxHelpers + { + public static string MakeCamel(string name) => $"{char.ToUpperInvariant(name[0])}{name.Substring(1)}"; + public static string MakeAllLower(string name) => $"@{name}"; + + public static readonly SyntaxToken Async = Token(SyntaxKind.AsyncKeyword); + public static readonly SyntaxToken Public = Token(SyntaxKind.PublicKeyword); + public static readonly SyntaxToken Private = Token(SyntaxKind.PrivateKeyword); + public static readonly SyntaxToken Readonly = Token(SyntaxKind.ReadOnlyKeyword); + public static readonly SyntaxToken Static = Token(SyntaxKind.StaticKeyword); + public static readonly SyntaxToken Override = Token(SyntaxKind.OverrideKeyword); + public static readonly SyntaxToken Partial = Token(SyntaxKind.PartialKeyword); + public static readonly SyntaxToken This = Token(SyntaxKind.ThisKeyword); + + public static TypeSyntax Type(Type type) + { + switch (0) + { + case 0 when type == typeof(bool): + return PredefinedType(Token(SyntaxKind.BoolKeyword)); + + case 0 when type == typeof(sbyte): + return PredefinedType(Token(SyntaxKind.SByteKeyword)); + + case 0 when type == typeof(byte): + return PredefinedType(Token(SyntaxKind.ByteKeyword)); + + case 0 when type == typeof(short): + return PredefinedType(Token(SyntaxKind.ShortKeyword)); + + case 0 when type == typeof(ushort): + return PredefinedType(Token(SyntaxKind.UShortKeyword)); + + case 0 when type == typeof(int): + return PredefinedType(Token(SyntaxKind.IntKeyword)); + + case 0 when type == typeof(uint): + return PredefinedType(Token(SyntaxKind.UIntKeyword)); + + case 0 when type == typeof(long): + return PredefinedType(Token(SyntaxKind.LongKeyword)); + + case 0 when type == typeof(ulong): + return PredefinedType(Token(SyntaxKind.ULongKeyword)); + + case 0 when type == typeof(float): + return PredefinedType(Token(SyntaxKind.FloatKeyword)); + + case 0 when type == typeof(double): + return PredefinedType(Token(SyntaxKind.DoubleKeyword)); + + case 0 when type == typeof(string): + return PredefinedType(Token(SyntaxKind.StringKeyword)); + + case 0 when type == typeof(object): + return PredefinedType(Token(SyntaxKind.ObjectKeyword)); + + case 0 when type.IsGenericType: + return GenericName(type.Name.Substring(0, type.Name.IndexOf('`'))) + .AddTypeArgumentListArguments(type.GetGenericArguments().Select(Type).ToArray()); + + default: + return ParseTypeName(type.Name); + } + } + + public static TypeSyntax Type() => Type(typeof(T)); + + public static ExpressionSyntax ValueOf(object value) + { + switch (value) + { + case bool x: + return LiteralExpression(x ? SyntaxKind.TrueLiteralExpression : SyntaxKind.FalseLiteralExpression); + + case sbyte x: + return CastExpression(Type(), LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x))); + + case byte x: + return CastExpression(Type(), LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x))); + + case short x: + return CastExpression(Type(), LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x))); + + case ushort x: + return CastExpression(Type(), LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x))); + + case int x: + return LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x)); + + case uint x: + return LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x)); + + case long x: + return LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x)); + + case ulong x: + return LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x)); + + case float x: + return LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x)); + + case double x: + return LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x)); + + case string x: + return LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(x)); + + case null: + return LiteralExpression(SyntaxKind.NullLiteralExpression); + + default: + throw new NotImplementedException(); + } + } + } +} diff --git a/CapnpC.CSharp.Generator/CodeGen/WriterSnippetGen.cs b/CapnpC.CSharp.Generator/CodeGen/WriterSnippetGen.cs new file mode 100644 index 0000000..262b8eb --- /dev/null +++ b/CapnpC.CSharp.Generator/CodeGen/WriterSnippetGen.cs @@ -0,0 +1,403 @@ +using System.Collections.Generic; +using System.Linq; +using CapnpC.CSharp.Generator.Model; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; +using static CapnpC.CSharp.Generator.CodeGen.SyntaxHelpers; + +namespace CapnpC.CSharp.Generator.CodeGen +{ + class WriterSnippetGen + { + readonly GenNames _names; + + public WriterSnippetGen(GenNames names) + { + _names = names; + } + + IEnumerable MakeWriterStructMembers(TypeDefinition structType) + { + yield return ConstructorDeclaration(_names.WriterStruct.Identifier) + .AddModifiers(Public) + .WithBody( + Block( + ExpressionStatement( + InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + ThisExpression(), + IdentifierName(SerializerStateWorder.SetStructName))) + .AddArgumentListArguments( + Argument( + LiteralExpression( + SyntaxKind.NumericLiteralExpression, + Literal(structType.StructDataWordCount))), + Argument( + LiteralExpression( + SyntaxKind.NumericLiteralExpression, + Literal(structType.StructPointerCount))))))); + } + + IEnumerable MakeGroupWriterStructMembers() + { + yield return ConstructorDeclaration(_names.WriterStruct.Identifier) + .AddModifiers(Public) + .WithBody(Block()); + } + + PropertyDeclarationSyntax MakeWriterProperty( + TypeSyntax type, + string name, + ExpressionSyntax getter, + ExpressionSyntax setter, + bool cast, + bool cond) + { + if (cast) + { + getter = CastExpression(type, getter); + } + + if (cond) + { + getter = ConditionalExpression( + BinaryExpression( + SyntaxKind.EqualsExpression, + _names.UnionDiscriminatorProp.IdentifierName, + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + _names.UnionDiscriminatorEnum.IdentifierName, + IdentifierName(name))), + getter, + LiteralExpression( + SyntaxKind.DefaultLiteralExpression, + Token(SyntaxKind.DefaultKeyword))); + } + + var accessors = new AccessorDeclarationSyntax[setter != null ? 2 : 1]; + + accessors[0] = AccessorDeclaration(SyntaxKind.GetAccessorDeclaration) + .WithExpressionBody(ArrowExpressionClause(getter)) + .WithSemicolonToken(Token(SyntaxKind.SemicolonToken)); + + if (setter != null) + { + accessors[1] = AccessorDeclaration(SyntaxKind.SetAccessorDeclaration) + .WithExpressionBody(ArrowExpressionClause(setter)) + .WithSemicolonToken(Token(SyntaxKind.SemicolonToken)); + } + + return PropertyDeclaration(type, name) + .AddModifiers(Public) + .AddAccessorListAccessors(accessors); + } + + ExpressionSyntax MakePointerSyntax(TypeSyntax type, object index) => + InvocationExpression( + GenericName(nameof(Capnp.SerializerState.BuildPointer)) + .AddTypeArgumentListArguments(type)) + .AddArgumentListArguments( + Argument(ValueOf(index))); + + ExpressionSyntax MakeReadCapSyntax(TypeSyntax type, object index) => + InvocationExpression( + GenericName(nameof(Capnp.SerializerState.ReadCap)) + .AddTypeArgumentListArguments(type)) + .AddArgumentListArguments( + Argument(ValueOf(index))); + + ExpressionSyntax MakeTypedPointerSyntax(object index, TypeSyntax type) => + InvocationExpression( + GenericName(nameof(Capnp.SerializerState.BuildPointer)) + .AddTypeArgumentListArguments(type)) + .AddArgumentListArguments( + Argument(ValueOf(index))); + + ExpressionSyntax MakeLinkSyntax(object index) => + InvocationExpression( + IdentifierName(SerializerStateWorder.LinkName)) + .AddArgumentListArguments( + Argument(ValueOf(index)), + Argument(IdentifierName("value"))); + + ExpressionSyntax MakeLinkObjectSyntax(object index) => + InvocationExpression( + IdentifierName(nameof(Capnp.SerializerState.LinkObject))) + .AddArgumentListArguments( + Argument(ValueOf(index)), + Argument(IdentifierName("value"))); + + PropertyDeclarationSyntax MakePointerProperty(TypeSyntax type, string name, object index, bool cast, bool cond) + { + ExpressionSyntax getter = MakePointerSyntax(type, index); + ExpressionSyntax setter = MakeLinkSyntax(index); + + return MakeWriterProperty(type, name, getter, setter, cast, cond); + } + + PropertyDeclarationSyntax MakePointerAsStructProperty( + TypeSyntax type, string name, object index, + bool cast, bool cond) + { + ExpressionSyntax getter = MakeTypedPointerSyntax(index, type); + ExpressionSyntax setter = MakeLinkSyntax(index); + + return MakeWriterProperty(type, name, getter, setter, cast, cond); + } + + PropertyDeclarationSyntax MakeProperty( + TypeSyntax outerType, + TypeSyntax innerType, + string name, + string readName, + string writeName, + object indexOrBitOffset, + ExpressionSyntax secondArg, + bool cast, + bool cond, + bool pasd) + { + var getter = InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + ThisExpression(), + IdentifierName(readName))) + .AddArgumentListArguments( + Argument(ValueOf(indexOrBitOffset)), + Argument(secondArg)); + + ExpressionSyntax value = IdentifierName("value"); + + if (cast) + { + value = CastExpression(innerType, value); + } + + var setter = InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + ThisExpression(), + IdentifierName(writeName))) + .AddArgumentListArguments( + Argument(ValueOf(indexOrBitOffset)), + Argument(value), + Argument(secondArg)); + + if (pasd) + { + setter.AddArgumentListArguments(Argument(secondArg)); + } + + return MakeWriterProperty(outerType, name, getter, setter, cast, cond); + } + + PropertyDeclarationSyntax MakePrimitiveProperty(Field field, string readName) + { + return MakeProperty(Type(), null, _names.GetCodeIdentifier(field).ToString(), + readName, + nameof(Capnp.SerializerExtensions.WriteData), + field.BitOffset.Value, + ValueOf(field.DefaultValue.ScalarValue), + false, + field.DiscValue.HasValue, + true); + } + + PropertyDeclarationSyntax MakeEnumProperty(Field field, string readName) + { + return MakeProperty(_names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.NotRelevant), Type(), + _names.GetCodeIdentifier(field).ToString(), + readName, + nameof(Capnp.SerializerExtensions.WriteData), + field.BitOffset.Value, + ValueOf(field.DefaultValue.ScalarValue), + true, + field.DiscValue.HasValue, + true); + } + + PropertyDeclarationSyntax MakeTextProperty(Field field) + { + return MakeProperty(Type(), null, + _names.GetCodeIdentifier(field).ToString(), + nameof(Capnp.SerializerState.ReadText), + nameof(Capnp.SerializerState.WriteText), + (int)field.Offset, + ValueOf(field.DefaultValue.ScalarValue), + false, + field.DiscValue.HasValue, + false); + } + + PropertyDeclarationSyntax MakeStructProperty(Field field) + { + var qtype = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Writer); + + return MakePointerAsStructProperty(qtype, _names.GetCodeIdentifier(field).ToString(), + (int)field.Offset, false, field.DiscValue.HasValue); + } + + PropertyDeclarationSyntax MakeGroupProperty(Field field) + { + var type = QualifiedName( + _names.MakeTypeName(field.Type.Definition).IdentifierName, + _names.WriterStruct.IdentifierName); + + var getter = InvocationExpression( + GenericName(nameof(Capnp.SerializerState.Rewrap)) + .AddTypeArgumentListArguments(type)); + + return MakeWriterProperty(type, _names.GetCodeIdentifier(field).ToString(), getter, null, false, field.DiscValue.HasValue); + } + + PropertyDeclarationSyntax MakeListProperty(Field field) + { + var qtype = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Writer); + + return MakePointerProperty(qtype, _names.GetCodeIdentifier(field).ToString(), + (int)field.Offset, false, field.DiscValue.HasValue); + } + + PropertyDeclarationSyntax MakePointerProperty(Field field) + { + var type = IdentifierName(nameof(Capnp.DynamicSerializerState)); + + return MakePointerProperty(type, _names.GetCodeIdentifier(field).ToString(), (int)field.Offset, false, field.DiscValue.HasValue); + } + + PropertyDeclarationSyntax MakeCapProperty(Field field) + { + var type = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Writer); + int index = (int)field.Offset; + string name = _names.GetCodeIdentifier(field).ToString(); + ExpressionSyntax getter = MakeReadCapSyntax(type, index); + ExpressionSyntax setter = MakeLinkObjectSyntax(index); + + return MakeWriterProperty(type, name, getter, setter, false, field.DiscValue.HasValue); + } + + PropertyDeclarationSyntax MakeWriterUnionSelector(TypeDefinition def) + { + return MakeProperty( + _names.UnionDiscriminatorEnum.IdentifierName, + Type(), + _names.UnionDiscriminatorProp.ToString(), + nameof(Capnp.SerializerExtensions.ReadDataUShort), + nameof(Capnp.SerializerExtensions.WriteData), + def.UnionInfo.TagOffset, + ValueOf(default(ushort)), + true, false, true); + } + + PropertyDeclarationSyntax MakeWriterFieldProperty(Field field) + { + switch (field.Type.Tag) + { + case TypeTag.Bool: + return MakePrimitiveProperty(field, + nameof(Capnp.SerializerExtensions.ReadDataBool)); + + case TypeTag.S8: + return MakePrimitiveProperty(field, + nameof(Capnp.SerializerExtensions.ReadDataSByte)); + + case TypeTag.U8: + return MakePrimitiveProperty(field, + nameof(Capnp.SerializerExtensions.ReadDataByte)); + + case TypeTag.S16: + return MakePrimitiveProperty(field, + nameof(Capnp.SerializerExtensions.ReadDataShort)); + + case TypeTag.U16: + return MakePrimitiveProperty(field, + nameof(Capnp.SerializerExtensions.ReadDataUShort)); + + case TypeTag.S32: + return MakePrimitiveProperty(field, + nameof(Capnp.SerializerExtensions.ReadDataInt)); + + case TypeTag.U32: + return MakePrimitiveProperty(field, + nameof(Capnp.SerializerExtensions.ReadDataUInt)); + + case TypeTag.S64: + return MakePrimitiveProperty(field, + nameof(Capnp.SerializerExtensions.ReadDataLong)); + + case TypeTag.U64: + return MakePrimitiveProperty(field, + nameof(Capnp.SerializerExtensions.ReadDataULong)); + + case TypeTag.F32: + return MakePrimitiveProperty(field, + nameof(Capnp.SerializerExtensions.ReadDataFloat)); + + case TypeTag.F64: + return MakePrimitiveProperty(field, + nameof(Capnp.SerializerExtensions.ReadDataDouble)); + + case TypeTag.Enum: + return MakeEnumProperty(field, nameof(Capnp.SerializerExtensions.ReadDataUShort)); + + case TypeTag.Text: + return MakeTextProperty(field); + + case TypeTag.Struct: + return MakeStructProperty(field); + + case TypeTag.Group: + return MakeGroupProperty(field); + + case TypeTag.List: + case TypeTag.Data: + return MakeListProperty(field); + + case TypeTag.AnyPointer: + case TypeTag.StructPointer: + case TypeTag.ListPointer: + return MakePointerProperty(field); + + case TypeTag.CapabilityPointer: + case TypeTag.Interface: + return MakeCapProperty(field); + + default: + return null; + } + } + + public ClassDeclarationSyntax MakeWriterStruct(TypeDefinition def) + { + var WriterDecl = ClassDeclaration(_names.WriterStruct.ToString()) + .AddModifiers(Public) + .AddBaseListTypes( + SimpleBaseType(IdentifierName(nameof(Capnp.SerializerState)))); + + var members = def.Tag == TypeTag.Group ? + MakeGroupWriterStructMembers() : + MakeWriterStructMembers(def); + + WriterDecl = WriterDecl.AddMembers(members.ToArray()); + + if (def.UnionInfo != null) + { + WriterDecl = WriterDecl.AddMembers(MakeWriterUnionSelector(def)); + } + + foreach (var field in def.Fields) + { + var propDecl = MakeWriterFieldProperty(field); + + if (propDecl != null) + { + WriterDecl = WriterDecl.AddMembers(propDecl); + } + } + + return WriterDecl; + } + } +} diff --git a/CapnpC.CSharp.Generator/FileGenerationResult.cs b/CapnpC.CSharp.Generator/FileGenerationResult.cs new file mode 100644 index 0000000..6d035e0 --- /dev/null +++ b/CapnpC.CSharp.Generator/FileGenerationResult.cs @@ -0,0 +1,52 @@ +using System; + +namespace CapnpC.CSharp.Generator +{ + /// + /// Represents the generation result of a single .capnp file + /// + public class FileGenerationResult + { + /// + /// Constructs an instance in case of successful generation + /// + /// path to .capnp file + /// generated C# code + public FileGenerationResult(string capnpFilePath, string generatedContent) + { + CapnpFilePath = capnpFilePath; + GeneratedContent = generatedContent; + } + + /// + /// Constructs an instance in case of unsuccessful generation + /// + /// path to .capnp file + /// Exception giving details on the error which prevented generation + public FileGenerationResult(string capnpFilePath, Exception exception) + { + CapnpFilePath = capnpFilePath; + Exception = exception; + } + + /// + /// Path to .capnp file + /// + public string CapnpFilePath { get; } + + /// + /// Generated C# or null if generation failed + /// + public string GeneratedContent { get; } + + /// + /// Exception giving details on the error which prevented generation + /// + public Exception Exception { get; } + + /// + /// true iff generation was successful + /// + public bool IsSuccess => !string.IsNullOrEmpty(GeneratedContent); + } +} diff --git a/CapnpC.CSharp.Generator/GenerationResult.cs b/CapnpC.CSharp.Generator/GenerationResult.cs new file mode 100644 index 0000000..3f40fc5 --- /dev/null +++ b/CapnpC.CSharp.Generator/GenerationResult.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; + +namespace CapnpC.CSharp.Generator +{ + /// + /// Represents a .capnp -> code generator result + /// + public class GenerationResult + { + /// + /// Constructs an instance in case of at least partially successful generation. + /// + /// Generation result per file to generate + public GenerationResult(IReadOnlyList generatedFiles) + { + GeneratedFiles = generatedFiles; + } + + /// + /// Constructs an instance in case of total failure. + /// + /// Exception with details on error + public GenerationResult(Exception exception) + { + Exception = exception; + } + + /// + /// Generation result per file to generate or null in case of total failure + /// + public IReadOnlyList GeneratedFiles { get; } + + /// + /// Exception with details on error or null in case of success + /// + public Exception Exception { get; } + + /// + /// true iff generation was successful + /// + public bool IsSuccess => GeneratedFiles != null; + } +} diff --git a/CapnpC.CSharp.Generator/Model/AbstractType.cs b/CapnpC.CSharp.Generator/Model/AbstractType.cs new file mode 100644 index 0000000..6b6d4c7 --- /dev/null +++ b/CapnpC.CSharp.Generator/Model/AbstractType.cs @@ -0,0 +1,45 @@ +using System.Collections.Generic; + +namespace CapnpC.CSharp.Generator.Model +{ + abstract class AbstractType + { + public TypeTag Tag { get; set; } + protected List Fields { get; } = new List(); + + public uint? FixedBitWidth + { + get + { + switch (Tag) + { + case TypeTag.Bool: + return 1; + + case TypeTag.U8: + case TypeTag.S8: + return 8; + + case TypeTag.U16: + case TypeTag.S16: + case TypeTag.Enum: + case TypeTag.AnyEnum: + return 16; + + case TypeTag.U32: + case TypeTag.S32: + case TypeTag.F32: + return 32; + + case TypeTag.U64: + case TypeTag.S64: + case TypeTag.F64: + return 64; + + default: + return null; + } + } + } + } +} diff --git a/CapnpC.CSharp.Generator/Model/Annotation.cs b/CapnpC.CSharp.Generator/Model/Annotation.cs new file mode 100644 index 0000000..8b5d40b --- /dev/null +++ b/CapnpC.CSharp.Generator/Model/Annotation.cs @@ -0,0 +1,23 @@ +using System.Diagnostics; + +namespace CapnpC.CSharp.Generator.Model +{ + class Annotation : IDefinition + { + public ulong Id { get; } + public bool IsGenerated { get; } + public TypeTag Tag { get => TypeTag.Annotation; } + public IHasNestedDefinitions DeclaringElement { get; } + + public Type Type { get; set; } + + public Annotation(ulong id, IHasNestedDefinitions parent) + { + Trace.Assert(parent != null); + Id = id; + IsGenerated = (parent as IDefinition).IsGenerated; + DeclaringElement = parent; + parent.NestedDefinitions.Add(this); + } + } +} diff --git a/CapnpC.CSharp.Generator/Model/Constant.cs b/CapnpC.CSharp.Generator/Model/Constant.cs new file mode 100644 index 0000000..a01ac7d --- /dev/null +++ b/CapnpC.CSharp.Generator/Model/Constant.cs @@ -0,0 +1,23 @@ +using System.Diagnostics; + +namespace CapnpC.CSharp.Generator.Model +{ + class Constant : IDefinition + { + public ulong Id { get; } + public bool IsGenerated { get; } + public TypeTag Tag { get => TypeTag.Const; } + public IHasNestedDefinitions DeclaringElement { get; } + + public Value Value { get; set; } + + public Constant(ulong id, IHasNestedDefinitions parent) + { + Trace.Assert(parent != null); + Id = id; + IsGenerated = (parent as IDefinition).IsGenerated; + DeclaringElement = parent; + parent.NestedDefinitions.Add(this); + } + } +} diff --git a/CapnpC.CSharp.Generator/Model/DefinitionManager.cs b/CapnpC.CSharp.Generator/Model/DefinitionManager.cs new file mode 100644 index 0000000..bd638f7 --- /dev/null +++ b/CapnpC.CSharp.Generator/Model/DefinitionManager.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace CapnpC.CSharp.Generator.Model +{ + class DefinitionManager + { + readonly Dictionary _id2def = new Dictionary(); + + public GenFile CreateFile(ulong id, bool isGenerated) + => CreateId(id, () => new GenFile(id, isGenerated)); + public GenFile GetExistingFile(ulong id) + => GetId(id, TypeTag.File); + + public TypeDefinition CreateTypeDef(ulong id, TypeTag tag, IHasNestedDefinitions decl) + => CreateId(id, () => new TypeDefinition(tag, id, decl)); + public TypeDefinition GetExistingTypeDef(ulong id, TypeTag tag) + { + var def = GetId(id, tag); + if (def.Tag == TypeTag.Unknown) def.Tag = tag; + return def; + } + + public Annotation CreateAnnotation(ulong id, IHasNestedDefinitions decl) + => CreateId(id, () => new Annotation(id, decl)); + public Annotation GetExistingAnnotation(ulong id) + => GetId(id, TypeTag.Annotation); + + public Constant CreateConstant(ulong id, IHasNestedDefinitions decl) + => CreateId(id, () => new Constant(id, decl)); + public Constant GetExistingConstant(ulong id) + => GetId(id, TypeTag.Const); + + public IDefinition GetExistingDef(ulong id, TypeTag tag) + => GetId(id, tag); + + public IEnumerable Files + { + get => _id2def.Values.Where(d => d.Tag == TypeTag.File).Select(f => f as GenFile); + } + + T CreateId(ulong id, Func creator) where T : class, IDefinition + { + if (_id2def.TryGetValue(id, out var d)) + { + throw new ArgumentException(nameof(id), $"Attempting to redefine {d.Tag.ToString()} {id.StrId()} (as {nameof(T)})."); + } + var def = creator(); + _id2def.Add(id, def); + return def as T; + } + + T GetId(ulong id, TypeTag tag) where T : IDefinition + { + if (!_id2def.TryGetValue(id, out var anyDef)) + { + throw new ArgumentOutOfRangeException($"Attempting to retrieve nonexistent node {id.StrId()}."); + } + if (!(anyDef is T def) || (tag != TypeTag.Unknown && def.Tag != tag)) + { + throw new ArgumentOutOfRangeException($"Attempting to retrieve {tag.ToString()} {id.StrId()}, but found {anyDef.Tag.ToString()} instead."); + } + return def; + } + } +} diff --git a/CapnpC.CSharp.Generator/Model/Enumerant.cs b/CapnpC.CSharp.Generator/Model/Enumerant.cs new file mode 100644 index 0000000..4ba17f6 --- /dev/null +++ b/CapnpC.CSharp.Generator/Model/Enumerant.cs @@ -0,0 +1,14 @@ +namespace CapnpC.CSharp.Generator.Model +{ + class Enumerant + { + string _literal; + public TypeDefinition TypeDefinition { get; set; } + public string Literal { + get => _literal; + set => _literal = IdentifierRenamer.ToNonKeyword(value); + } + public ushort? Ordinal { get; set; } + public int CodeOrder { get; set; } + } +} diff --git a/CapnpC.CSharp.Generator/Model/Field.cs b/CapnpC.CSharp.Generator/Model/Field.cs new file mode 100644 index 0000000..017112c --- /dev/null +++ b/CapnpC.CSharp.Generator/Model/Field.cs @@ -0,0 +1,52 @@ +namespace CapnpC.CSharp.Generator.Model +{ + class Field + { + public TypeDefinition DeclaringType { get; set; } + public Field Parent { get; set; } + public string Name { get; set; } + public Type Type { get; set; } + public Value DefaultValue { get; set; } + public bool DefaultValueIsExplicit { get; set; } + public ushort? DiscValue { get; set; } + public uint Offset { get; set; } + public int CodeOrder { get; set; } + + public ulong? BitOffset => (ulong)Offset * Type?.FixedBitWidth; + + public Field Clone() + { + var field = new Field() + { + DeclaringType = DeclaringType, + Parent = Parent, + Name = Name, + Type = Type, + DefaultValue = DefaultValue, + DefaultValueIsExplicit = DefaultValueIsExplicit, + DiscValue = DiscValue, + Offset = Offset, + CodeOrder = CodeOrder, + }; + field.InheritFreeGenericParameters(); + return field; + } + + public void InheritFreeGenericParameters() + { + Type.InheritFreeParameters(DeclaringType); + } + + public override bool Equals(object obj) + { + return obj is Field other && + DeclaringType == other.DeclaringType && + Name == other.Name; + } + + public override int GetHashCode() + { + return (DeclaringType, Name).GetHashCode(); + } + } +} diff --git a/CapnpC.CSharp.Generator/Model/GenFile.cs b/CapnpC.CSharp.Generator/Model/GenFile.cs new file mode 100644 index 0000000..217a760 --- /dev/null +++ b/CapnpC.CSharp.Generator/Model/GenFile.cs @@ -0,0 +1,25 @@ +using System.Collections.Generic; + +namespace CapnpC.CSharp.Generator.Model +{ + class GenFile: IDefinition, IHasNestedDefinitions + { + public ulong Id { get; } + public bool IsGenerated { get; } + public TypeTag Tag { get => TypeTag.File; } + public IHasNestedDefinitions DeclaringElement { get => null; } + + public string Name { get; set; } + public string[] Namespace { get; set; } + + public IEnumerable NestedTypes { get => this.GetNestedTypes(); } + public ICollection NestedDefinitions { get; } = new List(); + public ICollection Constants { get; } = new List(); + + public GenFile(ulong id, bool isGenerated) + { + Id = id; + IsGenerated = isGenerated; + } + } +} diff --git a/CapnpC.CSharp.Generator/Model/GenericParameter.cs b/CapnpC.CSharp.Generator/Model/GenericParameter.cs new file mode 100644 index 0000000..eaca7b9 --- /dev/null +++ b/CapnpC.CSharp.Generator/Model/GenericParameter.cs @@ -0,0 +1,26 @@ +namespace CapnpC.CSharp.Generator.Model +{ + class GenericParameter + { + public IHasGenericParameters DeclaringEntity { get; set; } + public int Index { get; set; } + public string Name => DeclaringEntity.GenericParameters[Index]; + + public override bool Equals(object obj) + { + // Instead of equality by Name, we could instead take (DeclaringEntity, Index), but there is a caveat: + // Since methods can also own generic parameters, we have different classes of declaring entities involved. + // Both the method will define generic parameters, and the Cap'n'p-generated params/result structs. + // Therefore we end in two GenericParameter instances, one with the Method as declaring entity, the + // other one with the params/result type definition as declaring entity. They are semantically the same, + // and the easy way to match them is by Name. Equality by Name is the only working choice, even though + // it feels a little less reboust than by matching declaring entity + parameter position. + return obj is GenericParameter other && Name == other.Name; + } + + public override int GetHashCode() + { + return Name.GetHashCode(); + } + } +} diff --git a/CapnpC.CSharp.Generator/Model/HasGenericParameters.cs b/CapnpC.CSharp.Generator/Model/HasGenericParameters.cs new file mode 100644 index 0000000..55531b0 --- /dev/null +++ b/CapnpC.CSharp.Generator/Model/HasGenericParameters.cs @@ -0,0 +1,19 @@ +using System.Collections.Generic; + +namespace CapnpC.CSharp.Generator.Model +{ + static class HasGenericParameters + { + public static IEnumerable GetLocalTypeParameters(this IHasGenericParameters me) + { + for (int i = 0; i < me.GenericParameters.Count; i++) + { + yield return new GenericParameter() + { + DeclaringEntity = me, + Index = i + }; + } + } + } +} diff --git a/CapnpC.CSharp.Generator/Model/IDefinition.cs b/CapnpC.CSharp.Generator/Model/IDefinition.cs new file mode 100644 index 0000000..70b8501 --- /dev/null +++ b/CapnpC.CSharp.Generator/Model/IDefinition.cs @@ -0,0 +1,11 @@ + +namespace CapnpC.CSharp.Generator.Model +{ + interface IDefinition + { + ulong Id { get; } + bool IsGenerated { get; } + TypeTag Tag { get; } + IHasNestedDefinitions DeclaringElement { get; } + } +} diff --git a/CapnpC.CSharp.Generator/Model/IHasGenericParameters.cs b/CapnpC.CSharp.Generator/Model/IHasGenericParameters.cs new file mode 100644 index 0000000..fa71f35 --- /dev/null +++ b/CapnpC.CSharp.Generator/Model/IHasGenericParameters.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace CapnpC.CSharp.Generator.Model +{ + interface IHasGenericParameters + { + List GenericParameters { get; } + } +} diff --git a/CapnpC.CSharp.Generator/Model/IHasNestedDefinitions.cs b/CapnpC.CSharp.Generator/Model/IHasNestedDefinitions.cs new file mode 100644 index 0000000..06051c8 --- /dev/null +++ b/CapnpC.CSharp.Generator/Model/IHasNestedDefinitions.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; +using System.Linq; + +namespace CapnpC.CSharp.Generator.Model +{ + interface IHasNestedDefinitions + { + IEnumerable NestedTypes { get; } + ICollection NestedDefinitions { get; } + ICollection Constants { get; } + } + + static partial class Extensions + { + public static IEnumerable GetNestedTypes(this IHasNestedDefinitions def) + => def.NestedDefinitions.Select(d => d as TypeDefinition).Where(d => d != null); + } +} diff --git a/CapnpC.CSharp.Generator/Model/IdentifierRenamer.cs b/CapnpC.CSharp.Generator/Model/IdentifierRenamer.cs new file mode 100644 index 0000000..0c0a6b5 --- /dev/null +++ b/CapnpC.CSharp.Generator/Model/IdentifierRenamer.cs @@ -0,0 +1,22 @@ +using Microsoft.CodeAnalysis.CSharp; +using System; +using System.Collections.Generic; +using System.Text; + +namespace CapnpC.CSharp.Generator.Model +{ + public class IdentifierRenamer + { + public static bool IsAnyKeyword(string str) + { + return SyntaxFacts.GetKeywordKind(str) != SyntaxKind.None + || SyntaxFacts.GetContextualKeywordKind(str) != SyntaxKind.None; + } + public static string ToNonKeyword(string str) + { + // Capnp schema identifiers should be already valid, but could be a keyword + if (IsAnyKeyword(str)) return $"@{str}"; + return str; + } + } +} diff --git a/CapnpC.CSharp.Generator/Model/InvalidSchemaException.cs b/CapnpC.CSharp.Generator/Model/InvalidSchemaException.cs new file mode 100644 index 0000000..839119f --- /dev/null +++ b/CapnpC.CSharp.Generator/Model/InvalidSchemaException.cs @@ -0,0 +1,11 @@ +using System; + +namespace CapnpC.CSharp.Generator.Model +{ + class InvalidSchemaException : Exception + { + public InvalidSchemaException(string message) : base(message) + { + } + } +} diff --git a/CapnpC.CSharp.Generator/Model/Method.cs b/CapnpC.CSharp.Generator/Model/Method.cs new file mode 100644 index 0000000..1d1ba7b --- /dev/null +++ b/CapnpC.CSharp.Generator/Model/Method.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; + +namespace CapnpC.CSharp.Generator.Model +{ + class Method: IHasGenericParameters + { + public TypeDefinition DeclaringInterface { get; set; } + public int Id { get; set; } + public string Name { get; set; } + public List Params { get; } = new List(); + public List Results { get; } = new List(); + public Type ParamsStruct { get; set; } + public Type ResultStruct { get; set; } + public List GenericParameters { get; } = new List(); + } +} diff --git a/CapnpC.CSharp.Generator/Model/SchemaModel.cs b/CapnpC.CSharp.Generator/Model/SchemaModel.cs new file mode 100644 index 0000000..9d9e223 --- /dev/null +++ b/CapnpC.CSharp.Generator/Model/SchemaModel.cs @@ -0,0 +1,783 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; + +namespace CapnpC.CSharp.Generator.Model +{ + class SchemaModel + { + readonly Schema.CodeGeneratorRequest.Reader _request; + readonly List _generatedFiles = new List(); + readonly DefinitionManager _typeDefMgr = new DefinitionManager(); + + readonly Dictionary _id2node = new Dictionary(); + + public SchemaModel(Schema.CodeGeneratorRequest.Reader request) + { + _request = request; + } + + public IReadOnlyList FilesToGenerate => _generatedFiles; + + Schema.Node.Reader? IdToNode(ulong id, bool mustExist) + { + if (_id2node.TryGetValue(id, out var node)) + return node; + if (mustExist) + throw new InvalidSchemaException($"Node with ID {id.StrId()} is required by the codegen backend but is missing."); + return null; + } + + Schema.Node.Reader IdToNode(ulong id) + { + return (Schema.Node.Reader)IdToNode(id, true); + } + + void Build() + { + if (_request.Nodes == null || _request.Nodes.Count == 0) + { + throw new InvalidSchemaException("No nodes, nothing to generate"); + } + + foreach (var node in _request.Nodes) + { + if (_id2node.TryGetValue(node.Id, out var existingNode)) + { + throw new InvalidSchemaException($"Node {node.StrId()} \"{node.DisplayName}\" has a duplicate ID, prior node was \"{existingNode.DisplayName}\""); + } + _id2node[node.Id] = node; + } + + var requestedFiles = _request.RequestedFiles.ToDictionary(req => req.Id); + BuildPass1(requestedFiles); + BuildPass2(requestedFiles); + } + + // First pass: create type definitions for each node. + + struct Pass1State + { + public HashSet unprocessedNodes; + public IHasNestedDefinitions parent; + } + + void BuildPass1(Dictionary requestedFiles) + { + Pass1State state = new Pass1State() + { + unprocessedNodes = new HashSet(_id2node.Keys) + }; + foreach (var node in _id2node.Values.Where(n => n.IsFile)) + { + GenFile file; + bool isGenerated = requestedFiles.TryGetValue(node.Id, out var req); + var filename = isGenerated ? req.Filename : node.DisplayName; + file = ProcessFilePass1(node.Id, filename, state, isGenerated); + if (isGenerated) + _generatedFiles.Add(file); + } + if (state.unprocessedNodes.Count != 0) + { + throw new InvalidSchemaException("Unreferenced nodes were present in the schema."); + } + } + + GenFile ProcessFilePass1(ulong id, string name, Pass1State state, bool isGenerated) + { + var file = _typeDefMgr.CreateFile(id, isGenerated); + var node = IdToNode(id); + state.parent = null; + file.Namespace = GetNamespaceAnnotation(node); + file.Name = name; + return ProcessNodePass1(id, name, state) as GenFile; + } + + IDefinition ProcessNodePass1(ulong id, string name, Pass1State state) + { + bool mustExist = state.parent == null || (state.parent as IDefinition).IsGenerated; + if (!(IdToNode(id, mustExist) is Schema.Node.Reader node)) + return null; + if (!state.unprocessedNodes.Remove(id)) + return null; + + IDefinition def = null; + bool processNestedNodes = false; + bool processFields = false; + bool processInterfaceMethods = false; + + switch (node.GetKind()) + { + case NodeKind.Annotation: + return _typeDefMgr.CreateAnnotation(id, state.parent); + case NodeKind.Const: + return _typeDefMgr.CreateConstant(id, state.parent); + case NodeKind.File: + if (state.parent != null) + throw new InvalidSchemaException($"Did not expect a file node {node.StrId()} to be a nested node."); + var file = _typeDefMgr.GetExistingFile(id); + file.Namespace = GetNamespaceAnnotation(node); + file.Name = name; + state.parent = file; + def = file; + processNestedNodes = true; + break; + case NodeKind.Enum: + break; + case NodeKind.Interface: + processNestedNodes = true; + processFields = true; + processInterfaceMethods = true; + break; + case NodeKind.Struct: + case NodeKind.Group: + processNestedNodes = true; + processFields = true; + break; + default: + throw new InvalidSchemaException($"Don't know how to process node {node.StrId()} \"{node.DisplayName}\""); + } + + if (def == null) + { + Trace.Assert(state.parent != null, $"The {node.GetTypeTag().ToString()} node {node.StrId()} was expected to have a parent."); + var typeDef = _typeDefMgr.CreateTypeDef(id, node.GetTypeTag(), state.parent); + typeDef.Name = name; + state.parent = typeDef; + def = typeDef; + } + + if (processNestedNodes && node.NestedNodes != null) + foreach (var nested in node.NestedNodes) + { + ProcessNodePass1(nested.Id, nested.Name, state); + } + if (processFields && node.Fields != null) + foreach (var field in node.Fields.Where(f => f.IsGroup)) + { + var group = IdToNode(field.Group_TypeId); + if (!group.IsStruct || !group.Struct_IsGroup) + { + throw new InvalidSchemaException($"Expected node with id {group.StrId()} to be a struct definition"); + } + ProcessNodePass1(field.Group_TypeId, field.Name, state); + } + if (processInterfaceMethods && node.Interface_Methods != null) + foreach (var method in node.Interface_Methods) + { + var pnode = IdToNode(method.ParamStructType); + if (pnode.ScopeId == 0) ProcessNodePass1(pnode.Id, null, state); // Anonymous generated type + pnode = IdToNode(method.ResultStructType); + if (pnode.ScopeId == 0) ProcessNodePass1(pnode.Id, null, state); // Anonymous generated type + } + return def; + } + + string[] GetNamespaceAnnotation(Schema.Node.Reader fileNode) + { + foreach (var annotation in fileNode.Annotations) + { + if (annotation.Id == 0xb9c6f99ebf805f2c) // Cxx namespace + { + return annotation.Value.Text.Split(new string[1] { "::" }, default); + } + } + return null; + } + + // 2nd pass: Generate types based on definitions + + struct Pass2State + { + public Method currentMethod; + public HashSet processedNodes; + } + + void BuildPass2(Dictionary requestedFiles) + { + var state = new Pass2State() { processedNodes = new HashSet() }; + foreach (var file in _typeDefMgr.Files) + { + var node = IdToNode(file.Id); + ProcessNestedNodes(node.NestedNodes, state, file.IsGenerated); + } + } + + void ProcessNestedNodes(IEnumerable nestedNodes, Pass2State state, bool mustExist) + { + foreach (var nestedNode in nestedNodes) + { + ProcessNode(nestedNode.Id, state, mustExist); + } + } + + void ProcessBrand(Schema.Brand.Reader brandReader, Type type, Pass2State state) + { + foreach (var scopeReader in brandReader.Scopes) + { + var whatToBind = ProcessTypeDef(scopeReader.ScopeId, state); + int index = 0; + + switch (0) + { + case 0 when scopeReader.IsBind: + foreach (var bindingReader in scopeReader.Bind) + { + var typeParameter = new GenericParameter() + { + DeclaringEntity = whatToBind, + Index = index++ + }; + + switch (0) + { + case 0 when bindingReader.IsType: + type.BindGenericParameter(typeParameter, ProcessType(bindingReader.Type, state)); + break; + + case 0 when bindingReader.IsUnbound: + type.BindGenericParameter(typeParameter, Types.FromParameter(typeParameter)); + break; + } + } + break; + + case 0 when scopeReader.IsInherit: + for (index = 0; index < type.DeclaringType.Definition.GenericParameters.Count; index++) + { + var typeParameter = new GenericParameter() + { + DeclaringEntity = whatToBind, + Index = index + }; + + type.BindGenericParameter(typeParameter, Types.FromParameter(typeParameter)); + } + break; + } + } + } + + Type ProcessType(Schema.Type.Reader typeReader, Pass2State state) + { + Type result; + + switch (0) + { + case 0 when typeReader.IsAnyPointer: + switch (0) + { + case 0 when typeReader.AnyPointer_IsParameter: + return Types.FromParameter( + new GenericParameter() + { + DeclaringEntity = ProcessTypeDef(typeReader.AnyPointer_Parameter_ScopeId, state), + Index = typeReader.AnyPointer_Parameter_ParameterIndex + }); + + case 0 when typeReader.AnyPointer_IsImplicitMethodParameter: + return Types.FromParameter( + new GenericParameter() + { + DeclaringEntity = state.currentMethod ?? throw new InvalidOperationException("current method not set"), + Index = typeReader.AnyPointer_ImplicitMethodParameter_ParameterIndex + }); + + case 0 when typeReader.AnyPointer_IsUnconstrained: + + switch (0) + { + case 0 when typeReader.AnyPointer_Unconstrained_IsAnyKind: + return Types.AnyPointer; + + case 0 when typeReader.AnyPointer_Unconstrained_IsCapability: + return Types.CapabilityPointer; + + case 0 when typeReader.AnyPointer_Unconstrained_IsList: + return Types.ListPointer; + + case 0 when typeReader.AnyPointer_Unconstrained_IsStruct: + return Types.StructPointer; + + default: + throw new NotImplementedException(); + } + + default: + throw new NotImplementedException(); + } + + case 0 when typeReader.IsBool: + return Types.Bool; + + case 0 when typeReader.IsData: + return Types.Data; + + case 0 when typeReader.IsFloat64: + return Types.F64; + + case 0 when typeReader.IsEnum: + return Types.FromDefinition(ProcessTypeDef(typeReader.Enum_TypeId, state, TypeTag.Enum)); + + case 0 when typeReader.IsFloat32: + return Types.F32; + + case 0 when typeReader.IsInt16: + return Types.S16; + + case 0 when typeReader.IsInt32: + return Types.S32; + + case 0 when typeReader.IsInt64: + return Types.S64; + + case 0 when typeReader.IsInt8: + return Types.S8; + + case 0 when typeReader.IsInterface: + result = Types.FromDefinition(ProcessTypeDef(typeReader.Interface_TypeId, state, TypeTag.Interface)); + ProcessBrand(typeReader.Interface_Brand, result, state); + return result; + + case 0 when typeReader.IsList: + return Types.List(ProcessType(typeReader.List_ElementType, state)); + + case 0 when typeReader.IsStruct: + result = Types.FromDefinition(ProcessTypeDef(typeReader.Struct_TypeId, state, TypeTag.Struct)); + ProcessBrand(typeReader.Struct_Brand, result, state); + return result; + + case 0 when typeReader.IsText: + return Types.Text; + + case 0 when typeReader.IsUInt16: + return Types.U16; + + case 0 when typeReader.IsUInt32: + return Types.U32; + + case 0 when typeReader.IsUInt64: + return Types.U64; + + case 0 when typeReader.IsUInt8: + return Types.U8; + + case 0 when typeReader.IsVoid: + return Types.Void; + + default: + throw new NotImplementedException(); + } + } + + Value ProcessValue(Schema.Value.Reader valueReader) + { + var value = new Value(); + + switch (0) + { + case 0 when valueReader.IsAnyPointer: + value.ScalarValue = valueReader.AnyPointer; + value.Type = Types.AnyPointer; + break; + + case 0 when valueReader.IsBool: + value.ScalarValue = valueReader.Bool; + value.Type = Types.Bool; + break; + + case 0 when valueReader.IsData: + value.Items.AddRange(valueReader.Data.CastByte().Select(Value.Scalar)); + value.Type = Types.Data; + break; + + case 0 when valueReader.IsEnum: + value.ScalarValue = valueReader.Enum; + value.Type = Types.AnyEnum; + break; + + case 0 when valueReader.IsFloat32: + value.ScalarValue = valueReader.Float32; + value.Type = Types.F32; + break; + + case 0 when valueReader.IsFloat64: + value.ScalarValue = valueReader.Float64; + value.Type = Types.F64; + break; + + case 0 when valueReader.IsInt16: + value.ScalarValue = valueReader.Int16; + value.Type = Types.S16; + break; + + case 0 when valueReader.IsInt32: + value.ScalarValue = valueReader.Int32; + value.Type = Types.S32; + break; + + case 0 when valueReader.IsInt64: + value.ScalarValue = valueReader.Int64; + value.Type = Types.S64; + break; + + case 0 when valueReader.IsInt8: + value.ScalarValue = valueReader.Int8; + value.Type = Types.S8; + break; + + case 0 when valueReader.IsInterface: + value.ScalarValue = null; + value.Type = Types.CapabilityPointer; + break; + + case 0 when valueReader.IsList: + value.RawValue = valueReader.List; + value.Type = Types.ListPointer; + break; + + case 0 when valueReader.IsStruct: + value.RawValue = valueReader.Struct; + value.Type = Types.StructPointer; + break; + + case 0 when valueReader.IsText: + value.ScalarValue = valueReader.Text; + value.Type = Types.Text; + break; + + case 0 when valueReader.IsUInt16: + value.ScalarValue = valueReader.UInt16; + value.Type = Types.U16; + break; + + case 0 when valueReader.IsUInt32: + value.ScalarValue = valueReader.UInt32; + value.Type = Types.U32; + break; + + case 0 when valueReader.IsUInt64: + value.ScalarValue = valueReader.UInt64; + value.Type = Types.U64; + break; + + case 0 when valueReader.IsUInt8: + value.ScalarValue = valueReader.UInt8; + value.Type = Types.U8; + break; + + case 0 when valueReader.IsVoid: + value.Type = Types.Void; + break; + + default: + throw new NotImplementedException(); + } + + return value; + } + + void ProcessFields(Schema.Node.Reader reader, TypeDefinition declaringType, List fields, Pass2State state) + { + if (reader.Fields == null) + { + return; + } + + foreach (var fieldReader in reader.Fields) + { + var field = new Field() + { + DeclaringType = declaringType, + Name = fieldReader.Name, + CodeOrder = fieldReader.CodeOrder + }; + + if (fieldReader.DiscriminantValue != Schema.Field.Reader.NoDiscriminant) + { + field.DiscValue = fieldReader.DiscriminantValue; + } + + switch (0) + { + case 0 when fieldReader.IsGroup: + var def = ProcessTypeDef(fieldReader.Group_TypeId, state, TypeTag.Group); + field.Type = Types.FromDefinition(def); + break; + + case 0 when fieldReader.IsSlot: + field.DefaultValue = ProcessValue(fieldReader.Slot_DefaultValue); + field.DefaultValueIsExplicit = fieldReader.Slot_HadExplicitDefault; + field.Offset = fieldReader.Slot_Offset; + field.Type = ProcessType(fieldReader.Slot_Type, state); + field.DefaultValue.Type = field.Type; + break; + + default: + throw new NotImplementedException(); + } + + field.InheritFreeGenericParameters(); + + fields.Add(field); + } + } + + TypeDefinition ProcessInterfaceOrStructTail(TypeDefinition def, Schema.Node.Reader reader, Pass2State state) + { + def.IsGeneric = reader.IsGeneric; + + if (def.IsGeneric) + { + foreach (var paramReader in reader.Parameters) + { + def.GenericParameters.Add(paramReader.Name); + } + } + + ProcessNestedNodes(reader.NestedNodes, state, def.File.IsGenerated); + + ProcessFields(reader, def, def.Fields, state); + + if (reader.IsInterface) + { + foreach (var methodReader in reader.Interface_Methods) + { + var method = new Method() + { + DeclaringInterface = def, + Id = def.Methods.Count, + Name = methodReader.Name + }; + foreach (var implicitParameterReader in methodReader.ImplicitParameters) + { + method.GenericParameters.Add(implicitParameterReader.Name); + } + state.currentMethod = method; + + def.Methods.Add(method); + + var paramNode = IdToNode(methodReader.ParamStructType); + var paramType = ProcessParameterList(paramNode, methodReader.ParamBrand, method.Params, state); + if (paramType != null) + { + paramType.SpecialName = SpecialName.MethodParamsStruct; + paramType.UsingMethod = method; + method.ParamsStruct = Types.FromDefinition(paramType); + } + else + { + method.ParamsStruct = method.Params[0].Type; + } + method.ParamsStruct.InheritFreeParameters(def); + method.ParamsStruct.InheritFreeParameters(method); + + var resultNode = IdToNode(methodReader.ResultStructType); + var resultType = ProcessParameterList(resultNode, methodReader.ResultBrand, method.Results, state); + if (resultType != null) + { + resultType.SpecialName = SpecialName.MethodResultStruct; + resultType.UsingMethod = method; + method.ResultStruct = Types.FromDefinition(resultType); + } + else + { + method.ResultStruct = method.Results[0].Type; + } + method.ResultStruct.InheritFreeParameters(def); + method.ResultStruct.InheritFreeParameters(method); + } + + state.currentMethod = null; + } + return def; + } + + TypeDefinition ProcessStruct(Schema.Node.Reader structReader, TypeDefinition def, Pass2State state) + { + def.StructDataWordCount = structReader.Struct_DataWordCount; + def.StructPointerCount = structReader.Struct_PointerCount; + + if (structReader.Struct_DiscriminantCount > 0) + { + def.UnionInfo = new TypeDefinition.DiscriminationInfo( + structReader.Struct_DiscriminantCount, + 16u * structReader.Struct_DiscriminantOffset); + } + + return ProcessInterfaceOrStructTail(def, structReader, state); + } + + TypeDefinition ProcessParameterList(Schema.Node.Reader reader, Schema.Brand.Reader brandReader, List list, Pass2State state) + { +//# If a named parameter list was specified in the method +//# declaration (rather than a single struct parameter type) then a corresponding struct type is +//# auto-generated. Such an auto-generated type will not be listed in the interface's +//# `nestedNodes` and its `scopeId` will be zero -- it is completely detached from the namespace. +//# (Awkwardly, it does of course inherit generic parameters from the method's scope, which makes +//# this a situation where you can't just climb the scope chain to find where a particular +//# generic parameter was introduced. Making the `scopeId` zero was a mistake.) + + if (!reader.IsStruct) + { + throw new InvalidSchemaException("Expected a struct"); + } + + var def = ProcessTypeDef(reader.Id, state, TypeTag.Struct); + + if (reader.ScopeId == 0) + { + // Auto-generated => Named parameter list + foreach (var field in def.Fields) list.Add(field); + return def; + } + else + { + // Single, anonymous, struct-typed parameter + var type = Types.FromDefinition(def); + ProcessBrand(brandReader, type, state); + var anon = new Field() { Type = type }; + list.Add(anon); + return null; + } + } + + TypeDefinition ProcessInterface(Schema.Node.Reader ifaceReader, TypeDefinition def, Pass2State state) + { + foreach (var superClassReader in ifaceReader.Interface_Superclasses) + { + var superClass = ProcessTypeDef(superClassReader.Id, state, TypeTag.Interface); + def.Superclasses.Add(Types.FromDefinition(superClass)); + } + + return ProcessInterfaceOrStructTail(def, ifaceReader, state); + } + + TypeDefinition ProcessEnum(Schema.Node.Reader enumReader, TypeDefinition def, Pass2State state) + { + foreach (var fieldReader in enumReader.Enumerants) + { + var field = new Enumerant() + { + TypeDefinition = def, + Literal = fieldReader.Name, + CodeOrder = fieldReader.CodeOrder + }; + + if (fieldReader.Ordinal_IsExplicit) + { + field.Ordinal = fieldReader.Ordinal_Explicit; + } + + def.Enumerants.Add(field); + } + return def; + } + + Constant ProcessConst(Schema.Node.Reader constReader, Constant @const, Pass2State state) + { + var value = ProcessValue(constReader.Const_Value); + value.Type = ProcessType(constReader.Const_Type, state); + @const.Value = value; + return @const; + } + + TypeDefinition ProcessTypeDef(ulong id, Pass2State state, TypeTag tag = default) + { + var def = ProcessNode(id, state, true, tag); + var typeDef = def as TypeDefinition; + if (typeDef == null) + throw new ArgumentException( + $"Expected node {id.StrId()} to be a TypeDefinition but got {def.GetType().Name} instead.", + nameof(id)); + return typeDef; + } + + IDefinition ProcessNode(ulong id, Pass2State state, bool mustExist, TypeTag tag = default) + { + if (!(IdToNode(id, mustExist) is Schema.Node.Reader node)) return null; + var kind = node.GetKind(); + if (tag == TypeTag.Unknown) tag = kind.GetTypeTag(); + var def = _typeDefMgr.GetExistingDef(id, tag); + if (state.processedNodes.Contains(id)) return def; + state.processedNodes.Add(id); + + switch (def) + { + case Annotation annotation: + return annotation; + case Constant constant: + def.DeclaringElement.Constants.Add(ProcessConst(node, constant, state)); + return def; + case TypeDefinition typeDef when kind == NodeKind.Enum: + return ProcessEnum(node, typeDef, state); + case TypeDefinition typeDef when kind == NodeKind.Interface: + return ProcessInterface(node, typeDef, state); + case TypeDefinition typeDef when kind == NodeKind.Struct || kind == NodeKind.Group: + return ProcessStruct(node, typeDef, state); + default: + throw new InvalidProgramException($"An unexpected node {node.StrId()} was found during the 2nd schema model building pass."); + } + } + + public static SchemaModel Create(Schema.CodeGeneratorRequest.Reader request) + { + var model = new SchemaModel(request); + model.Build(); + return model; + } + } + + public enum NodeKind + { + Unknown, + Annotation, + Const, + Enum, + File, + Interface, + Struct, + Group + } + + public static class SchemaExtensions + { + public static string GetName(this Schema.Node.Reader node) + => node.DisplayName.Substring((int)node.DisplayNamePrefixLength); + + public static string StrId(this Schema.Node.Reader node) + => $"0x{node.Id:X}"; + + public static string StrId(this ulong nodeId) + => $"0x{nodeId:X}"; + + public static NodeKind GetKind(this Schema.Node.Reader node) + { + if (node.IsStruct) + return node.Struct_IsGroup ? NodeKind.Group : NodeKind.Struct; + if (node.IsInterface) return NodeKind.Interface; + if (node.IsEnum) return NodeKind.Enum; + if (node.IsConst) return NodeKind.Const; + if (node.IsAnnotation) return NodeKind.Annotation; + if (node.IsFile) return NodeKind.File; + return NodeKind.Unknown; + } + + internal static TypeTag GetTypeTag(this NodeKind kind) + { + switch (kind) + { + case NodeKind.Enum: return TypeTag.Enum; + case NodeKind.Interface: return TypeTag.Interface; + case NodeKind.Struct: return TypeTag.Struct; + case NodeKind.Group: return TypeTag.Group; + default: return TypeTag.Unknown; + } + } + + internal static TypeTag GetTypeTag(this Schema.Node.Reader node) + => node.GetKind().GetTypeTag(); + } +} diff --git a/CapnpC.CSharp.Generator/Model/SpecialName.cs b/CapnpC.CSharp.Generator/Model/SpecialName.cs new file mode 100644 index 0000000..86887ab --- /dev/null +++ b/CapnpC.CSharp.Generator/Model/SpecialName.cs @@ -0,0 +1,9 @@ +namespace CapnpC.CSharp.Generator.Model +{ + enum SpecialName + { + NothingSpecial, + MethodParamsStruct, + MethodResultStruct + } +} diff --git a/CapnpC.CSharp.Generator/Model/Type.cs b/CapnpC.CSharp.Generator/Model/Type.cs new file mode 100644 index 0000000..087f507 --- /dev/null +++ b/CapnpC.CSharp.Generator/Model/Type.cs @@ -0,0 +1,201 @@ +using Capnp; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; + +namespace CapnpC.CSharp.Generator.Model +{ + class Type: AbstractType + { + // Representation of a type expression in the schema language + + public TypeDefinition Definition { get; set; } + // The model for all nodes that are not file nodes - they define types + + public GenericParameter Parameter { get; set; } + // A reference to type parameter in this scope + + public Type ElementType { get; set; } + // The type of a list element, if this is a list. + + readonly Dictionary _parameterBindings = + new Dictionary(); + public Type(TypeTag tag) + { + Tag = tag; + } + + public bool IsValueType + { + get + { + switch (Tag) + { + case TypeTag.AnyPointer: + case TypeTag.CapabilityPointer: + case TypeTag.Data: + case TypeTag.Group: + case TypeTag.Interface: + case TypeTag.List when ElementType.Tag != TypeTag.Void: + case TypeTag.ListPointer: + case TypeTag.Struct: + case TypeTag.StructPointer: + case TypeTag.Text: + case TypeTag.Void: + return false; + + default: + return true; + } + } + } + + public void InheritFreeParameters(IHasGenericParameters declaringType) + { + while (declaringType != null) + { + foreach (var p in declaringType.GetLocalTypeParameters()) + { + if (!_parameterBindings.ContainsKey(p)) + { + _parameterBindings[p] = Types.FromParameter(p); + } + } + + declaringType = (declaringType as TypeDefinition)?.DeclaringElement as IHasGenericParameters; + } + } + + Type SubstituteGenerics(Type type) + { + if (type == null) + { + return null; + } + + if (type.Parameter != null) + { + if (_parameterBindings.TryGetValue(type.Parameter, out var boundType)) + { + return boundType; + } + else + { + return Types.AnyPointer; + } + } + + var stype = new Type(type.Tag) + { + Definition = type.Definition, + ElementType = SubstituteGenerics(type.ElementType) + }; + + foreach (var kvp in type._parameterBindings) + { + var p = kvp.Value.Parameter; + + if (p != null && _parameterBindings.TryGetValue(p, out var boundType)) + { + stype._parameterBindings[kvp.Key] = boundType; + } + else + { + stype._parameterBindings[kvp.Key] = kvp.Value; + } + } + + return stype; + } + + Field SubstituteGenerics(Field field) + { + var result = field.Clone(); + result.Type = SubstituteGenerics(result.Type); + return result; + } + + public new IReadOnlyList Fields => Definition.Fields.LazyListSelect(SubstituteGenerics); + + public Type DeclaringType + { + get + { + var parentDef = Definition?.DeclaringElement as TypeDefinition; + // FIXME: Will become more sophisticated as soon as generics are implemented + return parentDef != null ? Types.FromDefinition(parentDef) : null; + } + } + + public (int, Type) GetRank() + { + var cur = this; + int rank = 0; + + while (cur.Tag == TypeTag.List) + { + cur = cur.ElementType; + ++rank; + } + + return (rank, cur); + } + + public IEnumerable AllImplementedClasses + { + get + { + var stk = new Stack(); + stk.Push(this); + var set = new HashSet(); + while (stk.Count > 0) + { + var def = stk.Pop(); + + if (def == null) + { + break; + } + + if (set.Add(def)) + { + foreach (var super in def.Definition.Superclasses) + { + stk.Push(super); + } + } + } + return set; + } + } + + public Type ResolveGenericParameter(GenericParameter genericParameter) + { + if (_parameterBindings.TryGetValue(genericParameter, out var type)) + { + return type; + } + else + { + return Types.AnyPointer; + } + } + + public void BindGenericParameter(GenericParameter genericParameter, Type boundType) + { + _parameterBindings.Add(genericParameter, boundType); + } + + public override bool Equals(object obj) + { + return obj is Type other && Definition == other.Definition; + } + + public override int GetHashCode() + { + return Definition?.GetHashCode() ?? 0; + } + } +} diff --git a/CapnpC.CSharp.Generator/Model/TypeCategory.cs b/CapnpC.CSharp.Generator/Model/TypeCategory.cs new file mode 100644 index 0000000..507659e --- /dev/null +++ b/CapnpC.CSharp.Generator/Model/TypeCategory.cs @@ -0,0 +1,8 @@ +namespace CapnpC.CSharp.Generator.Model +{ + enum TypeCategory + { + Value, + Pointer + } +} diff --git a/CapnpC.CSharp.Generator/Model/TypeDefinition.cs b/CapnpC.CSharp.Generator/Model/TypeDefinition.cs new file mode 100644 index 0000000..9a0557c --- /dev/null +++ b/CapnpC.CSharp.Generator/Model/TypeDefinition.cs @@ -0,0 +1,89 @@ +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; + +namespace CapnpC.CSharp.Generator.Model +{ + class TypeDefinition : AbstractType, IDefinition, IHasNestedDefinitions, IHasGenericParameters + { + public class DiscriminationInfo + { + public DiscriminationInfo(ushort numOptions, uint tagOffset) + { + NumOptions = numOptions; + TagOffset = tagOffset; + } + + public ushort NumOptions { get; } + public uint TagOffset { get; } + } + + public TypeDefinition(TypeTag tag, ulong id, IHasNestedDefinitions parent) + { + Trace.Assert(parent != null); + Tag = tag; + Id = id; + IsGenerated = (parent as IDefinition).IsGenerated; + DeclaringElement = parent; + if (tag == TypeTag.Group) + ((TypeDefinition)parent).NestedGroups.Add(this); + else + parent.NestedDefinitions.Add(this); + } + + public ulong Id { get; } + public bool IsGenerated { get; } + public IHasNestedDefinitions DeclaringElement { get; } + + public Method UsingMethod { get; set; } + public string Name { get; set; } + public SpecialName SpecialName { get; set; } + public DiscriminationInfo UnionInfo { get; set; } + public new List Fields => base.Fields; + public List Enumerants { get; } = new List(); + public ICollection NestedDefinitions { get; } = new List(); + public IEnumerable NestedTypes { get => this.GetNestedTypes(); } + public List NestedGroups { get; } = new List(); + public ICollection Constants { get; } = new List(); + public List Methods { get; } = new List(); + public List Superclasses { get; } = new List(); + public List GenericParameters { get; } = new List(); + public bool IsGeneric { get; set; } + public ushort StructDataWordCount { get; set; } + public ushort StructPointerCount { get; set; } + + public IEnumerable DefinitionHierarchy + { + get + { + IHasNestedDefinitions cur = this; + + while (cur is TypeDefinition def) + { + yield return def; + cur = def.DeclaringElement; + } + } + } + + public GenFile File + { + get + { + IHasNestedDefinitions cur = this; + while (cur is TypeDefinition def) cur = def.DeclaringElement; + return cur as GenFile; + } + } + + public IEnumerable AllTypeParameters + { + get + { + return from def in DefinitionHierarchy + from p in def.GetLocalTypeParameters() + select p; + } + } + } +} diff --git a/CapnpC.CSharp.Generator/Model/TypeTag.cs b/CapnpC.CSharp.Generator/Model/TypeTag.cs new file mode 100644 index 0000000..756e229 --- /dev/null +++ b/CapnpC.CSharp.Generator/Model/TypeTag.cs @@ -0,0 +1,36 @@ +namespace CapnpC.CSharp.Generator.Model +{ + enum TypeTag + { + Unknown, + Void, + Bool, + S8, + U8, + S16, + U16, + S32, + U32, + S64, + U64, + F32, + F64, + List, + Data, + Text, + AnyPointer, + StructPointer, + ListPointer, + CapabilityPointer, + ParameterPointer, + ImplicitMethodParameterPointer, + Struct, + Group, + Interface, + Enum, + AnyEnum, + Const, + Annotation, + File + } +} diff --git a/CapnpC.CSharp.Generator/Model/Types.cs b/CapnpC.CSharp.Generator/Model/Types.cs new file mode 100644 index 0000000..c655010 --- /dev/null +++ b/CapnpC.CSharp.Generator/Model/Types.cs @@ -0,0 +1,56 @@ +using System; + +namespace CapnpC.CSharp.Generator.Model +{ + static class Types + { + public static readonly Type Void = new Type(TypeTag.Void); + public static readonly Type Bool = new Type(TypeTag.Bool); + public static readonly Type S8 = new Type(TypeTag.S8); + public static readonly Type U8 = new Type(TypeTag.U8); + public static readonly Type S16 = new Type(TypeTag.S16); + public static readonly Type U16 = new Type(TypeTag.U16); + public static readonly Type S32 = new Type(TypeTag.S32); + public static readonly Type U32 = new Type(TypeTag.U32); + public static readonly Type S64 = new Type(TypeTag.S64); + public static readonly Type U64 = new Type(TypeTag.U64); + public static readonly Type F32 = new Type(TypeTag.F32); + public static readonly Type F64 = new Type(TypeTag.F64); + public static readonly Type AnyPointer = new Type(TypeTag.AnyPointer); + public static readonly Type StructPointer = new Type(TypeTag.StructPointer); + public static readonly Type ListPointer = new Type(TypeTag.ListPointer); + public static readonly Type CapabilityPointer = new Type(TypeTag.CapabilityPointer); + public static readonly Type Data = new Type(TypeTag.Data); + public static readonly Type Text = new Type(TypeTag.Text); + public static readonly Type AnyEnum = new Type(TypeTag.AnyEnum); + + public static Type List(Type elementType) + { + return new Type(TypeTag.List) + { + ElementType = elementType + }; + } + + public static Type FromDefinition(TypeDefinition def) + { + if (def.Tag == TypeTag.Unknown) + { + throw new InvalidOperationException("Oops, type definition is not yet valid, cannot create type"); + } + + return new Type(def.Tag) + { + Definition = def + }; + } + + public static Type FromParameter(GenericParameter genericParameter) + { + return new Type(TypeTag.AnyPointer) + { + Parameter = genericParameter + }; + } + } +} diff --git a/CapnpC.CSharp.Generator/Model/Value.cs b/CapnpC.CSharp.Generator/Model/Value.cs new file mode 100644 index 0000000..21c27aa --- /dev/null +++ b/CapnpC.CSharp.Generator/Model/Value.cs @@ -0,0 +1,300 @@ +using Capnp; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace CapnpC.CSharp.Generator.Model +{ + class Value + { + public static Value Scalar(T scalar) + { + var value = new Value() + { + ScalarValue = scalar + }; + + if (typeof(T) == typeof(bool)) + value.Type = Types.Bool; + else if (typeof(T) == typeof(float)) + value.Type = Types.F32; + else if (typeof(T) == typeof(double)) + value.Type = Types.F64; + else if (typeof(T) == typeof(sbyte)) + value.Type = Types.S8; + else if (typeof(T) == typeof(byte)) + value.Type = Types.U8; + else if (typeof(T) == typeof(short)) + value.Type = Types.S16; + else if (typeof(T) == typeof(ushort)) + value.Type = Types.U16; + else if (typeof(T) == typeof(int)) + value.Type = Types.S32; + else if (typeof(T) == typeof(uint)) + value.Type = Types.U32; + else if (typeof(T) == typeof(long)) + value.Type = Types.S64; + else if (typeof(T) == typeof(ulong)) + value.Type = Types.U64; + else if (typeof(T) == typeof(string)) + value.Type = Types.Text; + else + throw new NotImplementedException(); + + return value; + } + + public Type Type { get; set; } + public object ScalarValue { get; set; } + public Capnp.DeserializerState RawValue { get; set; } + public List Items { get; } = new List(); + public int VoidListCount { get; set; } + public ushort DiscriminatorValue { get; private set; } + public List<(Field, Value)> Fields { get; } = new List<(Field, Value)>(); + + public Enumerant GetEnumerant() + { + if (Type.Tag != TypeTag.Enum) + throw new InvalidOperationException(); + + if (Type.Definition.Enumerants[0].Ordinal.HasValue) + return Type.Definition.Enumerants.Single(e => e.Ordinal == (ushort)ScalarValue); + else + return Type.Definition.Enumerants[(ushort)ScalarValue]; + } + + void DecodeStruct() + { + if (RawValue.Kind != Capnp.ObjectKind.Struct) + { + throw new NotSupportedException(); + } + + var def = Type.Definition; + + if (def.UnionInfo != null) + { + DiscriminatorValue = RawValue.ReadDataUShort(def.UnionInfo.TagOffset, ushort.MaxValue); + } + + foreach (var field in Type.Fields) + { + if (field.DiscValue.HasValue && field.DiscValue.Value != DiscriminatorValue) + continue; + + Value value = new Value() + { + Type = field.Type + }; + + switch (field.Type.Tag) + { + case TypeTag.AnyEnum: + value.ScalarValue = field.DefaultValue?.ScalarValue as ushort? ?? 0; + break; + + case TypeTag.AnyPointer: + value.RawValue = RawValue.StructReadPointer((int)field.Offset); + break; + + case TypeTag.Bool: + value.ScalarValue = RawValue.ReadDataBool(field.BitOffset.Value, (field.DefaultValue?.ScalarValue as bool?) ?? false); + break; + + case TypeTag.CapabilityPointer: + case TypeTag.Interface: + continue; + + case TypeTag.Data: + case TypeTag.Group: + case TypeTag.Struct: + case TypeTag.List: + case TypeTag.Text: + value.RawValue = RawValue.StructReadPointer((int)field.Offset); + value.Decode(); + break; + + case TypeTag.ListPointer: + case TypeTag.StructPointer: + value.RawValue = RawValue.StructReadPointer((int)field.Offset); + break; + + case TypeTag.Enum: + value.ScalarValue = field.DefaultValue?.ScalarValue as ushort? ?? ushort.MaxValue; + break; + + case TypeTag.F32: + value = Scalar(RawValue.ReadDataFloat(field.BitOffset.Value, (field.DefaultValue?.ScalarValue as float?) ?? 0.0f)); + break; + + case TypeTag.F64: + value = Scalar(RawValue.ReadDataDouble(field.BitOffset.Value, (field.DefaultValue?.ScalarValue as double?) ?? 0.0f)); + break; + + case TypeTag.S16: + value = Scalar(RawValue.ReadDataShort(field.BitOffset.Value, (field.DefaultValue?.ScalarValue as short?) ?? 0)); + break; + + case TypeTag.S32: + value = Scalar(RawValue.ReadDataInt(field.BitOffset.Value, (field.DefaultValue?.ScalarValue as int?) ?? 0)); + break; + + case TypeTag.S64: + value = Scalar(RawValue.ReadDataLong(field.BitOffset.Value, (field.DefaultValue?.ScalarValue as long?) ?? 0)); + break; + + case TypeTag.S8: + value = Scalar(RawValue.ReadDataSByte(field.BitOffset.Value, (field.DefaultValue?.ScalarValue as sbyte?) ?? 0)); + break; + + case TypeTag.U16: + value = Scalar(RawValue.ReadDataUShort(field.BitOffset.Value, (field.DefaultValue?.ScalarValue as ushort?) ?? 0)); + break; + + case TypeTag.U32: + value = Scalar(RawValue.ReadDataUInt(field.BitOffset.Value, (field.DefaultValue?.ScalarValue as uint?) ?? 0)); + break; + + case TypeTag.U64: + value = Scalar(RawValue.ReadDataULong(field.BitOffset.Value, (field.DefaultValue?.ScalarValue as ulong?) ?? 0)); + break; + + case TypeTag.U8: + value = Scalar(RawValue.ReadDataByte(field.BitOffset.Value, (field.DefaultValue?.ScalarValue as byte?) ?? 0)); + break; + + case TypeTag.Void: + continue; + + default: + throw new NotImplementedException(); + } + + Fields.Add((field, value)); + } + } + + void DecodeList() + { + switch (Type.Tag) + { + case TypeTag.Data: + Items.AddRange(RawValue.RequireList().CastByte().Select(Scalar)); + break; + + case TypeTag.List: + switch (Type.ElementType.Tag) + { + case TypeTag.AnyEnum: + case TypeTag.Enum: + Items.AddRange(RawValue.RequireList().CastUShort().Select(u => { + var v = Scalar(u); + v.Type = Type.ElementType; + return v; })); + break; + + case TypeTag.AnyPointer: + Items.AddRange(RawValue.RequireList().Cast(d => new Value() { Type = Type.ElementType, RawValue = d })); + break; + + case TypeTag.Bool: + Items.AddRange(RawValue.RequireList().CastBool().Select(Scalar)); + break; + + case TypeTag.Data: + case TypeTag.Group: + case TypeTag.Struct: + case TypeTag.List: + Items.AddRange(RawValue.RequireList().Cast(d => { + var v = new Value() { Type = Type.ElementType, RawValue = d }; + v.Decode(); + return v; + })); + break; + + case TypeTag.Text: + Items.AddRange(RawValue.RequireList().CastText2().Select(Scalar)); + break; + + case TypeTag.F32: + Items.AddRange(RawValue.RequireList().CastFloat().Select(Scalar)); + break; + + case TypeTag.F64: + Items.AddRange(RawValue.RequireList().CastDouble().Select(Scalar)); + break; + + case TypeTag.S8: + Items.AddRange(RawValue.RequireList().CastSByte().Select(Scalar)); + break; + + case TypeTag.S16: + Items.AddRange(RawValue.RequireList().CastShort().Select(Scalar)); + break; + + case TypeTag.S32: + Items.AddRange(RawValue.RequireList().CastInt().Select(Scalar)); + break; + + case TypeTag.S64: + Items.AddRange(RawValue.RequireList().CastLong().Select(Scalar)); + break; + + case TypeTag.Void: + VoidListCount = RawValue.RequireList().Count; + break; + + case TypeTag.U16: + Items.AddRange(RawValue.RequireList().CastUShort().Select(Scalar)); + break; + + case TypeTag.U32: + Items.AddRange(RawValue.RequireList().CastUInt().Select(Scalar)); + break; + + case TypeTag.U64: + Items.AddRange(RawValue.RequireList().CastULong().Select(Scalar)); + break; + + case TypeTag.U8: + Items.AddRange(RawValue.RequireList().CastByte().Select(Scalar)); + break; + + default: + throw new NotImplementedException(); + } + break; + + case TypeTag.ListPointer: + Items.AddRange(RawValue.RequireList().Cast(d => new Value() { Type = Type.ElementType, RawValue = d })); + break; + + case TypeTag.Text: + ScalarValue = RawValue.RequireList().CastText(); + break; + } + } + + public void Decode() + { + if (RawValue.Kind == ObjectKind.Nil) return; + + switch (Type.Tag) + { + case TypeTag.Group: + case TypeTag.Struct: + DecodeStruct(); + break; + + case TypeTag.List: + case TypeTag.ListPointer: + case TypeTag.Text: + case TypeTag.Data: + DecodeList(); + break; + } + + RawValue = default(Capnp.DeserializerState); + } + } +} diff --git a/CapnpC.CSharp.Generator/Schema/SchemaSerialization.cs b/CapnpC.CSharp.Generator/Schema/SchemaSerialization.cs new file mode 100644 index 0000000..0655f7d --- /dev/null +++ b/CapnpC.CSharp.Generator/Schema/SchemaSerialization.cs @@ -0,0 +1,1575 @@ +using Capnp; +using System.Collections.Generic; + +namespace CapnpC.CSharp.Generator.Schema +{ + namespace Superclass + { + public struct Reader + { + public DeserializerState State { get; } + + public Reader(DeserializerState ctx) + { + State = ctx; + } + + public static Reader Create(DeserializerState ctx) => new Reader(ctx); + + public ulong Id => State.ReadDataULong(0); + public Brand.Reader Brand => State.ReadStruct(0, Schema.Brand.Reader.Create); + } + + public class Writer: SerializerState + { + public Writer() + { + SetStruct(1, 1); + } + + public ulong Id + { + get => this.ReadDataULong(0); + set => this.WriteData(0, value); + } + + public Brand.Writer Brand + { + get => BuildPointer(0); + set => Link(0, value); + } + } + } + + namespace Method + { + public struct Reader + { + public DeserializerState State { get; } + + public Reader(DeserializerState ctx) + { + State = ctx; + } + + public static Reader Create(DeserializerState ctx) => new Reader(ctx); + + public string Name => State.ReadText(0); + public ushort CodeOrder => State.ReadDataUShort(0); + public IReadOnlyList ImplicitParameters => State.ReadListOfStructs(4, Node.Parameter.Reader.Create); + public ulong ParamStructType => State.ReadDataULong(64); + public Brand.Reader ParamBrand => State.ReadStruct(2, Brand.Reader.Create); + public ulong ResultStructType => State.ReadDataULong(128); + public Brand.Reader ResultBrand => State.ReadStruct(3, Brand.Reader.Create); + public IReadOnlyList Annotations => State.ReadListOfStructs(1, Annotation.Reader.Create); + } + + public class Writer: SerializerState + { + public Writer() + { + SetStruct(5, 3); + } + + public string Name + { + get => ReadText(0); + set => WriteText(0, value); + } + + public ushort CodeOrder + { + get => this.ReadDataUShort(0); + set => this.WriteData(0, value); + } + + public ListOfStructsSerializer ImplicitParameters + { + get => BuildPointer>(4); + set => Link(4, value); + } + + public ref ulong ParamStructType => ref this.RefData(8); + + public Brand.Writer ParamBrand + { + get => BuildPointer(2); + set => Link(2, value); + } + + public ulong ResultStructType + { + get => this.ReadDataULong(128); + set => this.WriteData(128, value); + } + + public Brand.Writer ResultBrand + { + get => BuildPointer(3); + set => Link(3, value); + } + + public ListOfStructsSerializer Annotations + { + get => BuildPointer>(1); + set => Link(1, value); + } + } + } + + namespace Type + { + public struct Reader + { + public DeserializerState State { get; } + + public Reader(DeserializerState ctx) + { + State = ctx; + } + + public static Reader Create(DeserializerState ctx) => new Reader(ctx); + + public ushort Tag => State.ReadDataUShort(0); + public bool IsVoid => Tag == 0; + public bool IsBool => Tag == 1; + public bool IsInt8 => Tag == 2; + public bool IsInt16 => Tag == 3; + public bool IsInt32 => Tag == 4; + public bool IsInt64 => Tag == 5; + public bool IsUInt8 => Tag == 6; + public bool IsUInt16 => Tag == 7; + public bool IsUInt32 => Tag == 8; + public bool IsUInt64 => Tag == 9; + public bool IsFloat32 => Tag == 10; + public bool IsFloat64 => Tag == 11; + public bool IsText => Tag == 12; + public bool IsData => Tag == 13; + public bool IsList => Tag == 14; + public Reader List_ElementType => IsList ? State.ReadStruct(0, Create) : default; + public bool IsEnum => Tag == 15; + public ulong Enum_TypeId => IsEnum ? State.ReadDataULong(64) : 0; + public Brand.Reader Enum_Brand => IsEnum ? State.ReadStruct(0, Brand.Reader.Create) : default; + public bool IsStruct => Tag == 16; + public ulong Struct_TypeId => IsStruct ? State.ReadDataULong(64) : 0; + public Brand.Reader Struct_Brand => IsStruct ? State.ReadStruct(0, Brand.Reader.Create) : default; + public bool IsInterface => Tag == 17; + public ulong Interface_TypeId => IsInterface ? State.ReadDataULong(64) : 0; + public Brand.Reader Interface_Brand => IsInterface ? State.ReadStruct(0, Brand.Reader.Create) : default; + public bool IsAnyPointer => Tag == 18; + public ushort AnyPointer_Tag => IsAnyPointer ? State.ReadDataUShort(64) : default; + public bool AnyPointer_IsUnconstrained => IsAnyPointer && AnyPointer_Tag == 0; + public ushort AnyPointer_Unconstrained_Tag => AnyPointer_IsUnconstrained ? State.ReadDataUShort(80) : (ushort)0; + public bool AnyPointer_Unconstrained_IsAnyKind => AnyPointer_IsUnconstrained && AnyPointer_Unconstrained_Tag == 0; + public bool AnyPointer_Unconstrained_IsStruct => AnyPointer_IsUnconstrained && AnyPointer_Unconstrained_Tag == 1; + public bool AnyPointer_Unconstrained_IsList => AnyPointer_IsUnconstrained && AnyPointer_Unconstrained_Tag == 2; + public bool AnyPointer_Unconstrained_IsCapability => AnyPointer_IsUnconstrained && AnyPointer_Unconstrained_Tag == 3; + public bool AnyPointer_IsParameter => IsAnyPointer && AnyPointer_Tag == 1; + public ulong AnyPointer_Parameter_ScopeId => AnyPointer_IsParameter ? State.ReadDataULong(128) : 0; + public ushort AnyPointer_Parameter_ParameterIndex => AnyPointer_IsParameter ? State.ReadDataUShort(80) : (ushort)0; + public bool AnyPointer_IsImplicitMethodParameter => AnyPointer_Tag == 2; + public ushort AnyPointer_ImplicitMethodParameter_ParameterIndex => AnyPointer_IsImplicitMethodParameter ? State.ReadDataUShort(80) : default; + } + + public class Writer: SerializerState + { + public Writer() + { + SetStruct(3, 1); + } + + public ref ushort Tag => ref this.RefData(0); + + public bool IsVoid + { + get => Tag == 0; + set => Tag = 0; + } + + public bool IsBool + { + get => Tag == 1; + set => Tag = 1; + } + + public bool IsInt8 + { + get => Tag == 2; + set => Tag = 2; + } + + public bool IsInt16 + { + get => Tag == 3; + set => Tag = 3; + } + + public bool IsInt32 + { + get => Tag == 4; + set => Tag = 4; + } + + public bool IsInt64 + { + get => Tag == 5; + set => Tag = 5; + } + + public bool IsUInt8 + { + get => Tag == 6; + set => Tag = 6; + } + + public bool IsUInt16 + { + get => Tag == 7; + set => Tag = 7; + } + + public bool IsUInt32 + { + get => Tag == 8; + set => Tag = 8; + } + + public bool IsUInt64 + { + get => Tag == 9; + set => Tag = 9; + } + + public bool IsFloat32 + { + get => Tag == 10; + set => Tag = 10; + } + + public bool IsFloat64 + { + get => Tag == 11; + set => Tag = 11; + } + + public bool IsText + { + get => Tag == 12; + set => Tag = 12; + } + + public bool IsData + { + get => Tag == 13; + set => Tag = 13; + } + + public bool IsList + { + get => Tag == 14; + set => Tag = 14; + } + + public Writer List_ElementType + { + get => IsList ? BuildPointer(0) : default; + set { Link(0, value); } + } + + public bool IsEnum + { + get => Tag == 15; + set => Tag = 15; + } + + public ulong Enum_TypeId + { + get => IsEnum ? this.ReadDataULong(64) : 0; + set { this.WriteData(64, value); } + } + + public Brand.Writer Enum_Brand + { + get => IsEnum ? BuildPointer(0) : default; + set => Link(0, value); + } + + public bool IsStruct + { + get => Tag == 16; + set => Tag = 16; + } + + public ulong Struct_TypeId + { + get => IsStruct ? this.ReadDataULong(64) : 0; + set => this.WriteData(64, value); + } + + public Brand.Writer Struct_Brand + { + get => IsStruct ? BuildPointer(0) : default; + set => Link(0, value); + } + + public bool IsInterface + { + get => Tag == 17; + set => Tag = 17; + } + + public ulong Interface_TypeId + { + get => IsStruct ? this.ReadDataULong(64) : 0; + set => this.WriteData(64, value); + } + + public Brand.Writer Interface_Brand + { + get => IsStruct ? BuildPointer(0) : default; + set => Link(0, value); + } + + public bool IsAnyPointer + { + get => Tag == 18; + set => Tag = 18; + } + + public ushort AnyPointer_Tag + { + get => IsAnyPointer ? this.ReadDataUShort(64) : default; + set => this.WriteData(64, value); + } + + public bool AnyPointer_IsUnconstrained + { + get => IsAnyPointer && AnyPointer_Tag == 0; + set => AnyPointer_Tag = 0; + } + + public ushort AnyPointer_Unconstrained_Tag + { + get => AnyPointer_IsUnconstrained ? this.ReadDataUShort(80) : (ushort)0; + set => this.WriteData(80, value); + } + + public bool AnyPointer_Unconstrained_IsAnyKind + { + get => AnyPointer_IsUnconstrained && AnyPointer_Unconstrained_Tag == 0; + set => AnyPointer_Unconstrained_Tag = 0; + } + + public bool AnyPointer_Unconstrained_IsStruct + { + get => AnyPointer_IsUnconstrained && AnyPointer_Unconstrained_Tag == 1; + set => AnyPointer_Unconstrained_Tag = 1; + } + + public bool AnyPointer_Unconstrained_IsList + { + get => AnyPointer_IsUnconstrained && AnyPointer_Unconstrained_Tag == 2; + set => AnyPointer_Unconstrained_Tag = 2; + } + + public bool AnyPointer_Unconstrained_IsCapability + { + get => AnyPointer_IsUnconstrained && AnyPointer_Unconstrained_Tag == 3; + set => AnyPointer_Unconstrained_Tag = 3; + } + + public bool AnyPointer_IsParameter + { + get => IsAnyPointer && AnyPointer_Tag == 1; + set => AnyPointer_Tag = 1; + } + + public ulong AnyPointer_Parameter_ScopeId + { + get => AnyPointer_IsParameter ? this.ReadDataULong(128) : 0; + set => this.WriteData(128, value); + } + + public ushort AnyPointer_Parameter_ParameterIndex + { + get => AnyPointer_IsParameter ? this.ReadDataUShort(80) : (ushort)0; + set => this.WriteData(80, value); + } + + public bool AnyPointer_IsImplicitMethodParameter + { + get => AnyPointer_Tag == 2; + set => AnyPointer_Tag = 2; + } + + public ushort AnyPointer_ImplicitMethodParameter_ParameterIndex + { + get => AnyPointer_IsImplicitMethodParameter ? this.ReadDataUShort(80) : default; + set => this.WriteData(80, value); + } + } + } + + namespace Brand + { + namespace Scope + { + public struct Reader + { + public DeserializerState State { get; } + + public Reader(DeserializerState ctx) + { + State = ctx; + } + + public static Reader Create(DeserializerState ctx) => new Reader(ctx); + + public ulong ScopeId => State.ReadDataULong(0); + public ushort Tag => State.ReadDataUShort(64); + public bool IsBind => Tag == 0; + public IReadOnlyList Bind => IsBind ? State.ReadListOfStructs(0, Binding.Reader.Create) : null; + public bool IsInherit => Tag == 1; + } + + public class Writer: SerializerState + { + public Writer() + { + SetStruct(2, 1); + } + + public ulong ScopeId + { + get => this.ReadDataULong(0); + set => this.WriteData(0, value); + } + + public ushort Tag + { + get => this.ReadDataUShort(64); + set => this.WriteData(64, value); + } + + public bool IsBind + { + get => Tag == 0; + set => Tag = 0; + } + + public ListOfStructsSerializer Bind + { + get => IsBind ? BuildPointer>(0) : default; + set => Link(0, value); + } + + public bool IsInherit + { + get => Tag == 1; + set => Tag = 1; + } + } + + namespace Binding + { + public struct Reader + { + public DeserializerState State { get; } + + public Reader(DeserializerState ctx) + { + State = ctx; + } + + public static Reader Create(DeserializerState ctx) => new Reader(ctx); + + public ushort Tag => State.ReadDataUShort(0); + public bool IsUnbound => Tag == 0; + public bool IsType => Tag == 1; + public Type.Reader Type => IsType ? State.ReadStruct(0, Schema.Type.Reader.Create) : default; + } + + public class Writer: SerializerState + { + public Writer() + { + SetStruct(1, 1); + } + + public ushort Tag + { + get => this.ReadDataUShort(0); + set => this.WriteData(0, value); + } + + public bool IsUnbound + { + get => Tag == 0; + set => Tag = 0; + } + + public bool IsType + { + get => Tag == 1; + set => Tag = 1; + } + + public Type.Writer Type + { + get => IsType ? BuildPointer(0) : default; + set => Link(0, value); + } + } + } + } + + public struct Reader + { + public DeserializerState State { get; } + + public Reader(DeserializerState ctx) + { + State = ctx; + } + + public static Reader Create(DeserializerState ctx) => new Reader(ctx); + + public IReadOnlyList Scopes => State.ReadListOfStructs(0, Scope.Reader.Create); + } + + public class Writer: SerializerState + { + public Writer() + { + SetStruct(0, 1); + } + + public ListOfStructsSerializer Scopes + { + get => BuildPointer>(0); + set => Link(0, value); + } + } + } + + namespace Value + { + public struct Reader + { + public DeserializerState State { get; } + + public Reader(DeserializerState ctx) + { + State = ctx; + } + + public static Reader Create(DeserializerState ctx) => new Reader(ctx); + + public ushort Tag => State.ReadDataUShort(0); + public bool IsVoid => Tag == 0; + public bool IsBool => Tag == 1; + public bool Bool => IsBool ? State.ReadDataBool(16) : default; + public bool IsInt8 => Tag == 2; + public sbyte Int8 => IsInt8 ? State.ReadDataSByte(16) : default; + public bool IsInt16 => Tag == 3; + public short Int16 => IsInt16 ? State.ReadDataShort(16) : default; + public bool IsInt32 => Tag == 4; + public int Int32 => IsInt32 ? State.ReadDataInt(32) : default; + public bool IsInt64 => Tag == 5; + public long Int64 => IsInt64 ? State.ReadDataLong(64) : default; + public bool IsUInt8 => Tag == 6; + public byte UInt8 => IsUInt8 ? State.ReadDataByte(16) : default; + public bool IsUInt16 => Tag == 7; + public ushort UInt16 => IsUInt16 ? State.ReadDataUShort(16) : default; + public bool IsUInt32 => Tag == 8; + public uint UInt32 => IsUInt32 ? State.ReadDataUInt(32) : default; + public bool IsUInt64 => Tag == 9; + public ulong UInt64 => IsUInt64 ? State.ReadDataULong(64) : default; + public bool IsFloat32 => Tag == 10; + public float Float32 => IsFloat32 ? State.ReadDataFloat(32) : default; + public bool IsFloat64 => Tag == 11; + public double Float64 => IsFloat64 ? State.ReadDataDouble(64) : default; + public bool IsText => Tag == 12; + public string Text => IsText ? State.ReadText(0) : default; + public bool IsData => Tag == 13; + public ListDeserializer Data => IsData ? State.ReadList(0) : default; + public bool IsList => Tag == 14; + public DeserializerState List => IsList ? State.StructReadPointer(0) : default; + public bool IsEnum => Tag == 15; + public ushort Enum => IsEnum ? State.ReadDataUShort(16) : default; + public bool IsStruct => Tag == 16; + public DeserializerState Struct => IsStruct ? State.StructReadPointer(0) : default; + public bool IsInterface => Tag == 17; + public bool IsAnyPointer => Tag == 18; + public DeserializerState AnyPointer => IsAnyPointer ? State.StructReadPointer(0) : default; + } + + public class Writer: SerializerState + { + public Writer() + { + SetStruct(2, 1); + } + + public ushort Tag + { + get => this.ReadDataUShort(0); + set => this.WriteData(0, value); + } + + public bool IsVoid + { + get => Tag == 0; + set => Tag = 0; + } + + public bool IsBool + { + get => Tag == 1; + set => Tag = 1; + } + + public bool Bool + { + get => IsBool ? this.ReadDataBool(16) : default; + set => this.WriteData(16, value); + } + + public bool IsInt8 + { + get => Tag == 2; + set => Tag = 2; + } + + public sbyte Int8 + { + get => IsInt8 ? this.ReadDataSByte(16) : default; + set => this.WriteData(16, value); + } + + public bool IsInt16 + { + get => Tag == 3; + set => Tag = 3; + } + + public short Int16 + { + get => IsInt16 ? this.ReadDataShort(16) : default; + set => this.WriteData(16, value); + } + + public bool IsInt32 + { + get => Tag == 4; + set => Tag = 4; + } + + public int Int32 + { + get => IsInt32 ? this.ReadDataInt(32) : default; + set => this.WriteData(32, value); + } + + public bool IsInt64 + { + get => Tag == 5; + set => Tag = 5; + } + + public long Int64 + { + get => IsInt64 ? this.ReadDataLong(64) : default; + set => this.WriteData(64, value); + } + + public bool IsUInt8 + { + get => Tag == 6; + set => Tag = 6; + } + + public byte UInt8 + { + get => IsUInt8 ? this.ReadDataByte(16) : default; + set => this.WriteData(16, value); + } + + public bool IsUInt16 + { + get => Tag == 7; + set => Tag = 7; + } + + public ushort UInt16 + { + get => IsUInt16 ? this.ReadDataUShort(16) : default; + set => this.WriteData(16, value); + } + + public bool IsUInt32 + { + get => Tag == 8; + set => Tag = 8; + } + + public uint UInt32 + { + get => IsUInt32 ? this.ReadDataUInt(32) : default; + set => this.WriteData(32, value); + } + + public bool IsUInt64 + { + get => Tag == 9; + set => Tag = 9; + } + + public ulong UInt64 + { + get => IsUInt64 ? this.ReadDataULong(64) : default; + set => this.WriteData(64, value); + } + + public bool IsFloat32 + { + get => Tag == 10; + set => Tag = 10; + } + + public float Float32 + { + get => IsFloat32 ? this.ReadDataFloat(32) : default; + set => this.WriteData(32, value); + } + + public bool IsFloat64 + { + get => Tag == 11; + set => Tag = 11; + } + + public double Float64 + { + get => IsFloat64 ? this.ReadDataDouble(64) : default; + set => this.WriteData(64, value); + } + + public bool IsText + { + get => Tag == 12; + set => Tag = 12; + } + + public string Text + { + get => IsText ? ReadText(0) : default; + set => WriteText(0, value); + } + + public bool IsData + { + get => Tag == 13; + set => Tag = 13; + } + + public SerializerState Data + { + get => IsData ? BuildPointer(0) : default; + set => Link(0, value); + } + + public bool IsList + { + get => Tag == 14; + set => Tag = 14; + } + + public SerializerState List + { + get => IsList ? BuildPointer(0) : default; + set => Link(0, value); + } + + public bool IsEnum + { + get => Tag == 15; + set => Tag = 15; + } + + public ushort Enum + { + get => IsEnum ? this.ReadDataUShort(16) : default; + set => this.WriteData(16, value); + } + + public bool IsStruct + { + get => Tag == 16; + set => Tag = 16; + } + + public SerializerState Struct + { + get => IsStruct ? BuildPointer(0) : default; + set => Link(0, value); + } + + public bool IsInterface + { + get => Tag == 17; + set => Tag = 17; + } + + public bool IsAnyPointer + { + get => Tag == 18; + set => Tag = 18; + } + + public SerializerState AnyPointer + { + get => IsAnyPointer ? BuildPointer(0) : default; + set => Link(0, value); + } + } + } + + namespace Annotation + { + public struct Reader + { + public DeserializerState State { get; } + + public Reader(DeserializerState ctx) + { + State = ctx; + } + + public static Reader Create(DeserializerState ctx) => new Reader(ctx); + + public ulong Id => State.ReadDataULong(0); + public Brand.Reader Brand => State.ReadStruct(1, Schema.Brand.Reader.Create); + public Value.Reader Value => State.ReadStruct(0, Schema.Value.Reader.Create); + } + + public class Writer: SerializerState + { + public Writer() + { + SetStruct(1, 2); + } + + public ref ulong Id => ref this.RefData(0); + + public Brand.Writer Brand + { + get => BuildPointer(1); + set => Link(1, value); + } + + public Value.Writer Value + { + get => BuildPointer(0); + set => Link(0, value); + } + } + } + + public enum ElementSize: ushort + { + Empty = 0, + Bit = 1, + Byte = 2, + TwoBytes = 3, + FourBytes = 4, + EightBytes = 5, + Pointer = 6, + InlineComposite = 7 + } + + namespace Field + { + public struct Reader + { + public DeserializerState State { get; } + + public Reader(DeserializerState ctx) + { + State = ctx; + } + + public static Reader Create(DeserializerState ctx) => new Reader(ctx); + + public string Name => State.ReadText(0); + public ushort CodeOrder => State.ReadDataUShort(0); + public IReadOnlyList Annotations => State.ReadListOfStructs(1, Annotation.Reader.Create); + public ushort DiscriminantValue => State.ReadDataUShort(16, 65535); + public ushort Tag => State.ReadDataUShort(64); + public bool IsSlot => Tag == 0; + public uint Slot_Offset => IsSlot ? State.ReadDataUInt(32) : default; + public Type.Reader Slot_Type => IsSlot ? State.ReadStruct(2, Type.Reader.Create) : default; + public Value.Reader Slot_DefaultValue => IsSlot ? State.ReadStruct(3, Value.Reader.Create) : default; + public bool Slot_HadExplicitDefault => IsSlot ? State.ReadDataBool(128) : default; + public bool IsGroup => Tag == 1; + public ulong Group_TypeId => IsGroup ? State.ReadDataULong(128) : default; + public ushort Ordinal_Tag => State.ReadDataUShort(80); + public bool Ordinal_IsImplicit => Ordinal_Tag == 0; + public bool Ordinal_IsExplicit => Ordinal_Tag == 1; + public ushort Ordinal_Explicit => Ordinal_IsExplicit ? State.ReadDataUShort(96) : default; + + public const ushort NoDiscriminant = 0xffff; + } + + public class Writer: SerializerState + { + public Writer() + { + SetStruct(3, 3); + } + + public string Name + { + get => ReadText(0); + set => WriteText(0, value); + } + + public ref ushort CodeOrder => ref this.RefData(0); + + public ListOfStructsSerializer Annotations + { + get => BuildPointer>(1); + set => Link(1, value); + } + + public ushort DiscriminantValue + { + get => this.ReadDataUShort(16, 65535); + set => this.WriteData(16, value, (ushort)65535); + } + + public ref ushort Tag => ref this.RefData(8); + + public bool IsSlot + { + get => Tag == 0; + set => Tag = 0; + } + + public uint Slot_Offset + { + get => IsSlot ? this.ReadDataUInt(32) : default; + set => this.WriteData(32, value); + } + + public Type.Writer Slot_Type + { + get => IsSlot ? BuildPointer(2) : default; + set => Link(2, value); + } + + public Value.Writer Slot_DefaultValue + { + get => IsSlot ? BuildPointer(3) : default; + set => Link(3, value); + } + + public bool Slot_HadExplicitDefault + { + get => IsSlot ? this.ReadDataBool(128) : default; + set => this.WriteData(128, value); + } + + public bool IsGroup + { + get => Tag == 1; + set => Tag = 1; + } + + public ref ulong Group_TypeId => ref this.RefData(2); + + public ref ushort Ordinal_Tag => ref this.RefData(5); + + public bool Ordinal_IsImplicit + { + get => Ordinal_Tag == 0; + set => Ordinal_Tag = 0; + } + + public bool Ordinal_IsExplicit + { + get => Ordinal_Tag == 1; + set => Ordinal_Tag = 1; + } + + public ref ushort Ordinal_Explicit => ref this.RefData(6); + } + } + + namespace Node + { + namespace Parameter + { + public struct Reader + { + public DeserializerState State { get; } + + public Reader(DeserializerState ctx) + { + State = ctx; + } + + public static Reader Create(DeserializerState ctx) => new Reader(ctx); + + public string Name => State.ReadText(0); + } + + public class Writer: SerializerState + { + public Writer() + { + SetStruct(0, 1); + } + + public string Name + { + get => ReadText(0); + set => WriteText(0, value); + } + } + } + + namespace NestedNode + { + public struct Reader + { + public DeserializerState State { get; } + + public Reader(DeserializerState ctx) + { + State = ctx; + } + + public static Reader Create(DeserializerState ctx) => new Reader(ctx); + + public string Name => State.ReadText(0); + public ulong Id => State.ReadDataULong(0); + } + + public class Writer: SerializerState + { + public Writer() + { + SetStruct(1, 1); + } + + public string Name + { + get => ReadText(0); + set => WriteText(0, value); + } + + public ref ulong Id => ref this.RefData(0); + } + } + + namespace SourceInfo + { + namespace Member + { + public struct Reader + { + public DeserializerState State { get; } + + public Reader(DeserializerState ctx) + { + State = ctx; + } + + public static Reader Create(DeserializerState ctx) => new Reader(ctx); + + public string DocComment => State.ReadText(0); + } + + public class Writer: SerializerState + { + public Writer() + { + SetStruct(0, 1); + } + + public string DocComment + { + get => ReadText(0); + set => WriteText(0, value); + } + } + } + + public struct Reader + { + public DeserializerState State { get; } + + public Reader(DeserializerState ctx) + { + State = ctx; + } + + public static Reader Create(DeserializerState ctx) => new Reader(ctx); + + public ulong Id => State.ReadDataULong(0); + public string DocComment => State.ReadText(0); + public IReadOnlyList Members => State.ReadListOfStructs(1, Member.Reader.Create); + } + + public class Writer: SerializerState + { + public Writer() + { + SetStruct(1, 2); + } + + public ref ulong Id => ref this.RefData(0); + + public string DocComment + { + get => ReadText(0); + set => WriteText(0, value); + } + + public ListOfStructsSerializer Members + { + get => BuildPointer>(1); + set => Link(1, value); + } + } + } + + public struct Reader + { + public DeserializerState State { get; } + + public Reader(DeserializerState ctx) + { + State = ctx; + } + + public static Reader Create(DeserializerState ctx) => new Reader(ctx); + + public ulong Id => State.ReadDataULong(0); + public string DisplayName => State.ReadText(0); + public uint DisplayNamePrefixLength => State.ReadDataUInt(64); + public ulong ScopeId => State.ReadDataULong(128); + public IReadOnlyList Parameters => State.ReadListOfStructs(5, Parameter.Reader.Create); + public bool IsGeneric => State.ReadDataBool(288); + public IReadOnlyList NestedNodes => State.ReadListOfStructs(1, NestedNode.Reader.Create); + public IReadOnlyList Annotations => State.ReadListOfStructs(2, Annotation.Reader.Create); + public ushort Tag => State.ReadDataUShort(96); + public bool IsFile => Tag == 0; + public bool IsStruct => Tag == 1; + public ushort Struct_DataWordCount => IsStruct ? State.ReadDataUShort(112) : default; + public ushort Struct_PointerCount => IsStruct ? State.ReadDataUShort(192) : default; + public ElementSize Struct_PreferredListEncoding => IsStruct ? (ElementSize)State.ReadDataUShort(208) : default; + public bool Struct_IsGroup => IsStruct ? State.ReadDataBool(224) : default; + public ushort Struct_DiscriminantCount => IsStruct ? State.ReadDataUShort(240) : default; + public uint Struct_DiscriminantOffset => IsStruct ? State.ReadDataUInt(256) : default; + public IReadOnlyList Fields => IsStruct ? State.ReadListOfStructs(3, Field.Reader.Create) : default; + public bool IsEnum => Tag == 2; + public IReadOnlyList Enumerants => IsEnum ? State.ReadListOfStructs(3, Field.Reader.Create) : default; + public bool IsInterface => Tag == 3; + public IReadOnlyList Interface_Methods => IsInterface ? State.ReadListOfStructs(3, Method.Reader.Create) : default; + public IReadOnlyList Interface_Superclasses => IsInterface ? State.ReadListOfStructs(4, Superclass.Reader.Create) : default; + public bool IsConst => Tag == 4; + public Type.Reader Const_Type => IsConst ? State.ReadStruct(3, Type.Reader.Create) : default; + public Value.Reader Const_Value => IsConst ? State.ReadStruct(4, Value.Reader.Create) : default; + public bool IsAnnotation => Tag == 5; + public Type.Reader Annotation_Type => IsAnnotation ? State.ReadStruct(3, Type.Reader.Create) : default; + public bool Annotation_TargetsFile => IsAnnotation ? State.ReadDataBool(112) : default; + public bool Annotation_TargetsConst => IsAnnotation ? State.ReadDataBool(113) : default; + public bool Annotation_TargetsEnum => IsAnnotation ? State.ReadDataBool(114) : default; + public bool Annotation_TargetsEnumerant => IsAnnotation ? State.ReadDataBool(115) : default; + public bool Annotation_TargetsStruct => IsAnnotation ? State.ReadDataBool(116) : default; + public bool Annotation_TargetsField => IsAnnotation ? State.ReadDataBool(117) : default; + public bool Annotation_TargetsUnion => IsAnnotation ? State.ReadDataBool(118) : default; + public bool Annotation_TargetsGroup => IsAnnotation ? State.ReadDataBool(119) : default; + public bool Annotation_TargetsInterface => IsAnnotation ? State.ReadDataBool(120) : default; + public bool Annotation_TargetsMethod => IsAnnotation ? State.ReadDataBool(121) : default; + public bool Annotation_TargetsParam => IsAnnotation ? State.ReadDataBool(122) : default; + public bool Annotation_TargetsAnnotation => IsAnnotation ? State.ReadDataBool(123) : default; + } + + public class Writer: SerializerState + { + public Writer() + { + SetStruct(5, 6); + } + + public ulong Id + { + get => this.ReadDataULong(0); + set => this.WriteData(0, value); + } + + public string DisplayName + { + get => ReadText(0); + set => WriteText(0, value); + } + + public ref uint DisplayNamePrefixLength => ref this.RefData(2); + + public ref ulong ScopeId => ref this.RefData(2); + + public ListOfStructsSerializer Parameters + { + get => BuildPointer>(5); + set => Link(5, value); + } + + public bool IsGeneric + { + get => this.ReadDataBool(288); + set => this.WriteData(288, value); + } + + public ListOfStructsSerializer NestedNodes + { + get => BuildPointer>(1); + set => Link(1, value); + } + + public ListOfStructsSerializer Annotations + { + get => BuildPointer>(2); + set => Link(2, value); + } + + public ref ushort Tag => ref this.RefData(6); + + public bool IsFile + { + get => Tag == 0; + set => Tag = 0; + } + + public bool IsStruct + { + get => Tag == 1; + set => Tag = 1; + } + + public ref ushort Struct_DataWordCount => ref this.RefData(7); + + public ref ushort Struct_PointerCount => ref this.RefData(12); + + public ref ElementSize Struct_PreferredListEncoding => ref this.RefData(13); + + public bool Struct_IsGroup + { + get => IsStruct ? this.ReadDataBool(224) : default; + set => this.WriteData(224, value); + } + + public ref ushort Struct_DiscriminantCount => ref this.RefData(15); + + public ref uint Struct_DiscriminantOffset => ref this.RefData(8); + + public ListOfStructsSerializer Fields + { + get => BuildPointer>(3); + set => Link(3, value); + } + + public bool IsEnum + { + get => Tag == 2; + set => Tag = 2; + } + + public ListOfStructsSerializer Enumerants + { + get => BuildPointer>(3); + set => Link(3, value); + } + + public bool IsInterface + { + get => Tag == 3; + set => Tag = 3; + } + + public ListOfStructsSerializer Interface_Methods + { + get => BuildPointer>(3); + set => Link(3, value); + } + + public ListOfStructsSerializer Interface_Superclasses + { + get => IsInterface ? BuildPointer>(4) : default; + set => Link(4, value); + } + + public bool IsConst + { + get => Tag == 4; + set => Tag = 4; + } + + public Type.Writer Const_Type + { + get => IsConst ? BuildPointer(3) : default; + set => Link(3, value); + } + + public Value.Writer Const_Value + { + get => IsConst ? BuildPointer(4) : default; + set => Link(4, value); + } + + public bool IsAnnotation + { + get => Tag == 5; + set => Tag = 5; + } + + public Type.Writer Annotation_Type + { + get => IsAnnotation ? BuildPointer(3) : default; + set => Link(3, value); + } + + public bool Annotation_TargetsFile + { + get => IsAnnotation ? this.ReadDataBool(112) : default; + set => this.WriteData(112, value); + } + + public bool Annotation_TargetsConst + { + get => IsAnnotation ? this.ReadDataBool(113) : default; + set => this.WriteData(113, value); + } + + public bool Annotation_TargetsEnum + { + get => IsAnnotation ? this.ReadDataBool(114) : default; + set => this.WriteData(114, value); + } + + public bool Annotation_TargetsEnumerant + { + get => IsAnnotation ? this.ReadDataBool(115) : default; + set => this.WriteData(115, value); + } + + public bool Annotation_TargetsStruct + { + get => IsAnnotation ? this.ReadDataBool(116) : default; + set => this.WriteData(116, value); + } + + public bool Annotation_TargetsField + { + get => IsAnnotation ? this.ReadDataBool(117) : default; + set => this.WriteData(117, value); + } + + public bool Annotation_TargetsUnion + { + get => IsAnnotation ? this.ReadDataBool(118) : default; + set => this.WriteData(118, value); + } + + public bool Annotation_TargetsGroup + { + get => IsAnnotation ? this.ReadDataBool(119) : default; + set => this.WriteData(119, value); + } + + public bool Annotation_TargetsInterface + { + get => IsAnnotation ? this.ReadDataBool(120) : default; + set => this.WriteData(120, value); + } + + public bool Annotation_TargetsMethod + { + get => IsAnnotation ? this.ReadDataBool(121) : default; + set => this.WriteData(121, value); + } + + public bool Annotation_TargetsParam + { + get => IsAnnotation ? this.ReadDataBool(122) : default; + set => this.WriteData(122, value); + } + + public bool Annotation_TargetsAnnotation + { + get => IsAnnotation ? this.ReadDataBool(123) : default; + set => this.WriteData(123, value); + } + } + } + + namespace CapnpVersion + { + public struct Reader + { + public DeserializerState State { get; } + + public Reader(DeserializerState ctx) + { + State = ctx; + } + + public static Reader Create(DeserializerState ctx) => new Reader(ctx); + + public ushort Major => State.ReadDataUShort(0); + public byte Minor => State.ReadDataByte(16); + public byte Micro => State.ReadDataByte(24); + } + + public class Writer: SerializerState + { + public Writer() + { + SetStruct(1, 0); + } + + public ref ushort Major => ref this.RefData(0); + public ref byte Minor => ref this.RefData(2); + public ref byte Micro => ref this.RefData(3); + } + } + + namespace CodeGeneratorRequest + { + namespace RequestedFile + { + namespace Import + { + public struct Reader + { + public DeserializerState State { get; } + + public Reader(DeserializerState ctx) + { + State = ctx; + } + + public static Reader Create(DeserializerState ctx) => new Reader(ctx); + + public ulong Id => State.ReadDataULong(0); + public string Name => State.ReadText(0); + } + + public class Writer: SerializerState + { + public Writer() + { + SetStruct(1, 1); + } + + public ref ulong Id => ref this.RefData(0); + + public string Name + { + get => ReadText(0); + set => WriteText(0, value); + } + } + } + + public struct Reader + { + public DeserializerState State { get; } + + public Reader(DeserializerState ctx) + { + State = ctx; + } + + public static Reader Create(DeserializerState ctx) => new Reader(ctx); + + public ulong Id => State.ReadDataULong(0); + public string Filename => State.ReadText(0); + public IReadOnlyList Imports => State.ReadListOfStructs(1, Import.Reader.Create); + } + + public class Writer: SerializerState + { + public Writer() + { + SetStruct(1, 2); + } + + public ref ulong Id => ref this.RefData(0); + + public string Filename + { + get => ReadText(0); + set => WriteText(0, value); + } + + public ListOfStructsSerializer Imports + { + get => BuildPointer>(1); + set => Link(1, value); + } + } + } + + public struct Reader + { + public DeserializerState State { get; } + + public Reader(DeserializerState ctx) + { + State = ctx; + } + + public static Reader Create(DeserializerState ctx) => new Reader(ctx); + + public CapnpVersion.Reader CapnpVersion => State.ReadStruct(2, Schema.CapnpVersion.Reader.Create); + public IReadOnlyList Nodes => State.ReadListOfStructs(0, Node.Reader.Create); + public IReadOnlyList SourceInfo => State.ReadListOfStructs(3, Node.SourceInfo.Reader.Create); + public IReadOnlyList RequestedFiles => State.ReadListOfStructs(1, RequestedFile.Reader.Create); + } + + public class Writer: SerializerState + { + public Writer() + { + SetStruct(0, 3); + } + + public CapnpVersion.Writer CapnpVersion + { + get => BuildPointer(2); + set => Link(2, value); + } + + public ListOfStructsSerializer Nodes + { + get => BuildPointer>(0); + set => Link(0, value); + } + + public ListOfStructsSerializer SourceInfo + { + get => BuildPointer>(3); + set => Link(3, value); + } + + public ListOfStructsSerializer RequestedFiles + { + get => BuildPointer>(1); + set => Link(1, value); + } + } + } +} diff --git a/CapnpC.CSharp.Generator/Schema/schema-with-offsets.capnp b/CapnpC.CSharp.Generator/Schema/schema-with-offsets.capnp new file mode 100644 index 0000000..45fe760 --- /dev/null +++ b/CapnpC.CSharp.Generator/Schema/schema-with-offsets.capnp @@ -0,0 +1,235 @@ +# schema.capnp +@0xa93fc509624c72d9; +$import "/capnp/c++.capnp".namespace("capnp::schema"); +struct Node @0xe682ab4cf923a417 { # 40 bytes, 6 ptrs + id @0 :UInt64; # bits[0, 64) + displayName @1 :Text; # ptr[0] + displayNamePrefixLength @2 :UInt32; # bits[64, 96) + scopeId @3 :UInt64; # bits[128, 192) + parameters @32 :List(Parameter); # ptr[5] + isGeneric @33 :Bool; # bits[288, 289) + nestedNodes @4 :List(NestedNode); # ptr[1] + annotations @5 :List(Annotation); # ptr[2] + union { # tag bits [96, 112) + file @6 :Void; # bits[0, 0), union tag = 0 + struct :group { # union tag = 1 + dataWordCount @7 :UInt16; # bits[112, 128) + pointerCount @8 :UInt16; # bits[192, 208) + preferredListEncoding @9 :ElementSize; # bits[208, 224) + isGroup @10 :Bool; # bits[224, 225) + discriminantCount @11 :UInt16; # bits[240, 256) + discriminantOffset @12 :UInt32; # bits[256, 288) + fields @13 :List(Field); # ptr[3] + } + enum :group { # union tag = 2 + enumerants @14 :List(Enumerant); # ptr[3] + } + interface :group { # union tag = 3 + methods @15 :List(Method); # ptr[3] + superclasses @31 :List(Superclass); # ptr[4] + } + const :group { # union tag = 4 + type @16 :Type; # ptr[3] + value @17 :Value; # ptr[4] + } + annotation :group { # union tag = 5 + type @18 :Type; # ptr[3] + targetsFile @19 :Bool; # bits[112, 113) + targetsConst @20 :Bool; # bits[113, 114) + targetsEnum @21 :Bool; # bits[114, 115) + targetsEnumerant @22 :Bool; # bits[115, 116) + targetsStruct @23 :Bool; # bits[116, 117) + targetsField @24 :Bool; # bits[117, 118) + targetsUnion @25 :Bool; # bits[118, 119) + targetsGroup @26 :Bool; # bits[119, 120) + targetsInterface @27 :Bool; # bits[120, 121) + targetsMethod @28 :Bool; # bits[121, 122) + targetsParam @29 :Bool; # bits[122, 123) + targetsAnnotation @30 :Bool; # bits[123, 124) + } + } + struct Parameter @0xb9521bccf10fa3b1 { # 0 bytes, 1 ptrs + name @0 :Text; # ptr[0] + } + struct NestedNode @0xdebf55bbfa0fc242 { # 8 bytes, 1 ptrs + name @0 :Text; # ptr[0] + id @1 :UInt64; # bits[0, 64) + } + struct SourceInfo @0xf38e1de3041357ae { # 8 bytes, 2 ptrs + id @0 :UInt64; # bits[0, 64) + docComment @1 :Text; # ptr[0] + members @2 :List(Member); # ptr[1] + struct Member @0xc2ba9038898e1fa2 { # 0 bytes, 1 ptrs + docComment @0 :Text; # ptr[0] + } + } +} +struct Field @0x9aad50a41f4af45f { # 24 bytes, 4 ptrs + name @0 :Text; # ptr[0] + codeOrder @1 :UInt16; # bits[0, 16) + annotations @2 :List(Annotation); # ptr[1] + discriminantValue @3 :UInt16 = 65535; # bits[16, 32) + union { # tag bits [64, 80) + slot :group { # union tag = 0 + offset @4 :UInt32; # bits[32, 64) + type @5 :Type; # ptr[2] + defaultValue @6 :Value; # ptr[3] + hadExplicitDefault @10 :Bool; # bits[128, 129) + } + group :group { # union tag = 1 + typeId @7 :UInt64; # bits[128, 192) + } + } + ordinal :group { + union { # tag bits [80, 96) + implicit @8 :Void; # bits[0, 0), union tag = 0 + explicit @9 :UInt16; # bits[96, 112), union tag = 1 + } + } + const noDiscriminant @0x97b14cbe7cfec712 :UInt16 = 65535; +} +struct Enumerant @0x978a7cebdc549a4d { # 8 bytes, 2 ptrs + name @0 :Text; # ptr[0] + codeOrder @1 :UInt16; # bits[0, 16) + annotations @2 :List(Annotation); # ptr[1] +} +struct Superclass @0xa9962a9ed0a4d7f8 { # 8 bytes, 1 ptrs + id @0 :UInt64; # bits[0, 64) + brand @1 :Brand; # ptr[0] +} +struct Method @0x9500cce23b334d80 { # 24 bytes, 5 ptrs + name @0 :Text; # ptr[0] + codeOrder @1 :UInt16; # bits[0, 16) + implicitParameters @7 :List(Node.Parameter); # ptr[4] + paramStructType @2 :UInt64; # bits[64, 128) + paramBrand @5 :Brand; # ptr[2] + resultStructType @3 :UInt64; # bits[128, 192) + resultBrand @6 :Brand; # ptr[3] + annotations @4 :List(Annotation); # ptr[1] +} +struct Type @0xd07378ede1f9cc60 { # 24 bytes, 1 ptrs + union { # tag bits [0, 16) + void @0 :Void; # bits[0, 0), union tag = 0 + bool @1 :Void; # bits[0, 0), union tag = 1 + int8 @2 :Void; # bits[0, 0), union tag = 2 + int16 @3 :Void; # bits[0, 0), union tag = 3 + int32 @4 :Void; # bits[0, 0), union tag = 4 + int64 @5 :Void; # bits[0, 0), union tag = 5 + uint8 @6 :Void; # bits[0, 0), union tag = 6 + uint16 @7 :Void; # bits[0, 0), union tag = 7 + uint32 @8 :Void; # bits[0, 0), union tag = 8 + uint64 @9 :Void; # bits[0, 0), union tag = 9 + float32 @10 :Void; # bits[0, 0), union tag = 10 + float64 @11 :Void; # bits[0, 0), union tag = 11 + text @12 :Void; # bits[0, 0), union tag = 12 + data @13 :Void; # bits[0, 0), union tag = 13 + list :group { # union tag = 14 + elementType @14 :Type; # ptr[0] + } + enum :group { # union tag = 15 + typeId @15 :UInt64; # bits[64, 128) + brand @21 :Brand; # ptr[0] + } + struct :group { # union tag = 16 + typeId @16 :UInt64; # bits[64, 128) + brand @22 :Brand; # ptr[0] + } + interface :group { # union tag = 17 + typeId @17 :UInt64; # bits[64, 128) + brand @23 :Brand; # ptr[0] + } + anyPointer :group { # union tag = 18 + union { # tag bits [64, 80) + unconstrained :group { # union tag = 0 + union { # tag bits [80, 96) + anyKind @18 :Void; # bits[0, 0), union tag = 0 + struct @25 :Void; # bits[0, 0), union tag = 1 + list @26 :Void; # bits[0, 0), union tag = 2 + capability @27 :Void; # bits[0, 0), union tag = 3 + } + } + parameter :group { # union tag = 1 + scopeId @19 :UInt64; # bits[128, 192) + parameterIndex @20 :UInt16; # bits[80, 96) + } + implicitMethodParameter :group { # union tag = 2 + parameterIndex @24 :UInt16; # bits[80, 96) + } + } + } + } +} +struct Brand @0x903455f06065422b { # 0 bytes, 1 ptrs + scopes @0 :List(Scope); # ptr[0] + struct Scope @0xabd73485a9636bc9 { # 16 bytes, 1 ptrs + scopeId @0 :UInt64; # bits[0, 64) + union { # tag bits [64, 80) + bind @1 :List(Binding); # ptr[0], union tag = 0 + inherit @2 :Void; # bits[0, 0), union tag = 1 + } + } + struct Binding @0xc863cd16969ee7fc { # 8 bytes, 1 ptrs + union { # tag bits [0, 16) + unbound @0 :Void; # bits[0, 0), union tag = 0 + type @1 :Type; # ptr[0], union tag = 1 + } + } +} +struct Value @0xce23dcd2d7b00c9b { # 16 bytes, 1 ptrs + union { # tag bits [0, 16) + void @0 :Void; # bits[0, 0), union tag = 0 + bool @1 :Bool; # bits[16, 17), union tag = 1 + int8 @2 :Int8; # bits[16, 24), union tag = 2 + int16 @3 :Int16; # bits[16, 32), union tag = 3 + int32 @4 :Int32; # bits[32, 64), union tag = 4 + int64 @5 :Int64; # bits[64, 128), union tag = 5 + uint8 @6 :UInt8; # bits[16, 24), union tag = 6 + uint16 @7 :UInt16; # bits[16, 32), union tag = 7 + uint32 @8 :UInt32; # bits[32, 64), union tag = 8 + uint64 @9 :UInt64; # bits[64, 128), union tag = 9 + float32 @10 :Float32; # bits[32, 64), union tag = 10 + float64 @11 :Float64; # bits[64, 128), union tag = 11 + text @12 :Text; # ptr[0], union tag = 12 + data @13 :Data; # ptr[0], union tag = 13 + list @14 :AnyPointer; # ptr[0], union tag = 14 + enum @15 :UInt16; # bits[16, 32), union tag = 15 + struct @16 :AnyPointer; # ptr[0], union tag = 16 + interface @17 :Void; # bits[0, 0), union tag = 17 + anyPointer @18 :AnyPointer; # ptr[0], union tag = 18 + } +} +struct Annotation @0xf1c8950dab257542 { # 8 bytes, 2 ptrs + id @0 :UInt64; # bits[0, 64) + brand @2 :Brand; # ptr[1] + value @1 :Value; # ptr[0] +} +enum ElementSize @0xd1958f7dba521926 { + empty @0; + bit @1; + byte @2; + twoBytes @3; + fourBytes @4; + eightBytes @5; + pointer @6; + inlineComposite @7; +} +struct CapnpVersion @0xd85d305b7d839963 { # 8 bytes, 0 ptrs + major @0 :UInt16; # bits[0, 16) + minor @1 :UInt8; # bits[16, 24) + micro @2 :UInt8; # bits[24, 32) +} +struct CodeGeneratorRequest @0xbfc546f6210ad7ce { # 0 bytes, 4 ptrs + capnpVersion @2 :CapnpVersion; # ptr[2] + nodes @0 :List(Node); # ptr[0] + sourceInfo @3 :List(Node.SourceInfo); # ptr[3] + requestedFiles @1 :List(RequestedFile); # ptr[1] + struct RequestedFile @0xcfea0eb02e810062 { # 8 bytes, 2 ptrs + id @0 :UInt64; # bits[0, 64) + filename @1 :Text; # ptr[0] + imports @2 :List(Import); # ptr[1] + struct Import @0xae504193122357e5 { # 8 bytes, 1 ptrs + id @0 :UInt64; # bits[0, 64) + name @1 :Text; # ptr[0] + } + } +} diff --git a/Capnpc.Csharp.MsBuild.Generation/CapnpFileCodeBehindGenerator.cs b/Capnpc.Csharp.MsBuild.Generation/CapnpFileCodeBehindGenerator.cs index ff6d30e..6802c12 100644 --- a/Capnpc.Csharp.MsBuild.Generation/CapnpFileCodeBehindGenerator.cs +++ b/Capnpc.Csharp.MsBuild.Generation/CapnpFileCodeBehindGenerator.cs @@ -21,8 +21,10 @@ namespace Capnpc.Csharp.MsBuild.Generation public IEnumerable GenerateFilesForProject( string projectPath, - List capnpFiles, - string projectFolder) + List capnpFiles, + string projectFolder, + string workingDirectory, + string additionalOptions) { using (var capnpCodeBehindGenerator = new CapnpCodeBehindGenerator()) { diff --git a/Capnpc.Csharp.MsBuild.Generation/GenerateCapnpFileCodeBehindTask.cs b/Capnpc.Csharp.MsBuild.Generation/GenerateCapnpFileCodeBehindTask.cs index c120448..b4b9269 100644 --- a/Capnpc.Csharp.MsBuild.Generation/GenerateCapnpFileCodeBehindTask.cs +++ b/Capnpc.Csharp.MsBuild.Generation/GenerateCapnpFileCodeBehindTask.cs @@ -25,6 +25,10 @@ namespace Capnpc.Csharp.MsBuild.Generation public ITaskItem[] CapnpFiles { get; set; } + public string WorkingDirectory { get; set; } + + public string AdditionalOptions { get; set; } + [Output] public ITaskItem[] GeneratedFiles { get; private set; } @@ -59,7 +63,9 @@ namespace Capnpc.Csharp.MsBuild.Generation var generatedFiles = generator.GenerateFilesForProject( ProjectPath, capnpFiles, - ProjectFolder); + ProjectFolder, + WorkingDirectory, + AdditionalOptions); GeneratedFiles = generatedFiles.Select(file => new TaskItem { ItemSpec = file }).ToArray(); diff --git a/Capnpc.Csharp.MsBuild.Generation/ICapnpCsharpGenerator.cs b/Capnpc.Csharp.MsBuild.Generation/ICapnpCsharpGenerator.cs index 4213d8d..d55ed1e 100644 --- a/Capnpc.Csharp.MsBuild.Generation/ICapnpCsharpGenerator.cs +++ b/Capnpc.Csharp.MsBuild.Generation/ICapnpCsharpGenerator.cs @@ -4,6 +4,6 @@ namespace Capnpc.Csharp.MsBuild.Generation { public interface ICapnpcCsharpGenerator { - IEnumerable GenerateFilesForProject(string projectPath, List capnpFiles, string projectFolder); + IEnumerable GenerateFilesForProject(string projectPath, List capnpFiles, string projectFolder, string workingDirectory, string additionalOptions); } } \ No newline at end of file diff --git a/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/CapnpFileType.xaml b/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/CapnpFileType.xaml index 51e0ab0..ec90cbe 100644 --- a/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/CapnpFileType.xaml +++ b/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/CapnpFileType.xaml @@ -25,10 +25,19 @@ - + + + + + + + + + + \ No newline at end of file From 2f21dc217a3de9a3c60f9095f78829c1e03768b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6llner?= Date: Tue, 10 Sep 2019 22:48:25 +0200 Subject: [PATCH 04/22] WIP --- Capnp.Net.sln | 12 +- .../CapnpC.CSharp.Generator.Tests.csproj | 21 +- .../CapnpMessageUnitTests.cs | 107 ++ .../CodeGenerator.feature | 48 + .../CodeGenerator.feature.cs | 96 +- .../CodeGeneratorUnitTests.cs | 14 +- .../Embedded Resources/Empty.capnp | 1 + .../Embedded Resources/Empty1.capnp | 1 + .../Embedded Resources}/UnitTest1.capnp | 0 .../Embedded Resources/UnitTest1.capnp.bin | Bin .../Embedded Resources/UnitTest10.capnp.bin | Bin .../Embedded Resources/UnitTest11.capnp.bin | Bin .../Embedded Resources/UnitTest2.capnp.bin | Bin .../Embedded Resources/UnitTest20.capnp.bin | Bin .../Embedded Resources/UnitTest3.capnp.bin | Bin .../Embedded Resources/UnitTest4.capnp.bin | Bin .../Embedded Resources/invalid.capnp | 11 + .../Embedded Resources/null.bin | 0 .../schema-with-offsets.capnp.bin | Bin .../Embedded Resources/test.capnp.bin | Bin .../Embedded Resources/test.cs | 0 .../FeatureSteps/CodeGeneratorSteps.cs | 149 ++ .../No Resources/UnitTest10.capnp | 0 .../No Resources/UnitTest10b.capnp | 0 .../No Resources/UnitTest11.capnp | 0 .../No Resources/UnitTest11b.capnp | 0 .../No Resources/UnitTest2.capnp | 0 .../No Resources/UnitTest20.capnp | 0 .../No Resources/UnitTest3.capnp | 0 .../No Resources/UnitTest4.capnp | 0 .../No Resources/UnitTest4b.capnp | 0 .../No Resources/test.capnp | 0 .../capnpc-csharp.tests.csproj | 4 + .../CapnpC.CSharp.Generator.csproj | 2 +- CapnpC.CSharp.Generator/CapnpCompilation.cs | 73 +- CapnpC.CSharp.Generator/CapnpMessage.cs | 116 ++ .../CapnpProcessFailure.cs | 23 + .../CodeGen/CodeGenerator.cs | 2 +- CapnpC.CSharp.Generator/GenerationResult.cs | 10 + .../BuildEngineMock.cs | 42 + ...npC.CSharp.MsBuild.Generation.Tests.csproj | 21 + .../GenerateCapnpFileCodeBehindTaskTest.cs | 51 + .../TaskItemMock.cs | 37 + .../CsFileGeneratorResult.cs | 51 + .../CapnpCodeBehindGenerator.cs | 82 +- .../CapnpFileCodeBehindGenerator.cs | 54 +- .../Capnpc.Csharp.MsBuild.Generation.csproj | 33 +- .../Capnpc.Csharp.MsBuild.Generation.nuspec | 7 +- .../CodeBehindWriter.cs | 15 +- .../FilePathGenerator.cs | 31 - .../FileSystemHelper.cs | 2 +- .../GenerateCapnpFileCodeBehindTask.cs | 2 +- .../Helper/LogExtensions.cs | 4 +- .../ICapnpCsharpGenerator.cs | 2 +- .../TestFileGeneratorResult.cs | 42 - .../TestGenerationError.cs | 6 - .../TestGeneratorResult.cs | 11 - .../CPS/Buildsystem/Rules/CapnpFileType.xaml | 4 +- .../Capnpc.Csharp.MsBuild.Generation.props | 6 +- .../Capnpc.Csharp.MsBuild.Generation.targets | 10 +- .../Capnpc.Csharp.MsBuild.Generation.tasks | 2 +- .../Capnpc.Csharp.MsBuild.Generation.props | 2 +- README.md | 2 +- appveyor.yml | 5 +- capnpc-csharp.tests/CodeGenerator.feature | 20 - .../FeatureSteps/CodeGeneratorSteps.cs | 83 - capnpc-csharp/Generator/CodeGenerator.cs | 182 -- capnpc-csharp/Generator/CommonSnippetGen.cs | 93 - .../Generator/DomainClassSnippetGen.cs | 972 ---------- capnpc-csharp/Generator/GenNames.cs | 601 ------- capnpc-csharp/Generator/GeneratorOptions.cs | 42 - .../Generator/InterfaceSnippetGen.cs | 844 --------- capnpc-csharp/Generator/Name.cs | 35 - capnpc-csharp/Generator/ReaderSnippetGen.cs | 715 -------- .../Generator/SerializerStateWorder.cs | 12 - capnpc-csharp/Generator/SkeletonWorder.cs | 12 - capnpc-csharp/Generator/SyntaxHelpers.cs | 128 -- capnpc-csharp/Generator/WriterSnippetGen.cs | 406 ----- capnpc-csharp/Model/AbstractType.cs | 45 - capnpc-csharp/Model/Annotation.cs | 23 - capnpc-csharp/Model/Constant.cs | 23 - capnpc-csharp/Model/DefinitionManager.cs | 67 - capnpc-csharp/Model/Enumerant.cs | 14 - capnpc-csharp/Model/Field.cs | 52 - capnpc-csharp/Model/GenFile.cs | 25 - capnpc-csharp/Model/GenericParameter.cs | 26 - capnpc-csharp/Model/HasGenericParameters.cs | 18 - capnpc-csharp/Model/IDefinition.cs | 11 - capnpc-csharp/Model/IHasGenericParameters.cs | 9 - capnpc-csharp/Model/IHasNestedDefinitions.cs | 18 - capnpc-csharp/Model/IdentifierRenamer.cs | 22 - capnpc-csharp/Model/InvalidSchemaException.cs | 11 - capnpc-csharp/Model/Method.cs | 16 - capnpc-csharp/Model/SchemaModel.cs | 783 -------- capnpc-csharp/Model/SpecialName.cs | 9 - capnpc-csharp/Model/Type.cs | 201 --- capnpc-csharp/Model/TypeCategory.cs | 8 - capnpc-csharp/Model/TypeDefinition.cs | 88 - capnpc-csharp/Model/TypeTag.cs | 36 - capnpc-csharp/Model/Types.cs | 56 - capnpc-csharp/Model/Value.cs | 300 ---- capnpc-csharp/Program.cs | 51 +- capnpc-csharp/Schema/SchemaSerialization.cs | 1577 ----------------- .../Schema/schema-with-offsets.capnp | 235 --- capnpc-csharp/capnpc-csharp.csproj | 1 + 105 files changed, 1045 insertions(+), 8039 deletions(-) rename capnpc-csharp.tests/capnpc-csharp.tests.csproj => CapnpC.CSharp.Generator.Tests/CapnpC.CSharp.Generator.Tests.csproj (74%) create mode 100644 CapnpC.CSharp.Generator.Tests/CapnpMessageUnitTests.cs create mode 100644 CapnpC.CSharp.Generator.Tests/CodeGenerator.feature rename {capnpc-csharp.tests => CapnpC.CSharp.Generator.Tests}/CodeGenerator.feature.cs (57%) rename capnpc-csharp.tests/UnitTests.cs => CapnpC.CSharp.Generator.Tests/CodeGeneratorUnitTests.cs (92%) create mode 100644 CapnpC.CSharp.Generator.Tests/Embedded Resources/Empty.capnp create mode 100644 CapnpC.CSharp.Generator.Tests/Embedded Resources/Empty1.capnp rename {capnpc-csharp.tests/No Resources => CapnpC.CSharp.Generator.Tests/Embedded Resources}/UnitTest1.capnp (100%) rename {capnpc-csharp.tests => CapnpC.CSharp.Generator.Tests}/Embedded Resources/UnitTest1.capnp.bin (100%) rename {capnpc-csharp.tests => CapnpC.CSharp.Generator.Tests}/Embedded Resources/UnitTest10.capnp.bin (100%) rename {capnpc-csharp.tests => CapnpC.CSharp.Generator.Tests}/Embedded Resources/UnitTest11.capnp.bin (100%) rename {capnpc-csharp.tests => CapnpC.CSharp.Generator.Tests}/Embedded Resources/UnitTest2.capnp.bin (100%) rename {capnpc-csharp.tests => CapnpC.CSharp.Generator.Tests}/Embedded Resources/UnitTest20.capnp.bin (100%) rename {capnpc-csharp.tests => CapnpC.CSharp.Generator.Tests}/Embedded Resources/UnitTest3.capnp.bin (100%) rename {capnpc-csharp.tests => CapnpC.CSharp.Generator.Tests}/Embedded Resources/UnitTest4.capnp.bin (100%) create mode 100644 CapnpC.CSharp.Generator.Tests/Embedded Resources/invalid.capnp rename {capnpc-csharp.tests => CapnpC.CSharp.Generator.Tests}/Embedded Resources/null.bin (100%) rename {capnpc-csharp.tests => CapnpC.CSharp.Generator.Tests}/Embedded Resources/schema-with-offsets.capnp.bin (100%) rename {capnpc-csharp.tests => CapnpC.CSharp.Generator.Tests}/Embedded Resources/test.capnp.bin (100%) rename {capnpc-csharp.tests => CapnpC.CSharp.Generator.Tests}/Embedded Resources/test.cs (100%) create mode 100644 CapnpC.CSharp.Generator.Tests/FeatureSteps/CodeGeneratorSteps.cs rename {capnpc-csharp.tests => CapnpC.CSharp.Generator.Tests}/No Resources/UnitTest10.capnp (100%) rename {capnpc-csharp.tests => CapnpC.CSharp.Generator.Tests}/No Resources/UnitTest10b.capnp (100%) rename {capnpc-csharp.tests => CapnpC.CSharp.Generator.Tests}/No Resources/UnitTest11.capnp (100%) rename {capnpc-csharp.tests => CapnpC.CSharp.Generator.Tests}/No Resources/UnitTest11b.capnp (100%) rename {capnpc-csharp.tests => CapnpC.CSharp.Generator.Tests}/No Resources/UnitTest2.capnp (100%) rename {capnpc-csharp.tests => CapnpC.CSharp.Generator.Tests}/No Resources/UnitTest20.capnp (100%) rename {capnpc-csharp.tests => CapnpC.CSharp.Generator.Tests}/No Resources/UnitTest3.capnp (100%) rename {capnpc-csharp.tests => CapnpC.CSharp.Generator.Tests}/No Resources/UnitTest4.capnp (100%) rename {capnpc-csharp.tests => CapnpC.CSharp.Generator.Tests}/No Resources/UnitTest4b.capnp (100%) rename {capnpc-csharp.tests => CapnpC.CSharp.Generator.Tests}/No Resources/test.capnp (100%) create mode 100644 CapnpC.CSharp.Generator.Tests/capnpc-csharp.tests.csproj create mode 100644 CapnpC.CSharp.Generator/CapnpMessage.cs create mode 100644 CapnpC.CSharp.Generator/CapnpProcessFailure.cs create mode 100644 CapnpC.CSharp.MsBuild.Generation.Tests/BuildEngineMock.cs create mode 100644 CapnpC.CSharp.MsBuild.Generation.Tests/CapnpC.CSharp.MsBuild.Generation.Tests.csproj create mode 100644 CapnpC.CSharp.MsBuild.Generation.Tests/GenerateCapnpFileCodeBehindTaskTest.cs create mode 100644 CapnpC.CSharp.MsBuild.Generation.Tests/TaskItemMock.cs create mode 100644 CapnpC.CSharp.MsBuild.Generation/CsFileGeneratorResult.cs delete mode 100644 Capnpc.Csharp.MsBuild.Generation/FilePathGenerator.cs delete mode 100644 Capnpc.Csharp.MsBuild.Generation/TestFileGeneratorResult.cs delete mode 100644 Capnpc.Csharp.MsBuild.Generation/TestGenerationError.cs delete mode 100644 Capnpc.Csharp.MsBuild.Generation/TestGeneratorResult.cs delete mode 100644 capnpc-csharp.tests/CodeGenerator.feature delete mode 100644 capnpc-csharp.tests/FeatureSteps/CodeGeneratorSteps.cs delete mode 100644 capnpc-csharp/Generator/CodeGenerator.cs delete mode 100644 capnpc-csharp/Generator/CommonSnippetGen.cs delete mode 100644 capnpc-csharp/Generator/DomainClassSnippetGen.cs delete mode 100644 capnpc-csharp/Generator/GenNames.cs delete mode 100644 capnpc-csharp/Generator/GeneratorOptions.cs delete mode 100644 capnpc-csharp/Generator/InterfaceSnippetGen.cs delete mode 100644 capnpc-csharp/Generator/Name.cs delete mode 100644 capnpc-csharp/Generator/ReaderSnippetGen.cs delete mode 100644 capnpc-csharp/Generator/SerializerStateWorder.cs delete mode 100644 capnpc-csharp/Generator/SkeletonWorder.cs delete mode 100644 capnpc-csharp/Generator/SyntaxHelpers.cs delete mode 100644 capnpc-csharp/Generator/WriterSnippetGen.cs delete mode 100644 capnpc-csharp/Model/AbstractType.cs delete mode 100644 capnpc-csharp/Model/Annotation.cs delete mode 100644 capnpc-csharp/Model/Constant.cs delete mode 100644 capnpc-csharp/Model/DefinitionManager.cs delete mode 100644 capnpc-csharp/Model/Enumerant.cs delete mode 100644 capnpc-csharp/Model/Field.cs delete mode 100644 capnpc-csharp/Model/GenFile.cs delete mode 100644 capnpc-csharp/Model/GenericParameter.cs delete mode 100644 capnpc-csharp/Model/HasGenericParameters.cs delete mode 100644 capnpc-csharp/Model/IDefinition.cs delete mode 100644 capnpc-csharp/Model/IHasGenericParameters.cs delete mode 100644 capnpc-csharp/Model/IHasNestedDefinitions.cs delete mode 100644 capnpc-csharp/Model/IdentifierRenamer.cs delete mode 100644 capnpc-csharp/Model/InvalidSchemaException.cs delete mode 100644 capnpc-csharp/Model/Method.cs delete mode 100644 capnpc-csharp/Model/SchemaModel.cs delete mode 100644 capnpc-csharp/Model/SpecialName.cs delete mode 100644 capnpc-csharp/Model/Type.cs delete mode 100644 capnpc-csharp/Model/TypeCategory.cs delete mode 100644 capnpc-csharp/Model/TypeDefinition.cs delete mode 100644 capnpc-csharp/Model/TypeTag.cs delete mode 100644 capnpc-csharp/Model/Types.cs delete mode 100644 capnpc-csharp/Model/Value.cs delete mode 100644 capnpc-csharp/Schema/SchemaSerialization.cs delete mode 100644 capnpc-csharp/Schema/schema-with-offsets.capnp diff --git a/Capnp.Net.sln b/Capnp.Net.sln index 15732e6..38c77ca 100644 --- a/Capnp.Net.sln +++ b/Capnp.Net.sln @@ -11,11 +11,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Capnp.Net.Runtime.Tests.Std EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Capnp.Net.Runtime.Tests.Core21", "Capnp.Net.Runtime.Tests.Core21\Capnp.Net.Runtime.Tests.Core21.csproj", "{58E8FFC8-D207-4B0F-842A-58ED9D3D9EEF}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "capnpc-csharp.tests", "capnpc-csharp.tests\capnpc-csharp.tests.csproj", "{B77AC567-E232-4072-85C3-8689566BF3D4}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CapnpC.CSharp.Generator.Tests", "CapnpC.CSharp.Generator.Tests\CapnpC.CSharp.Generator.Tests.csproj", "{B77AC567-E232-4072-85C3-8689566BF3D4}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Capnpc.Csharp.MsBuild.Generation", "Capnpc.Csharp.MsBuild.Generation\Capnpc.Csharp.MsBuild.Generation.csproj", "{1EFC1F20-C7BB-4F44-8BF9-DBB123AACCF4}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CapnpC.CSharp.MsBuild.Generation", "CapnpC.CSharp.MsBuild.Generation\CapnpC.CSharp.MsBuild.Generation.csproj", "{1EFC1F20-C7BB-4F44-8BF9-DBB123AACCF4}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CapnpC.CSharp.Generator", "CapnpC.CSharp.Generator\CapnpC.CSharp.Generator.csproj", "{C3A3BB49-356E-4762-A190-76D877BE18F7}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CapnpC.CSharp.Generator", "CapnpC.CSharp.Generator\CapnpC.CSharp.Generator.csproj", "{C3A3BB49-356E-4762-A190-76D877BE18F7}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CapnpC.CSharp.MsBuild.Generation.Tests", "CapnpC.CSharp.MsBuild.Generation.Tests\CapnpC.CSharp.MsBuild.Generation.Tests.csproj", "{EF05AD68-DE31-448E-B88D-4144F928ED5D}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -51,6 +53,10 @@ Global {C3A3BB49-356E-4762-A190-76D877BE18F7}.Debug|Any CPU.Build.0 = Debug|Any CPU {C3A3BB49-356E-4762-A190-76D877BE18F7}.Release|Any CPU.ActiveCfg = Release|Any CPU {C3A3BB49-356E-4762-A190-76D877BE18F7}.Release|Any CPU.Build.0 = Release|Any CPU + {EF05AD68-DE31-448E-B88D-4144F928ED5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EF05AD68-DE31-448E-B88D-4144F928ED5D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EF05AD68-DE31-448E-B88D-4144F928ED5D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EF05AD68-DE31-448E-B88D-4144F928ED5D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/capnpc-csharp.tests/capnpc-csharp.tests.csproj b/CapnpC.CSharp.Generator.Tests/CapnpC.CSharp.Generator.Tests.csproj similarity index 74% rename from capnpc-csharp.tests/capnpc-csharp.tests.csproj rename to CapnpC.CSharp.Generator.Tests/CapnpC.CSharp.Generator.Tests.csproj index ce9a24e..5228560 100644 --- a/capnpc-csharp.tests/capnpc-csharp.tests.csproj +++ b/CapnpC.CSharp.Generator.Tests/CapnpC.CSharp.Generator.Tests.csproj @@ -2,7 +2,7 @@ netcoreapp2.2 - capnpc_csharp.Tests + CapnpC.CSharp.Generator.Tests false @@ -16,17 +16,18 @@ - - - - + + + - + + + @@ -34,9 +35,13 @@ + + + + @@ -47,6 +52,10 @@ + + + + SpecFlowSingleFileGenerator diff --git a/CapnpC.CSharp.Generator.Tests/CapnpMessageUnitTests.cs b/CapnpC.CSharp.Generator.Tests/CapnpMessageUnitTests.cs new file mode 100644 index 0000000..ce21560 --- /dev/null +++ b/CapnpC.CSharp.Generator.Tests/CapnpMessageUnitTests.cs @@ -0,0 +1,107 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using System.Text; + +namespace CapnpC.CSharp.Generator.Tests +{ + [TestClass] + public class CapnpMessageUnitTests + { + [TestMethod] + public void ParseError() + { + var msg = new CapnpMessage(@"f:\code\invalid.capnp:5:1: error: Parse error."); + Assert.AreEqual(@"f:\code\invalid.capnp:5:1: error: Parse error.", msg.FullMessage); + Assert.IsTrue(msg.IsParseSuccess); + Assert.AreEqual(@"f:\code\invalid.capnp", msg.FileName); + Assert.AreEqual(5, msg.Line); + Assert.AreEqual(1, msg.Column); + Assert.AreEqual(0, msg.EndColumn); + Assert.AreEqual("error", msg.Category); + Assert.AreEqual("Parse error.", msg.MessageText); + } + + [TestMethod] + public void ColumnSpan() + { + var msg = new CapnpMessage(@"f:\code\invalid.capnp:10:7-8: error: Duplicate ordinal number."); + Assert.IsTrue(msg.IsParseSuccess); + Assert.AreEqual(@"f:\code\invalid.capnp", msg.FileName); + Assert.AreEqual(10, msg.Line); + Assert.AreEqual(7, msg.Column); + Assert.AreEqual(8, msg.EndColumn); + Assert.AreEqual("error", msg.Category); + Assert.AreEqual("Duplicate ordinal number.", msg.MessageText); + } + + [TestMethod] + public void NoSuchFile() + { + var msg = new CapnpMessage(@"C:\ProgramData\chocolatey\lib\capnproto\tools\capnproto-tools-win32-0.7.0\capnp.exe compile: doesnotexist.capnp: no such file"); + Assert.IsFalse(msg.IsParseSuccess); + Assert.AreEqual(@"C:\ProgramData\chocolatey\lib\capnproto\tools\capnproto-tools-win32-0.7.0\capnp.exe compile: doesnotexist.capnp: no such file", msg.FullMessage); + } + + [TestMethod] + public void NoId() + { + var msg = new CapnpMessage(@"empty.capnp:1:1: error: File does not declare an ID. I've generated one for you. Add this line to your file: @0xc82955a0c779197d;"); + Assert.IsTrue(msg.IsParseSuccess); + Assert.AreEqual("empty.capnp", msg.FileName); + Assert.AreEqual(1, msg.Line); + Assert.AreEqual(1, msg.Column); + Assert.AreEqual("error", msg.Category); + Assert.AreEqual("File does not declare an ID. I've generated one for you. Add this line to your file: @0xc82955a0c779197d;", msg.MessageText); + } + + [TestMethod] + public void AnnoyingNTFSAlternateDataStream1() + { + var msg = new CapnpMessage(@"3:2:1:1: error: File does not declare an ID. I've generated one for you. Add this line to your file: @0xc82955a0c779197d;"); + Assert.IsTrue(msg.IsParseSuccess); + Assert.AreEqual("3:2", msg.FileName); + Assert.AreEqual(1, msg.Line); + Assert.AreEqual(1, msg.Column); + Assert.AreEqual("error", msg.Category); + Assert.AreEqual("File does not declare an ID. I've generated one for you. Add this line to your file: @0xc82955a0c779197d;", msg.MessageText); + } + + [TestMethod] + public void AnnoyingNTFSAlternateDataStream2() + { + var msg = new CapnpMessage(@"c:\3:2:1:1: error: File does not declare an ID. I've generated one for you. Add this line to your file: @0xc82955a0c779197d;"); + Assert.IsTrue(msg.IsParseSuccess); + Assert.AreEqual(@"c:\3:2", msg.FileName); + Assert.AreEqual(1, msg.Line); + Assert.AreEqual(1, msg.Column); + Assert.AreEqual("error", msg.Category); + Assert.AreEqual("File does not declare an ID. I've generated one for you. Add this line to your file: @0xc82955a0c779197d;", msg.MessageText); + } + + [TestMethod] + public void AnnoyingNTFSAlternateDataStream3() + { + var msg = new CapnpMessage(@"\\?\c:\3:2:1:1: error: File does not declare an ID. I've generated one for you. Add this line to your file: @0xc82955a0c779197d;"); + Assert.IsTrue(msg.IsParseSuccess); + Assert.AreEqual(@"\\?\c:\3:2", msg.FileName); + Assert.AreEqual(1, msg.Line); + Assert.AreEqual(1, msg.Column); + Assert.AreEqual("error", msg.Category); + Assert.AreEqual("File does not declare an ID. I've generated one for you. Add this line to your file: @0xc82955a0c779197d;", msg.MessageText); + } + + [TestMethod] + public void AnnoyingNTFSAlternateDataStream4() + { + var msg = new CapnpMessage(@"1:2-3:10:7-8: error: Duplicate ordinal number."); + Assert.IsTrue(msg.IsParseSuccess); + Assert.AreEqual(@"1:2-3", msg.FileName); + Assert.AreEqual(10, msg.Line); + Assert.AreEqual(7, msg.Column); + Assert.AreEqual(8, msg.EndColumn); + Assert.AreEqual("error", msg.Category); + Assert.AreEqual("Duplicate ordinal number.", msg.MessageText); + } + } +} diff --git a/CapnpC.CSharp.Generator.Tests/CodeGenerator.feature b/CapnpC.CSharp.Generator.Tests/CodeGenerator.feature new file mode 100644 index 0000000..239fd3d --- /dev/null +++ b/CapnpC.CSharp.Generator.Tests/CodeGenerator.feature @@ -0,0 +1,48 @@ +Feature: CodeGenerator + In order to ensure that the generator backend produces valid output + As a contributor + I want to get notified when there is any deviation from reference output + +Scenario: Comparing backend output with reference + Given I have a binary code generator request "test.capnp.bin" + And my reference output is "test.cs" + When I invoke capnpc-csharp + Then the generated output must match the reference + +Scenario Outline: Invalid binary code generator requests + Given I have a binary code generator request + When I invoke capnpc-csharp + Then the invocation must fail + +Examples: + | bin | + | null.bin | + | test.cs | + +Scenario: Combining frontend and backend + Given capnp.exe is installed on my system + And I have a schema "UnitTest1.capnp" + When I try to generate code from that schema + Then code generation must succeed + +Scenario: Missing frontend + Given capnp.exe is not installed on my system + And I have a schema "UnitTest1.capnp" + When I try to generate code from that schema + Then the invocation must fail + +Scenario: Schema without ID + Given capnp.exe is installed on my system + And I have a schema "Empty1.capnp" + When I try to generate code from that schema + Then the invocation must fail + And the reason must be bad input + And the error output must contain "File does not declare an ID" + +Scenario: Multiple errors + Given capnp.exe is installed on my system + And I have a schema "invalid.capnp" + When I try to generate code from that schema + Then the invocation must fail + And the reason must be bad input + And the error output must contain multiple messages diff --git a/capnpc-csharp.tests/CodeGenerator.feature.cs b/CapnpC.CSharp.Generator.Tests/CodeGenerator.feature.cs similarity index 57% rename from capnpc-csharp.tests/CodeGenerator.feature.cs rename to CapnpC.CSharp.Generator.Tests/CodeGenerator.feature.cs index 74bf043..c01b9e3 100644 --- a/capnpc-csharp.tests/CodeGenerator.feature.cs +++ b/CapnpC.CSharp.Generator.Tests/CodeGenerator.feature.cs @@ -10,7 +10,7 @@ // ------------------------------------------------------------------------------ #region Designer generated code #pragma warning disable -namespace capnpc_csharp.Tests +namespace CapnpC.CSharp.Generator.Tests { using TechTalk.SpecFlow; @@ -63,7 +63,7 @@ namespace capnpc_csharp.Tests if (((testRunner.FeatureContext != null) && (testRunner.FeatureContext.FeatureInfo.Title != "CodeGenerator"))) { - global::capnpc_csharp.Tests.CodeGeneratorFeature.FeatureSetup(null); + global::CapnpC.CSharp.Generator.Tests.CodeGeneratorFeature.FeatureSetup(null); } } @@ -149,6 +149,98 @@ this.InvalidBinaryCodeGeneratorRequests("null.bin", ((string[])(null))); this.InvalidBinaryCodeGeneratorRequests("test.cs", ((string[])(null))); #line hidden } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Combining frontend and backend")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "CodeGenerator")] + public virtual void CombiningFrontendAndBackend() + { + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Combining frontend and backend", null, ((string[])(null))); +#line 22 +this.ScenarioInitialize(scenarioInfo); + this.ScenarioStart(); +#line 23 + testRunner.Given("capnp.exe is installed on my system", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line 24 + testRunner.And("I have a schema \"UnitTest1.capnp\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line 25 + testRunner.When("I try to generate code from that schema", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line 26 + testRunner.Then("code generation must succeed", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden + this.ScenarioCleanup(); + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Missing frontend")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "CodeGenerator")] + public virtual void MissingFrontend() + { + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Missing frontend", null, ((string[])(null))); +#line 28 +this.ScenarioInitialize(scenarioInfo); + this.ScenarioStart(); +#line 29 + testRunner.Given("capnp.exe is not installed on my system", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line 30 + testRunner.And("I have a schema \"UnitTest1.capnp\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line 31 + testRunner.When("I try to generate code from that schema", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line 32 + testRunner.Then("the invocation must fail", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden + this.ScenarioCleanup(); + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Schema without ID")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "CodeGenerator")] + public virtual void SchemaWithoutID() + { + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Schema without ID", null, ((string[])(null))); +#line 34 +this.ScenarioInitialize(scenarioInfo); + this.ScenarioStart(); +#line 35 + testRunner.Given("capnp.exe is installed on my system", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line 36 + testRunner.And("I have a schema \"Empty1.capnp\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line 37 + testRunner.When("I try to generate code from that schema", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line 38 + testRunner.Then("the invocation must fail", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line 39 + testRunner.And("the reason must be bad input", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line 40 + testRunner.And("the error output must contain \"File does not declare an ID\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden + this.ScenarioCleanup(); + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Multiple errors")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "CodeGenerator")] + public virtual void MultipleErrors() + { + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Multiple errors", null, ((string[])(null))); +#line 42 +this.ScenarioInitialize(scenarioInfo); + this.ScenarioStart(); +#line 43 + testRunner.Given("capnp.exe is installed on my system", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line 44 + testRunner.And("I have a schema \"invalid.capnp\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line 45 + testRunner.When("I try to generate code from that schema", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line 46 + testRunner.Then("the invocation must fail", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line 47 + testRunner.And("the reason must be bad input", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line 48 + testRunner.And("the error output must contain multiple messages", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden + this.ScenarioCleanup(); + } } } #pragma warning restore diff --git a/capnpc-csharp.tests/UnitTests.cs b/CapnpC.CSharp.Generator.Tests/CodeGeneratorUnitTests.cs similarity index 92% rename from capnpc-csharp.tests/UnitTests.cs rename to CapnpC.CSharp.Generator.Tests/CodeGeneratorUnitTests.cs index e2b80d5..bfec1b7 100644 --- a/capnpc-csharp.tests/UnitTests.cs +++ b/CapnpC.CSharp.Generator.Tests/CodeGeneratorUnitTests.cs @@ -1,13 +1,13 @@ using Capnp; -using Model = CapnpC.Model; -using Generator = CapnpC.Generator; -using CodeGeneratorRequest = CapnpC.Schema.CodeGeneratorRequest; +using Model = CapnpC.CSharp.Generator.Model; +using CodeGen = CapnpC.CSharp.Generator.CodeGen; +using CodeGeneratorRequest = CapnpC.CSharp.Generator.Schema.CodeGeneratorRequest; using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.Collections.Generic; using System.Linq; -namespace capnpc_csharp.Tests +namespace CapnpC.CSharp.Generator.Tests { [TestClass] public class CodeGeneratorUnitTests @@ -98,13 +98,13 @@ namespace capnpc_csharp.Tests struct Run { public Model.SchemaModel Model; - public Generator.CodeGenerator CodeGen; + public CodeGen.CodeGenerator CodeGen; public Model.GenFile FirstFile; public string Code; } - static Generator.CodeGenerator NewGeneratorFor(Model.SchemaModel model) - => new Generator.CodeGenerator(model, new Generator.GeneratorOptions()); + static CodeGen.CodeGenerator NewGeneratorFor(Model.SchemaModel model) + => new CodeGen.CodeGenerator(model, new CodeGen.GeneratorOptions()); Run LoadAndGenerate(string inputName, int? testNum = null) { diff --git a/CapnpC.CSharp.Generator.Tests/Embedded Resources/Empty.capnp b/CapnpC.CSharp.Generator.Tests/Embedded Resources/Empty.capnp new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/CapnpC.CSharp.Generator.Tests/Embedded Resources/Empty.capnp @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/CapnpC.CSharp.Generator.Tests/Embedded Resources/Empty1.capnp b/CapnpC.CSharp.Generator.Tests/Embedded Resources/Empty1.capnp new file mode 100644 index 0000000..e02abfc --- /dev/null +++ b/CapnpC.CSharp.Generator.Tests/Embedded Resources/Empty1.capnp @@ -0,0 +1 @@ + diff --git a/capnpc-csharp.tests/No Resources/UnitTest1.capnp b/CapnpC.CSharp.Generator.Tests/Embedded Resources/UnitTest1.capnp similarity index 100% rename from capnpc-csharp.tests/No Resources/UnitTest1.capnp rename to CapnpC.CSharp.Generator.Tests/Embedded Resources/UnitTest1.capnp diff --git a/capnpc-csharp.tests/Embedded Resources/UnitTest1.capnp.bin b/CapnpC.CSharp.Generator.Tests/Embedded Resources/UnitTest1.capnp.bin similarity index 100% rename from capnpc-csharp.tests/Embedded Resources/UnitTest1.capnp.bin rename to CapnpC.CSharp.Generator.Tests/Embedded Resources/UnitTest1.capnp.bin diff --git a/capnpc-csharp.tests/Embedded Resources/UnitTest10.capnp.bin b/CapnpC.CSharp.Generator.Tests/Embedded Resources/UnitTest10.capnp.bin similarity index 100% rename from capnpc-csharp.tests/Embedded Resources/UnitTest10.capnp.bin rename to CapnpC.CSharp.Generator.Tests/Embedded Resources/UnitTest10.capnp.bin diff --git a/capnpc-csharp.tests/Embedded Resources/UnitTest11.capnp.bin b/CapnpC.CSharp.Generator.Tests/Embedded Resources/UnitTest11.capnp.bin similarity index 100% rename from capnpc-csharp.tests/Embedded Resources/UnitTest11.capnp.bin rename to CapnpC.CSharp.Generator.Tests/Embedded Resources/UnitTest11.capnp.bin diff --git a/capnpc-csharp.tests/Embedded Resources/UnitTest2.capnp.bin b/CapnpC.CSharp.Generator.Tests/Embedded Resources/UnitTest2.capnp.bin similarity index 100% rename from capnpc-csharp.tests/Embedded Resources/UnitTest2.capnp.bin rename to CapnpC.CSharp.Generator.Tests/Embedded Resources/UnitTest2.capnp.bin diff --git a/capnpc-csharp.tests/Embedded Resources/UnitTest20.capnp.bin b/CapnpC.CSharp.Generator.Tests/Embedded Resources/UnitTest20.capnp.bin similarity index 100% rename from capnpc-csharp.tests/Embedded Resources/UnitTest20.capnp.bin rename to CapnpC.CSharp.Generator.Tests/Embedded Resources/UnitTest20.capnp.bin diff --git a/capnpc-csharp.tests/Embedded Resources/UnitTest3.capnp.bin b/CapnpC.CSharp.Generator.Tests/Embedded Resources/UnitTest3.capnp.bin similarity index 100% rename from capnpc-csharp.tests/Embedded Resources/UnitTest3.capnp.bin rename to CapnpC.CSharp.Generator.Tests/Embedded Resources/UnitTest3.capnp.bin diff --git a/capnpc-csharp.tests/Embedded Resources/UnitTest4.capnp.bin b/CapnpC.CSharp.Generator.Tests/Embedded Resources/UnitTest4.capnp.bin similarity index 100% rename from capnpc-csharp.tests/Embedded Resources/UnitTest4.capnp.bin rename to CapnpC.CSharp.Generator.Tests/Embedded Resources/UnitTest4.capnp.bin diff --git a/CapnpC.CSharp.Generator.Tests/Embedded Resources/invalid.capnp b/CapnpC.CSharp.Generator.Tests/Embedded Resources/invalid.capnp new file mode 100644 index 0000000..b56b978 --- /dev/null +++ b/CapnpC.CSharp.Generator.Tests/Embedded Resources/invalid.capnp @@ -0,0 +1,11 @@ +@0xa5ac546b7bf6fbbc + +enum Enumerant { + byte @0; + bit @1; +} + +struct Foo { + foo @0: UInt8; + bar @0: UInt8; +} diff --git a/capnpc-csharp.tests/Embedded Resources/null.bin b/CapnpC.CSharp.Generator.Tests/Embedded Resources/null.bin similarity index 100% rename from capnpc-csharp.tests/Embedded Resources/null.bin rename to CapnpC.CSharp.Generator.Tests/Embedded Resources/null.bin diff --git a/capnpc-csharp.tests/Embedded Resources/schema-with-offsets.capnp.bin b/CapnpC.CSharp.Generator.Tests/Embedded Resources/schema-with-offsets.capnp.bin similarity index 100% rename from capnpc-csharp.tests/Embedded Resources/schema-with-offsets.capnp.bin rename to CapnpC.CSharp.Generator.Tests/Embedded Resources/schema-with-offsets.capnp.bin diff --git a/capnpc-csharp.tests/Embedded Resources/test.capnp.bin b/CapnpC.CSharp.Generator.Tests/Embedded Resources/test.capnp.bin similarity index 100% rename from capnpc-csharp.tests/Embedded Resources/test.capnp.bin rename to CapnpC.CSharp.Generator.Tests/Embedded Resources/test.capnp.bin diff --git a/capnpc-csharp.tests/Embedded Resources/test.cs b/CapnpC.CSharp.Generator.Tests/Embedded Resources/test.cs similarity index 100% rename from capnpc-csharp.tests/Embedded Resources/test.cs rename to CapnpC.CSharp.Generator.Tests/Embedded Resources/test.cs diff --git a/CapnpC.CSharp.Generator.Tests/FeatureSteps/CodeGeneratorSteps.cs b/CapnpC.CSharp.Generator.Tests/FeatureSteps/CodeGeneratorSteps.cs new file mode 100644 index 0000000..83fc17a --- /dev/null +++ b/CapnpC.CSharp.Generator.Tests/FeatureSteps/CodeGeneratorSteps.cs @@ -0,0 +1,149 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Reflection; +using TechTalk.SpecFlow; + +namespace CapnpC.CSharp.Generator.Tests +{ + [Binding] + public class CodeGeneratorSteps + { + Stream _inputStream; + string _inputSchemaFileName; + string _inputSchema; + string _referenceOutputContent; + + GenerationResult _result; + + public static Stream LoadResource(string name) + { + var assembly = Assembly.GetExecutingAssembly(); + string[] names = assembly.GetManifestResourceNames(); + string urn = Array.Find(names, n => n.EndsWith(name, StringComparison.OrdinalIgnoreCase)); + Assert.IsNotNull(urn, $"Test specification error: {name} does not exist"); + return assembly.GetManifestResourceStream(urn); + } + + internal static bool IsCapnpExeInstalled() + { + using (var process = Process.Start("where", "capnp.exe")) + { + if (process == null) + Assert.Fail("Unable to start 'where'"); + + process.WaitForExit(); + + return process.ExitCode == 0; + } + } + + [Given(@"I have a binary code generator request ""(.*)""")] + [Given(@"I have a binary code generator request (.*)")] + public void GivenIHaveABinaryCodeGeneratorRequest(string binaryRequestFileName) + { + _inputStream = LoadResource(binaryRequestFileName); + } + + [Given(@"my reference output is ""(.*)""")] + public void GivenMyReferenceOutputIs(string expectedOutputFileName) + { + using (var stream = LoadResource(expectedOutputFileName)) + using (var reader = new StreamReader(stream)) + { + _referenceOutputContent = reader.ReadToEnd(); + } + } + + [When(@"I invoke capnpc-csharp")] + public void WhenIInvokeCapnpc_Csharp() + { + using (_inputStream) + { + _result = CapnpCompilation.GenerateFromStream(_inputStream); + } + } + + [Then(@"the generated output must match the reference")] + public void ThenTheGeneratedOutputMustMatchTheReference() + { + Assert.IsTrue(_result.IsSuccess, $"Tool invocation failed: {_result.Exception?.Message}"); + Assert.AreEqual(_referenceOutputContent, _result.GeneratedFiles.Single().GeneratedContent); + } + + [Then(@"the invocation must fail")] + public void ThenTheInvocationMustFail() + { + Assert.IsFalse(_result.IsSuccess, "Tool invocation was supposed to fail, but it didn't"); + Assert.IsNotNull(_result.Exception, "Expected an exception"); + } + + [Given(@"capnp\.exe is installed on my system")] + public void GivenCapnp_ExeIsInstalledOnMySystem() + { + if (!IsCapnpExeInstalled()) + { + Assert.Inconclusive("capnp.exe not found. Precondition of this test is not met."); + } + } + + [Given(@"I have a schema ""(.*)""")] + public void GivenIHaveASchema(string capnpFileName) + { + _inputSchemaFileName = capnpFileName; + + using (var stream = LoadResource(capnpFileName)) + using (var reader = new StreamReader(stream)) + { + _inputSchema = reader.ReadToEnd(); + } + } + + [When(@"I try to generate code from that schema")] + public void WhenIWantToGenerateCodeFromThatSchema() + { + string path = Path.Combine(Path.GetTempPath(), _inputSchemaFileName); + File.WriteAllText(path, _inputSchema); + _result = CapnpCompilation.InvokeCapnpAndGenerate(new string[] { path }); + } + + [Then(@"code generation must succeed")] + public void ThenCodeGenerationMustSucceed() + { + Assert.IsNotNull(_result, "expected generation result"); + Assert.IsTrue(_result.IsSuccess, $"Tool invocation failed: {_result.Exception?.Message}"); + Assert.IsTrue(_result.GeneratedFiles.Count == 1, "Expected exactly one file"); + Assert.IsTrue(_result.GeneratedFiles[0].IsSuccess, $"Code generation failed: {_result.GeneratedFiles[0].Exception?.Message}"); + Assert.IsFalse(string.IsNullOrEmpty(_result.GeneratedFiles[0].GeneratedContent), "Expected non-empty generated content"); + } + + [Given(@"capnp\.exe is not installed on my system")] + public void GivenCapnp_ExeIsNotInstalledOnMySystem() + { + if (IsCapnpExeInstalled()) + { + Assert.Inconclusive("capnp.exe found. Precondition of this test is not met."); + } + } + + [Then(@"the reason must be bad input")] + public void ThenTheReasonMustBeBadInput() + { + Assert.IsTrue(_result.ErrorCategory == CapnpProcessFailure.BadInput); + } + + [Then(@"the error output must contain ""(.*)""")] + public void ThenTheErrorOutputMustContain(string p0) + { + Assert.IsTrue(_result.Messages.Any(m => m.FullMessage.Contains(p0))); + } + + [Then(@"the error output must contain multiple messages")] + public void ThenTheErrorOutputMustContainMultipleMessages() + { + Assert.IsTrue(_result.Messages.Count >= 2); + } + } +} diff --git a/capnpc-csharp.tests/No Resources/UnitTest10.capnp b/CapnpC.CSharp.Generator.Tests/No Resources/UnitTest10.capnp similarity index 100% rename from capnpc-csharp.tests/No Resources/UnitTest10.capnp rename to CapnpC.CSharp.Generator.Tests/No Resources/UnitTest10.capnp diff --git a/capnpc-csharp.tests/No Resources/UnitTest10b.capnp b/CapnpC.CSharp.Generator.Tests/No Resources/UnitTest10b.capnp similarity index 100% rename from capnpc-csharp.tests/No Resources/UnitTest10b.capnp rename to CapnpC.CSharp.Generator.Tests/No Resources/UnitTest10b.capnp diff --git a/capnpc-csharp.tests/No Resources/UnitTest11.capnp b/CapnpC.CSharp.Generator.Tests/No Resources/UnitTest11.capnp similarity index 100% rename from capnpc-csharp.tests/No Resources/UnitTest11.capnp rename to CapnpC.CSharp.Generator.Tests/No Resources/UnitTest11.capnp diff --git a/capnpc-csharp.tests/No Resources/UnitTest11b.capnp b/CapnpC.CSharp.Generator.Tests/No Resources/UnitTest11b.capnp similarity index 100% rename from capnpc-csharp.tests/No Resources/UnitTest11b.capnp rename to CapnpC.CSharp.Generator.Tests/No Resources/UnitTest11b.capnp diff --git a/capnpc-csharp.tests/No Resources/UnitTest2.capnp b/CapnpC.CSharp.Generator.Tests/No Resources/UnitTest2.capnp similarity index 100% rename from capnpc-csharp.tests/No Resources/UnitTest2.capnp rename to CapnpC.CSharp.Generator.Tests/No Resources/UnitTest2.capnp diff --git a/capnpc-csharp.tests/No Resources/UnitTest20.capnp b/CapnpC.CSharp.Generator.Tests/No Resources/UnitTest20.capnp similarity index 100% rename from capnpc-csharp.tests/No Resources/UnitTest20.capnp rename to CapnpC.CSharp.Generator.Tests/No Resources/UnitTest20.capnp diff --git a/capnpc-csharp.tests/No Resources/UnitTest3.capnp b/CapnpC.CSharp.Generator.Tests/No Resources/UnitTest3.capnp similarity index 100% rename from capnpc-csharp.tests/No Resources/UnitTest3.capnp rename to CapnpC.CSharp.Generator.Tests/No Resources/UnitTest3.capnp diff --git a/capnpc-csharp.tests/No Resources/UnitTest4.capnp b/CapnpC.CSharp.Generator.Tests/No Resources/UnitTest4.capnp similarity index 100% rename from capnpc-csharp.tests/No Resources/UnitTest4.capnp rename to CapnpC.CSharp.Generator.Tests/No Resources/UnitTest4.capnp diff --git a/capnpc-csharp.tests/No Resources/UnitTest4b.capnp b/CapnpC.CSharp.Generator.Tests/No Resources/UnitTest4b.capnp similarity index 100% rename from capnpc-csharp.tests/No Resources/UnitTest4b.capnp rename to CapnpC.CSharp.Generator.Tests/No Resources/UnitTest4b.capnp diff --git a/capnpc-csharp.tests/No Resources/test.capnp b/CapnpC.CSharp.Generator.Tests/No Resources/test.capnp similarity index 100% rename from capnpc-csharp.tests/No Resources/test.capnp rename to CapnpC.CSharp.Generator.Tests/No Resources/test.capnp diff --git a/CapnpC.CSharp.Generator.Tests/capnpc-csharp.tests.csproj b/CapnpC.CSharp.Generator.Tests/capnpc-csharp.tests.csproj new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/CapnpC.CSharp.Generator.Tests/capnpc-csharp.tests.csproj @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/CapnpC.CSharp.Generator/CapnpC.CSharp.Generator.csproj b/CapnpC.CSharp.Generator/CapnpC.CSharp.Generator.csproj index 53233fd..377d454 100644 --- a/CapnpC.CSharp.Generator/CapnpC.CSharp.Generator.csproj +++ b/CapnpC.CSharp.Generator/CapnpC.CSharp.Generator.csproj @@ -1,7 +1,7 @@  - netcoreapp2.1 + netstandard2.0;netcoreapp2.1 diff --git a/CapnpC.CSharp.Generator/CapnpCompilation.cs b/CapnpC.CSharp.Generator/CapnpCompilation.cs index 9f1a0a4..ec4c342 100644 --- a/CapnpC.CSharp.Generator/CapnpCompilation.cs +++ b/CapnpC.CSharp.Generator/CapnpCompilation.cs @@ -1,7 +1,12 @@ using Capnp; using System; +using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Runtime.CompilerServices; +using System.Text.RegularExpressions; + +[assembly: InternalsVisibleTo("CapnpC.CSharp.Generator.Tests")] namespace CapnpC.CSharp.Generator { @@ -23,13 +28,7 @@ namespace CapnpC.CSharp.Generator try { - WireFrame segments; - - using (input) - { - segments = Framing.ReadSegments(input); - } - + var segments = Framing.ReadSegments(input); var dec = DeserializerState.CreateRoot(segments); var reader = Schema.CodeGeneratorRequest.Reader.Create(dec); var model = Model.SchemaModel.Create(reader); @@ -42,8 +41,66 @@ namespace CapnpC.CSharp.Generator } } - public static GenerationResult InvokeCapnpcAndGenerate() + /// + /// Invokes "capnp.exe -o-" with given additional arguments and redirects the output to the C# generator backend. + /// + /// additional command line arguments + /// generation result + /// is null + public static GenerationResult InvokeCapnpAndGenerate(IEnumerable arguments) { + if (arguments == null) + throw new ArgumentNullException(nameof(arguments)); + + using (var compiler = new Process()) + { + var argList = new List(); + argList.Add("compile"); + argList.Add($"-o-"); + argList.AddRange(arguments); + + compiler.StartInfo.FileName = "capnp.exe"; + compiler.StartInfo.Arguments = string.Join(" ", argList); + compiler.StartInfo.UseShellExecute = false; + compiler.StartInfo.RedirectStandardOutput = true; + compiler.StartInfo.RedirectStandardError = true; + + try + { + compiler.Start(); + } + catch (Exception exception) + { + return new GenerationResult(exception) + { + ErrorCategory = CapnpProcessFailure.NotFound + }; + } + + var result = GenerateFromStream(compiler.StandardOutput.BaseStream); + + var messageList = new List(); + + while (!compiler.StandardError.EndOfStream) + { + messageList.Add(new CapnpMessage(compiler.StandardError.ReadLine())); + } + + result.Messages = messageList; + + if (!result.IsSuccess) + { + compiler.WaitForExit(); + int exitCode = compiler.ExitCode; + + if (exitCode == 0) + result.ErrorCategory = CapnpProcessFailure.BadOutput; + else + result.ErrorCategory = CapnpProcessFailure.BadInput; + } + + return result; + } } } } diff --git a/CapnpC.CSharp.Generator/CapnpMessage.cs b/CapnpC.CSharp.Generator/CapnpMessage.cs new file mode 100644 index 0000000..0cc60b8 --- /dev/null +++ b/CapnpC.CSharp.Generator/CapnpMessage.cs @@ -0,0 +1,116 @@ +using System.Runtime.CompilerServices; +using System.Text.RegularExpressions; + +[assembly: InternalsVisibleTo("CapnpC.CSharp.Generator.Tests")] + +namespace CapnpC.CSharp.Generator +{ + /// + /// Represents a capnp.exe output message + /// + public class CapnpMessage + { + // capnp outputs look like this: + // empty.capnp:1:1: error: File does not declare an ID. I've generated one for you. Add this line to your file: @0xc82955a0c779197d; + // f:\code\invalid.capnp:9:7-8: error: Ordinal @0 originally used here. + // Parsing them is harder than it seems because the colon may be part of the file name (as in the example above). + // And it becomes even worse! NTFS has a rarely used feature called "alternate data streams", identified by a colon: + // f:\code\somefile:stream.capnp:9:7-8: error: Ordinal @0 originally used here. + // What about a name which looks like a line number? (Hint: the 10 denotes the alternate data stream) + // f:\code\somefile:10:9:7-8: error: Ordinal @0 originally used here. + // Watching for the *last* colon as message separator does not work either, either. See first example. + // Strategy: Watch out for the *last* occurence of pattern :[line]:[column] + + static readonly Regex LineColumnRegex = new Regex(@":(?\d+):(?\d+)(-(?\d+))?:", RegexOptions.Compiled | RegexOptions.RightToLeft); + + /// + /// Constructs an instance from given message + /// + /// output message (one line) + public CapnpMessage(string fullMessage) + { + FullMessage = fullMessage; + + var match = LineColumnRegex.Match(fullMessage); + + if (match.Success) + { + IsParseSuccess = true; + FileName = fullMessage.Substring(0, match.Index); + var lineMatch = match.Groups["Line"]; + if (lineMatch.Success) + { + int.TryParse(lineMatch.Value, out int value); + Line = value; + } + var columnMatch = match.Groups["Column"]; + if (columnMatch.Success) + { + int.TryParse(columnMatch.Value, out int value); + Column = value; + } + var endColumnMatch = match.Groups["EndColumn"]; + if (endColumnMatch.Success) + { + int.TryParse(endColumnMatch.Value, out int value); + EndColumn = value; + } + + int restIndex = match.Index + match.Length; + int bodyIndex = fullMessage.IndexOf(':', restIndex); + + if (bodyIndex >= 0) + { + Category = fullMessage.Substring(restIndex, bodyIndex - restIndex).Trim(); + MessageText = fullMessage.Substring(bodyIndex + 1).Trim(); + } + else + { + // Never observed "in the wild", just in case... + Category = string.Empty; + MessageText = fullMessage.Substring(restIndex).Trim(); + } + } + } + + /// + /// The original message + /// + public string FullMessage { get; } + + /// + /// Whether the message could be decompsed into [filename]:[line]:[column]: [category]: [text] + /// + public bool IsParseSuccess { get; } + + /// + /// Parsed file name (null iff not IsParseSuccess) + /// + public string FileName { get; } + + /// + /// Parsed line (0 if not IsParseSuccess) + /// + public int Line { get; } + + /// + /// Parsed column (0 if not IsParseSuccess) + /// + public int Column { get; } + + /// + /// Parsed end column (0 if there is none) + /// + public int EndColumn { get; } + + /// + /// Parsed category (e.g. "error", null iff not IsParseSuccess) + /// + public string Category { get; } + + /// + /// Parsed message body text (0 if not IsParseSuccess) + /// + public string MessageText { get; } + } +} diff --git a/CapnpC.CSharp.Generator/CapnpProcessFailure.cs b/CapnpC.CSharp.Generator/CapnpProcessFailure.cs new file mode 100644 index 0000000..1d51c0f --- /dev/null +++ b/CapnpC.CSharp.Generator/CapnpProcessFailure.cs @@ -0,0 +1,23 @@ +namespace CapnpC.CSharp.Generator +{ + /// + /// Why did invocation of capnpc.exe fail? + /// + public enum CapnpProcessFailure + { + /// + /// Because capnpc.exe was not found. It is probably not installed. + /// + NotFound, + + /// + /// Because it exited with an error. Probably invalid .capnp file input. + /// + BadInput, + + /// + /// Because it produced an apparently bad code generation request. + /// + BadOutput + } +} diff --git a/CapnpC.CSharp.Generator/CodeGen/CodeGenerator.cs b/CapnpC.CSharp.Generator/CodeGen/CodeGenerator.cs index c983ccc..d873108 100644 --- a/CapnpC.CSharp.Generator/CodeGen/CodeGenerator.cs +++ b/CapnpC.CSharp.Generator/CodeGen/CodeGenerator.cs @@ -11,7 +11,7 @@ using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; using static SyntaxHelpers; - class CodeGenerator + internal class CodeGenerator { readonly SchemaModel _model; readonly GenNames _names; diff --git a/CapnpC.CSharp.Generator/GenerationResult.cs b/CapnpC.CSharp.Generator/GenerationResult.cs index 3f40fc5..672759a 100644 --- a/CapnpC.CSharp.Generator/GenerationResult.cs +++ b/CapnpC.CSharp.Generator/GenerationResult.cs @@ -40,5 +40,15 @@ namespace CapnpC.CSharp.Generator /// true iff generation was successful /// public bool IsSuccess => GeneratedFiles != null; + + /// + /// Messages read from standard error. Valid for both failure and success (capnp might spit out some warnings). + /// + public IReadOnlyList Messages { get; internal set; } + + /// + /// Error classification (if any error) + /// + public CapnpProcessFailure ErrorCategory { get; internal set; } } } diff --git a/CapnpC.CSharp.MsBuild.Generation.Tests/BuildEngineMock.cs b/CapnpC.CSharp.MsBuild.Generation.Tests/BuildEngineMock.cs new file mode 100644 index 0000000..f5afe60 --- /dev/null +++ b/CapnpC.CSharp.MsBuild.Generation.Tests/BuildEngineMock.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections; +using Microsoft.Build.Framework; + +namespace CapnpC.CSharp.MsBuild.Generation.Tests +{ + class BuildEngineMock : IBuildEngine + { + public bool ContinueOnError => true; + + public int LineNumberOfTaskNode => 0; + + public int ColumnNumberOfTaskNode => 0; + + public string ProjectFileOfTaskNode => null; + + public bool BuildProjectFile(string projectFileName, string[] targetNames, IDictionary globalProperties, IDictionary targetOutputs) + { + return true; + } + + public void LogCustomEvent(CustomBuildEventArgs e) + { + Console.WriteLine(e.Message); + } + + public void LogErrorEvent(BuildErrorEventArgs e) + { + Console.WriteLine(e.Message); + } + + public void LogMessageEvent(BuildMessageEventArgs e) + { + Console.WriteLine(e.Message); + } + + public void LogWarningEvent(BuildWarningEventArgs e) + { + Console.WriteLine(e.Message); + } + } +} diff --git a/CapnpC.CSharp.MsBuild.Generation.Tests/CapnpC.CSharp.MsBuild.Generation.Tests.csproj b/CapnpC.CSharp.MsBuild.Generation.Tests/CapnpC.CSharp.MsBuild.Generation.Tests.csproj new file mode 100644 index 0000000..fe274f1 --- /dev/null +++ b/CapnpC.CSharp.MsBuild.Generation.Tests/CapnpC.CSharp.MsBuild.Generation.Tests.csproj @@ -0,0 +1,21 @@ + + + + netcoreapp2.2 + + false + + + + + + + + + + + + + + + diff --git a/CapnpC.CSharp.MsBuild.Generation.Tests/GenerateCapnpFileCodeBehindTaskTest.cs b/CapnpC.CSharp.MsBuild.Generation.Tests/GenerateCapnpFileCodeBehindTaskTest.cs new file mode 100644 index 0000000..b6a7c6b --- /dev/null +++ b/CapnpC.CSharp.MsBuild.Generation.Tests/GenerateCapnpFileCodeBehindTaskTest.cs @@ -0,0 +1,51 @@ +using CapnpC.CSharp.Generator.Tests; +using Microsoft.Build.Framework; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.IO; + +namespace CapnpC.CSharp.MsBuild.Generation.Tests +{ + [TestClass] + public class GenerateCapnpFileCodeBehindTaskTest + { + string LoadResourceContent(string name) + { + using (var stream = CodeGeneratorSteps.LoadResource("UnitTest1.capnp")) + using (var reader = new StreamReader(stream)) + { + return reader.ReadToEnd(); + } + } + + [TestMethod] + public void ExecutionWithoutParameters() + { + var task = new GenerateCapnpFileCodeBehindTask(); + task.BuildEngine = new BuildEngineMock(); + task.Execute(); + // Should not crash. Should Execute() return true or false if there is no input? + } + + [TestMethod] + public void SimpleGeneration() + { + string capnpFile = "UnitTask1.capnp"; + string content = LoadResourceContent(capnpFile); + string tmpPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); + Directory.CreateDirectory(tmpPath); + string capnpPath = Path.Combine(tmpPath, capnpFile); + File.WriteAllText(capnpPath, content); + + var task = new GenerateCapnpFileCodeBehindTask(); + task.BuildEngine = new BuildEngineMock(); + task.ProjectPath = Path.Combine(tmpPath, "doesnotneedtoexist.csproj"); + task.CapnpFiles = new ITaskItem[1] { new TaskItemMock() { ItemSpec = capnpPath } }; + Assert.IsTrue(task.Execute()); + Assert.IsNotNull(task.GeneratedFiles); + Assert.AreEqual(1, task.GeneratedFiles.Length); + string csPath = Path.Combine(tmpPath, task.GeneratedFiles[0].ItemSpec); + Assert.AreEqual(capnpPath + ".cs", csPath); + Assert.IsTrue(File.Exists(csPath)); + } + } +} diff --git a/CapnpC.CSharp.MsBuild.Generation.Tests/TaskItemMock.cs b/CapnpC.CSharp.MsBuild.Generation.Tests/TaskItemMock.cs new file mode 100644 index 0000000..6cf0f5a --- /dev/null +++ b/CapnpC.CSharp.MsBuild.Generation.Tests/TaskItemMock.cs @@ -0,0 +1,37 @@ +using System.Collections; +using Microsoft.Build.Framework; + +namespace CapnpC.CSharp.MsBuild.Generation.Tests +{ + + class TaskItemMock : ITaskItem + { + public string ItemSpec { get; set; } + + public ICollection MetadataNames => null; + + public int MetadataCount => 0; + + public IDictionary CloneCustomMetadata() + { + return null; + } + + public void CopyMetadataTo(ITaskItem destinationItem) + { + } + + public string GetMetadata(string metadataName) + { + return null; + } + + public void RemoveMetadata(string metadataName) + { + } + + public void SetMetadata(string metadataName, string metadataValue) + { + } + } +} diff --git a/CapnpC.CSharp.MsBuild.Generation/CsFileGeneratorResult.cs b/CapnpC.CSharp.MsBuild.Generation/CsFileGeneratorResult.cs new file mode 100644 index 0000000..75961ac --- /dev/null +++ b/CapnpC.CSharp.MsBuild.Generation/CsFileGeneratorResult.cs @@ -0,0 +1,51 @@ +using CapnpC.CSharp.Generator; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace CapnpC.CSharp.MsBuild.Generation +{ + public class CsFileGeneratorResult + { + public CsFileGeneratorResult(FileGenerationResult generatorResult, string fileName, IReadOnlyList messages) + { + if (generatorResult == null) + { + throw new ArgumentNullException(nameof(generatorResult)); + } + + Filename = fileName ?? throw new ArgumentNullException(nameof(fileName)); + + Error = generatorResult.Exception?.Message; + GeneratedCode = generatorResult.GeneratedContent; + Messages = messages; + } + + public CsFileGeneratorResult(string error) + { + Error = error; + } + + public CsFileGeneratorResult(string error, IReadOnlyList messages) + { + Error = error; + Messages = messages; + } + + /// + /// The error, if any. + /// + public string Error { get; } + + /// + /// The generated code. + /// + public string GeneratedCode { get; } + + public IReadOnlyList Messages { get; } + + public bool Success => Error == null; + + public string Filename { get; } + } +} \ No newline at end of file diff --git a/Capnpc.Csharp.MsBuild.Generation/CapnpCodeBehindGenerator.cs b/Capnpc.Csharp.MsBuild.Generation/CapnpCodeBehindGenerator.cs index 97ab0ba..71c0592 100644 --- a/Capnpc.Csharp.MsBuild.Generation/CapnpCodeBehindGenerator.cs +++ b/Capnpc.Csharp.MsBuild.Generation/CapnpCodeBehindGenerator.cs @@ -1,41 +1,85 @@ -using System; +using CapnpC.CSharp.Generator; +using System; using System.Collections.Generic; using System.IO; -namespace Capnpc.Csharp.MsBuild.Generation +namespace CapnpC.CSharp.MsBuild.Generation { public class CapnpCodeBehindGenerator : IDisposable { - //private SpecFlowProject _specFlowProject; - //private ITestGenerator _testGenerator; public void InitializeProject(string projectPath) { - //_specFlowProject = MsBuildProjectReader.LoadSpecFlowProjectFromMsBuild(Path.GetFullPath(projectPath), rootNamespace); - - //var projectSettings = _specFlowProject.ProjectSettings; - - //var testGeneratorFactory = new TestGeneratorFactory(); - - //_testGenerator = testGeneratorFactory.CreateGenerator(projectSettings, generatorPlugins); } - public TestFileGeneratorResult GenerateCodeBehindFile(string capnpFile) + public CsFileGeneratorResult GenerateCodeBehindFile(string capnpFile) { - //var featureFileInput = new FeatureFileInput(featureFile); - //var generatedFeatureFileName = Path.GetFileName(_testGenerator.GetTestFullPath(featureFileInput)); + // Works around a weird capnp.exe behavior: When the input file is empty, it will spit out an exception dump + // instead of a parse error. But the parse error is nice because it contains a generated ID. We want the parse error! + // Workaround: Generate a temporary file that contains a single line break (such that it is not empty...) + try + { + if (File.Exists(capnpFile) && new FileInfo(capnpFile).Length == 0) + { + string tempFile = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + ".capnp"); - //var testGeneratorResult = _testGenerator.GenerateTestFile(featureFileInput, new GenerationSettings()); + File.WriteAllText(tempFile, Environment.NewLine); + try + { + return GenerateCodeBehindFile(tempFile); + } + finally + { + File.Delete(tempFile); + } + } + } + catch + { + } - return new TestFileGeneratorResult( - new TestGeneratorResult() { GeneratedTestCode = "//dummy" }, - capnpFile + ".cs"); + var result = CapnpCompilation.InvokeCapnpAndGenerate(new string[] { capnpFile }); + + if (result.IsSuccess) + { + if (result.GeneratedFiles.Count == 1) + { + return new CsFileGeneratorResult( + result.GeneratedFiles[0], + capnpFile + ".cs", + result.Messages); + } + else + { + return new CsFileGeneratorResult( + "Code generation produced more than one file. This is not supported.", + result.Messages); + } + } + else + { + switch (result.ErrorCategory) + { + case CapnpProcessFailure.NotFound: + return new CsFileGeneratorResult("Unable to find capnp.exe - please install capnproto on your system first."); + + case CapnpProcessFailure.BadInput: + return new CsFileGeneratorResult("Invalid schema", result.Messages); + + case CapnpProcessFailure.BadOutput: + return new CsFileGeneratorResult( + "Internal error: capnp.exe produced a binary code generation request which was not understood by the backend", + result.Messages); + + default: + throw new NotSupportedException("Invalid error category"); + } + } } public void Dispose() { - //_testGenerator?.Dispose(); } } } \ No newline at end of file diff --git a/Capnpc.Csharp.MsBuild.Generation/CapnpFileCodeBehindGenerator.cs b/Capnpc.Csharp.MsBuild.Generation/CapnpFileCodeBehindGenerator.cs index 6802c12..188830b 100644 --- a/Capnpc.Csharp.MsBuild.Generation/CapnpFileCodeBehindGenerator.cs +++ b/Capnpc.Csharp.MsBuild.Generation/CapnpFileCodeBehindGenerator.cs @@ -5,16 +5,13 @@ using System.Text; using System.Threading.Tasks; using Microsoft.Build.Utilities; -namespace Capnpc.Csharp.MsBuild.Generation +namespace CapnpC.CSharp.MsBuild.Generation { public class CapnpFileCodeBehindGenerator : ICapnpcCsharpGenerator { - private readonly FilePathGenerator _filePathGenerator; - public CapnpFileCodeBehindGenerator(TaskLoggingHelper log) { Log = log ?? throw new ArgumentNullException(nameof(log)); - _filePathGenerator = new FilePathGenerator(); } public TaskLoggingHelper Log { get; } @@ -39,33 +36,44 @@ namespace Capnpc.Csharp.MsBuild.Generation foreach (var capnpFile in capnpFiles) { - var capnpFileItemSpec = capnpFile; - var generatorResult = capnpCodeBehindGenerator.GenerateCodeBehindFile(capnpFileItemSpec); + var generatorResult = capnpCodeBehindGenerator.GenerateCodeBehindFile(capnpFile); if (!generatorResult.Success) { - foreach (var error in generatorResult.Errors) + if (!string.IsNullOrEmpty(generatorResult.Error)) { - //Log.LogError( - // null, - // null, - // null, - // featureFile, - // error.Line, - // error.LinePosition, - // 0, - // 0, - // error.Message); + Log.LogError("{0}", generatorResult.Error); } + + if (generatorResult.Messages != null) + { + foreach (var message in generatorResult.Messages) + { + if (message.IsParseSuccess) + { + Log.LogError( + subcategory: null, + errorCode: null, + helpKeyword: null, + file: capnpFile, + lineNumber: message.Line, + columnNumber: message.Column, + endLineNumber: message.Line, + endColumnNumber: message.EndColumn == 0 ? message.Column : message.EndColumn, + "{0}", + message.MessageText); + } + else + { + Log.LogError("{0}", message.FullMessage); + } + } + } + continue; } - var targetFilePath = _filePathGenerator.GenerateFilePath( - projectFolder, - capnpFile, - generatorResult.Filename); - - var resultedFile = codeBehindWriter.WriteCodeBehindFile(targetFilePath, capnpFile, generatorResult); + var resultedFile = codeBehindWriter.WriteCodeBehindFile(generatorResult.Filename, generatorResult); yield return FileSystemHelper.GetRelativePath(resultedFile, projectFolder); } diff --git a/Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.csproj b/Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.csproj index 67c482c..bbb9e95 100644 --- a/Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.csproj +++ b/Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.csproj @@ -2,9 +2,6 @@ net471;netcoreapp2.1 false - $(MSBuildThisFileDirectory)Capnpc.Csharp.MsBuild.Generation.nuspec - true - true true @@ -12,6 +9,13 @@ true true $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb + 1.0.0.0 + 1.0.0.0 + 1.0.0 + + $(MSBuildThisFileDirectory)CapnpC.CSharp.MsBuild.Generation.nuspec + version=$(Version) + true @@ -54,6 +58,12 @@ + + + true + + + Microsoft.Build @@ -68,11 +78,28 @@ + + Always + + + Always + + + Always + + + Always + + + Always + MSBuild:Compile + Always MSBuild:Compile + Always diff --git a/Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.nuspec b/Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.nuspec index 887d527..d5073c9 100644 --- a/Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.nuspec +++ b/Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.nuspec @@ -1,9 +1,9 @@ - Capnpc.Csharp.MsBuild.Generation - 1.0.0 - Capnpc.Csharp.MsBuild.Generation + CapnpC.CSharp.MsBuild.Generation + $version$ + CapnpC.CSharp.MsBuild.Generation Christian Köllner and contributors Christian Köllner Package to enable the .capnp -> .cs file generation during build time @@ -15,6 +15,7 @@ capnproto csharp msbuild Christian Köllner and contributors + diff --git a/Capnpc.Csharp.MsBuild.Generation/CodeBehindWriter.cs b/Capnpc.Csharp.MsBuild.Generation/CodeBehindWriter.cs index f581de3..3ff276b 100644 --- a/Capnpc.Csharp.MsBuild.Generation/CodeBehindWriter.cs +++ b/Capnpc.Csharp.MsBuild.Generation/CodeBehindWriter.cs @@ -2,7 +2,7 @@ using System.IO; using Microsoft.Build.Utilities; -namespace Capnpc.Csharp.MsBuild.Generation +namespace CapnpC.CSharp.MsBuild.Generation { public class CodeBehindWriter { @@ -13,14 +13,8 @@ namespace Capnpc.Csharp.MsBuild.Generation public TaskLoggingHelper Log { get; } - public string WriteCodeBehindFile(string outputPath, string capnpFile, TestFileGeneratorResult testFileGeneratorResult) + public string WriteCodeBehindFile(string outputPath, CsFileGeneratorResult testFileGeneratorResult) { - //if (string.IsNullOrEmpty(testFileGeneratorResult.Filename)) - //{ - // Log?.LogWithNameTag(Log.LogError, $"{featureFile} has no generated filename"); - // return null; - //} - string directoryPath = Path.GetDirectoryName(outputPath) ?? throw new InvalidOperationException(); Log?.LogWithNameTag(Log.LogMessage, directoryPath); @@ -35,11 +29,6 @@ namespace Capnpc.Csharp.MsBuild.Generation } else { - if (!Directory.Exists(directoryPath)) - { - Directory.CreateDirectory(directoryPath); - } - File.WriteAllText(outputPath, testFileGeneratorResult.GeneratedCode); } diff --git a/Capnpc.Csharp.MsBuild.Generation/FilePathGenerator.cs b/Capnpc.Csharp.MsBuild.Generation/FilePathGenerator.cs deleted file mode 100644 index 4ac982d..0000000 --- a/Capnpc.Csharp.MsBuild.Generation/FilePathGenerator.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.IO; - -namespace Capnpc.Csharp.MsBuild.Generation -{ - public class FilePathGenerator - { - public string GenerateFilePath(string projectFolder, string capnpFileName, string generatedCodeBehindFileName) - { - if (projectFolder is null) - { - throw new ArgumentNullException(nameof(projectFolder)); - } - - if (capnpFileName is null) - { - throw new ArgumentNullException(nameof(capnpFileName)); - } - - if (generatedCodeBehindFileName is null) - { - throw new ArgumentNullException(nameof(generatedCodeBehindFileName)); - } - - string featureFileFullPath = Path.GetFullPath(Path.Combine(projectFolder, capnpFileName)); - string featureFileDirPath = Path.GetDirectoryName(featureFileFullPath); - - return Path.Combine(featureFileDirPath, generatedCodeBehindFileName); - } - } -} diff --git a/Capnpc.Csharp.MsBuild.Generation/FileSystemHelper.cs b/Capnpc.Csharp.MsBuild.Generation/FileSystemHelper.cs index d27428f..d538531 100644 --- a/Capnpc.Csharp.MsBuild.Generation/FileSystemHelper.cs +++ b/Capnpc.Csharp.MsBuild.Generation/FileSystemHelper.cs @@ -4,7 +4,7 @@ using System.Diagnostics; using System.IO; using System.Text; -namespace Capnpc.Csharp.MsBuild.Generation +namespace CapnpC.CSharp.MsBuild.Generation { public static class FileSystemHelper { diff --git a/Capnpc.Csharp.MsBuild.Generation/GenerateCapnpFileCodeBehindTask.cs b/Capnpc.Csharp.MsBuild.Generation/GenerateCapnpFileCodeBehindTask.cs index b4b9269..d29cf8d 100644 --- a/Capnpc.Csharp.MsBuild.Generation/GenerateCapnpFileCodeBehindTask.cs +++ b/Capnpc.Csharp.MsBuild.Generation/GenerateCapnpFileCodeBehindTask.cs @@ -7,7 +7,7 @@ using System.Resources; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; -namespace Capnpc.Csharp.MsBuild.Generation +namespace CapnpC.CSharp.MsBuild.Generation { public class GenerateCapnpFileCodeBehindTask : Task { diff --git a/Capnpc.Csharp.MsBuild.Generation/Helper/LogExtensions.cs b/Capnpc.Csharp.MsBuild.Generation/Helper/LogExtensions.cs index 1343a80..3203bea 100644 --- a/Capnpc.Csharp.MsBuild.Generation/Helper/LogExtensions.cs +++ b/Capnpc.Csharp.MsBuild.Generation/Helper/LogExtensions.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; using Microsoft.Build.Utilities; -namespace Capnpc.Csharp.MsBuild.Generation +namespace CapnpC.CSharp.MsBuild.Generation { public static class LogExtensions { @@ -15,7 +15,7 @@ namespace Capnpc.Csharp.MsBuild.Generation string message, params object[] messageArgs) { - string fullMessage = $"[SpecFlow] {message}"; + string fullMessage = $"[Cap'n Proto] {message}"; loggingMethod?.Invoke(fullMessage, messageArgs); } } diff --git a/Capnpc.Csharp.MsBuild.Generation/ICapnpCsharpGenerator.cs b/Capnpc.Csharp.MsBuild.Generation/ICapnpCsharpGenerator.cs index d55ed1e..de828fd 100644 --- a/Capnpc.Csharp.MsBuild.Generation/ICapnpCsharpGenerator.cs +++ b/Capnpc.Csharp.MsBuild.Generation/ICapnpCsharpGenerator.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Capnpc.Csharp.MsBuild.Generation +namespace CapnpC.CSharp.MsBuild.Generation { public interface ICapnpcCsharpGenerator { diff --git a/Capnpc.Csharp.MsBuild.Generation/TestFileGeneratorResult.cs b/Capnpc.Csharp.MsBuild.Generation/TestFileGeneratorResult.cs deleted file mode 100644 index 36ab361..0000000 --- a/Capnpc.Csharp.MsBuild.Generation/TestFileGeneratorResult.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Capnpc.Csharp.MsBuild.Generation -{ - public class TestFileGeneratorResult - { - public TestFileGeneratorResult(TestGeneratorResult generatorResult, string fileName) - { - if (generatorResult == null) - { - throw new ArgumentNullException(nameof(generatorResult)); - } - - Filename = fileName ?? throw new ArgumentNullException(nameof(fileName)); - - Errors = generatorResult.Errors; - IsUpToDate = generatorResult.IsUpToDate; - GeneratedCode = generatorResult.GeneratedTestCode; - } - - /// - /// The errors, if any. - /// - public IEnumerable Errors { get; } - - /// - /// The generated file was up-to-date. - /// - public bool IsUpToDate { get; } - - /// - /// The generated code. - /// - public string GeneratedCode { get; } - - public bool Success => Errors == null || !Errors.Any(); - - public string Filename { get; } - } -} \ No newline at end of file diff --git a/Capnpc.Csharp.MsBuild.Generation/TestGenerationError.cs b/Capnpc.Csharp.MsBuild.Generation/TestGenerationError.cs deleted file mode 100644 index 1bf834c..0000000 --- a/Capnpc.Csharp.MsBuild.Generation/TestGenerationError.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Capnpc.Csharp.MsBuild.Generation -{ - public class TestGenerationError - { - } -} \ No newline at end of file diff --git a/Capnpc.Csharp.MsBuild.Generation/TestGeneratorResult.cs b/Capnpc.Csharp.MsBuild.Generation/TestGeneratorResult.cs deleted file mode 100644 index 35b34e3..0000000 --- a/Capnpc.Csharp.MsBuild.Generation/TestGeneratorResult.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Collections.Generic; - -namespace Capnpc.Csharp.MsBuild.Generation -{ - public class TestGeneratorResult - { - public IEnumerable Errors { get; internal set; } - public bool IsUpToDate { get; internal set; } - public string GeneratedTestCode { get; internal set; } - } -} \ No newline at end of file diff --git a/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/CapnpFileType.xaml b/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/CapnpFileType.xaml index ec90cbe..72e5c94 100644 --- a/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/CapnpFileType.xaml +++ b/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/CapnpFileType.xaml @@ -29,7 +29,7 @@ - + \ No newline at end of file diff --git a/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.props b/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.props index fe7e57a..bc41f4e 100644 --- a/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.props +++ b/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.props @@ -54,7 +54,7 @@ - after deletion of a feature file - after pulling latest changes from version control with above changes --> - + - + @@ -128,6 +128,6 @@ - after deletion of a capnp file - after pulling latest changes from version control with above changes --> - + \ No newline at end of file diff --git a/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.tasks b/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.tasks index b20fdae..9859d7b 100644 --- a/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.tasks +++ b/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.tasks @@ -1,3 +1,3 @@  - + \ No newline at end of file diff --git a/Capnpc.Csharp.MsBuild.Generation/buildMultiTargeting/Capnpc.Csharp.MsBuild.Generation.props b/Capnpc.Csharp.MsBuild.Generation/buildMultiTargeting/Capnpc.Csharp.MsBuild.Generation.props index f3c49ea..62930dd 100644 --- a/Capnpc.Csharp.MsBuild.Generation/buildMultiTargeting/Capnpc.Csharp.MsBuild.Generation.props +++ b/Capnpc.Csharp.MsBuild.Generation/buildMultiTargeting/Capnpc.Csharp.MsBuild.Generation.props @@ -1,5 +1,5 @@  - + \ No newline at end of file diff --git a/README.md b/README.md index db6030c..829271a 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ Solution/project structure is as follows: * Capnp.Net.Runtime is the runtime implementation, a .NET assembly. * capnpc-csharp is the generator backend for C# language. * Capnp.Net.Runtime.Tests is an MS Unit Testing assembly, containing - you guessed it - the test suite. - * capnpc-csharp.tests contains the generator backend test suite. + * CapnpC.CSharp.Generator.Tests contains the generator backend test suite. - CapnpCompatTest.sln compiles to a native x86 executable which depends on the original Cap'n Proto C++ implementation. It is (partially) required by the test suite for interoperability testing. ## Features diff --git a/appveyor.yml b/appveyor.yml index b08ea80..00636e7 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -29,7 +29,7 @@ before_build: - cmd: dotnet restore ./Capnp.Net.Runtime.Tests/Capnp.Net.Runtime.Tests.Std20.csproj --verbosity m - cmd: dotnet restore ./Capnp.Net.Runtime.Tests.Core21/Capnp.Net.Runtime.Tests.Core21.csproj --verbosity m - cmd: dotnet restore ./capnpc-csharp/capnpc-csharp.csproj --verbosity m - - cmd: dotnet restore ./capnpc-csharp.tests/capnpc-csharp.tests.csproj --verbosity m + - cmd: dotnet restore ./CapnpC.CSharp.Generator.Tests/CapnpC.CSharp.Generator.Tests.csproj --verbosity m build_script: - cmd: msbuild ./Capnp.Net.sln /p:Configuration="Debug" - cmd: msbuild ./Capnp.Net.sln /p:Configuration="Release" @@ -50,11 +50,12 @@ artifacts: type: NuGetPackage clone_depth: 1 test_script: - - cmd: vstest.console /logger:Appveyor /inIsolation capnpc-csharp.tests\bin\Release\netcoreapp2.2\capnpc-csharp.tests.dll + - cmd: vstest.console /logger:Appveyor /inIsolation CapnpC.CSharp.Generator.Tests\bin\Release\netcoreapp2.2\CapnpC.CSharp.Generator.Tests.dll - cmd: cd %APPVEYOR_BUILD_FOLDER%\chocolatey\install - cmd: choco install capnpc-csharp --source=".;https://chocolatey.org/api/v2" --force -y - cmd: cd %APPVEYOR_BUILD_FOLDER%\install-test - cmd: compile-test + - cmd: vstest.console /logger:Appveyor /inIsolation CapnpC.CSharp.Generator.Tests\bin\Release\netcoreapp2.2\CapnpC.CSharp.Generator.Tests.dll - cmd: choco uninstall capnpc-csharp -y - cmd: notinstalled-test - cmd: cd %APPVEYOR_BUILD_FOLDER%\chocolatey\install diff --git a/capnpc-csharp.tests/CodeGenerator.feature b/capnpc-csharp.tests/CodeGenerator.feature deleted file mode 100644 index 89768b9..0000000 --- a/capnpc-csharp.tests/CodeGenerator.feature +++ /dev/null @@ -1,20 +0,0 @@ -Feature: CodeGenerator - In order to ensure that the generator backend produces valid output - As a contributor - I want to get notified when there is any deviation from reference output - -Scenario: Comparing backend output with reference - Given I have a binary code generator request "test.capnp.bin" - And my reference output is "test.cs" - When I invoke capnpc-csharp - Then the generated output must match the reference - -Scenario Outline: Invalid binary code generator requests - Given I have a binary code generator request - When I invoke capnpc-csharp - Then the invocation must fail - -Examples: - | bin | - | null.bin | - | test.cs | \ No newline at end of file diff --git a/capnpc-csharp.tests/FeatureSteps/CodeGeneratorSteps.cs b/capnpc-csharp.tests/FeatureSteps/CodeGeneratorSteps.cs deleted file mode 100644 index 4d3a893..0000000 --- a/capnpc-csharp.tests/FeatureSteps/CodeGeneratorSteps.cs +++ /dev/null @@ -1,83 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.IO; -using System.Reflection; -using TechTalk.SpecFlow; - -namespace capnpc_csharp.Tests -{ - [Binding] - public class CodeGeneratorSteps - { - Stream _inputStream; - string _referenceOutputContent; - string _exceptedOutputFileName; - string _actualGeneratedContent; - bool _success; - Exception _generateException; - - internal static Stream LoadResource(string name) - { - var assembly = Assembly.GetExecutingAssembly(); - string[] names = assembly.GetManifestResourceNames(); - string urn = Array.Find(names, n => n.EndsWith(name, StringComparison.OrdinalIgnoreCase)); - Assert.IsNotNull(urn, $"Test specification error: {name} does not exist"); - return assembly.GetManifestResourceStream(urn); - } - - [Given(@"I have a binary code generator request ""(.*)""")] - [Given(@"I have a binary code generator request (.*)")] - public void GivenIHaveABinaryCodeGeneratorRequest(string binaryRequestFileName) - { - _inputStream = LoadResource(binaryRequestFileName); - } - - [Given(@"my reference output is ""(.*)""")] - public void GivenMyReferenceOutputIs(string expectedOutputFileName) - { - _exceptedOutputFileName = expectedOutputFileName; - using (var stream = LoadResource(expectedOutputFileName)) - using (var reader = new StreamReader(stream)) - { - _referenceOutputContent = reader.ReadToEnd(); - } - } - - [When(@"I invoke capnpc-csharp")] - public void WhenIInvokeCapnpc_Csharp() - { - try - { - using (_inputStream) - { - string tempDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); - Directory.CreateDirectory(tempDir); - Environment.CurrentDirectory = tempDir; - - CapnpC.Program.GenerateFromStream(_inputStream); - - string outPath = Path.Combine(tempDir, _exceptedOutputFileName); - _actualGeneratedContent = File.ReadAllText(outPath); - _success = true; - } - } - catch (Exception exception) - { - _generateException = exception; - } - } - - [Then(@"the generated output must match the reference")] - public void ThenTheGeneratedOutputMustMatchTheReference() - { - Assert.IsTrue(_success, $"Code generation failed: {_generateException?.Message}"); - Assert.AreEqual(_referenceOutputContent, _actualGeneratedContent); - } - - [Then(@"the invocation must fail")] - public void ThenTheInvocationMustFail() - { - Assert.IsFalse(_success, "Code generation was supposed to fail, but it didn't"); - } - } -} diff --git a/capnpc-csharp/Generator/CodeGenerator.cs b/capnpc-csharp/Generator/CodeGenerator.cs deleted file mode 100644 index e401b3a..0000000 --- a/capnpc-csharp/Generator/CodeGenerator.cs +++ /dev/null @@ -1,182 +0,0 @@ -namespace CapnpC.Generator -{ - using System; - using System.Collections.Generic; - using System.IO; - using System.Linq; - using System.Text; - using CapnpC.Model; - using Microsoft.CodeAnalysis; - using Microsoft.CodeAnalysis.CSharp; - using Microsoft.CodeAnalysis.CSharp.Syntax; - using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; - using static SyntaxHelpers; - - class CodeGenerator - { - readonly SchemaModel _model; - readonly GenNames _names; - readonly CommonSnippetGen _commonGen; - readonly DomainClassSnippetGen _domClassGen; - readonly ReaderSnippetGen _readerGen; - readonly WriterSnippetGen _writerGen; - readonly InterfaceSnippetGen _interfaceGen; - - public CodeGenerator(SchemaModel model, GeneratorOptions options) - { - _model = model; - _names = new GenNames(options); - _commonGen = new CommonSnippetGen(_names); - _domClassGen = new DomainClassSnippetGen(_names); - _readerGen = new ReaderSnippetGen(_names); - _writerGen = new WriterSnippetGen(_names); - _interfaceGen = new InterfaceSnippetGen(_names); - } - - internal GenNames GetNames() => _names; - - IEnumerable TransformEnum(TypeDefinition def) - { - yield return _commonGen.MakeEnum(def); - } - - IEnumerable MakeTypeParameters(TypeDefinition def) - { - foreach (string name in def.GenericParameters) - { - yield return TypeParameter(_names.GetGenericTypeParameter(name).Identifier); - } - } - - IEnumerable MakeTypeParameterConstraints(TypeDefinition def) - { - foreach (string name in def.GenericParameters) - { - yield return TypeParameterConstraintClause( - _names.GetGenericTypeParameter(name).IdentifierName) - .AddConstraints(ClassOrStructConstraint(SyntaxKind.ClassConstraint)); - } - } - - IEnumerable TransformStruct(TypeDefinition def) - { - var topDecl = ClassDeclaration(_names.MakeTypeName(def).Identifier) - .AddModifiers(Public) - .AddBaseListTypes(SimpleBaseType(Type())); - - if (def.GenericParameters.Count > 0) - { - topDecl = topDecl - .AddTypeParameterListParameters(MakeTypeParameters(def).ToArray()) - .AddConstraintClauses(MakeTypeParameterConstraints(def).ToArray()); - } - - if (def.UnionInfo != null) - { - topDecl = topDecl.AddMembers(_commonGen.MakeUnionSelectorEnum(def)); - } - - topDecl = topDecl.AddMembers(_domClassGen.MakeDomainClassMembers(def)); - topDecl = topDecl.AddMembers(_readerGen.MakeReaderStruct(def)); - topDecl = topDecl.AddMembers(_writerGen.MakeWriterStruct(def)); - - foreach (var nestedGroup in def.NestedGroups) - { - topDecl = topDecl.AddMembers(Transform(nestedGroup).ToArray()); - } - - foreach (var nestedDef in def.NestedTypes) - { - topDecl = topDecl.AddMembers(Transform(nestedDef).ToArray()); - } - - yield return topDecl; - } - - IEnumerable TransformInterface(TypeDefinition def) - { - yield return _interfaceGen.MakeInterface(def); - yield return _interfaceGen.MakeProxy(def); - yield return _interfaceGen.MakeSkeleton(def); - - if (_interfaceGen.RequiresPipeliningSupport(def)) - { - yield return _interfaceGen.MakePipeliningSupport(def); - } - - if (def.NestedTypes.Any()) - { - var ns = ClassDeclaration( - _names.MakeTypeName(def, NameUsage.Namespace).ToString()) - .AddModifiers(Public, Static); - - if (def.GenericParameters.Count > 0) - { - ns = ns - .AddTypeParameterListParameters(MakeTypeParameters(def).ToArray()) - .AddConstraintClauses(MakeTypeParameterConstraints(def).ToArray()); - } - - foreach (var nestedDef in def.NestedTypes) - { - ns = ns.AddMembers(Transform(nestedDef).ToArray()); - } - - yield return ns; - } - } - - IEnumerable Transform(TypeDefinition def) - { - switch (def.Tag) - { - case TypeTag.Enum: - return TransformEnum(def); - - case TypeTag.Group: - case TypeTag.Struct: - return TransformStruct(def); - - case TypeTag.Interface: - return TransformInterface(def); - - default: - throw new NotSupportedException($"Cannot declare type of kind {def.Tag} here"); - } - } - - internal string Transform(GenFile file) - { - NameSyntax topNamespace = GenNames.NamespaceName(file.Namespace) ?? _names.TopNamespace; - - var ns = NamespaceDeclaration(topNamespace); - - foreach (var def in file.NestedTypes) - { - ns = ns.AddMembers(Transform(def).ToArray()); - } - - var cu = CompilationUnit().AddUsings( - UsingDirective(ParseName("Capnp")), - UsingDirective(ParseName("Capnp.Rpc")), - UsingDirective(ParseName("System")), - UsingDirective(ParseName("System.Collections.Generic")), - UsingDirective(ParseName("System.Threading")), - UsingDirective(ParseName("System.Threading.Tasks"))); - - cu = cu.AddMembers(ns); - - return cu.NormalizeWhitespace().ToFullString(); - } - - public void Generate() - { - foreach (var file in _model.FilesToGenerate) - { - string content = Transform(file); - string path = Path.ChangeExtension(file.Name, ".cs"); - File.WriteAllText(path, content); - } - } - } -} diff --git a/capnpc-csharp/Generator/CommonSnippetGen.cs b/capnpc-csharp/Generator/CommonSnippetGen.cs deleted file mode 100644 index 2e1797d..0000000 --- a/capnpc-csharp/Generator/CommonSnippetGen.cs +++ /dev/null @@ -1,93 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using CapnpC.Model; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; -using static CapnpC.Generator.SyntaxHelpers; - -namespace CapnpC.Generator -{ - class CommonSnippetGen - { - readonly GenNames _names; - - public CommonSnippetGen(GenNames names) - { - _names = names; - } - - public EnumDeclarationSyntax MakeUnionSelectorEnum(TypeDefinition def) - { - var whichEnum = EnumDeclaration(_names.UnionDiscriminatorEnum.ToString()) - .AddModifiers(Public) - .AddBaseListTypes(SimpleBaseType(Type())); - - var discFields = def.Fields.Where(f => f.DiscValue.HasValue); - - foreach (var discField in discFields) - { - whichEnum = whichEnum.AddMembers( - EnumMemberDeclaration(_names.GetCodeIdentifier(discField).Identifier) - .WithEqualsValue( - EqualsValueClause(LiteralExpression( - SyntaxKind.NumericLiteralExpression, - Literal(discField.DiscValue.Value))))); - } - - var ndecl = EnumMemberDeclaration(_names.UnionDiscriminatorUndefined.ToString()).WithEqualsValue( - EqualsValueClause( - LiteralExpression( - SyntaxKind.NumericLiteralExpression, - Literal(Schema.Field.Reader.NoDiscriminant)))); - - whichEnum = whichEnum.AddMembers(ndecl); - - return whichEnum; - } - - public EnumDeclarationSyntax MakeEnum(TypeDefinition def) - { - var decl = EnumDeclaration(def.Name) - .AddModifiers(Public) - .AddBaseListTypes(SimpleBaseType(Type())); - - foreach (var enumerant in def.Enumerants.OrderBy(e => e.CodeOrder)) - { - var mdecl = EnumMemberDeclaration(enumerant.Literal); - - if (enumerant.Ordinal.HasValue) - { - mdecl = mdecl.WithEqualsValue( - EqualsValueClause( - LiteralExpression( - SyntaxKind.NumericLiteralExpression, - Literal(enumerant.Ordinal.Value)))); - } - - decl = decl.AddMembers(mdecl); - } - - return decl; - } - - public static IEnumerable MakeCommaSeparatedList(IEnumerable expressions) - { - bool first = true; - - foreach (var expr in expressions) - { - if (first) - first = false; - else - yield return Token(SyntaxKind.CommaToken); - - yield return expr; - } - } - - } -} diff --git a/capnpc-csharp/Generator/DomainClassSnippetGen.cs b/capnpc-csharp/Generator/DomainClassSnippetGen.cs deleted file mode 100644 index 5b27495..0000000 --- a/capnpc-csharp/Generator/DomainClassSnippetGen.cs +++ /dev/null @@ -1,972 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using CapnpC.Model; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; -using static CapnpC.Generator.SyntaxHelpers; - -namespace CapnpC.Generator -{ - class DomainClassSnippetGen - { - readonly GenNames _names; - - public DomainClassSnippetGen(GenNames names) - { - _names = names; - } - - MemberDeclarationSyntax MakeUnionField(Field field) - { - var type = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.DomainClassNullable); - - switch (field.Type.Tag) - { - case TypeTag.Void: - return null; - - default: - return PropertyDeclaration(type, - _names.GetCodeIdentifier(field).Identifier) - .AddModifiers(Public).AddAccessorListAccessors( - AccessorDeclaration(SyntaxKind.GetAccessorDeclaration) - .WithExpressionBody( - ArrowExpressionClause( - ConditionalExpression( - BinaryExpression( - SyntaxKind.EqualsExpression, - _names.UnionDiscriminatorField.IdentifierName, - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - _names.UnionDiscriminatorEnum.IdentifierName, - _names.GetCodeIdentifier(field).IdentifierName)), - CastExpression(type, - _names.UnionContentField.IdentifierName), - LiteralExpression( - SyntaxKind.NullLiteralExpression)))) - .WithSemicolonToken( - Token(SyntaxKind.SemicolonToken)), - AccessorDeclaration( - SyntaxKind.SetAccessorDeclaration) - .WithBody( - Block( - ExpressionStatement( - AssignmentExpression( - SyntaxKind.SimpleAssignmentExpression, - _names.UnionDiscriminatorField.IdentifierName, - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - _names.UnionDiscriminatorEnum.IdentifierName, - _names.GetCodeIdentifier(field).IdentifierName))), - ExpressionStatement( - AssignmentExpression( - SyntaxKind.SimpleAssignmentExpression, - _names.UnionContentField.IdentifierName, - IdentifierName("value")))))); - } - } - - MemberDeclarationSyntax MakeStructField(Field field) - { - if (field.Type.Tag == TypeTag.Void) - { - return null; - } - - var prop = PropertyDeclaration(_names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.DomainClass), - _names.GetCodeIdentifier(field).Identifier) - .AddModifiers(Public).AddAccessorListAccessors( - AccessorDeclaration(SyntaxKind.GetAccessorDeclaration) - .WithSemicolonToken(Token(SyntaxKind.SemicolonToken)), - AccessorDeclaration(SyntaxKind.SetAccessorDeclaration) - .WithSemicolonToken(Token(SyntaxKind.SemicolonToken))); - - if (field.DefaultValueIsExplicit && field.Type.IsValueType) - { - prop = prop.WithInitializer( - EqualsValueClause(MakeDefaultValue(field))) - .WithSemicolonToken(Token(SyntaxKind.SemicolonToken)); - } - - return prop; - } - - MemberDeclarationSyntax MakeUnionDiscriminatorField() - { - return FieldDeclaration( - VariableDeclaration(_names.UnionDiscriminatorEnum.IdentifierName) - .AddVariables( - VariableDeclarator(_names.UnionDiscriminatorField.Identifier) - .WithInitializer( - EqualsValueClause( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - _names.UnionDiscriminatorEnum.IdentifierName, - _names.UnionDiscriminatorUndefined.IdentifierName))))) - .AddModifiers(Private); - } - - MemberDeclarationSyntax MakeUnionContentField() - { - return FieldDeclaration( - VariableDeclaration(SyntaxHelpers.Type()) - .WithVariables( - SingletonSeparatedList( - VariableDeclarator(_names.UnionContentField.Identifier)))) - .AddModifiers(Private); - } - - IEnumerable MakeInitializerAssignments(Value structValue, TypeDefinition scope) - { - foreach (var fieldValue in structValue.Fields) - { - var valueExpr = MakeValue(fieldValue.Item2, scope); - if (valueExpr == null) - continue; - - yield return AssignmentExpression( - SyntaxKind.SimpleAssignmentExpression, - _names.GetCodeIdentifier(fieldValue.Item1).IdentifierName, - valueExpr); - } - } - - ExpressionSyntax MakeValue(Value value, TypeDefinition scope) - { - switch (value.Type.Tag) - { - case TypeTag.AnyEnum: - return LiteralExpression( - SyntaxKind.NumericLiteralExpression, Literal((ushort)value.ScalarValue)); - - case TypeTag.Bool: - - if ((bool)value.ScalarValue) - return LiteralExpression(SyntaxKind.TrueLiteralExpression); - else - return LiteralExpression(SyntaxKind.FalseLiteralExpression); - - case TypeTag.Data: - return ArrayCreationExpression(ArrayType( - PredefinedType(Token(SyntaxKind.ByteKeyword))) - .WithRankSpecifiers( - SingletonList( - ArrayRankSpecifier( - SingletonSeparatedList( - OmittedArraySizeExpression()))))) - .WithInitializer( - InitializerExpression( - SyntaxKind.ArrayInitializerExpression) - .AddExpressions(value.Items.Select(v => MakeValue(v, scope)).ToArray())); - - case TypeTag.Enum: - return MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, - _names.MakeTypeSyntax(value.Type, scope, TypeUsage.NotRelevant), - IdentifierName(value.GetEnumerant().Literal)); - - case TypeTag.F32: - switch ((float)value.ScalarValue) - { - case float.NaN: - return MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - IdentifierName("float"), - IdentifierName(nameof(float.NaN))); - - case float.NegativeInfinity: - return MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - IdentifierName("float"), - IdentifierName(nameof(float.NegativeInfinity))); - - case float.PositiveInfinity: - return MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - IdentifierName("float"), - IdentifierName(nameof(float.PositiveInfinity))); - - default: - return LiteralExpression(SyntaxKind.NumericLiteralExpression, - Literal((float)value.ScalarValue)); - } - - case TypeTag.F64: - switch ((double)value.ScalarValue) - { - case double.NaN: - return MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - IdentifierName("double"), - IdentifierName(nameof(double.NaN))); - - case double.NegativeInfinity: - return MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - IdentifierName("double"), - IdentifierName(nameof(double.NegativeInfinity))); - - case double.PositiveInfinity: - return MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - IdentifierName("double"), - IdentifierName(nameof(double.PositiveInfinity))); - - default: - return LiteralExpression(SyntaxKind.NumericLiteralExpression, - Literal((double)value.ScalarValue)); - } - - case TypeTag.S8: - return LiteralExpression(SyntaxKind.NumericLiteralExpression, - Literal((sbyte)value.ScalarValue)); - - case TypeTag.S16: - return LiteralExpression(SyntaxKind.NumericLiteralExpression, - Literal((short)value.ScalarValue)); - - case TypeTag.S32: - return LiteralExpression(SyntaxKind.NumericLiteralExpression, - Literal((int)value.ScalarValue)); - - case TypeTag.S64: - return LiteralExpression(SyntaxKind.NumericLiteralExpression, - Literal((long)value.ScalarValue)); - - case TypeTag.U8: - return LiteralExpression(SyntaxKind.NumericLiteralExpression, - Literal((byte)value.ScalarValue)); - - case TypeTag.U16: - return LiteralExpression(SyntaxKind.NumericLiteralExpression, - Literal((ushort)value.ScalarValue)); - - case TypeTag.U32: - return LiteralExpression(SyntaxKind.NumericLiteralExpression, - Literal((uint)value.ScalarValue)); - - case TypeTag.U64: - return LiteralExpression(SyntaxKind.NumericLiteralExpression, - Literal((ulong)value.ScalarValue)); - - case TypeTag.Text: - value.Decode(); - return value.ScalarValue == null ? - LiteralExpression(SyntaxKind.NullLiteralExpression) : - LiteralExpression(SyntaxKind.StringLiteralExpression, - Literal((string)value.ScalarValue)); - - case TypeTag.Group: - case TypeTag.Struct: - value.Decode(); - - return ObjectCreationExpression( - _names.MakeTypeSyntax(value.Type, scope, TypeUsage.DomainClass)) - .WithArgumentList(ArgumentList()) - .WithInitializer( - InitializerExpression( - SyntaxKind.ObjectInitializerExpression) - .AddExpressions(MakeInitializerAssignments(value, scope).ToArray())); - - case TypeTag.ListPointer: - // TBD - return LiteralExpression(SyntaxKind.NullLiteralExpression); - - case TypeTag.List when value.Type.ElementType.Tag == TypeTag.Void: - value.Decode(); - - return LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal((int)value.VoidListCount)); - - case TypeTag.List: - value.Decode(); - - return ArrayCreationExpression(ArrayType( - _names.MakeTypeSyntax(value.Type.ElementType, scope, TypeUsage.DomainClass)) - .WithRankSpecifiers( - SingletonList( - ArrayRankSpecifier( - SingletonSeparatedList( - OmittedArraySizeExpression()))))) - .WithInitializer( - InitializerExpression( - SyntaxKind.ArrayInitializerExpression) - .AddExpressions(value.Items.Select(v => MakeValue(v, scope)).ToArray())); - - case TypeTag.AnyPointer: - case TypeTag.CapabilityPointer: - // TBD - return null; - - case TypeTag.Interface: - return null; - - default: - throw new NotImplementedException(); - } - } - - ExpressionSyntax MakeDefaultValue(Field field) - { - if (field.DefaultValueIsExplicit) - { - return MakeValue(field.DefaultValue, field.DeclaringType); - } - else - { - switch (field.Type.Tag) - { - case TypeTag.AnyEnum: - case TypeTag.S16: - case TypeTag.S32: - case TypeTag.S64: - case TypeTag.S8: - case TypeTag.U16: - case TypeTag.U32: - case TypeTag.U64: - case TypeTag.U8: - return LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0)); - - case TypeTag.AnyPointer: - case TypeTag.CapabilityPointer: - case TypeTag.Data: - case TypeTag.Group: - case TypeTag.Interface: - case TypeTag.List: - case TypeTag.ListPointer: - case TypeTag.Struct: - case TypeTag.StructPointer: - case TypeTag.Text: - return LiteralExpression(SyntaxKind.NullLiteralExpression); - - case TypeTag.Bool: - return LiteralExpression(SyntaxKind.FalseLiteralExpression); - - case TypeTag.Enum: - return MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.NotRelevant), - _names.UnionDiscriminatorUndefined.IdentifierName); - - case TypeTag.F32: - return LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0.0f)); - - case TypeTag.F64: - return LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0.0)); - - default: - throw new NotImplementedException(); - } - } - } - - IEnumerable MakeUnionDiscriminatorSetter(TypeDefinition def) - { - var unionFields = def.Fields.Where(f => f.DiscValue.HasValue); - - foreach (var unionField in unionFields) - { - var section = SwitchSection() - .WithLabels( - SingletonList( - CaseSwitchLabel(MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - _names.UnionDiscriminatorEnum.IdentifierName, - _names.GetCodeIdentifier(unionField).IdentifierName)))); - - if (unionField.Type.Tag != TypeTag.Void) - { - section = section.AddStatements( - ExpressionStatement( - AssignmentExpression( - SyntaxKind.SimpleAssignmentExpression, - _names.UnionContentField.IdentifierName, - MakeDefaultValue(unionField)))); - } - - section = section.AddStatements(BreakStatement()); - - yield return section; - } - } - - MemberDeclarationSyntax MakeUnionDiscriminatorProperty(TypeDefinition def) - { - return PropertyDeclaration(_names.UnionDiscriminatorEnum.IdentifierName, - _names.UnionDiscriminatorProp.Identifier) - .AddModifiers(Public).AddAccessorListAccessors( - AccessorDeclaration(SyntaxKind.GetAccessorDeclaration) - .WithExpressionBody( - ArrowExpressionClause(_names.UnionDiscriminatorField.IdentifierName)) - .WithSemicolonToken(Token(SyntaxKind.SemicolonToken)), - AccessorDeclaration(SyntaxKind.SetAccessorDeclaration) - .WithBody( - Block( - IfStatement( - BinaryExpression( - SyntaxKind.EqualsExpression, - IdentifierName("value"), - _names.UnionDiscriminatorField.IdentifierName), - ReturnStatement()), - ExpressionStatement( - AssignmentExpression( - SyntaxKind.SimpleAssignmentExpression, - _names.UnionDiscriminatorField.IdentifierName, - IdentifierName("value"))), - SwitchStatement(IdentifierName("value")) - .WithOpenParenToken( - Token(SyntaxKind.OpenParenToken)) - .WithCloseParenToken( - Token(SyntaxKind.CloseParenToken)) - .AddSections(MakeUnionDiscriminatorSetter(def).ToArray())))); - } - - MemberDeclarationSyntax MakeField(Field field) - { - if (field.DiscValue.HasValue) - return MakeUnionField(field); - else - return MakeStructField(field); - } - - ExpressionSyntax MakeListSerializeParticle(Model.Type type, ExpressionSyntax writer, ExpressionSyntax domain) - { - string s = $"_s{type.GetRank().Item1}"; - string v = $"_v{type.GetRank().Item1}"; - - switch (type.ElementType?.Tag) - { - case TypeTag.List: - case TypeTag.ListPointer: - case TypeTag.Struct: - case TypeTag.Group: - case TypeTag.StructPointer: - case TypeTag.Data: - - return InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - writer, - IdentifierName(nameof(Capnp.ListOfPrimitivesSerializer.Init)))) - .AddArgumentListArguments( - Argument(domain), - Argument( - ParenthesizedLambdaExpression( - MakeComplexSerializeParticle( - type.ElementType, - IdentifierName(s), - IdentifierName(v))) - .AddParameterListParameters( - Parameter(Identifier(s)), - Parameter(Identifier(v))))); - - default: - return InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - writer, - IdentifierName(nameof(Capnp.ListOfPrimitivesSerializer.Init)))) - .AddArgumentListArguments(Argument(domain)); - } - } - - ExpressionSyntax MakeComplexSerializeParticle(Model.Type type, ExpressionSyntax writer, ExpressionSyntax domain) - { - switch (type.Tag) - { - case TypeTag.Data: - case TypeTag.List: - return MakeListSerializeParticle(type, writer, domain); - - case TypeTag.Struct: - case TypeTag.Group: - return ConditionalAccessExpression(domain, - InvocationExpression(MemberBindingExpression(_names.SerializeMethod.IdentifierName)) - .AddArgumentListArguments(Argument(writer))); - - default: - throw new NotImplementedException(); - } - } - - StatementSyntax MakeSerializeMethodFieldAssignment(Field field) - { - var writerProp = MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - _names.WriterParameter.IdentifierName, - _names.GetCodeIdentifier(field).IdentifierName); - - switch (field.Type.Tag) - { - case TypeTag.Bool: - case TypeTag.Enum: - case TypeTag.F32: - case TypeTag.F64: - case TypeTag.S16: - case TypeTag.S32: - case TypeTag.S64: - case TypeTag.S8: - case TypeTag.U16: - case TypeTag.U32: - case TypeTag.U64: - case TypeTag.U8: - case TypeTag.AnyEnum: - case TypeTag.List when field.Type.Tag == TypeTag.Void: - if (field.DiscValue.HasValue) - { - return ExpressionStatement( - AssignmentExpression( - SyntaxKind.SimpleAssignmentExpression, - writerProp, - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - _names.GetCodeIdentifier(field).IdentifierName, - IdentifierName(nameof(Nullable.Value))))); - } - else - { - return ExpressionStatement( - AssignmentExpression( - SyntaxKind.SimpleAssignmentExpression, - writerProp, - _names.GetCodeIdentifier(field).IdentifierName)); - } - - case TypeTag.AnyPointer: - case TypeTag.ListPointer: - case TypeTag.StructPointer: - return ExpressionStatement( - InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - _names.WriterParameter.IdentifierName, - _names.GetCodeIdentifier(field).IdentifierName), - IdentifierName(nameof(Capnp.DynamicSerializerState.SetObject)))) - .AddArgumentListArguments( - Argument(_names.GetCodeIdentifier(field).IdentifierName))); - - case TypeTag.CapabilityPointer: - case TypeTag.Interface: - return ExpressionStatement( - AssignmentExpression( - SyntaxKind.SimpleAssignmentExpression, - writerProp, - _names.GetCodeIdentifier(field).IdentifierName)); - - case TypeTag.Text: - return ExpressionStatement( - AssignmentExpression( - SyntaxKind.SimpleAssignmentExpression, - writerProp, - _names.GetCodeIdentifier(field).IdentifierName)); - - case TypeTag.Data: - case TypeTag.List: - case TypeTag.Struct: - case TypeTag.Group: - return ExpressionStatement( - MakeComplexSerializeParticle( - field.Type, - writerProp, - _names.GetCodeIdentifier(field).IdentifierName)); - - case TypeTag.Void: - return null; - - default: - throw new NotImplementedException(); - } - } - - StatementSyntax MakeApplyDefaultsMethodFieldAssignment(Field field) - { - var lhs = _names.GetCodeIdentifier(field).IdentifierName; - var rhs = MakeDefaultValue(field); - - if (rhs == null) - { - return null; - } - - return ExpressionStatement( - AssignmentExpression( - SyntaxKind.SimpleAssignmentExpression, - lhs, - BinaryExpression(SyntaxKind.CoalesceExpression, - lhs, rhs))); - } - - ExpressionSyntax MakeInnerStructListConversion(ExpressionSyntax context, TypeSyntax elementType) - { - return InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - context, - IdentifierName(nameof(Capnp.ReadOnlyListExtensions.ToReadOnlyList)))) - .AddArgumentListArguments(Argument( - SimpleLambdaExpression(Parameter(Identifier("_")), - InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - IdentifierName(nameof(Capnp.CapnpSerializable)), - GenericName(nameof(Capnp.CapnpSerializable.Create)) - .AddTypeArgumentListArguments(elementType))) - .AddArgumentListArguments(Argument(IdentifierName("_")))))); - } - - ExpressionSyntax MakeStructListConversion(ExpressionSyntax context, TypeSyntax elementType, int rank) - { - if (rank == 1) - { - return MakeInnerStructListConversion(context, elementType); - } - - string lambdaVarName = $"_{rank}"; - - return InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - context, - IdentifierName(nameof(Capnp.ReadOnlyListExtensions.ToReadOnlyList)))) - .AddArgumentListArguments(Argument( - SimpleLambdaExpression( - Parameter(Identifier(lambdaVarName)), - MakeStructListConversion(IdentifierName(lambdaVarName), elementType, rank - 1)))); - } - - ExpressionSyntax MakeAnyListConversion(ExpressionSyntax context) - { - return InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - context, - IdentifierName(nameof(Capnp.ReadOnlyListExtensions.ToReadOnlyList)))) - .AddArgumentListArguments(Argument( - SimpleLambdaExpression( - Parameter(Identifier("_")), - CastExpression(Type(), IdentifierName("_"))))); - } - - ExpressionSyntax MakeDeserializeMethodRightHandSide(Field field) - { - switch (field.Type.Tag) - { - case TypeTag.Struct: - case TypeTag.Group: - case TypeTag.StructPointer: - case TypeTag.AnyPointer: - return InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - IdentifierName(nameof(Capnp.CapnpSerializable)), - GenericName(nameof(Capnp.CapnpSerializable.Create)) - .AddTypeArgumentListArguments( - _names.MakeTypeSyntax( - field.Type, - field.DeclaringType, - TypeUsage.DomainClass)))) - .AddArgumentListArguments(Argument(MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - _names.ReaderParameter.IdentifierName, - _names.GetCodeIdentifier(field).IdentifierName))); - - case TypeTag.Void: - return null; - - case TypeTag.List: - (var rank, var elementType) = field.Type.GetRank(); - if (elementType.Tag != TypeTag.Struct) - break; - - return MakeStructListConversion( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - _names.ReaderParameter.IdentifierName, - _names.GetCodeIdentifier(field).IdentifierName), - _names.MakeTypeSyntax(elementType, field.DeclaringType, TypeUsage.DomainClass), - rank); - - case TypeTag.ListPointer: - return MakeAnyListConversion( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - _names.ReaderParameter.IdentifierName, - _names.GetCodeIdentifier(field).IdentifierName)); - } - - return MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - _names.ReaderParameter.IdentifierName, - _names.GetCodeIdentifier(field).IdentifierName); - } - - IEnumerable MakeSerializeMethodSwitchSections(TypeDefinition def) - { - var unionFields = def.Fields.Where(f => f.DiscValue.HasValue); - - foreach (var unionField in unionFields) - { - var section = SwitchSection() - .AddLabels( - CaseSwitchLabel(MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - _names.UnionDiscriminatorEnum.IdentifierName, - _names.GetCodeIdentifier(unionField).IdentifierName))); - - if (unionField.Type.Tag != TypeTag.Void) - { - ExpressionSyntax right = _names.GetCodeIdentifier(unionField).IdentifierName; - - var syntax = _names.MakeTypeSyntax(unionField.Type, unionField.DeclaringType, TypeUsage.DomainClassNullable); - - if (syntax is NullableTypeSyntax) - { - right = MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - right, - IdentifierName(nameof(Nullable.Value))); - } - - section = section.AddStatements(MakeSerializeMethodFieldAssignment(unionField)); - } - - section = section.AddStatements(BreakStatement()); - - yield return section; - } - } - - IEnumerable MakeDeserializeMethodSwitchSections(TypeDefinition def) - { - var unionFields = def.Fields.Where(f => f.DiscValue.HasValue); - - foreach (var unionField in unionFields) - { - var section = SwitchSection() - .AddLabels( - CaseSwitchLabel(MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - _names.UnionDiscriminatorEnum.IdentifierName, - _names.GetCodeIdentifier(unionField).IdentifierName))); - - switch (unionField.Type.Tag) - { - case TypeTag.Void: - section = section.AddStatements( - ExpressionStatement(AssignmentExpression( - SyntaxKind.SimpleAssignmentExpression, - _names.UnionDiscriminatorProp.IdentifierName, - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - _names.ReaderParameter.IdentifierName, - _names.UnionDiscriminatorProp.IdentifierName)))); - break; - - default: - section = section.AddStatements( - ExpressionStatement(AssignmentExpression( - SyntaxKind.SimpleAssignmentExpression, - _names.GetCodeIdentifier(unionField).IdentifierName, - MakeDeserializeMethodRightHandSide(unionField)))); - break; - - } - - section = section.AddStatements(BreakStatement()); - - yield return section; - } - } - - IEnumerable MakeSerializeStatements(TypeDefinition def) - { - if (def.UnionInfo != null) - { - yield return ExpressionStatement(AssignmentExpression( - SyntaxKind.SimpleAssignmentExpression, - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - _names.WriterParameter.IdentifierName, - _names.UnionDiscriminatorProp.IdentifierName), - _names.UnionDiscriminatorProp.IdentifierName)); - - yield return SwitchStatement(_names.UnionDiscriminatorProp.IdentifierName) - .WithOpenParenToken(Token(SyntaxKind.OpenParenToken)) - .WithCloseParenToken(Token(SyntaxKind.CloseParenToken)) - .AddSections(MakeSerializeMethodSwitchSections(def).ToArray()); - } - - var nondiscFields = def.Fields.Where(f => !f.DiscValue.HasValue && f.Type.Tag != TypeTag.Void); - - foreach (var field in nondiscFields) - { - var asmt = MakeSerializeMethodFieldAssignment(field); - - if (asmt != null) - { - yield return asmt; - } - } - } - - IEnumerable MakeApplyDefaultsStatements(TypeDefinition def) - { - var relevantFields = def.Fields.Where( - f => !f.DiscValue.HasValue && - f.Type.Tag != TypeTag.Void && - f.DefaultValueIsExplicit && - !f.Type.IsValueType); - - foreach (var field in relevantFields) - { - var asmt = MakeApplyDefaultsMethodFieldAssignment(field); - - if (asmt != null) - { - yield return asmt; - } - } - } - - MemberDeclarationSyntax MakeSerializeMethod(TypeDefinition def) - { - return MethodDeclaration(PredefinedType( - Token(SyntaxKind.VoidKeyword)), - _names.SerializeMethod.Identifier) - .AddModifiers(Public) - .AddParameterListParameters( - Parameter(_names.WriterParameter.Identifier) - .WithType(_names.WriterStruct.IdentifierName)) - .AddBodyStatements(MakeSerializeStatements(def).ToArray()); - } - - MemberDeclarationSyntax MakeSerializeInterfaceMethod() - { - return MethodDeclaration(PredefinedType(Token(SyntaxKind.VoidKeyword)), - Identifier(nameof(Capnp.ICapnpSerializable.Serialize))) - .WithExplicitInterfaceSpecifier( - ExplicitInterfaceSpecifier(IdentifierName(nameof(Capnp.ICapnpSerializable)))) - .AddParameterListParameters( - Parameter(_names.AnonymousParameter.Identifier) - .WithType(Type())) - .AddBodyStatements( - ExpressionStatement( - InvocationExpression(_names.SerializeMethod.IdentifierName) - .AddArgumentListArguments( - Argument( - InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - _names.AnonymousParameter.IdentifierName, - GenericName(Identifier(nameof(Capnp.SerializerState.Rewrap))) - .AddTypeArgumentListArguments(_names.WriterStruct.IdentifierName))))))); - } - - MemberDeclarationSyntax MakeApplyDefaultsMethod(TypeDefinition def) - { - return MethodDeclaration(PredefinedType( - Token(SyntaxKind.VoidKeyword)), - _names.ApplyDefaultsMethod.Identifier) - .AddModifiers(Public) - .AddBodyStatements(MakeApplyDefaultsStatements(def).ToArray()); - } - - IEnumerable MakeDeserializeStatements(TypeDefinition def) - { - var relevantFields = def.Fields.Where( - f => !f.DiscValue.HasValue && - f.Type.Tag != TypeTag.Void); - - foreach (var field in relevantFields) - { - var rhs = MakeDeserializeMethodRightHandSide(field); - - if (rhs != null) - { - yield return ExpressionStatement(AssignmentExpression( - SyntaxKind.SimpleAssignmentExpression, - _names.GetCodeIdentifier(field).IdentifierName, - rhs)); - } - } - } - - MemberDeclarationSyntax MakeDeserializeMethod(TypeDefinition def) - { - var stmts = new List(); - - stmts.Add(LocalDeclarationStatement( - VariableDeclaration(IdentifierName("var")) - .AddVariables( - VariableDeclarator(_names.ReaderParameter.Identifier) - .WithInitializer( - EqualsValueClause( - InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - _names.ReaderStruct.IdentifierName, - _names.ReaderCreateMethod.IdentifierName)) - .AddArgumentListArguments( - Argument(_names.AnonymousParameter.IdentifierName))))))); - - - if (def.UnionInfo != null) - { - stmts.Add(SwitchStatement( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - _names.ReaderParameter.IdentifierName, - _names.UnionDiscriminatorProp.IdentifierName)) - .WithOpenParenToken(Token(SyntaxKind.OpenParenToken)) - .WithCloseParenToken(Token(SyntaxKind.CloseParenToken)) - .AddSections(MakeDeserializeMethodSwitchSections(def).ToArray())); - } - - stmts.AddRange(MakeDeserializeStatements(def)); - stmts.Add(ExpressionStatement(InvocationExpression( - _names.ApplyDefaultsMethod.IdentifierName))); - - return MethodDeclaration(PredefinedType(Token(SyntaxKind.VoidKeyword)), - Identifier(nameof(Capnp.ICapnpSerializable.Deserialize))) - .WithExplicitInterfaceSpecifier( - ExplicitInterfaceSpecifier(IdentifierName(nameof(Capnp.ICapnpSerializable)))) - .AddParameterListParameters( - Parameter(_names.AnonymousParameter.Identifier) - .WithType(Type())) - .AddBodyStatements(stmts.ToArray()); - } - - IEnumerable EnumerateDomainClassMembers(TypeDefinition def) - { - yield return MakeDeserializeMethod(def); - - if (def.UnionInfo != null) - { - yield return MakeUnionDiscriminatorField(); - yield return MakeUnionContentField(); - yield return MakeUnionDiscriminatorProperty(def); - } - - yield return MakeSerializeMethod(def); - yield return MakeSerializeInterfaceMethod(); - yield return MakeApplyDefaultsMethod(def); - - foreach (var field in def.Fields) - { - var decl = MakeField(field); - - if (decl != null) - yield return decl; - } - } - - public MemberDeclarationSyntax[] MakeDomainClassMembers(TypeDefinition def) - { - return EnumerateDomainClassMembers(def).ToArray(); - } - } -} diff --git a/capnpc-csharp/Generator/GenNames.cs b/capnpc-csharp/Generator/GenNames.cs deleted file mode 100644 index f842413..0000000 --- a/capnpc-csharp/Generator/GenNames.cs +++ /dev/null @@ -1,601 +0,0 @@ -using CapnpC.Model; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; - -namespace CapnpC.Generator -{ - enum NameUsage - { - Default, - Interface, - Proxy, - Skeleton, - Namespace - } - - enum TypeUsage - { - NotRelevant, - DomainClass, - DomainClassNullable, - Reader, - Writer - } - - class GenNames - { - readonly Dictionary _fieldNameMap = new Dictionary(); - - public NameSyntax TopNamespace { get; set; } - public Name ReaderStruct { get; } - public Name ReaderParameter { get; } - public Name WriterParameter { get; } - public Name WriterStruct { get; } - public Name ReaderCreateMethod { get; } - public Name ReaderContextField { get; } - public Name ContextParameter { get; } - public Name GroupReaderContextArg { get; } - public Name GroupWriterContextArg { get; } - public Name UnionDiscriminatorEnum { get; } - public Name UnionDiscriminatorProp { get; } - public Name UnionDiscriminatorUndefined { get; } - public Name UnionDiscriminatorField { get; } - public Name UnionContentField { get; } - public Name AnonymousParameter { get; } - public Name CancellationTokenParameter { get; } - public Name ParamsLocal { get; } - public Name DeserializerLocal { get; } - public Name SerializerLocal { get; } - public Name ResultLocal { get; } - public Name SerializeMethod { get; } - public Name ApplyDefaultsMethod { get; } - public Name InstLocalName { get; } - public string ParamsStructFormat { get; } - public string ResultStructFormat { get; } - public string PropertyNamedLikeTypeRenameFormat { get; } - public string GenericTypeParameterFormat { get; } - public Name PipeliningExtensionsClassName { get; } - public string MemberAccessPathNameFormat { get; } - public Name TaskParameter { get; } - public Name EagerMethod { get; } - - public GenNames(GeneratorOptions options) - { - TopNamespace = new Name(options.TopNamespaceName).IdentifierName; - ReaderStruct = new Name(options.ReaderStructName); - WriterStruct = new Name(options.WriterStructName); - ReaderParameter = new Name(options.ReaderParameterName); - WriterParameter = new Name(options.WriterParameterName); - ReaderCreateMethod = new Name(options.ReaderCreateMethodName); - ReaderContextField = new Name(options.ReaderContextFieldName); - ContextParameter = new Name(options.ContextParameterName); - GroupReaderContextArg = new Name(options.GroupReaderContextArgName); - GroupWriterContextArg = new Name(options.GroupWriterContextArgName); - UnionDiscriminatorEnum = new Name(options.UnionDisciminatorEnumName); - UnionDiscriminatorProp = new Name(options.UnionDiscriminatorPropName); - UnionDiscriminatorUndefined = new Name(options.UnionDisciminatorUndefinedName); - UnionDiscriminatorField = new Name(options.UnionDiscriminatorFieldName); - UnionContentField = new Name(options.UnionContentFieldName); - SerializeMethod = new Name(options.SerializeMethodName); - ApplyDefaultsMethod = new Name(options.ApplyDefaultsMethodName); - AnonymousParameter = new Name(options.AnonymousParameterName); - CancellationTokenParameter = new Name(options.CancellationTokenParameterName); - ParamsLocal = new Name(options.ParamsLocalName); - DeserializerLocal = new Name(options.DeserializerLocalName); - SerializerLocal = new Name(options.SerializerLocalName); - ResultLocal = new Name(options.ResultLocalName); - InstLocalName = new Name(options.InstLocalName); - ParamsStructFormat = options.ParamsStructFormat; - ResultStructFormat = options.ResultStructFormat; - PropertyNamedLikeTypeRenameFormat = options.PropertyNamedLikeTypeRenameFormat; - GenericTypeParameterFormat = options.GenericTypeParameterFormat; - PipeliningExtensionsClassName = new Name(options.PipeliningExtensionsClassName); - MemberAccessPathNameFormat = options.MemberAccessPathNameFormat; - TaskParameter = new Name(options.TaskParameterName); - EagerMethod = new Name(options.EagerMethodName); - } - - public Name MakeTypeName(TypeDefinition def, NameUsage usage = NameUsage.Default) - { - if (def.Tag == TypeTag.Group) - { - return new Name(SyntaxHelpers.MakeAllLower(def.Name)); - } - else - { - string name; - - switch (usage) - { - case NameUsage.Default: - if (def.Tag == TypeTag.Interface) - goto case NameUsage.Interface; - - switch (def.SpecialName) - { - case SpecialName.NothingSpecial: - name = def.Name; - break; - - case SpecialName.MethodParamsStruct: - name = MakeParamsStructName(def.UsingMethod); - break; - - case SpecialName.MethodResultStruct: - name = MakeResultStructName(def.UsingMethod); - break; - - default: - throw new NotImplementedException(); - } - break; - - case NameUsage.Namespace: - name = def.Name; - break; - - case NameUsage.Interface: - name = "I" + def.Name; - break; - - case NameUsage.Proxy: - name = def.Name + "Proxy"; - break; - - case NameUsage.Skeleton: - name = def.Name + "Skeleton"; - break; - - default: - throw new NotImplementedException(); - } - - return new Name(name); - } - } - - public SimpleNameSyntax MakeGenericTypeName(TypeDefinition def, NameUsage usage = NameUsage.Default) - { - var name = MakeTypeName(def, usage); - - if (def.GenericParameters.Count > 0) - { - return GenericName(name.Identifier) - .AddTypeArgumentListArguments(def - .GenericParameters - .Select(p => GetGenericTypeParameter(p).IdentifierName).ToArray()); - } - else - { - return name.IdentifierName; - } - } - - TypeSyntax ResolveGenericParameter(GenericParameter p, Model.Type boundType, TypeDefinition def) - { - var type = boundType.ResolveGenericParameter(p); - return MakeTypeSyntax(type, def, TypeUsage.DomainClass); - } - - public SimpleNameSyntax MakeGenericTypeName(TypeDefinition def, Model.Type boundType, NameUsage usage = NameUsage.Default) - { - var name = MakeTypeName(def, usage); - - if (def.GenericParameters.Count > 0) - { - return GenericName(name.Identifier) - .AddTypeArgumentListArguments(def - .GetLocalTypeParameters() - .Select(p => ResolveGenericParameter(p, boundType, def)).ToArray()); - } - else - { - return name.IdentifierName; - } - } - - public SimpleNameSyntax MakeGenericTypeNameForAttribute(TypeDefinition def, NameUsage usage) - { - var name = MakeTypeName(def, usage); - - if (def.GenericParameters.Count > 0) - { - return GenericName(name.Identifier).AddTypeArgumentListArguments(); - } - else - { - return name.IdentifierName; - } - } - - public static NameSyntax NamespaceName(string[] @namespace) - { - NameSyntax ident = null; - if (@namespace != null) - { - ident = IdentifierName(SyntaxHelpers.MakeCamel(@namespace[0])); - foreach (string name in @namespace.Skip(1)) - { - var temp = IdentifierName(SyntaxHelpers.MakeCamel(name)); - ident = QualifiedName(ident, temp); - } - } - return ident; - } - - NameSyntax GetNamespaceFor(TypeDefinition def) => NamespaceName(def?.File?.Namespace); - - internal NameSyntax GetQName(Model.Type type, TypeDefinition scope) - { - // FIXME: With the help of the 'scope' parameter we will be able to generate abbreviated - // qualified names. Unfortunately the commented approach is too naive. It will fail if - // there are multiple objects with identical name up the hierarchy. We will need a more - // sophisticated algorithm. - - var scopeSet = new HashSet(); - //while (scope != null) - //{ - // scopeSet.Add(scope); - // scope = scope.DeclaringElement as TypeDefinition; - //} - - if (type.Definition != null) - { - var stack = new Stack(); - - var def = type.Definition; - stack.Push(MakeGenericTypeName(def, type, NameUsage.Default)); - - while (def.DeclaringElement is TypeDefinition pdef && !scopeSet.Contains(pdef)) - { - stack.Push(MakeGenericTypeName(pdef, type, NameUsage.Namespace)); - def = pdef; - } - - var qtype = - GetNamespaceFor(type.Definition) - ?? GetNamespaceFor(scope) - ?? TopNamespace; - - foreach (var name in stack) - { - qtype = QualifiedName(qtype, name); - } - - return qtype; - } - else - { - return GetGenericTypeParameter(type.Parameter.Name).IdentifierName; - } - } - - public TypeSyntax MakeListSerializerSyntax(Model.Type elementType, TypeDefinition scope) - { - switch (elementType.Tag) - { - case TypeTag.AnyPointer: - case TypeTag.StructPointer: - case TypeTag.ListPointer: - return SyntaxHelpers.Type>(); - - case TypeTag.CapabilityPointer: - return SyntaxHelpers.Type>(); - - case TypeTag.Data: - return SyntaxHelpers.Type>>(); - - case TypeTag.Enum: - return GenericName("ListOfPrimitivesSerializer") - .AddTypeArgumentListArguments(MakeTypeSyntax(elementType, scope, TypeUsage.Writer)); - - case TypeTag.Group: - case TypeTag.Struct: - return GenericName("ListOfStructsSerializer") - .AddTypeArgumentListArguments(MakeTypeSyntax(elementType, scope, TypeUsage.Writer)); - - case TypeTag.Interface: - return GenericName("ListOfCapsSerializer") - .AddTypeArgumentListArguments(MakeTypeSyntax(elementType, scope, TypeUsage.Writer)); - - case TypeTag.List: - return GenericName("ListOfPointersSerializer") - .AddTypeArgumentListArguments(MakeTypeSyntax(elementType, scope, TypeUsage.Writer)); - - case TypeTag.Text: - return SyntaxHelpers.Type(); - - case TypeTag.Void: - return SyntaxHelpers.Type(); - - case TypeTag.Bool: - return SyntaxHelpers.Type(); - - case TypeTag.F32: - return SyntaxHelpers.Type>(); - - case TypeTag.F64: - return SyntaxHelpers.Type>(); - - case TypeTag.S8: - return SyntaxHelpers.Type>(); - - case TypeTag.U8: - return SyntaxHelpers.Type>(); - - case TypeTag.S16: - return SyntaxHelpers.Type>(); - - case TypeTag.U16: - case TypeTag.AnyEnum: - return SyntaxHelpers.Type>(); - - case TypeTag.S32: - return SyntaxHelpers.Type>(); - - case TypeTag.U32: - return SyntaxHelpers.Type>(); - - case TypeTag.S64: - return SyntaxHelpers.Type>(); - - case TypeTag.U64: - return SyntaxHelpers.Type>(); - - default: - throw new NotImplementedException("Unexpected type tag, don't know how to deal with this"); - } - } - - TypeSyntax MaybeNullableValueType(TypeSyntax typeSyntax, TypeUsage usage) - { - switch (usage) - { - case TypeUsage.DomainClassNullable: - return NullableType(typeSyntax); - - default: - return typeSyntax; - } - } - - public TypeSyntax MakeTypeSyntax(Model.Type type, TypeDefinition scope, TypeUsage usage) - { - switch (type.Tag) - { - case TypeTag.AnyEnum: - return MaybeNullableValueType(SyntaxHelpers.Type(), usage); - - case TypeTag.CapabilityPointer: - if (type.Parameter != null) - { - return GetQName(type, scope); - } - else - { - return SyntaxHelpers.Type(); - } - - case TypeTag.AnyPointer: - case TypeTag.StructPointer: - switch (usage) - { - case TypeUsage.Reader: - return SyntaxHelpers.Type(); - - case TypeUsage.Writer: - return SyntaxHelpers.Type(); - - case TypeUsage.DomainClass: - case TypeUsage.DomainClassNullable: - if (type.Parameter != null) - { - return GetQName(type, scope); - } - else - { - return SyntaxHelpers.Type(); - } - - default: - throw new NotImplementedException(); - } - - case TypeTag.Bool: - return MaybeNullableValueType(SyntaxHelpers.Type(), usage); - - case TypeTag.Data: - switch (usage) - { - case TypeUsage.Reader: - case TypeUsage.DomainClass: - case TypeUsage.DomainClassNullable: - return SyntaxHelpers.Type>(); - - case TypeUsage.Writer: - return SyntaxHelpers.Type>(); - - default: - throw new NotImplementedException(); - } - - case TypeTag.Enum: - return MaybeNullableValueType(GetQName(type, scope), usage); - - case TypeTag.Interface: - return GetQName(type, scope); - - case TypeTag.Struct: - case TypeTag.Group: - switch (usage) - { - case TypeUsage.Writer: - return QualifiedName(GetQName(type, scope), WriterStruct.IdentifierName); - - case TypeUsage.Reader: - return QualifiedName(GetQName(type, scope), ReaderStruct.IdentifierName); - - case TypeUsage.DomainClass: - case TypeUsage.DomainClassNullable: - return GetQName(type, scope); - - default: - throw new NotImplementedException(); - } - - case TypeTag.F32: - return MaybeNullableValueType(SyntaxHelpers.Type(), usage); - - case TypeTag.F64: - return MaybeNullableValueType(SyntaxHelpers.Type(), usage); - - case TypeTag.List when type.ElementType.Tag == TypeTag.Void && usage != TypeUsage.Writer: - return MaybeNullableValueType(SyntaxHelpers.Type(), usage); - - case TypeTag.List: - switch (usage) - { - case TypeUsage.Writer: - return MakeListSerializerSyntax(type.ElementType, scope); - - case TypeUsage.Reader: - return GenericName(Identifier("IReadOnlyList")) - .AddTypeArgumentListArguments(MakeTypeSyntax(type.ElementType, scope, TypeUsage.Reader)); - - case TypeUsage.DomainClass: - case TypeUsage.DomainClassNullable: - return GenericName(Identifier("IReadOnlyList")) - .AddTypeArgumentListArguments(MakeTypeSyntax(type.ElementType, scope, TypeUsage.DomainClass)); - - default: - throw new NotImplementedException(); - } - - case TypeTag.ListPointer: - switch (usage) - { - case TypeUsage.Writer: - return SyntaxHelpers.Type(); - - case TypeUsage.Reader: - return SyntaxHelpers.Type>(); - - case TypeUsage.DomainClass: - case TypeUsage.DomainClassNullable: - return SyntaxHelpers.Type>(); - - default: - throw new NotImplementedException(); - } - - case TypeTag.S16: - return MaybeNullableValueType(SyntaxHelpers.Type(), usage); - - case TypeTag.S32: - return MaybeNullableValueType(SyntaxHelpers.Type(), usage); - - case TypeTag.S64: - return MaybeNullableValueType(SyntaxHelpers.Type(), usage); - - case TypeTag.S8: - return MaybeNullableValueType(SyntaxHelpers.Type(), usage); - - case TypeTag.Text: - return SyntaxHelpers.Type(); - - case TypeTag.U16: - return MaybeNullableValueType(SyntaxHelpers.Type(), usage); - - case TypeTag.U32: - return MaybeNullableValueType(SyntaxHelpers.Type(), usage); - - case TypeTag.U64: - return MaybeNullableValueType(SyntaxHelpers.Type(), usage); - - case TypeTag.U8: - return MaybeNullableValueType(SyntaxHelpers.Type(), usage); - - case TypeTag.Void: - return PredefinedType(Token(SyntaxKind.VoidKeyword)); - - default: - throw new NotImplementedException("Unexpected type tag, don't know how to deal with this"); - } - } - - public string MakeParamsStructName(Method method) - { - return string.Format(ParamsStructFormat, method.Name); - } - - public string MakeResultStructName(Method method) - { - return string.Format(ResultStructFormat, method.Name); - } - - public Name GetCodeIdentifier(Method method) - { - return new Name(SyntaxHelpers.MakeCamel(method.Name)); - } - - public Name GetCodeIdentifier(Field field) - { - if (_fieldNameMap.TryGetValue(field, out var name)) - { - return name; - } - - var def = field.DeclaringType; - - if (def == null) - { - // Method parameters are internally represented with the same class "Field". - // They do not have a declaring type. Anyway, they don't suffer from the field-name-equals-nested-type-name problem. - return new Name(SyntaxHelpers.MakeCamel(field.Name)); - } - - var typeNames = new HashSet(def.NestedTypes.Select(t => MakeTypeName(t))); - typeNames.Add(MakeTypeName(def)); - - foreach (var member in def.Fields) - { - var memberName = new Name(SyntaxHelpers.MakeCamel(member.Name)); - - while (typeNames.Contains(memberName)) - { - memberName = new Name(string.Format(PropertyNamedLikeTypeRenameFormat, memberName.ToString())); - } - - _fieldNameMap.Add(member, memberName); - } - - return _fieldNameMap[field]; - } - - public Name GetGenericTypeParameter(string name) - { - return new Name(string.Format(GenericTypeParameterFormat, name)); - } - - public Name MakePipeliningSupportExtensionMethodName(IReadOnlyList path) - { - if (path.Count == 1 && path[0].Offset == 0) - return EagerMethod; - else - return new Name(string.Join("_", path.Select(f => GetCodeIdentifier(f).ToString()))); - } - - public Name MakeMemberAccessPathFieldName(Method method, IReadOnlyList path) - { - return new Name(string.Format(MemberAccessPathNameFormat, - method.Name, - MakePipeliningSupportExtensionMethodName(path))); - } - } -} diff --git a/capnpc-csharp/Generator/GeneratorOptions.cs b/capnpc-csharp/Generator/GeneratorOptions.cs deleted file mode 100644 index 76faf93..0000000 --- a/capnpc-csharp/Generator/GeneratorOptions.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace CapnpC.Generator -{ - class GeneratorOptions - { - public string TopNamespaceName { get; set; } = "CapnpGen"; - public string ReaderStructName { get; set; } = "READER"; - public string WriterStructName { get; set; } = "WRITER"; - public string ReaderParameterName { get; set; } = "reader"; - public string WriterParameterName { get; set; } = "writer"; - public string ReaderCreateMethodName { get; set; } = "create"; - public string ReaderContextFieldName { get; set; } = "ctx"; - public string ContextParameterName { get; set; } = "ctx"; - public string GroupReaderContextArgName { get; set; } = "ctx"; - public string GroupWriterContextArgName { get; set; } = "ctx"; - public string UnionDisciminatorEnumName { get; set; } = "WHICH"; - public string UnionDiscriminatorPropName { get; set; } = "which"; - public string UnionDiscriminatorFieldName { get; set; } = "_which"; - public string UnionDisciminatorUndefinedName { get; set; } = "undefined"; - public string UnionContentFieldName { get; set; } = "_content"; - public string SerializeMethodName { get; set; } = "serialize"; - public string ApplyDefaultsMethodName { get; set; } = "applyDefaults"; - public string AnonymousParameterName { get; set; } = "arg_"; - public string CancellationTokenParameterName { get; set; } = "cancellationToken_"; - public string ParamsLocalName { get; set; } = "in_"; - public string DeserializerLocalName { get; set; } = "d_"; - public string SerializerLocalName { get; set; } = "s_"; - public string ResultLocalName { get; set; } = "r_"; - public string ParamsStructFormat { get; set; } = "Params_{0}"; - public string ResultStructFormat { get; set; } = "Result_{0}"; - public string PropertyNamedLikeTypeRenameFormat { get; set; } = "The{0}"; - public string InstLocalName { get; set; } = "inst"; - public string GenericTypeParameterFormat { get; set; } = "T{0}"; - public string PipeliningExtensionsClassName { get; set; } = "PipeliningSupportExtensions"; - public string MemberAccessPathNameFormat { get; set; } = "Path_{0}_{1}"; - public string TaskParameterName { get; set; } = "task"; - public string EagerMethodName { get; set; } = "Eager"; - } -} diff --git a/capnpc-csharp/Generator/InterfaceSnippetGen.cs b/capnpc-csharp/Generator/InterfaceSnippetGen.cs deleted file mode 100644 index f0adfaa..0000000 --- a/capnpc-csharp/Generator/InterfaceSnippetGen.cs +++ /dev/null @@ -1,844 +0,0 @@ -using CapnpC.Model; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; -using static CapnpC.Generator.SyntaxHelpers; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using System.Threading.Tasks; -using System.Threading; -using Microsoft.CodeAnalysis.CSharp; - -namespace CapnpC.Generator -{ - class InterfaceSnippetGen - { - readonly GenNames _names; - - public InterfaceSnippetGen(GenNames names) - { - _names = names; - } - - TypeSyntax TransformReturnType(Method method) - { - switch (method.Results.Count) - { - case 0: - return IdentifierName(nameof(Task)); - - case 1: - return GenericName(nameof(Task)).AddTypeArgumentListArguments( - _names.MakeTypeSyntax(method.Results[0].Type, method.DeclaringInterface, TypeUsage.DomainClass)); - - default: - return GenericName(nameof(Task)).AddTypeArgumentListArguments( - TupleType(SeparatedList( - method.Results.Select( - f => TupleElement(_names.MakeTypeSyntax(f.Type, method.DeclaringInterface, TypeUsage.DomainClass)))))); - } - } - - ParameterSyntax[] TransformParameters(Method method) - { - var list = new List(); - - if (method.Params.Count > 0) - { - var arg0 = method.Params[0]; - - if (arg0.Name == null) - { - list.Add(Parameter(_names.AnonymousParameter.Identifier) - .WithType(_names.MakeTypeSyntax(arg0.Type, method.DeclaringInterface, TypeUsage.DomainClass))); - } - else - { - foreach (var arg in method.Params) - { - list.Add(Parameter(Identifier(arg.Name)) - .WithType(_names.MakeTypeSyntax(arg.Type, method.DeclaringInterface, TypeUsage.DomainClass))); - } - } - } - - list.Add(Parameter(_names.CancellationTokenParameter.Identifier) - .WithType(IdentifierName(nameof(CancellationToken))) - .WithDefault(EqualsValueClause(LiteralExpression( - SyntaxKind.DefaultLiteralExpression, - Token(SyntaxKind.DefaultKeyword))))); - - return list.ToArray(); - } - - IEnumerable MakeTypeParameters(TypeDefinition def) - { - foreach (string name in def.GenericParameters) - { - yield return TypeParameter(_names.GetGenericTypeParameter(name).Identifier); - } - } - - IEnumerable MakeTypeParameterConstraints(TypeDefinition def) - { - foreach (string name in def.GenericParameters) - { - yield return TypeParameterConstraintClause( - _names.GetGenericTypeParameter(name).IdentifierName) - .AddConstraints(ClassOrStructConstraint(SyntaxKind.ClassConstraint)); - } - } - - public MemberDeclarationSyntax MakeInterface(TypeDefinition type) - { - var ifaceDecl = InterfaceDeclaration(_names.MakeTypeName(type, NameUsage.Interface).Identifier) - .AddModifiers(Public) - .AddAttributeLists( - AttributeList() - .AddAttributes( - Attribute(IdentifierName("Proxy")) - .AddArgumentListArguments( - AttributeArgument( - TypeOfExpression(_names.MakeGenericTypeNameForAttribute(type, NameUsage.Proxy)))), - Attribute(IdentifierName("Skeleton")) - .AddArgumentListArguments( - AttributeArgument( - TypeOfExpression(_names.MakeGenericTypeNameForAttribute(type, NameUsage.Skeleton)))))); - - if (type.GenericParameters.Count > 0) - { - ifaceDecl = ifaceDecl.AddTypeParameterListParameters(MakeTypeParameters(type).ToArray()); - } - - if (type.Superclasses.Count == 0) - { - ifaceDecl = ifaceDecl.AddBaseListTypes(SimpleBaseType(IdentifierName(nameof(IDisposable)))); - } - else - { - foreach (var superClass in type.Superclasses) - { - ifaceDecl = ifaceDecl.AddBaseListTypes( - SimpleBaseType(_names.MakeTypeSyntax( - superClass, type, - TypeUsage.NotRelevant))); - } - } - - foreach (var method in type.Methods) - { - var methodDecl = MethodDeclaration( - TransformReturnType(method), - _names.GetCodeIdentifier(method).Identifier) - .AddParameterListParameters(TransformParameters(method)) - .WithSemicolonToken(Token(SyntaxKind.SemicolonToken)); - - if (method.GenericParameters.Count > 0) - { - methodDecl = methodDecl - .AddTypeParameterListParameters(MakeTypeParameters(method).ToArray()) - .AddConstraintClauses(MakeTypeParameterConstraints(method).ToArray()); - - } - - ifaceDecl = ifaceDecl.AddMembers(methodDecl); - } - - return ifaceDecl; - } - - bool IsSubjectToPipelining(Model.Type type, HashSet visited) - { - if (!visited.Add(type)) - return false; - - switch (type.Tag) - { - case TypeTag.AnyPointer: - case TypeTag.CapabilityPointer: - case TypeTag.Interface: - case TypeTag.ListPointer: - case TypeTag.StructPointer: - return true; - - case TypeTag.List: - return IsSubjectToPipelining(type.ElementType, visited); - - case TypeTag.Struct: - return type.Fields.Any(f => IsSubjectToPipelining(f.Type, visited)); - - default: - return false; - } - } - - bool IsSubjectToPipelining(Method method) - { - return method.Results.Any(r => IsSubjectToPipelining(r.Type, new HashSet())); - } - - IEnumerable MakeProxyCallInitializerAssignments(Method method) - { - foreach (var methodParam in method.Params) - { - yield return AssignmentExpression( - SyntaxKind.SimpleAssignmentExpression, - _names.GetCodeIdentifier(methodParam).IdentifierName, - IdentifierName(methodParam.Name)); - } - } - - IEnumerable MakeProxyReturnResultTupleElements(Method method) - { - foreach (var item in method.ResultStruct.Fields) - { - yield return Argument(MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - _names.ResultLocal.IdentifierName, - _names.GetCodeIdentifier(item).IdentifierName)); - } - } - - StatementSyntax MakeProxyReturnResult(Method method) - { - if (method.ResultStruct.Definition.SpecialName == SpecialName.MethodResultStruct) - { - if (method.ResultStruct.Fields.Count == 0) - { - return ReturnStatement(); - } - else - { - return ReturnStatement(TupleExpression() - .AddArguments(MakeProxyReturnResultTupleElements(method).ToArray())); - } - - } - else - { - return ReturnStatement(_names.ResultLocal.IdentifierName); - } - } - - StatementSyntax MakeProxyCreateResult(Method method) - { - var resultType = method.ResultStruct; - var domainType = _names.MakeTypeSyntax(resultType, method.DeclaringInterface, TypeUsage.DomainClass); - - var createDomain = InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - IdentifierName(nameof(Capnp.CapnpSerializable)), - GenericName(nameof(Capnp.CapnpSerializable.Create)) - .AddTypeArgumentListArguments(domainType))) - .AddArgumentListArguments( - Argument(_names.DeserializerLocal.IdentifierName)); - - return LocalDeclarationStatement( - VariableDeclaration( - IdentifierName("var")) - .WithVariables( - SingletonSeparatedList( - VariableDeclarator( - _names.ResultLocal.Identifier) - .WithInitializer( - EqualsValueClause(createDomain))))); - } - - IEnumerable MakeTypeParameters(Method method) - { - foreach (string name in method.GenericParameters) - { - yield return TypeParameter(_names.GetGenericTypeParameter(name).Identifier); - } - } - - IEnumerable MakeTypeParameterConstraints(Method method) - { - foreach (string name in method.GenericParameters) - { - yield return TypeParameterConstraintClause( - _names.GetGenericTypeParameter(name).IdentifierName) - .AddConstraints(ClassOrStructConstraint(SyntaxKind.ClassConstraint)); - } - } - - public MemberDeclarationSyntax MakeProxy(TypeDefinition type) - { - var classDecl = ClassDeclaration(_names.MakeTypeName(type, NameUsage.Proxy).Identifier) - .AddModifiers(Public) - .AddBaseListTypes( - SimpleBaseType(Type()), - SimpleBaseType(_names.MakeGenericTypeName(type, NameUsage.Interface))); - - if (type.GenericParameters.Count > 0) - { - classDecl = classDecl - .AddTypeParameterListParameters(MakeTypeParameters(type).ToArray()) - .AddConstraintClauses(MakeTypeParameterConstraints(type).ToArray()); - } - - var allMethods = - from c in Types.FromDefinition(type).AllImplementedClasses - from m in c.Definition.Methods - select m; - - foreach (var method in allMethods) - { - var bodyStmts = new List(); - - bodyStmts.Add(LocalDeclarationStatement( - VariableDeclaration( - IdentifierName("var")) - .WithVariables( - SingletonSeparatedList( - VariableDeclarator( - _names.ParamsLocal.Identifier) - .WithInitializer( - EqualsValueClause( - InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - IdentifierName(nameof(Capnp.SerializerState)), - GenericName( - Identifier(nameof(Capnp.SerializerState.CreateForRpc))) - .WithTypeArgumentList( - TypeArgumentList( - SingletonSeparatedList( - _names.MakeTypeSyntax( - method.ParamsStruct, - method.ParamsStruct.Definition, - TypeUsage.Writer)))))))))))); - - if (method.ParamsStruct.Definition.SpecialName == SpecialName.MethodParamsStruct) - { - bodyStmts.Add(LocalDeclarationStatement( - VariableDeclaration( - IdentifierName("var")) - .WithVariables( - SingletonSeparatedList( - VariableDeclarator( - _names.AnonymousParameter.Identifier) - .WithInitializer( - EqualsValueClause( - ObjectCreationExpression( - _names.MakeTypeSyntax( - method.ParamsStruct, - method.ParamsStruct.Definition, - TypeUsage.DomainClass)) - .WithArgumentList( - ArgumentList()) - .WithInitializer( - InitializerExpression( - SyntaxKind.ObjectInitializerExpression, - SeparatedList( - CommonSnippetGen.MakeCommaSeparatedList( - MakeProxyCallInitializerAssignments(method)).ToArray()))))))))); - } - - bodyStmts.Add(ExpressionStatement( - InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - _names.AnonymousParameter.IdentifierName, - _names.SerializeMethod.IdentifierName)) - .AddArgumentListArguments( - Argument(_names.ParamsLocal.IdentifierName)))); - - var call = InvocationExpression(IdentifierName(nameof(Capnp.Rpc.BareProxy.Call))) - .AddArgumentListArguments( - Argument( - LiteralExpression(SyntaxKind.NumericLiteralExpression, - Literal(method.DeclaringInterface.Id))), - Argument( - LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(method.Id))), - Argument( - InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - _names.ParamsLocal.IdentifierName, - GenericName(nameof(Capnp.SerializerState.Rewrap)) - .AddTypeArgumentListArguments(Type()))) - .AddArgumentListArguments()), - Argument( - LiteralExpression(SyntaxKind.FalseLiteralExpression)), - Argument( - _names.CancellationTokenParameter.IdentifierName)); - - MethodDeclarationSyntax methodDecl; - - if (IsSubjectToPipelining(method)) - { - methodDecl = MethodDeclaration( - TransformReturnType(method), - _names.GetCodeIdentifier(method).Identifier) - .AddParameterListParameters(TransformParameters(method)) - .AddModifiers(Public); - - var pipelineAwareCall = InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - IdentifierName(nameof(Capnp.Rpc.Impatient)), - IdentifierName(nameof(Capnp.Rpc.Impatient.MakePipelineAware)))) - .AddArgumentListArguments( - Argument(call), - Argument(SimpleLambdaExpression( - Parameter(_names.DeserializerLocal.Identifier), - Block( - MakeProxyCreateResult(method), - MakeProxyReturnResult(method))))); - - bodyStmts.Add(ReturnStatement(pipelineAwareCall)); - } - else - { - methodDecl = MethodDeclaration( - TransformReturnType(method), - _names.GetCodeIdentifier(method).Identifier) - .AddParameterListParameters(TransformParameters(method)) - .AddModifiers(Public, Token(SyntaxKind.AsyncKeyword)); - - var whenReturned = MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - call, - IdentifierName(nameof(Capnp.Rpc.IPromisedAnswer.WhenReturned))); - - var assignAwaited = LocalDeclarationStatement( - VariableDeclaration( - IdentifierName("var")) - .AddVariables( - VariableDeclarator( - _names.DeserializerLocal.Identifier) - .WithInitializer( - EqualsValueClause( - AwaitExpression(whenReturned))))); - - bodyStmts.Add(assignAwaited); - bodyStmts.Add(MakeProxyCreateResult(method)); - bodyStmts.Add(MakeProxyReturnResult(method)); - } - - if (method.GenericParameters.Count > 0) - { - methodDecl = methodDecl - .AddTypeParameterListParameters(MakeTypeParameters(method).ToArray()) - .AddConstraintClauses(MakeTypeParameterConstraints(method).ToArray()); - } - - methodDecl = methodDecl.AddBodyStatements(bodyStmts.ToArray()); - - classDecl = classDecl.AddMembers(methodDecl); - } - - return classDecl; - } - - IEnumerable MakeSkeletonSetMethodTableArguments(TypeDefinition def) - { - foreach (var method in def.Methods) - { - if (method.GenericParameters.Count > 0) - { - yield return Argument( - GenericName(_names.GetCodeIdentifier(method).ToString()) - .AddTypeArgumentListArguments( - Enumerable.Repeat( - Type(), - method.GenericParameters.Count).ToArray())); - } - else - { - yield return Argument(_names.GetCodeIdentifier(method).IdentifierName); - } - } - } - - IEnumerable MakeSkeletonMethodResultStructInitializer(Method method) - { - foreach (var arg in method.Results) - { - yield return AssignmentExpression( - SyntaxKind.SimpleAssignmentExpression, - _names.GetCodeIdentifier(arg).IdentifierName, - IdentifierName(arg.Name)); - } - } - - IEnumerable MakeSkeletonMethodCallArgs(Method method) - { - foreach (var arg in method.ParamsStruct.Fields) - { - yield return Argument( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - _names.ParamsLocal.IdentifierName, - _names.GetCodeIdentifier(arg).IdentifierName)); - } - } - - StatementSyntax MakeSkeletonMethodSerializerLocalDeclaration(Method method) - { - return LocalDeclarationStatement( - VariableDeclaration( - IdentifierName("var")) - .WithVariables( - SingletonSeparatedList( - VariableDeclarator( - _names.SerializerLocal.Identifier) - .WithInitializer( - EqualsValueClause( - InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - IdentifierName(nameof(Capnp.SerializerState)), - GenericName( - Identifier(nameof(Capnp.SerializerState.CreateForRpc))) - .WithTypeArgumentList( - TypeArgumentList( - SingletonSeparatedList( - _names.MakeTypeSyntax( - method.ResultStruct, - method.ResultStruct.Definition, - TypeUsage.Writer))))))))))); - - } - - CSharpSyntaxNode MakeMaybeTailCallLambdaBody(Method method) - { - var block = Block( - MakeSkeletonMethodSerializerLocalDeclaration(method)); - - if (method.ResultStruct.Definition.SpecialName == SpecialName.MethodResultStruct) - { - block = block.AddStatements( - LocalDeclarationStatement( - VariableDeclaration( - IdentifierName("var")) - .AddVariables( - VariableDeclarator(_names.ResultLocal.Identifier) - .WithInitializer(EqualsValueClause(ObjectCreationExpression( - _names.MakeTypeSyntax( - method.ResultStruct, - method.ResultStruct.Definition, - TypeUsage.DomainClass)) - .WithInitializer( - InitializerExpression(SyntaxKind.ObjectInitializerExpression) - .AddExpressions( - MakeSkeletonMethodResultStructInitializer(method).ToArray()))))))); - } - - if (method.Results.Count > 0) - { - block = block.AddStatements( - ExpressionStatement( - InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - _names.ResultLocal.IdentifierName, - _names.SerializeMethod.IdentifierName)) - .AddArgumentListArguments( - Argument(_names.SerializerLocal.IdentifierName)))); - } - - block = block.AddStatements( - ReturnStatement(_names.SerializerLocal.IdentifierName)); - - return block; - } - - IEnumerable MakeSkeletonMethodBody(Method method) - { - var call = InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - IdentifierName(SkeletonWorder.ImplName), - _names.GetCodeIdentifier(method).IdentifierName)); - - if (method.Params.Count > 0) - { - var paramsType = method.ParamsStruct; - var domainType = _names.MakeTypeSyntax(paramsType, method.ParamsStruct.Definition, TypeUsage.DomainClass); - - var createDomain = InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - IdentifierName(nameof(Capnp.CapnpSerializable)), - GenericName(nameof(Capnp.CapnpSerializable.Create)) - .AddTypeArgumentListArguments(domainType))) - .AddArgumentListArguments( - Argument(_names.DeserializerLocal.IdentifierName)); - - if (method.ParamsStruct.Definition.SpecialName == SpecialName.MethodParamsStruct) - { - yield return LocalDeclarationStatement( - VariableDeclaration( - IdentifierName("var")) - .AddVariables( - VariableDeclarator(_names.ParamsLocal.Identifier) - .WithInitializer(EqualsValueClause(createDomain)))); - - call = call.AddArgumentListArguments( - MakeSkeletonMethodCallArgs(method).ToArray()); - } - else - { - call = call.AddArgumentListArguments( - Argument(createDomain)); - } - } - - call = call.AddArgumentListArguments( - Argument( - _names.CancellationTokenParameter.IdentifierName)); - - if (method.Results.Count == 0) - { - var awaitCall = AwaitExpression(call); - yield return ExpressionStatement(awaitCall); - yield return MakeSkeletonMethodSerializerLocalDeclaration(method); - yield return ReturnStatement(_names.SerializerLocal.IdentifierName); - } - else - { - ExpressionSyntax lambdaArg; - - if (method.ResultStruct.Definition.SpecialName == SpecialName.MethodResultStruct) - { - if (method.Results.Count == 1) - { - lambdaArg = SimpleLambdaExpression( - Parameter(Identifier(method.Results.Single().Name)), - MakeMaybeTailCallLambdaBody(method)); - } - else - { - lambdaArg = ParenthesizedLambdaExpression( - MakeMaybeTailCallLambdaBody(method)) - .AddParameterListParameters( - method.Results.Select(arg => Parameter(Identifier(arg.Name))).ToArray()); - } - } - else - { - lambdaArg = SimpleLambdaExpression( - Parameter(_names.ResultLocal.Identifier), - MakeMaybeTailCallLambdaBody(method)); - - } - - var maybeTailCall = InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - IdentifierName(nameof(Capnp.Rpc.Impatient)), - IdentifierName(nameof(Capnp.Rpc.Impatient.MaybeTailCall)))) - .AddArgumentListArguments( - Argument(call), - Argument(lambdaArg)); - - yield return ReturnStatement(maybeTailCall); - } - } - - IEnumerable MakeSkeletonMethods(TypeDefinition def) - { - foreach (var method in def.Methods) - { - var methodDecl = MethodDeclaration( - Type>(), - _names.GetCodeIdentifier(method).Identifier) - .AddParameterListParameters( - Parameter(_names.DeserializerLocal.Identifier) - .WithType(Type()), - Parameter(_names.CancellationTokenParameter.Identifier) - .WithType(Type())) - .AddBodyStatements( - MakeSkeletonMethodBody(method).ToArray()); - - if (method.Results.Count == 0) - { - methodDecl = methodDecl.AddModifiers(Async); - } - - if (method.GenericParameters.Count > 0) - { - methodDecl = methodDecl - .AddTypeParameterListParameters(MakeTypeParameters(method).ToArray()) - .AddConstraintClauses(MakeTypeParameterConstraints(method).ToArray()); - } - - yield return methodDecl; - } - } - - public MemberDeclarationSyntax MakeSkeleton(TypeDefinition type) - { - var name = _names.MakeTypeName(type, NameUsage.Skeleton).Identifier; - var classDecl = ClassDeclaration(name) - .AddModifiers(Public) - .AddBaseListTypes( - SimpleBaseType( - GenericName(nameof(Capnp.Rpc.Skeleton)) - .AddTypeArgumentListArguments( - _names.MakeGenericTypeName(type, NameUsage.Interface)))) - .AddMembers( - // C'tor - ConstructorDeclaration(name) - .AddModifiers(Public) - .AddBodyStatements( - ExpressionStatement( - InvocationExpression( - IdentifierName(SkeletonWorder.SetMethodTableName)) - .AddArgumentListArguments( - MakeSkeletonSetMethodTableArguments(type).ToArray()))), - // InterfaceId - PropertyDeclaration(Type(), nameof(Capnp.Rpc.Skeleton.InterfaceId)) - .AddModifiers(Public, Override) - .WithExpressionBody( - ArrowExpressionClause( - ValueOf(type.Id))) - .WithSemicolonToken( - Token(SyntaxKind.SemicolonToken))); - - if (type.GenericParameters.Count > 0) - { - classDecl = classDecl - .AddTypeParameterListParameters(MakeTypeParameters(type).ToArray()) - .AddConstraintClauses(MakeTypeParameterConstraints(type).ToArray()); - } - - classDecl = classDecl.AddMembers(MakeSkeletonMethods(type).ToArray()); - - return classDecl; - } - - public bool RequiresPipeliningSupport(TypeDefinition type) - { - return type.Methods.Any(m => ExpandPipeliningPaths(m).Any()); - } - - IEnumerable> ExpandPipeliningPaths(Method method) - { - var stack = new Stack>(); - foreach (var field in method.ResultStruct.Fields) - { - stack.Push(new List() { field }); - } - - while (stack.Count > 0) - { - var path = stack.Pop(); - var last = path[path.Count - 1]; - - switch (last.Type.Tag) - { - case TypeTag.Interface: - case TypeTag.CapabilityPointer: - yield return path; - break; - - case TypeTag.Struct: - foreach (var field in last.Type.Fields) - { - if (path.Contains(field)) - { - // Recursive structs protection - continue; - } - - var copy = new List(); - copy.AddRange(path); - copy.Add(field); - stack.Push(copy); - } - break; - } - } - } - - readonly HashSet<(string, string)> _existingExtensionMethods = new HashSet<(string, string)>(); - - public MemberDeclarationSyntax MakePipeliningSupport(TypeDefinition type) - { - var classDecl = ClassDeclaration(_names.PipeliningExtensionsClassName.Identifier) - .AddModifiers(Public, Static, Partial); - - foreach (var method in type.Methods) - { - foreach (var path in ExpandPipeliningPaths(method)) - { - var accessPath = _names.MakeMemberAccessPathFieldName(method, path); - var methodName = _names.MakePipeliningSupportExtensionMethodName(path); - var capType = path[path.Count - 1].Type; - var capTypeSyntax = _names.MakeTypeSyntax(capType, null, TypeUsage.DomainClass); - - if (!_existingExtensionMethods.Add((capTypeSyntax.ToString(), methodName.ToString()))) - { - continue; - } - - var pathDecl = FieldDeclaration( - VariableDeclaration( - IdentifierName(nameof(Capnp.Rpc.MemberAccessPath))) - .AddVariables( - VariableDeclarator( - accessPath.Identifier) - .WithInitializer( - EqualsValueClause( - ObjectCreationExpression( - IdentifierName(nameof(Capnp.Rpc.MemberAccessPath))) - .AddArgumentListArguments( - path.Select( - f => Argument( - LiteralExpression(SyntaxKind.NumericLiteralExpression, - Literal(f.Offset)))).ToArray()))))) - .AddModifiers(Static, Readonly); - - - var methodDecl = MethodDeclaration( - capTypeSyntax, - methodName.Identifier) - .AddModifiers(Public, Static) - .AddParameterListParameters( - Parameter( - _names.TaskParameter.Identifier) - .AddModifiers(This) - .WithType(TransformReturnType(method))) - .AddBodyStatements( - ReturnStatement( - CastExpression( - capTypeSyntax, - InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - IdentifierName(nameof(Capnp.Rpc.CapabilityReflection)), - GenericName( - Identifier(nameof(Capnp.Rpc.CapabilityReflection.CreateProxy))) - .AddTypeArgumentListArguments( - capTypeSyntax))) - .AddArgumentListArguments( - Argument( - InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - IdentifierName(nameof(Capnp.Rpc.Impatient)), - IdentifierName(nameof(Capnp.Rpc.Impatient.GetAnswer)))) - .AddArgumentListArguments( - Argument( - _names.TaskParameter.IdentifierName)), - IdentifierName(nameof(Capnp.Rpc.IPromisedAnswer.Access)))) - .AddArgumentListArguments( - Argument( - accessPath.IdentifierName))))))); - - classDecl = classDecl.AddMembers(pathDecl, methodDecl); - } - } - - return classDecl; - } - } -} diff --git a/capnpc-csharp/Generator/Name.cs b/capnpc-csharp/Generator/Name.cs deleted file mode 100644 index f85f324..0000000 --- a/capnpc-csharp/Generator/Name.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using System; -using System.Collections.Generic; -using System.Text; - -namespace CapnpC.Generator -{ - class Name - { - readonly string _name; - - public Name(string name) - { - _name = name ?? throw new ArgumentNullException(nameof(name)); - IdentifierName = SyntaxFactory.IdentifierName(_name); - Identifier = SyntaxFactory.Identifier(_name); - VariableDeclarator = SyntaxFactory.VariableDeclarator(_name); - } - - public IdentifierNameSyntax IdentifierName { get; } - public SyntaxToken Identifier { get; } - public VariableDeclaratorSyntax VariableDeclarator { get; } - - public override string ToString() => _name; - - public override bool Equals(object obj) - { - return obj is Name other && _name == other._name; - } - - public override int GetHashCode() => _name.GetHashCode(); - } -} diff --git a/capnpc-csharp/Generator/ReaderSnippetGen.cs b/capnpc-csharp/Generator/ReaderSnippetGen.cs deleted file mode 100644 index 9d57038..0000000 --- a/capnpc-csharp/Generator/ReaderSnippetGen.cs +++ /dev/null @@ -1,715 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using CapnpC.Model; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; -using static CapnpC.Generator.SyntaxHelpers; - -namespace CapnpC.Generator -{ - class ReaderSnippetGen - { - readonly GenNames _names; - - public ReaderSnippetGen(GenNames names) - { - _names = names; - } - - MemberDeclarationSyntax MakeReaderImplicitConversionOperator1() - { - return ConversionOperatorDeclaration( - Token(SyntaxKind.ImplicitKeyword), - IdentifierName(nameof(Capnp.DeserializerState))) - .WithModifiers( - TokenList( - new[]{ - Token(SyntaxKind.PublicKeyword), - Token(SyntaxKind.StaticKeyword)})) - .WithParameterList( - ParameterList( - SingletonSeparatedList( - Parameter(_names.ReaderParameter.Identifier) - .WithType(_names.ReaderStruct.IdentifierName)))) - .WithExpressionBody( - ArrowExpressionClause( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - _names.ReaderParameter.IdentifierName, - _names.ReaderContextField.IdentifierName))) - .WithSemicolonToken( - Token(SyntaxKind.SemicolonToken)); - } - - MemberDeclarationSyntax MakeReaderImplicitConversionOperator2() - { - return ConversionOperatorDeclaration( - Token(SyntaxKind.ImplicitKeyword), - _names.ReaderStruct.IdentifierName) - .WithModifiers( - TokenList( - new[] { - Token(SyntaxKind.PublicKeyword), - Token(SyntaxKind.StaticKeyword) })) - .WithParameterList( - ParameterList( - SingletonSeparatedList( - Parameter(_names.ReaderContextField.Identifier) - .WithType(Type())))) - .WithExpressionBody( - ArrowExpressionClause( - ObjectCreationExpression(_names.ReaderStruct.IdentifierName) - .WithArgumentList( - ArgumentList( - SingletonSeparatedList( - Argument(_names.ReaderContextField.IdentifierName)))))) - .WithSemicolonToken( - Token(SyntaxKind.SemicolonToken)); - } - - MemberDeclarationSyntax MakeReaderCreateMethod() - { - return MethodDeclaration(_names.ReaderStruct.IdentifierName, _names.ReaderCreateMethod.Identifier) - .AddModifiers(Public, Static) - .WithParameterList( - ParameterList( - SingletonSeparatedList( - Parameter(_names.ContextParameter.Identifier) - .WithType( - Type())))) - .WithExpressionBody( - ArrowExpressionClause( - ObjectCreationExpression(_names.ReaderStruct.IdentifierName) - .AddArgumentListArguments(Argument(_names.ContextParameter.IdentifierName)))) - .WithSemicolonToken(Token(SyntaxKind.SemicolonToken)); - } - - IEnumerable MakeReaderStructMembers() - { - yield return FieldDeclaration( - VariableDeclaration( - Type()) - .AddVariables(_names.ReaderContextField.VariableDeclarator)) - .AddModifiers(Readonly); - - yield return ConstructorDeclaration(_names.ReaderStruct.Identifier) - .AddModifiers(Public) - .WithParameterList( - ParameterList( - SingletonSeparatedList( - Parameter(_names.ContextParameter.Identifier) - .WithType(Type())))) - .WithBody( - Block( - SingletonList( - ExpressionStatement( - AssignmentExpression( - SyntaxKind.SimpleAssignmentExpression, - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - ThisExpression(), - _names.ReaderContextField.IdentifierName), - _names.ContextParameter.IdentifierName))))); - - yield return MakeReaderCreateMethod(); - yield return MakeReaderImplicitConversionOperator1(); - yield return MakeReaderImplicitConversionOperator2(); - } - - IEnumerable MakeGroupReaderStructMembers() - { - yield return FieldDeclaration( - VariableDeclaration( - Type()) - .AddVariables(_names.ReaderContextField.VariableDeclarator)) - .AddModifiers(Readonly); - - yield return ConstructorDeclaration(_names.ReaderStruct.Identifier) - .AddModifiers(Public) - .WithParameterList( - ParameterList( - SingletonSeparatedList(Parameter(_names.GroupReaderContextArg.Identifier) - .WithType(Type())))) - .WithBody( - Block( - SingletonList( - ExpressionStatement( - AssignmentExpression( - SyntaxKind.SimpleAssignmentExpression, - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - ThisExpression(), - _names.ReaderContextField.IdentifierName), - _names.GroupReaderContextArg.IdentifierName))))); - - yield return MakeReaderCreateMethod(); - yield return MakeReaderImplicitConversionOperator1(); - yield return MakeReaderImplicitConversionOperator2(); - } - - PropertyDeclarationSyntax MakeReaderProperty(TypeSyntax type, string name, ExpressionSyntax right, bool cond) - { - if (cond) - { - right = ConditionalExpression( - BinaryExpression( - SyntaxKind.EqualsExpression, - _names.UnionDiscriminatorProp.IdentifierName, - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - _names.UnionDiscriminatorEnum.IdentifierName, - IdentifierName(name))), - right, - LiteralExpression( - SyntaxKind.DefaultLiteralExpression, - Token(SyntaxKind.DefaultKeyword))); - } - - return PropertyDeclaration(type, name) - .AddModifiers(Public) - .WithExpressionBody(ArrowExpressionClause(right)) - .WithSemicolonToken(Token(SyntaxKind.SemicolonToken)); - } - - static Func MakeCastFunc(TypeSyntax type) => - x => CastExpression(type, x); - - static Func MakeListCastFunc(string castName, Field field) - { - // Insight: List may have complex default values (e.g. [true, false, false, true] as a - // valid default value for a list of bools. This does not yet fit the author's mindset. - - //if (field.DefaultValueIsExplicit) - //{ - // return x => InvocationExpression( - // MemberAccessExpression( - // SyntaxKind.SimpleMemberAccessExpression, - // x, - // IdentifierName(castName)) - // ) - // .AddArgumentListArguments( - // Argument(ValueOf(field.DefaultValue))); - //} - //else - - { - return x => InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - x, - IdentifierName(castName)) - ); - } - } - - static Func MakeListCastFuncWithCons( - string castName, ExpressionSyntax cons) - { - return x => InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - x, - IdentifierName(castName)) - ).AddArgumentListArguments(Argument(cons)); - } - - static Func MakeGenericListCastFunc(string castName, TypeSyntax genericArgument) - { - return x => InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - x, - GenericName(castName).AddTypeArgumentListArguments(genericArgument)) - ); - } - - PropertyDeclarationSyntax MakeReadProperty(TypeSyntax type, string name, SimpleNameSyntax readName, - object indexOrBitOffset, ExpressionSyntax secondArg, - Func cast, bool cond) - { - var right = InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - _names.ReaderContextField.IdentifierName, - readName)) - .AddArgumentListArguments( - Argument(ValueOf(indexOrBitOffset))); - - if (secondArg != null) - { - right = right.AddArgumentListArguments(Argument(secondArg)); - } - - ExpressionSyntax expr = right; - - if (cast != null) - { - expr = cast(expr); - } - - return MakeReaderProperty(type, name, expr, cond); - } - - PropertyDeclarationSyntax MakeReadProperty(TypeSyntax type, string name, string readName, - object indexOrBitOffset, ExpressionSyntax secondArg, - Func cast, bool cond) - { - return MakeReadProperty(type, name, IdentifierName(readName), indexOrBitOffset, secondArg, cast, cond); - } - - PropertyDeclarationSyntax MakeReadPrimitiveProperty(Field field, string readName) - { - return MakeReadProperty(Type(), _names.GetCodeIdentifier(field).ToString(), readName, field.BitOffset.Value, - ValueOf(field.DefaultValue.ScalarValue), null, field.DiscValue.HasValue); - } - - PropertyDeclarationSyntax MakeReadEnumProperty(Field field) - { - var typeSyntax = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Reader); - return MakeReadProperty(typeSyntax, - _names.GetCodeIdentifier(field).ToString(), - nameof(Capnp.SerializerExtensions.ReadDataUShort), field.BitOffset.Value, - ValueOf(field.DefaultValue.ScalarValue), - x => CastExpression(typeSyntax, x), - field.DiscValue.HasValue); - } - - PropertyDeclarationSyntax MakeReadTextProperty(Field field) - { - return MakeReadProperty(Type(), _names.GetCodeIdentifier(field).ToString(), - nameof(Capnp.DeserializerState.ReadText), (int)field.Offset, - ValueOf(field.DefaultValue.ScalarValue), null, field.DiscValue.HasValue); - } - - MemberAccessExpressionSyntax MakeReaderCreator(TypeSyntax qtype) - { - return MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - qtype, - _names.ReaderCreateMethod.IdentifierName); - } - - PropertyDeclarationSyntax MakeReadStructProperty(Field field) - { - var qtype = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Reader); - var creator = MakeReaderCreator(qtype); - - return MakeReadProperty(qtype, _names.GetCodeIdentifier(field).ToString(), - nameof(Capnp.DeserializerState.ReadStruct), (int)field.Offset, - creator, null, field.DiscValue.HasValue); - } - - PropertyDeclarationSyntax MakeReadGroupProperty(Field field) - { - var type = QualifiedName( - _names.MakeTypeName(field.Type.Definition).IdentifierName, - _names.ReaderStruct.IdentifierName); - - var right = ObjectCreationExpression(type) - .WithArgumentList( - ArgumentList( - SingletonSeparatedList( - Argument(_names.ReaderContextField.IdentifierName)))); - - return MakeReaderProperty(type, _names.GetCodeIdentifier(field).ToString(), right, field.DiscValue.HasValue); - } - - void MakeReadListPropertyImpl(Model.Type elementType, TypeDefinition scope, ExpressionSyntax context, int depth, - out TypeSyntax listType, out ExpressionSyntax impl) - { - var elementTypeSyntax = _names.MakeTypeSyntax(elementType, scope, TypeUsage.Reader); - listType = GenericName("IReadOnlyList").AddTypeArgumentListArguments(elementTypeSyntax); - - if (elementType.Tag == TypeTag.Interface || - elementType.Tag == TypeTag.CapabilityPointer) - { - if (depth == 0) - { - impl = InvocationExpression(MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - _names.ReaderContextField.IdentifierName, - GenericName(nameof(Capnp.DeserializerState.ReadCapList)) - .AddTypeArgumentListArguments(elementTypeSyntax) - )).AddArgumentListArguments(Argument(context)); - } - else - { - impl = InvocationExpression( - MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, - context, - GenericName(nameof(Capnp.DeserializerState.RequireCapList)) - .AddTypeArgumentListArguments(elementTypeSyntax) - )); - } - - return; - } - - if (depth == 0) - { - context = InvocationExpression(MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - _names.ReaderContextField.IdentifierName, - IdentifierName(nameof(Capnp.DeserializerState.ReadList)))) - .AddArgumentListArguments(Argument(context)); - } - else - { - context = InvocationExpression( - MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, - context, - IdentifierName(nameof(Capnp.DeserializerState.RequireList)) - )); - } - - string lambdaParamName = "_" + depth; - var lambdaParam = Parameter(Identifier(lambdaParamName)); - var lambdaArg = IdentifierName(lambdaParamName); - string castFuncName; - - switch (elementType.Tag) - { - case TypeTag.List: - { - - MakeReadListPropertyImpl( - elementType.ElementType, - scope, - lambdaArg, - depth + 1, - out var innerListType, - out var innerImpl); - - listType = GenericName("IReadOnlyList").AddTypeArgumentListArguments(innerListType); - - impl = InvocationExpression( - MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, - context, - IdentifierName(nameof(Capnp.ListDeserializer.Cast)))) - .AddArgumentListArguments( - Argument(SimpleLambdaExpression(lambdaParam, innerImpl))); - - return; - } - - case TypeTag.ListPointer: - { - listType = Type>(); - - context = InvocationExpression(MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - context, - IdentifierName(nameof(Capnp.DeserializerState.RequireList)) - )).AddArgumentListArguments(Argument(lambdaArg)); - - impl = InvocationExpression( - MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, - context, - IdentifierName(nameof(Capnp.ReadOnlyListExtensions.LazyListSelect)))) - .AddArgumentListArguments( - Argument(SimpleLambdaExpression(lambdaParam, context))); - - return; - } - - case TypeTag.Struct: - { - impl = InvocationExpression( - MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, - context, - IdentifierName(nameof(Capnp.ListDeserializer.Cast)))) - .AddArgumentListArguments( - Argument(MakeReaderCreator(elementTypeSyntax))); - - return; - } - - case TypeTag.Enum: - { - var cons = SimpleLambdaExpression( - lambdaParam, - CastExpression(elementTypeSyntax, lambdaArg)); - - impl = InvocationExpression( - MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, - context, - IdentifierName(nameof(Capnp.ListDeserializer.CastEnums)))) - .AddArgumentListArguments( - Argument(cons)); - - return; - } - - case TypeTag.AnyPointer: - case TypeTag.StructPointer: - { - listType = Type>(); - impl = context; - return; - } - - case TypeTag.Void: - { - listType = Type(); - impl = MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - context, - IdentifierName(nameof(Capnp.ListDeserializer.Count))); - return; - } - - case TypeTag.Data: - castFuncName = nameof(Capnp.ListDeserializer.CastData); - break; - - case TypeTag.Text: - castFuncName = nameof(Capnp.ListDeserializer.CastText2); - break; - - case TypeTag.Bool: - castFuncName = nameof(Capnp.ListDeserializer.CastBool); - break; - - case TypeTag.F32: - castFuncName = nameof(Capnp.ListDeserializer.CastFloat); - break; - - case TypeTag.F64: - castFuncName = nameof(Capnp.ListDeserializer.CastDouble); - break; - - case TypeTag.S8: - castFuncName = nameof(Capnp.ListDeserializer.CastSByte); - break; - - case TypeTag.U8: - castFuncName = nameof(Capnp.ListDeserializer.CastByte); - break; - - case TypeTag.S16: - castFuncName = nameof(Capnp.ListDeserializer.CastShort); - break; - - case TypeTag.U16: - case TypeTag.AnyEnum: - castFuncName = nameof(Capnp.ListDeserializer.CastUShort); - break; - - case TypeTag.S32: - castFuncName = nameof(Capnp.ListDeserializer.CastInt); - break; - - case TypeTag.U32: - castFuncName = nameof(Capnp.ListDeserializer.CastUInt); - break; - - case TypeTag.S64: - castFuncName = nameof(Capnp.ListDeserializer.CastLong); - break; - - case TypeTag.U64: - castFuncName = nameof(Capnp.ListDeserializer.CastULong); - break; - - default: - throw new NotImplementedException("Unexpected type tag, don't know how to deal with this"); - } - - impl = InvocationExpression(MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - context, - IdentifierName(castFuncName))); - } - - PropertyDeclarationSyntax MakeReadListProperty(Field field) - { - var elementType = field.Type.ElementType; - var context = ValueOf((int)field.Offset); - MakeReadListPropertyImpl(elementType, field.DeclaringType, context, 0, out var listType, out var impl); - return MakeReaderProperty(listType, _names.GetCodeIdentifier(field).ToString(), impl, field.DiscValue.HasValue); - } - - PropertyDeclarationSyntax MakeReadAnyListProperty(Field field) - { - var type = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Reader); - - return MakeReadProperty(type, _names.GetCodeIdentifier(field).ToString(), - nameof(Capnp.DeserializerState.ReadList), - (int)field.Offset, null, x => CastExpression(type, x), field.DiscValue.HasValue); - } - - PropertyDeclarationSyntax MakeReadCapProperty(Field field) - { - var type = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Reader); - var readName = GenericName(nameof(Capnp.DeserializerState.ReadCap)) - .AddTypeArgumentListArguments(type); - - return MakeReadProperty(type, _names.GetCodeIdentifier(field).ToString(), - readName, - (int)field.Offset, null, null, field.DiscValue.HasValue); - } - - PropertyDeclarationSyntax MakeReadAnyCapProperty(Field field) - { - var type = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Reader); - - return MakeReadProperty(type, _names.GetCodeIdentifier(field).ToString(), - nameof(Capnp.DeserializerState.ReadCap), - (int)field.Offset, null, null, field.DiscValue.HasValue); - } - - PropertyDeclarationSyntax MakeReadDataProperty(Field field) - { - var context = InvocationExpression(MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - _names.ReaderContextField.IdentifierName, - IdentifierName(nameof(Capnp.DeserializerState.ReadList)))) - .AddArgumentListArguments(Argument(ValueOf((int)field.Offset))); - var impl = InvocationExpression(MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - context, - IdentifierName(nameof(Capnp.ListDeserializer.CastByte)))); - - return MakeReaderProperty( - _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Reader), - _names.GetCodeIdentifier(field).ToString(), impl, field.DiscValue.HasValue); - } - - PropertyDeclarationSyntax MakeReadAnyPointerProperty(Field field) - { - var type = IdentifierName(nameof(Capnp.DeserializerState)); - - return MakeReadProperty(type, _names.GetCodeIdentifier(field).ToString(), - nameof(Capnp.DeserializerState.StructReadPointer), - (int)field.Offset, null, null, field.DiscValue.HasValue); - } - - PropertyDeclarationSyntax MakeReaderUnionSelector(TypeDefinition def) - { - var type = _names.UnionDiscriminatorEnum.IdentifierName; - return MakeReadProperty( - type, - _names.UnionDiscriminatorProp.ToString(), - nameof(Capnp.SerializerExtensions.ReadDataUShort), - def.UnionInfo.TagOffset, - ValueOf(default(ushort)), - MakeCastFunc(type), false); - } - - PropertyDeclarationSyntax MakeReaderFieldProperty(Field field) - { - switch (field.Type.Tag) - { - case TypeTag.Bool: - return MakeReadPrimitiveProperty(field, - nameof(Capnp.SerializerExtensions.ReadDataBool)); - - case TypeTag.S8: - return MakeReadPrimitiveProperty(field, - nameof(Capnp.SerializerExtensions.ReadDataSByte)); - - case TypeTag.U8: - return MakeReadPrimitiveProperty(field, - nameof(Capnp.SerializerExtensions.ReadDataByte)); - - case TypeTag.S16: - return MakeReadPrimitiveProperty(field, - nameof(Capnp.SerializerExtensions.ReadDataShort)); - - case TypeTag.U16: - return MakeReadPrimitiveProperty(field, - nameof(Capnp.SerializerExtensions.ReadDataUShort)); - - case TypeTag.S32: - return MakeReadPrimitiveProperty(field, - nameof(Capnp.SerializerExtensions.ReadDataInt)); - - case TypeTag.U32: - return MakeReadPrimitiveProperty(field, - nameof(Capnp.SerializerExtensions.ReadDataUInt)); - - case TypeTag.S64: - return MakeReadPrimitiveProperty(field, - nameof(Capnp.SerializerExtensions.ReadDataLong)); - - case TypeTag.U64: - return MakeReadPrimitiveProperty(field, - nameof(Capnp.SerializerExtensions.ReadDataULong)); - - case TypeTag.F32: - return MakeReadPrimitiveProperty(field, - nameof(Capnp.SerializerExtensions.ReadDataFloat)); - - case TypeTag.F64: - return MakeReadPrimitiveProperty(field, - nameof(Capnp.SerializerExtensions.ReadDataDouble)); - - case TypeTag.Enum: - return MakeReadEnumProperty(field); - - case TypeTag.Text: - return MakeReadTextProperty(field); - - case TypeTag.Struct: - return MakeReadStructProperty(field); - - case TypeTag.Group: - return MakeReadGroupProperty(field); - - case TypeTag.List: - return MakeReadListProperty(field); - - case TypeTag.Interface: - return MakeReadCapProperty(field); - - case TypeTag.CapabilityPointer: - return MakeReadAnyCapProperty(field); - - case TypeTag.ListPointer: - return MakeReadAnyListProperty(field); - - case TypeTag.AnyPointer: - case TypeTag.StructPointer: - return MakeReadAnyPointerProperty(field); - - case TypeTag.Data: - return MakeReadDataProperty(field); - - default: - return null; - } - } - - public StructDeclarationSyntax MakeReaderStruct(TypeDefinition def) - { - var readerDecl = StructDeclaration(_names.ReaderStruct.ToString()).AddModifiers(Public); - - var members = def.Tag == TypeTag.Group ? - MakeGroupReaderStructMembers() : - MakeReaderStructMembers(); - - readerDecl = readerDecl.AddMembers(members.ToArray()); - - if (def.UnionInfo != null) - { - readerDecl = readerDecl.AddMembers(MakeReaderUnionSelector(def)); - } - - foreach (var field in def.Fields) - { - var propDecl = MakeReaderFieldProperty(field); - - if (propDecl != null) - { - readerDecl = readerDecl.AddMembers(propDecl); - } - } - - return readerDecl; - } - } -} diff --git a/capnpc-csharp/Generator/SerializerStateWorder.cs b/capnpc-csharp/Generator/SerializerStateWorder.cs deleted file mode 100644 index 8f64689..0000000 --- a/capnpc-csharp/Generator/SerializerStateWorder.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Capnp; -using System.Collections.Generic; -using System.Text; - -namespace CapnpC.Generator -{ - class SerializerStateWorder: SerializerState - { - public const string LinkName = nameof(SerializerStateWorder.Link); - public const string SetStructName = nameof(SerializerStateWorder.SetStruct); - } -} diff --git a/capnpc-csharp/Generator/SkeletonWorder.cs b/capnpc-csharp/Generator/SkeletonWorder.cs deleted file mode 100644 index 0d34191..0000000 --- a/capnpc-csharp/Generator/SkeletonWorder.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace CapnpC.Generator -{ - class SkeletonWorder : Capnp.Rpc.Skeleton - { - public override ulong InterfaceId => throw new NotImplementedException(); - - public const string SetMethodTableName = nameof(SkeletonWorder.SetMethodTable); - public const string ImplName = nameof(SkeletonWorder.Impl); - } -} diff --git a/capnpc-csharp/Generator/SyntaxHelpers.cs b/capnpc-csharp/Generator/SyntaxHelpers.cs deleted file mode 100644 index 4d087ae..0000000 --- a/capnpc-csharp/Generator/SyntaxHelpers.cs +++ /dev/null @@ -1,128 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; - -namespace CapnpC.Generator -{ - static class SyntaxHelpers - { - public static string MakeCamel(string name) => $"{char.ToUpperInvariant(name[0])}{name.Substring(1)}"; - public static string MakeAllLower(string name) => $"@{name}"; - - public static readonly SyntaxToken Async = Token(SyntaxKind.AsyncKeyword); - public static readonly SyntaxToken Public = Token(SyntaxKind.PublicKeyword); - public static readonly SyntaxToken Private = Token(SyntaxKind.PrivateKeyword); - public static readonly SyntaxToken Readonly = Token(SyntaxKind.ReadOnlyKeyword); - public static readonly SyntaxToken Static = Token(SyntaxKind.StaticKeyword); - public static readonly SyntaxToken Override = Token(SyntaxKind.OverrideKeyword); - public static readonly SyntaxToken Partial = Token(SyntaxKind.PartialKeyword); - public static readonly SyntaxToken This = Token(SyntaxKind.ThisKeyword); - - public static TypeSyntax Type(Type type) - { - switch (0) - { - case 0 when type == typeof(bool): - return PredefinedType(Token(SyntaxKind.BoolKeyword)); - - case 0 when type == typeof(sbyte): - return PredefinedType(Token(SyntaxKind.SByteKeyword)); - - case 0 when type == typeof(byte): - return PredefinedType(Token(SyntaxKind.ByteKeyword)); - - case 0 when type == typeof(short): - return PredefinedType(Token(SyntaxKind.ShortKeyword)); - - case 0 when type == typeof(ushort): - return PredefinedType(Token(SyntaxKind.UShortKeyword)); - - case 0 when type == typeof(int): - return PredefinedType(Token(SyntaxKind.IntKeyword)); - - case 0 when type == typeof(uint): - return PredefinedType(Token(SyntaxKind.UIntKeyword)); - - case 0 when type == typeof(long): - return PredefinedType(Token(SyntaxKind.LongKeyword)); - - case 0 when type == typeof(ulong): - return PredefinedType(Token(SyntaxKind.ULongKeyword)); - - case 0 when type == typeof(float): - return PredefinedType(Token(SyntaxKind.FloatKeyword)); - - case 0 when type == typeof(double): - return PredefinedType(Token(SyntaxKind.DoubleKeyword)); - - case 0 when type == typeof(string): - return PredefinedType(Token(SyntaxKind.StringKeyword)); - - case 0 when type == typeof(object): - return PredefinedType(Token(SyntaxKind.ObjectKeyword)); - - case 0 when type.IsGenericType: - return GenericName(type.Name.Substring(0, type.Name.IndexOf('`'))) - .AddTypeArgumentListArguments(type.GetGenericArguments().Select(Type).ToArray()); - - default: - return ParseTypeName(type.Name); - } - } - - public static TypeSyntax Type() => Type(typeof(T)); - - public static ExpressionSyntax ValueOf(object value) - { - switch (value) - { - case bool x: - return LiteralExpression(x ? SyntaxKind.TrueLiteralExpression : SyntaxKind.FalseLiteralExpression); - - case sbyte x: - return CastExpression(Type(), LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x))); - - case byte x: - return CastExpression(Type(), LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x))); - - case short x: - return CastExpression(Type(), LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x))); - - case ushort x: - return CastExpression(Type(), LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x))); - - case int x: - return LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x)); - - case uint x: - return LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x)); - - case long x: - return LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x)); - - case ulong x: - return LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x)); - - case float x: - return LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x)); - - case double x: - return LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x)); - - case string x: - return LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(x)); - - case null: - return LiteralExpression(SyntaxKind.NullLiteralExpression); - - default: - throw new NotImplementedException(); - } - } - } -} diff --git a/capnpc-csharp/Generator/WriterSnippetGen.cs b/capnpc-csharp/Generator/WriterSnippetGen.cs deleted file mode 100644 index af62b09..0000000 --- a/capnpc-csharp/Generator/WriterSnippetGen.cs +++ /dev/null @@ -1,406 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using CapnpC.Model; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; -using static CapnpC.Generator.SyntaxHelpers; - -namespace CapnpC.Generator -{ - class WriterSnippetGen - { - readonly GenNames _names; - - public WriterSnippetGen(GenNames names) - { - _names = names; - } - - IEnumerable MakeWriterStructMembers(TypeDefinition structType) - { - yield return ConstructorDeclaration(_names.WriterStruct.Identifier) - .AddModifiers(Public) - .WithBody( - Block( - ExpressionStatement( - InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - ThisExpression(), - IdentifierName(SerializerStateWorder.SetStructName))) - .AddArgumentListArguments( - Argument( - LiteralExpression( - SyntaxKind.NumericLiteralExpression, - Literal(structType.StructDataWordCount))), - Argument( - LiteralExpression( - SyntaxKind.NumericLiteralExpression, - Literal(structType.StructPointerCount))))))); - } - - IEnumerable MakeGroupWriterStructMembers() - { - yield return ConstructorDeclaration(_names.WriterStruct.Identifier) - .AddModifiers(Public) - .WithBody(Block()); - } - - PropertyDeclarationSyntax MakeWriterProperty( - TypeSyntax type, - string name, - ExpressionSyntax getter, - ExpressionSyntax setter, - bool cast, - bool cond) - { - if (cast) - { - getter = CastExpression(type, getter); - } - - if (cond) - { - getter = ConditionalExpression( - BinaryExpression( - SyntaxKind.EqualsExpression, - _names.UnionDiscriminatorProp.IdentifierName, - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - _names.UnionDiscriminatorEnum.IdentifierName, - IdentifierName(name))), - getter, - LiteralExpression( - SyntaxKind.DefaultLiteralExpression, - Token(SyntaxKind.DefaultKeyword))); - } - - var accessors = new AccessorDeclarationSyntax[setter != null ? 2 : 1]; - - accessors[0] = AccessorDeclaration(SyntaxKind.GetAccessorDeclaration) - .WithExpressionBody(ArrowExpressionClause(getter)) - .WithSemicolonToken(Token(SyntaxKind.SemicolonToken)); - - if (setter != null) - { - accessors[1] = AccessorDeclaration(SyntaxKind.SetAccessorDeclaration) - .WithExpressionBody(ArrowExpressionClause(setter)) - .WithSemicolonToken(Token(SyntaxKind.SemicolonToken)); - } - - return PropertyDeclaration(type, name) - .AddModifiers(Public) - .AddAccessorListAccessors(accessors); - } - - ExpressionSyntax MakePointerSyntax(TypeSyntax type, object index) => - InvocationExpression( - GenericName(nameof(Capnp.SerializerState.BuildPointer)) - .AddTypeArgumentListArguments(type)) - .AddArgumentListArguments( - Argument(ValueOf(index))); - - ExpressionSyntax MakeReadCapSyntax(TypeSyntax type, object index) => - InvocationExpression( - GenericName(nameof(Capnp.SerializerState.ReadCap)) - .AddTypeArgumentListArguments(type)) - .AddArgumentListArguments( - Argument(ValueOf(index))); - - ExpressionSyntax MakeTypedPointerSyntax(object index, TypeSyntax type) => - InvocationExpression( - GenericName(nameof(Capnp.SerializerState.BuildPointer)) - .AddTypeArgumentListArguments(type)) - .AddArgumentListArguments( - Argument(ValueOf(index))); - - ExpressionSyntax MakeLinkSyntax(object index) => - InvocationExpression( - IdentifierName(SerializerStateWorder.LinkName)) - .AddArgumentListArguments( - Argument(ValueOf(index)), - Argument(IdentifierName("value"))); - - ExpressionSyntax MakeLinkObjectSyntax(object index) => - InvocationExpression( - IdentifierName(nameof(Capnp.SerializerState.LinkObject))) - .AddArgumentListArguments( - Argument(ValueOf(index)), - Argument(IdentifierName("value"))); - - PropertyDeclarationSyntax MakePointerProperty(TypeSyntax type, string name, object index, bool cast, bool cond) - { - ExpressionSyntax getter = MakePointerSyntax(type, index); - ExpressionSyntax setter = MakeLinkSyntax(index); - - return MakeWriterProperty(type, name, getter, setter, cast, cond); - } - - PropertyDeclarationSyntax MakePointerAsStructProperty( - TypeSyntax type, string name, object index, - bool cast, bool cond) - { - ExpressionSyntax getter = MakeTypedPointerSyntax(index, type); - ExpressionSyntax setter = MakeLinkSyntax(index); - - return MakeWriterProperty(type, name, getter, setter, cast, cond); - } - - PropertyDeclarationSyntax MakeProperty( - TypeSyntax outerType, - TypeSyntax innerType, - string name, - string readName, - string writeName, - object indexOrBitOffset, - ExpressionSyntax secondArg, - bool cast, - bool cond, - bool pasd) - { - var getter = InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - ThisExpression(), - IdentifierName(readName))) - .AddArgumentListArguments( - Argument(ValueOf(indexOrBitOffset)), - Argument(secondArg)); - - ExpressionSyntax value = IdentifierName("value"); - - if (cast) - { - value = CastExpression(innerType, value); - } - - var setter = InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - ThisExpression(), - IdentifierName(writeName))) - .AddArgumentListArguments( - Argument(ValueOf(indexOrBitOffset)), - Argument(value), - Argument(secondArg)); - - if (pasd) - { - setter.AddArgumentListArguments(Argument(secondArg)); - } - - return MakeWriterProperty(outerType, name, getter, setter, cast, cond); - } - - PropertyDeclarationSyntax MakePrimitiveProperty(Field field, string readName) - { - return MakeProperty(Type(), null, _names.GetCodeIdentifier(field).ToString(), - readName, - nameof(Capnp.SerializerExtensions.WriteData), - field.BitOffset.Value, - ValueOf(field.DefaultValue.ScalarValue), - false, - field.DiscValue.HasValue, - true); - } - - PropertyDeclarationSyntax MakeEnumProperty(Field field, string readName) - { - return MakeProperty(_names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.NotRelevant), Type(), - _names.GetCodeIdentifier(field).ToString(), - readName, - nameof(Capnp.SerializerExtensions.WriteData), - field.BitOffset.Value, - ValueOf(field.DefaultValue.ScalarValue), - true, - field.DiscValue.HasValue, - true); - } - - PropertyDeclarationSyntax MakeTextProperty(Field field) - { - return MakeProperty(Type(), null, - _names.GetCodeIdentifier(field).ToString(), - nameof(Capnp.SerializerState.ReadText), - nameof(Capnp.SerializerState.WriteText), - (int)field.Offset, - ValueOf(field.DefaultValue.ScalarValue), - false, - field.DiscValue.HasValue, - false); - } - - PropertyDeclarationSyntax MakeStructProperty(Field field) - { - var qtype = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Writer); - - return MakePointerAsStructProperty(qtype, _names.GetCodeIdentifier(field).ToString(), - (int)field.Offset, false, field.DiscValue.HasValue); - } - - PropertyDeclarationSyntax MakeGroupProperty(Field field) - { - var type = QualifiedName( - _names.MakeTypeName(field.Type.Definition).IdentifierName, - _names.WriterStruct.IdentifierName); - - var getter = InvocationExpression( - GenericName(nameof(Capnp.SerializerState.Rewrap)) - .AddTypeArgumentListArguments(type)); - - return MakeWriterProperty(type, _names.GetCodeIdentifier(field).ToString(), getter, null, false, field.DiscValue.HasValue); - } - - PropertyDeclarationSyntax MakeListProperty(Field field) - { - var qtype = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Writer); - - return MakePointerProperty(qtype, _names.GetCodeIdentifier(field).ToString(), - (int)field.Offset, false, field.DiscValue.HasValue); - } - - PropertyDeclarationSyntax MakePointerProperty(Field field) - { - var type = IdentifierName(nameof(Capnp.DynamicSerializerState)); - - return MakePointerProperty(type, _names.GetCodeIdentifier(field).ToString(), (int)field.Offset, false, field.DiscValue.HasValue); - } - - PropertyDeclarationSyntax MakeCapProperty(Field field) - { - var type = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Writer); - int index = (int)field.Offset; - string name = _names.GetCodeIdentifier(field).ToString(); - ExpressionSyntax getter = MakeReadCapSyntax(type, index); - ExpressionSyntax setter = MakeLinkObjectSyntax(index); - - return MakeWriterProperty(type, name, getter, setter, false, field.DiscValue.HasValue); - } - - PropertyDeclarationSyntax MakeWriterUnionSelector(TypeDefinition def) - { - return MakeProperty( - _names.UnionDiscriminatorEnum.IdentifierName, - Type(), - _names.UnionDiscriminatorProp.ToString(), - nameof(Capnp.SerializerExtensions.ReadDataUShort), - nameof(Capnp.SerializerExtensions.WriteData), - def.UnionInfo.TagOffset, - ValueOf(default(ushort)), - true, false, true); - } - - PropertyDeclarationSyntax MakeWriterFieldProperty(Field field) - { - switch (field.Type.Tag) - { - case TypeTag.Bool: - return MakePrimitiveProperty(field, - nameof(Capnp.SerializerExtensions.ReadDataBool)); - - case TypeTag.S8: - return MakePrimitiveProperty(field, - nameof(Capnp.SerializerExtensions.ReadDataSByte)); - - case TypeTag.U8: - return MakePrimitiveProperty(field, - nameof(Capnp.SerializerExtensions.ReadDataByte)); - - case TypeTag.S16: - return MakePrimitiveProperty(field, - nameof(Capnp.SerializerExtensions.ReadDataShort)); - - case TypeTag.U16: - return MakePrimitiveProperty(field, - nameof(Capnp.SerializerExtensions.ReadDataUShort)); - - case TypeTag.S32: - return MakePrimitiveProperty(field, - nameof(Capnp.SerializerExtensions.ReadDataInt)); - - case TypeTag.U32: - return MakePrimitiveProperty(field, - nameof(Capnp.SerializerExtensions.ReadDataUInt)); - - case TypeTag.S64: - return MakePrimitiveProperty(field, - nameof(Capnp.SerializerExtensions.ReadDataLong)); - - case TypeTag.U64: - return MakePrimitiveProperty(field, - nameof(Capnp.SerializerExtensions.ReadDataULong)); - - case TypeTag.F32: - return MakePrimitiveProperty(field, - nameof(Capnp.SerializerExtensions.ReadDataFloat)); - - case TypeTag.F64: - return MakePrimitiveProperty(field, - nameof(Capnp.SerializerExtensions.ReadDataDouble)); - - case TypeTag.Enum: - return MakeEnumProperty(field, nameof(Capnp.SerializerExtensions.ReadDataUShort)); - - case TypeTag.Text: - return MakeTextProperty(field); - - case TypeTag.Struct: - return MakeStructProperty(field); - - case TypeTag.Group: - return MakeGroupProperty(field); - - case TypeTag.List: - case TypeTag.Data: - return MakeListProperty(field); - - case TypeTag.AnyPointer: - case TypeTag.StructPointer: - case TypeTag.ListPointer: - return MakePointerProperty(field); - - case TypeTag.CapabilityPointer: - case TypeTag.Interface: - return MakeCapProperty(field); - - default: - return null; - } - } - - public ClassDeclarationSyntax MakeWriterStruct(TypeDefinition def) - { - var WriterDecl = ClassDeclaration(_names.WriterStruct.ToString()) - .AddModifiers(Public) - .AddBaseListTypes( - SimpleBaseType(IdentifierName(nameof(Capnp.SerializerState)))); - - var members = def.Tag == TypeTag.Group ? - MakeGroupWriterStructMembers() : - MakeWriterStructMembers(def); - - WriterDecl = WriterDecl.AddMembers(members.ToArray()); - - if (def.UnionInfo != null) - { - WriterDecl = WriterDecl.AddMembers(MakeWriterUnionSelector(def)); - } - - foreach (var field in def.Fields) - { - var propDecl = MakeWriterFieldProperty(field); - - if (propDecl != null) - { - WriterDecl = WriterDecl.AddMembers(propDecl); - } - } - - return WriterDecl; - } - } -} diff --git a/capnpc-csharp/Model/AbstractType.cs b/capnpc-csharp/Model/AbstractType.cs deleted file mode 100644 index 2c1451a..0000000 --- a/capnpc-csharp/Model/AbstractType.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System.Collections.Generic; - -namespace CapnpC.Model -{ - abstract class AbstractType - { - public TypeTag Tag { get; set; } - protected List Fields { get; } = new List(); - - public uint? FixedBitWidth - { - get - { - switch (Tag) - { - case TypeTag.Bool: - return 1; - - case TypeTag.U8: - case TypeTag.S8: - return 8; - - case TypeTag.U16: - case TypeTag.S16: - case TypeTag.Enum: - case TypeTag.AnyEnum: - return 16; - - case TypeTag.U32: - case TypeTag.S32: - case TypeTag.F32: - return 32; - - case TypeTag.U64: - case TypeTag.S64: - case TypeTag.F64: - return 64; - - default: - return null; - } - } - } - } -} diff --git a/capnpc-csharp/Model/Annotation.cs b/capnpc-csharp/Model/Annotation.cs deleted file mode 100644 index 36191b6..0000000 --- a/capnpc-csharp/Model/Annotation.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Diagnostics; - -namespace CapnpC.Model -{ - class Annotation : IDefinition - { - public ulong Id { get; } - public bool IsGenerated { get; } - public TypeTag Tag { get => TypeTag.Annotation; } - public IHasNestedDefinitions DeclaringElement { get; } - - public Type Type { get; set; } - - public Annotation(ulong id, IHasNestedDefinitions parent) - { - Trace.Assert(parent != null); - Id = id; - IsGenerated = (parent as IDefinition).IsGenerated; - DeclaringElement = parent; - parent.NestedDefinitions.Add(this); - } - } -} diff --git a/capnpc-csharp/Model/Constant.cs b/capnpc-csharp/Model/Constant.cs deleted file mode 100644 index 5879100..0000000 --- a/capnpc-csharp/Model/Constant.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Diagnostics; - -namespace CapnpC.Model -{ - class Constant : IDefinition - { - public ulong Id { get; } - public bool IsGenerated { get; } - public TypeTag Tag { get => TypeTag.Const; } - public IHasNestedDefinitions DeclaringElement { get; } - - public Value Value { get; set; } - - public Constant(ulong id, IHasNestedDefinitions parent) - { - Trace.Assert(parent != null); - Id = id; - IsGenerated = (parent as IDefinition).IsGenerated; - DeclaringElement = parent; - parent.NestedDefinitions.Add(this); - } - } -} diff --git a/capnpc-csharp/Model/DefinitionManager.cs b/capnpc-csharp/Model/DefinitionManager.cs deleted file mode 100644 index 95b9183..0000000 --- a/capnpc-csharp/Model/DefinitionManager.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -namespace CapnpC.Model -{ - class DefinitionManager - { - readonly Dictionary _id2def = new Dictionary(); - - public GenFile CreateFile(ulong id, bool isGenerated) - => CreateId(id, () => new GenFile(id, isGenerated)); - public GenFile GetExistingFile(ulong id) - => GetId(id, TypeTag.File); - - public TypeDefinition CreateTypeDef(ulong id, TypeTag tag, IHasNestedDefinitions decl) - => CreateId(id, () => new TypeDefinition(tag, id, decl)); - public TypeDefinition GetExistingTypeDef(ulong id, TypeTag tag) - { - var def = GetId(id, tag); - if (def.Tag == TypeTag.Unknown) def.Tag = tag; - return def; - } - - public Annotation CreateAnnotation(ulong id, IHasNestedDefinitions decl) - => CreateId(id, () => new Annotation(id, decl)); - public Annotation GetExistingAnnotation(ulong id) - => GetId(id, TypeTag.Annotation); - - public Constant CreateConstant(ulong id, IHasNestedDefinitions decl) - => CreateId(id, () => new Constant(id, decl)); - public Constant GetExistingConstant(ulong id) - => GetId(id, TypeTag.Const); - - public IDefinition GetExistingDef(ulong id, TypeTag tag) - => GetId(id, tag); - - public IEnumerable Files - { - get => _id2def.Values.Where(d => d.Tag == TypeTag.File).Select(f => f as GenFile); - } - - T CreateId(ulong id, Func creator) where T : class, IDefinition - { - if (_id2def.TryGetValue(id, out var d)) - { - throw new ArgumentException(nameof(id), $"Attempting to redefine {d.Tag.ToString()} {id.StrId()} (as {nameof(T)})."); - } - var def = creator(); - _id2def.Add(id, def); - return def as T; - } - - T GetId(ulong id, TypeTag tag) where T : IDefinition - { - if (!_id2def.TryGetValue(id, out var anyDef)) - { - throw new ArgumentOutOfRangeException($"Attempting to retrieve nonexistent node {id.StrId()}."); - } - if (!(anyDef is T def) || (tag != TypeTag.Unknown && def.Tag != tag)) - { - throw new ArgumentOutOfRangeException($"Attempting to retrieve {tag.ToString()} {id.StrId()}, but found {anyDef.Tag.ToString()} instead."); - } - return def; - } - } -} diff --git a/capnpc-csharp/Model/Enumerant.cs b/capnpc-csharp/Model/Enumerant.cs deleted file mode 100644 index 96d9137..0000000 --- a/capnpc-csharp/Model/Enumerant.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace CapnpC.Model -{ - class Enumerant - { - string _literal; - public TypeDefinition TypeDefinition { get; set; } - public string Literal { - get => _literal; - set => _literal = IdentifierRenamer.ToNonKeyword(value); - } - public ushort? Ordinal { get; set; } - public int CodeOrder { get; set; } - } -} diff --git a/capnpc-csharp/Model/Field.cs b/capnpc-csharp/Model/Field.cs deleted file mode 100644 index eee384b..0000000 --- a/capnpc-csharp/Model/Field.cs +++ /dev/null @@ -1,52 +0,0 @@ -namespace CapnpC.Model -{ - class Field - { - public TypeDefinition DeclaringType { get; set; } - public Field Parent { get; set; } - public string Name { get; set; } - public Type Type { get; set; } - public Value DefaultValue { get; set; } - public bool DefaultValueIsExplicit { get; set; } - public ushort? DiscValue { get; set; } - public uint Offset { get; set; } - public int CodeOrder { get; set; } - - public ulong? BitOffset => (ulong)Offset * Type?.FixedBitWidth; - - public Field Clone() - { - var field = new Field() - { - DeclaringType = DeclaringType, - Parent = Parent, - Name = Name, - Type = Type, - DefaultValue = DefaultValue, - DefaultValueIsExplicit = DefaultValueIsExplicit, - DiscValue = DiscValue, - Offset = Offset, - CodeOrder = CodeOrder, - }; - field.InheritFreeGenericParameters(); - return field; - } - - public void InheritFreeGenericParameters() - { - Type.InheritFreeParameters(DeclaringType); - } - - public override bool Equals(object obj) - { - return obj is Field other && - DeclaringType == other.DeclaringType && - Name == other.Name; - } - - public override int GetHashCode() - { - return (DeclaringType, Name).GetHashCode(); - } - } -} diff --git a/capnpc-csharp/Model/GenFile.cs b/capnpc-csharp/Model/GenFile.cs deleted file mode 100644 index f889fce..0000000 --- a/capnpc-csharp/Model/GenFile.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System.Collections.Generic; - -namespace CapnpC.Model -{ - class GenFile: IDefinition, IHasNestedDefinitions - { - public ulong Id { get; } - public bool IsGenerated { get; } - public TypeTag Tag { get => TypeTag.File; } - public IHasNestedDefinitions DeclaringElement { get => null; } - - public string Name { get; set; } - public string[] Namespace { get; set; } - - public IEnumerable NestedTypes { get => this.GetNestedTypes(); } - public ICollection NestedDefinitions { get; } = new List(); - public ICollection Constants { get; } = new List(); - - public GenFile(ulong id, bool isGenerated) - { - Id = id; - IsGenerated = isGenerated; - } - } -} diff --git a/capnpc-csharp/Model/GenericParameter.cs b/capnpc-csharp/Model/GenericParameter.cs deleted file mode 100644 index 8526b0d..0000000 --- a/capnpc-csharp/Model/GenericParameter.cs +++ /dev/null @@ -1,26 +0,0 @@ -namespace CapnpC.Model -{ - class GenericParameter - { - public IHasGenericParameters DeclaringEntity { get; set; } - public int Index { get; set; } - public string Name => DeclaringEntity.GenericParameters[Index]; - - public override bool Equals(object obj) - { - // Instead of equality by Name, we could instead take (DeclaringEntity, Index), but there is a caveat: - // Since methods can also own generic parameters, we have different classes of declaring entities involved. - // Both the method will define generic parameters, and the Cap'n'p-generated params/result structs. - // Therefore we end in two GenericParameter instances, one with the Method as declaring entity, the - // other one with the params/result type definition as declaring entity. They are semantically the same, - // and the easy way to match them is by Name. Equality by Name is the only working choice, even though - // it feels a little less reboust than by matching declaring entity + parameter position. - return obj is GenericParameter other && Name == other.Name; - } - - public override int GetHashCode() - { - return Name.GetHashCode(); - } - } -} diff --git a/capnpc-csharp/Model/HasGenericParameters.cs b/capnpc-csharp/Model/HasGenericParameters.cs deleted file mode 100644 index 6636ff4..0000000 --- a/capnpc-csharp/Model/HasGenericParameters.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Collections.Generic; -namespace CapnpC.Model -{ - static class HasGenericParameters - { - public static IEnumerable GetLocalTypeParameters(this IHasGenericParameters me) - { - for (int i = 0; i < me.GenericParameters.Count; i++) - { - yield return new GenericParameter() - { - DeclaringEntity = me, - Index = i - }; - } - } - } -} diff --git a/capnpc-csharp/Model/IDefinition.cs b/capnpc-csharp/Model/IDefinition.cs deleted file mode 100644 index 9bd8572..0000000 --- a/capnpc-csharp/Model/IDefinition.cs +++ /dev/null @@ -1,11 +0,0 @@ - -namespace CapnpC.Model -{ - interface IDefinition - { - ulong Id { get; } - bool IsGenerated { get; } - TypeTag Tag { get; } - IHasNestedDefinitions DeclaringElement { get; } - } -} diff --git a/capnpc-csharp/Model/IHasGenericParameters.cs b/capnpc-csharp/Model/IHasGenericParameters.cs deleted file mode 100644 index 5b9ce58..0000000 --- a/capnpc-csharp/Model/IHasGenericParameters.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Collections.Generic; - -namespace CapnpC.Model -{ - interface IHasGenericParameters - { - List GenericParameters { get; } - } -} diff --git a/capnpc-csharp/Model/IHasNestedDefinitions.cs b/capnpc-csharp/Model/IHasNestedDefinitions.cs deleted file mode 100644 index 3885c60..0000000 --- a/capnpc-csharp/Model/IHasNestedDefinitions.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Collections.Generic; -using System.Linq; - -namespace CapnpC.Model -{ - interface IHasNestedDefinitions - { - IEnumerable NestedTypes { get; } - ICollection NestedDefinitions { get; } - ICollection Constants { get; } - } - - static partial class Extensions - { - public static IEnumerable GetNestedTypes(this IHasNestedDefinitions def) - => def.NestedDefinitions.Select(d => d as TypeDefinition).Where(d => d != null); - } -} diff --git a/capnpc-csharp/Model/IdentifierRenamer.cs b/capnpc-csharp/Model/IdentifierRenamer.cs deleted file mode 100644 index 9c6ff07..0000000 --- a/capnpc-csharp/Model/IdentifierRenamer.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Microsoft.CodeAnalysis.CSharp; -using System; -using System.Collections.Generic; -using System.Text; - -namespace CapnpC.Model -{ - public class IdentifierRenamer - { - public static bool IsAnyKeyword(string str) - { - return SyntaxFacts.GetKeywordKind(str) != SyntaxKind.None - || SyntaxFacts.GetContextualKeywordKind(str) != SyntaxKind.None; - } - public static string ToNonKeyword(string str) - { - // Capnp schema identifiers should be already valid, but could be a keyword - if (IsAnyKeyword(str)) return $"@{str}"; - return str; - } - } -} diff --git a/capnpc-csharp/Model/InvalidSchemaException.cs b/capnpc-csharp/Model/InvalidSchemaException.cs deleted file mode 100644 index 4732ca8..0000000 --- a/capnpc-csharp/Model/InvalidSchemaException.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; - -namespace CapnpC.Model -{ - class InvalidSchemaException : Exception - { - public InvalidSchemaException(string message) : base(message) - { - } - } -} diff --git a/capnpc-csharp/Model/Method.cs b/capnpc-csharp/Model/Method.cs deleted file mode 100644 index e263f89..0000000 --- a/capnpc-csharp/Model/Method.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Collections.Generic; - -namespace CapnpC.Model -{ - class Method: IHasGenericParameters - { - public TypeDefinition DeclaringInterface { get; set; } - public int Id { get; set; } - public string Name { get; set; } - public List Params { get; } = new List(); - public List Results { get; } = new List(); - public Type ParamsStruct { get; set; } - public Type ResultStruct { get; set; } - public List GenericParameters { get; } = new List(); - } -} diff --git a/capnpc-csharp/Model/SchemaModel.cs b/capnpc-csharp/Model/SchemaModel.cs deleted file mode 100644 index bd758c6..0000000 --- a/capnpc-csharp/Model/SchemaModel.cs +++ /dev/null @@ -1,783 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; - -namespace CapnpC.Model -{ - class SchemaModel - { - readonly Schema.CodeGeneratorRequest.Reader _request; - readonly List _generatedFiles = new List(); - readonly DefinitionManager _typeDefMgr = new DefinitionManager(); - - readonly Dictionary _id2node = new Dictionary(); - - public SchemaModel(Schema.CodeGeneratorRequest.Reader request) - { - _request = request; - } - - public IReadOnlyList FilesToGenerate => _generatedFiles; - - Schema.Node.Reader? IdToNode(ulong id, bool mustExist) - { - if (_id2node.TryGetValue(id, out var node)) - return node; - if (mustExist) - throw new InvalidSchemaException($"Node with ID {id.StrId()} is required by the codegen backend but is missing."); - return null; - } - - Schema.Node.Reader IdToNode(ulong id) - { - return (Schema.Node.Reader)IdToNode(id, true); - } - - void Build() - { - if (_request.Nodes == null || _request.Nodes.Count == 0) - { - throw new InvalidSchemaException("No nodes, nothing to generate"); - } - - foreach (var node in _request.Nodes) - { - if (_id2node.TryGetValue(node.Id, out var existingNode)) - { - throw new InvalidSchemaException($"Node {node.StrId()} \"{node.DisplayName}\" has a duplicate ID, prior node was \"{existingNode.DisplayName}\""); - } - _id2node[node.Id] = node; - } - - var requestedFiles = _request.RequestedFiles.ToDictionary(req => req.Id); - BuildPass1(requestedFiles); - BuildPass2(requestedFiles); - } - - // First pass: create type definitions for each node. - - struct Pass1State - { - public HashSet unprocessedNodes; - public IHasNestedDefinitions parent; - } - - void BuildPass1(Dictionary requestedFiles) - { - Pass1State state = new Pass1State() - { - unprocessedNodes = new HashSet(_id2node.Keys) - }; - foreach (var node in _id2node.Values.Where(n => n.IsFile)) - { - GenFile file; - bool isGenerated = requestedFiles.TryGetValue(node.Id, out var req); - var filename = isGenerated ? req.Filename : node.DisplayName; - file = ProcessFilePass1(node.Id, filename, state, isGenerated); - if (isGenerated) - _generatedFiles.Add(file); - } - if (state.unprocessedNodes.Count != 0) - { - throw new InvalidSchemaException("Unreferenced nodes were present in the schema."); - } - } - - GenFile ProcessFilePass1(ulong id, string name, Pass1State state, bool isGenerated) - { - var file = _typeDefMgr.CreateFile(id, isGenerated); - var node = IdToNode(id); - state.parent = null; - file.Namespace = GetNamespaceAnnotation(node); - file.Name = name; - return ProcessNodePass1(id, name, state) as GenFile; - } - - IDefinition ProcessNodePass1(ulong id, string name, Pass1State state) - { - bool mustExist = state.parent == null || (state.parent as IDefinition).IsGenerated; - if (!(IdToNode(id, mustExist) is Schema.Node.Reader node)) - return null; - if (!state.unprocessedNodes.Remove(id)) - return null; - - IDefinition def = null; - bool processNestedNodes = false; - bool processFields = false; - bool processInterfaceMethods = false; - - switch (node.GetKind()) - { - case NodeKind.Annotation: - return _typeDefMgr.CreateAnnotation(id, state.parent); - case NodeKind.Const: - return _typeDefMgr.CreateConstant(id, state.parent); - case NodeKind.File: - if (state.parent != null) - throw new InvalidSchemaException($"Did not expect a file node {node.StrId()} to be a nested node."); - var file = _typeDefMgr.GetExistingFile(id); - file.Namespace = GetNamespaceAnnotation(node); - file.Name = name; - state.parent = file; - def = file; - processNestedNodes = true; - break; - case NodeKind.Enum: - break; - case NodeKind.Interface: - processNestedNodes = true; - processFields = true; - processInterfaceMethods = true; - break; - case NodeKind.Struct: - case NodeKind.Group: - processNestedNodes = true; - processFields = true; - break; - default: - throw new InvalidSchemaException($"Don't know how to process node {node.StrId()} \"{node.DisplayName}\""); - } - - if (def == null) - { - Trace.Assert(state.parent != null, $"The {node.GetTypeTag().ToString()} node {node.StrId()} was expected to have a parent."); - var typeDef = _typeDefMgr.CreateTypeDef(id, node.GetTypeTag(), state.parent); - typeDef.Name = name; - state.parent = typeDef; - def = typeDef; - } - - if (processNestedNodes && node.NestedNodes != null) - foreach (var nested in node.NestedNodes) - { - ProcessNodePass1(nested.Id, nested.Name, state); - } - if (processFields && node.Fields != null) - foreach (var field in node.Fields.Where(f => f.IsGroup)) - { - var group = IdToNode(field.Group_TypeId); - if (!group.IsStruct || !group.Struct_IsGroup) - { - throw new InvalidSchemaException($"Expected node with id {group.StrId()} to be a struct definition"); - } - ProcessNodePass1(field.Group_TypeId, field.Name, state); - } - if (processInterfaceMethods && node.Interface_Methods != null) - foreach (var method in node.Interface_Methods) - { - var pnode = IdToNode(method.ParamStructType); - if (pnode.ScopeId == 0) ProcessNodePass1(pnode.Id, null, state); // Anonymous generated type - pnode = IdToNode(method.ResultStructType); - if (pnode.ScopeId == 0) ProcessNodePass1(pnode.Id, null, state); // Anonymous generated type - } - return def; - } - - string[] GetNamespaceAnnotation(Schema.Node.Reader fileNode) - { - foreach (var annotation in fileNode.Annotations) - { - if (annotation.Id == 0xb9c6f99ebf805f2c) // Cxx namespace - { - return annotation.Value.Text.Split(new string[1] { "::" }, default); - } - } - return null; - } - - // 2nd pass: Generate types based on definitions - - struct Pass2State - { - public Method currentMethod; - public HashSet processedNodes; - } - - void BuildPass2(Dictionary requestedFiles) - { - var state = new Pass2State() { processedNodes = new HashSet() }; - foreach (var file in _typeDefMgr.Files) - { - var node = IdToNode(file.Id); - ProcessNestedNodes(node.NestedNodes, state, file.IsGenerated); - } - } - - void ProcessNestedNodes(IEnumerable nestedNodes, Pass2State state, bool mustExist) - { - foreach (var nestedNode in nestedNodes) - { - ProcessNode(nestedNode.Id, state, mustExist); - } - } - - void ProcessBrand(Schema.Brand.Reader brandReader, Type type, Pass2State state) - { - foreach (var scopeReader in brandReader.Scopes) - { - var whatToBind = ProcessTypeDef(scopeReader.ScopeId, state); - int index = 0; - - switch (0) - { - case 0 when scopeReader.IsBind: - foreach (var bindingReader in scopeReader.Bind) - { - var typeParameter = new GenericParameter() - { - DeclaringEntity = whatToBind, - Index = index++ - }; - - switch (0) - { - case 0 when bindingReader.IsType: - type.BindGenericParameter(typeParameter, ProcessType(bindingReader.Type, state)); - break; - - case 0 when bindingReader.IsUnbound: - type.BindGenericParameter(typeParameter, Types.FromParameter(typeParameter)); - break; - } - } - break; - - case 0 when scopeReader.IsInherit: - for (index = 0; index < type.DeclaringType.Definition.GenericParameters.Count; index++) - { - var typeParameter = new GenericParameter() - { - DeclaringEntity = whatToBind, - Index = index - }; - - type.BindGenericParameter(typeParameter, Types.FromParameter(typeParameter)); - } - break; - } - } - } - - Type ProcessType(Schema.Type.Reader typeReader, Pass2State state) - { - Type result; - - switch (0) - { - case 0 when typeReader.IsAnyPointer: - switch (0) - { - case 0 when typeReader.AnyPointer_IsParameter: - return Types.FromParameter( - new GenericParameter() - { - DeclaringEntity = ProcessTypeDef(typeReader.AnyPointer_Parameter_ScopeId, state), - Index = typeReader.AnyPointer_Parameter_ParameterIndex - }); - - case 0 when typeReader.AnyPointer_IsImplicitMethodParameter: - return Types.FromParameter( - new GenericParameter() - { - DeclaringEntity = state.currentMethod ?? throw new InvalidOperationException("current method not set"), - Index = typeReader.AnyPointer_ImplicitMethodParameter_ParameterIndex - }); - - case 0 when typeReader.AnyPointer_IsUnconstrained: - - switch (0) - { - case 0 when typeReader.AnyPointer_Unconstrained_IsAnyKind: - return Types.AnyPointer; - - case 0 when typeReader.AnyPointer_Unconstrained_IsCapability: - return Types.CapabilityPointer; - - case 0 when typeReader.AnyPointer_Unconstrained_IsList: - return Types.ListPointer; - - case 0 when typeReader.AnyPointer_Unconstrained_IsStruct: - return Types.StructPointer; - - default: - throw new NotImplementedException(); - } - - default: - throw new NotImplementedException(); - } - - case 0 when typeReader.IsBool: - return Types.Bool; - - case 0 when typeReader.IsData: - return Types.Data; - - case 0 when typeReader.IsFloat64: - return Types.F64; - - case 0 when typeReader.IsEnum: - return Types.FromDefinition(ProcessTypeDef(typeReader.Enum_TypeId, state, TypeTag.Enum)); - - case 0 when typeReader.IsFloat32: - return Types.F32; - - case 0 when typeReader.IsInt16: - return Types.S16; - - case 0 when typeReader.IsInt32: - return Types.S32; - - case 0 when typeReader.IsInt64: - return Types.S64; - - case 0 when typeReader.IsInt8: - return Types.S8; - - case 0 when typeReader.IsInterface: - result = Types.FromDefinition(ProcessTypeDef(typeReader.Interface_TypeId, state, TypeTag.Interface)); - ProcessBrand(typeReader.Interface_Brand, result, state); - return result; - - case 0 when typeReader.IsList: - return Types.List(ProcessType(typeReader.List_ElementType, state)); - - case 0 when typeReader.IsStruct: - result = Types.FromDefinition(ProcessTypeDef(typeReader.Struct_TypeId, state, TypeTag.Struct)); - ProcessBrand(typeReader.Struct_Brand, result, state); - return result; - - case 0 when typeReader.IsText: - return Types.Text; - - case 0 when typeReader.IsUInt16: - return Types.U16; - - case 0 when typeReader.IsUInt32: - return Types.U32; - - case 0 when typeReader.IsUInt64: - return Types.U64; - - case 0 when typeReader.IsUInt8: - return Types.U8; - - case 0 when typeReader.IsVoid: - return Types.Void; - - default: - throw new NotImplementedException(); - } - } - - Value ProcessValue(Schema.Value.Reader valueReader) - { - var value = new Value(); - - switch (0) - { - case 0 when valueReader.IsAnyPointer: - value.ScalarValue = valueReader.AnyPointer; - value.Type = Types.AnyPointer; - break; - - case 0 when valueReader.IsBool: - value.ScalarValue = valueReader.Bool; - value.Type = Types.Bool; - break; - - case 0 when valueReader.IsData: - value.Items.AddRange(valueReader.Data.CastByte().Select(Value.Scalar)); - value.Type = Types.Data; - break; - - case 0 when valueReader.IsEnum: - value.ScalarValue = valueReader.Enum; - value.Type = Types.AnyEnum; - break; - - case 0 when valueReader.IsFloat32: - value.ScalarValue = valueReader.Float32; - value.Type = Types.F32; - break; - - case 0 when valueReader.IsFloat64: - value.ScalarValue = valueReader.Float64; - value.Type = Types.F64; - break; - - case 0 when valueReader.IsInt16: - value.ScalarValue = valueReader.Int16; - value.Type = Types.S16; - break; - - case 0 when valueReader.IsInt32: - value.ScalarValue = valueReader.Int32; - value.Type = Types.S32; - break; - - case 0 when valueReader.IsInt64: - value.ScalarValue = valueReader.Int64; - value.Type = Types.S64; - break; - - case 0 when valueReader.IsInt8: - value.ScalarValue = valueReader.Int8; - value.Type = Types.S8; - break; - - case 0 when valueReader.IsInterface: - value.ScalarValue = null; - value.Type = Types.CapabilityPointer; - break; - - case 0 when valueReader.IsList: - value.RawValue = valueReader.List; - value.Type = Types.ListPointer; - break; - - case 0 when valueReader.IsStruct: - value.RawValue = valueReader.Struct; - value.Type = Types.StructPointer; - break; - - case 0 when valueReader.IsText: - value.ScalarValue = valueReader.Text; - value.Type = Types.Text; - break; - - case 0 when valueReader.IsUInt16: - value.ScalarValue = valueReader.UInt16; - value.Type = Types.U16; - break; - - case 0 when valueReader.IsUInt32: - value.ScalarValue = valueReader.UInt32; - value.Type = Types.U32; - break; - - case 0 when valueReader.IsUInt64: - value.ScalarValue = valueReader.UInt64; - value.Type = Types.U64; - break; - - case 0 when valueReader.IsUInt8: - value.ScalarValue = valueReader.UInt8; - value.Type = Types.U8; - break; - - case 0 when valueReader.IsVoid: - value.Type = Types.Void; - break; - - default: - throw new NotImplementedException(); - } - - return value; - } - - void ProcessFields(Schema.Node.Reader reader, TypeDefinition declaringType, List fields, Pass2State state) - { - if (reader.Fields == null) - { - return; - } - - foreach (var fieldReader in reader.Fields) - { - var field = new Field() - { - DeclaringType = declaringType, - Name = fieldReader.Name, - CodeOrder = fieldReader.CodeOrder - }; - - if (fieldReader.DiscriminantValue != Schema.Field.Reader.NoDiscriminant) - { - field.DiscValue = fieldReader.DiscriminantValue; - } - - switch (0) - { - case 0 when fieldReader.IsGroup: - var def = ProcessTypeDef(fieldReader.Group_TypeId, state, TypeTag.Group); - field.Type = Types.FromDefinition(def); - break; - - case 0 when fieldReader.IsSlot: - field.DefaultValue = ProcessValue(fieldReader.Slot_DefaultValue); - field.DefaultValueIsExplicit = fieldReader.Slot_HadExplicitDefault; - field.Offset = fieldReader.Slot_Offset; - field.Type = ProcessType(fieldReader.Slot_Type, state); - field.DefaultValue.Type = field.Type; - break; - - default: - throw new NotImplementedException(); - } - - field.InheritFreeGenericParameters(); - - fields.Add(field); - } - } - - TypeDefinition ProcessInterfaceOrStructTail(TypeDefinition def, Schema.Node.Reader reader, Pass2State state) - { - def.IsGeneric = reader.IsGeneric; - - if (def.IsGeneric) - { - foreach (var paramReader in reader.Parameters) - { - def.GenericParameters.Add(paramReader.Name); - } - } - - ProcessNestedNodes(reader.NestedNodes, state, def.File.IsGenerated); - - ProcessFields(reader, def, def.Fields, state); - - if (reader.IsInterface) - { - foreach (var methodReader in reader.Interface_Methods) - { - var method = new Method() - { - DeclaringInterface = def, - Id = def.Methods.Count, - Name = methodReader.Name - }; - foreach (var implicitParameterReader in methodReader.ImplicitParameters) - { - method.GenericParameters.Add(implicitParameterReader.Name); - } - state.currentMethod = method; - - def.Methods.Add(method); - - var paramNode = IdToNode(methodReader.ParamStructType); - var paramType = ProcessParameterList(paramNode, methodReader.ParamBrand, method.Params, state); - if (paramType != null) - { - paramType.SpecialName = SpecialName.MethodParamsStruct; - paramType.UsingMethod = method; - method.ParamsStruct = Types.FromDefinition(paramType); - } - else - { - method.ParamsStruct = method.Params[0].Type; - } - method.ParamsStruct.InheritFreeParameters(def); - method.ParamsStruct.InheritFreeParameters(method); - - var resultNode = IdToNode(methodReader.ResultStructType); - var resultType = ProcessParameterList(resultNode, methodReader.ResultBrand, method.Results, state); - if (resultType != null) - { - resultType.SpecialName = SpecialName.MethodResultStruct; - resultType.UsingMethod = method; - method.ResultStruct = Types.FromDefinition(resultType); - } - else - { - method.ResultStruct = method.Results[0].Type; - } - method.ResultStruct.InheritFreeParameters(def); - method.ResultStruct.InheritFreeParameters(method); - } - - state.currentMethod = null; - } - return def; - } - - TypeDefinition ProcessStruct(Schema.Node.Reader structReader, TypeDefinition def, Pass2State state) - { - def.StructDataWordCount = structReader.Struct_DataWordCount; - def.StructPointerCount = structReader.Struct_PointerCount; - - if (structReader.Struct_DiscriminantCount > 0) - { - def.UnionInfo = new TypeDefinition.DiscriminationInfo( - structReader.Struct_DiscriminantCount, - 16u * structReader.Struct_DiscriminantOffset); - } - - return ProcessInterfaceOrStructTail(def, structReader, state); - } - - TypeDefinition ProcessParameterList(Schema.Node.Reader reader, Schema.Brand.Reader brandReader, List list, Pass2State state) - { -//# If a named parameter list was specified in the method -//# declaration (rather than a single struct parameter type) then a corresponding struct type is -//# auto-generated. Such an auto-generated type will not be listed in the interface's -//# `nestedNodes` and its `scopeId` will be zero -- it is completely detached from the namespace. -//# (Awkwardly, it does of course inherit generic parameters from the method's scope, which makes -//# this a situation where you can't just climb the scope chain to find where a particular -//# generic parameter was introduced. Making the `scopeId` zero was a mistake.) - - if (!reader.IsStruct) - { - throw new InvalidSchemaException("Expected a struct"); - } - - var def = ProcessTypeDef(reader.Id, state, TypeTag.Struct); - - if (reader.ScopeId == 0) - { - // Auto-generated => Named parameter list - foreach (var field in def.Fields) list.Add(field); - return def; - } - else - { - // Single, anonymous, struct-typed parameter - var type = Types.FromDefinition(def); - ProcessBrand(brandReader, type, state); - var anon = new Field() { Type = type }; - list.Add(anon); - return null; - } - } - - TypeDefinition ProcessInterface(Schema.Node.Reader ifaceReader, TypeDefinition def, Pass2State state) - { - foreach (var superClassReader in ifaceReader.Interface_Superclasses) - { - var superClass = ProcessTypeDef(superClassReader.Id, state, TypeTag.Interface); - def.Superclasses.Add(Types.FromDefinition(superClass)); - } - - return ProcessInterfaceOrStructTail(def, ifaceReader, state); - } - - TypeDefinition ProcessEnum(Schema.Node.Reader enumReader, TypeDefinition def, Pass2State state) - { - foreach (var fieldReader in enumReader.Enumerants) - { - var field = new Enumerant() - { - TypeDefinition = def, - Literal = fieldReader.Name, - CodeOrder = fieldReader.CodeOrder - }; - - if (fieldReader.Ordinal_IsExplicit) - { - field.Ordinal = fieldReader.Ordinal_Explicit; - } - - def.Enumerants.Add(field); - } - return def; - } - - Constant ProcessConst(Schema.Node.Reader constReader, Constant @const, Pass2State state) - { - var value = ProcessValue(constReader.Const_Value); - value.Type = ProcessType(constReader.Const_Type, state); - @const.Value = value; - return @const; - } - - TypeDefinition ProcessTypeDef(ulong id, Pass2State state, TypeTag tag = default) - { - var def = ProcessNode(id, state, true, tag); - var typeDef = def as TypeDefinition; - if (typeDef == null) - throw new ArgumentException( - $"Expected node {id.StrId()} to be a TypeDefinition but got {def.GetType().Name} instead.", - nameof(id)); - return typeDef; - } - - IDefinition ProcessNode(ulong id, Pass2State state, bool mustExist, TypeTag tag = default) - { - if (!(IdToNode(id, mustExist) is Schema.Node.Reader node)) return null; - var kind = node.GetKind(); - if (tag == TypeTag.Unknown) tag = kind.GetTypeTag(); - var def = _typeDefMgr.GetExistingDef(id, tag); - if (state.processedNodes.Contains(id)) return def; - state.processedNodes.Add(id); - - switch (def) - { - case Annotation annotation: - return annotation; - case Constant constant: - def.DeclaringElement.Constants.Add(ProcessConst(node, constant, state)); - return def; - case TypeDefinition typeDef when kind == NodeKind.Enum: - return ProcessEnum(node, typeDef, state); - case TypeDefinition typeDef when kind == NodeKind.Interface: - return ProcessInterface(node, typeDef, state); - case TypeDefinition typeDef when kind == NodeKind.Struct || kind == NodeKind.Group: - return ProcessStruct(node, typeDef, state); - default: - throw new InvalidProgramException($"An unexpected node {node.StrId()} was found during the 2nd schema model building pass."); - } - } - - public static SchemaModel Create(Schema.CodeGeneratorRequest.Reader request) - { - var model = new SchemaModel(request); - model.Build(); - return model; - } - } - - public enum NodeKind - { - Unknown, - Annotation, - Const, - Enum, - File, - Interface, - Struct, - Group - } - - public static class SchemaExtensions - { - public static string GetName(this Schema.Node.Reader node) - => node.DisplayName.Substring((int)node.DisplayNamePrefixLength); - - public static string StrId(this Schema.Node.Reader node) - => $"0x{node.Id:X}"; - - public static string StrId(this ulong nodeId) - => $"0x{nodeId:X}"; - - public static NodeKind GetKind(this Schema.Node.Reader node) - { - if (node.IsStruct) - return node.Struct_IsGroup ? NodeKind.Group : NodeKind.Struct; - if (node.IsInterface) return NodeKind.Interface; - if (node.IsEnum) return NodeKind.Enum; - if (node.IsConst) return NodeKind.Const; - if (node.IsAnnotation) return NodeKind.Annotation; - if (node.IsFile) return NodeKind.File; - return NodeKind.Unknown; - } - - internal static TypeTag GetTypeTag(this NodeKind kind) - { - switch (kind) - { - case NodeKind.Enum: return TypeTag.Enum; - case NodeKind.Interface: return TypeTag.Interface; - case NodeKind.Struct: return TypeTag.Struct; - case NodeKind.Group: return TypeTag.Group; - default: return TypeTag.Unknown; - } - } - - internal static TypeTag GetTypeTag(this Schema.Node.Reader node) - => node.GetKind().GetTypeTag(); - } -} diff --git a/capnpc-csharp/Model/SpecialName.cs b/capnpc-csharp/Model/SpecialName.cs deleted file mode 100644 index 89f546f..0000000 --- a/capnpc-csharp/Model/SpecialName.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace CapnpC.Model -{ - enum SpecialName - { - NothingSpecial, - MethodParamsStruct, - MethodResultStruct - } -} diff --git a/capnpc-csharp/Model/Type.cs b/capnpc-csharp/Model/Type.cs deleted file mode 100644 index 17f2736..0000000 --- a/capnpc-csharp/Model/Type.cs +++ /dev/null @@ -1,201 +0,0 @@ -using Capnp; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; - -namespace CapnpC.Model -{ - class Type: AbstractType - { - // Representation of a type expression in the schema language - - public TypeDefinition Definition { get; set; } - // The model for all nodes that are not file nodes - they define types - - public GenericParameter Parameter { get; set; } - // A reference to type parameter in this scope - - public Type ElementType { get; set; } - // The type of a list element, if this is a list. - - readonly Dictionary _parameterBindings = - new Dictionary(); - public Type(TypeTag tag) - { - Tag = tag; - } - - public bool IsValueType - { - get - { - switch (Tag) - { - case TypeTag.AnyPointer: - case TypeTag.CapabilityPointer: - case TypeTag.Data: - case TypeTag.Group: - case TypeTag.Interface: - case TypeTag.List when ElementType.Tag != TypeTag.Void: - case TypeTag.ListPointer: - case TypeTag.Struct: - case TypeTag.StructPointer: - case TypeTag.Text: - case TypeTag.Void: - return false; - - default: - return true; - } - } - } - - public void InheritFreeParameters(IHasGenericParameters declaringType) - { - while (declaringType != null) - { - foreach (var p in declaringType.GetLocalTypeParameters()) - { - if (!_parameterBindings.ContainsKey(p)) - { - _parameterBindings[p] = Types.FromParameter(p); - } - } - - declaringType = (declaringType as TypeDefinition)?.DeclaringElement as IHasGenericParameters; - } - } - - Type SubstituteGenerics(Type type) - { - if (type == null) - { - return null; - } - - if (type.Parameter != null) - { - if (_parameterBindings.TryGetValue(type.Parameter, out var boundType)) - { - return boundType; - } - else - { - return Types.AnyPointer; - } - } - - var stype = new Type(type.Tag) - { - Definition = type.Definition, - ElementType = SubstituteGenerics(type.ElementType) - }; - - foreach (var kvp in type._parameterBindings) - { - var p = kvp.Value.Parameter; - - if (p != null && _parameterBindings.TryGetValue(p, out var boundType)) - { - stype._parameterBindings[kvp.Key] = boundType; - } - else - { - stype._parameterBindings[kvp.Key] = kvp.Value; - } - } - - return stype; - } - - Field SubstituteGenerics(Field field) - { - var result = field.Clone(); - result.Type = SubstituteGenerics(result.Type); - return result; - } - - public new IReadOnlyList Fields => Definition.Fields.LazyListSelect(SubstituteGenerics); - - public Type DeclaringType - { - get - { - var parentDef = Definition?.DeclaringElement as TypeDefinition; - // FIXME: Will become more sophisticated as soon as generics are implemented - return parentDef != null ? Types.FromDefinition(parentDef) : null; - } - } - - public (int, Type) GetRank() - { - var cur = this; - int rank = 0; - - while (cur.Tag == TypeTag.List) - { - cur = cur.ElementType; - ++rank; - } - - return (rank, cur); - } - - public IEnumerable AllImplementedClasses - { - get - { - var stk = new Stack(); - stk.Push(this); - var set = new HashSet(); - while (stk.Count > 0) - { - var def = stk.Pop(); - - if (def == null) - { - break; - } - - if (set.Add(def)) - { - foreach (var super in def.Definition.Superclasses) - { - stk.Push(super); - } - } - } - return set; - } - } - - public Type ResolveGenericParameter(GenericParameter genericParameter) - { - if (_parameterBindings.TryGetValue(genericParameter, out var type)) - { - return type; - } - else - { - return Types.AnyPointer; - } - } - - public void BindGenericParameter(GenericParameter genericParameter, Type boundType) - { - _parameterBindings.Add(genericParameter, boundType); - } - - public override bool Equals(object obj) - { - return obj is Type other && Definition == other.Definition; - } - - public override int GetHashCode() - { - return Definition?.GetHashCode() ?? 0; - } - } -} diff --git a/capnpc-csharp/Model/TypeCategory.cs b/capnpc-csharp/Model/TypeCategory.cs deleted file mode 100644 index 3411ac1..0000000 --- a/capnpc-csharp/Model/TypeCategory.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace CapnpC.Model -{ - enum TypeCategory - { - Value, - Pointer - } -} diff --git a/capnpc-csharp/Model/TypeDefinition.cs b/capnpc-csharp/Model/TypeDefinition.cs deleted file mode 100644 index dcbe512..0000000 --- a/capnpc-csharp/Model/TypeDefinition.cs +++ /dev/null @@ -1,88 +0,0 @@ -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -namespace CapnpC.Model -{ - class TypeDefinition : AbstractType, IDefinition, IHasNestedDefinitions, IHasGenericParameters - { - public class DiscriminationInfo - { - public DiscriminationInfo(ushort numOptions, uint tagOffset) - { - NumOptions = numOptions; - TagOffset = tagOffset; - } - - public ushort NumOptions { get; } - public uint TagOffset { get; } - } - - public TypeDefinition(TypeTag tag, ulong id, IHasNestedDefinitions parent) - { - Trace.Assert(parent != null); - Tag = tag; - Id = id; - IsGenerated = (parent as IDefinition).IsGenerated; - DeclaringElement = parent; - if (tag == TypeTag.Group) - ((TypeDefinition)parent).NestedGroups.Add(this); - else - parent.NestedDefinitions.Add(this); - } - - public ulong Id { get; } - public bool IsGenerated { get; } - public IHasNestedDefinitions DeclaringElement { get; } - - public Method UsingMethod { get; set; } - public string Name { get; set; } - public SpecialName SpecialName { get; set; } - public DiscriminationInfo UnionInfo { get; set; } - public new List Fields => base.Fields; - public List Enumerants { get; } = new List(); - public ICollection NestedDefinitions { get; } = new List(); - public IEnumerable NestedTypes { get => this.GetNestedTypes(); } - public List NestedGroups { get; } = new List(); - public ICollection Constants { get; } = new List(); - public List Methods { get; } = new List(); - public List Superclasses { get; } = new List(); - public List GenericParameters { get; } = new List(); - public bool IsGeneric { get; set; } - public ushort StructDataWordCount { get; set; } - public ushort StructPointerCount { get; set; } - - public IEnumerable DefinitionHierarchy - { - get - { - IHasNestedDefinitions cur = this; - - while (cur is TypeDefinition def) - { - yield return def; - cur = def.DeclaringElement; - } - } - } - - public GenFile File - { - get - { - IHasNestedDefinitions cur = this; - while (cur is TypeDefinition def) cur = def.DeclaringElement; - return cur as GenFile; - } - } - - public IEnumerable AllTypeParameters - { - get - { - return from def in DefinitionHierarchy - from p in def.GetLocalTypeParameters() - select p; - } - } - } -} diff --git a/capnpc-csharp/Model/TypeTag.cs b/capnpc-csharp/Model/TypeTag.cs deleted file mode 100644 index 122b6d7..0000000 --- a/capnpc-csharp/Model/TypeTag.cs +++ /dev/null @@ -1,36 +0,0 @@ -namespace CapnpC.Model -{ - enum TypeTag - { - Unknown, - Void, - Bool, - S8, - U8, - S16, - U16, - S32, - U32, - S64, - U64, - F32, - F64, - List, - Data, - Text, - AnyPointer, - StructPointer, - ListPointer, - CapabilityPointer, - ParameterPointer, - ImplicitMethodParameterPointer, - Struct, - Group, - Interface, - Enum, - AnyEnum, - Const, - Annotation, - File - } -} diff --git a/capnpc-csharp/Model/Types.cs b/capnpc-csharp/Model/Types.cs deleted file mode 100644 index ee20603..0000000 --- a/capnpc-csharp/Model/Types.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; - -namespace CapnpC.Model -{ - static class Types - { - public static readonly Type Void = new Type(TypeTag.Void); - public static readonly Type Bool = new Type(TypeTag.Bool); - public static readonly Type S8 = new Type(TypeTag.S8); - public static readonly Type U8 = new Type(TypeTag.U8); - public static readonly Type S16 = new Type(TypeTag.S16); - public static readonly Type U16 = new Type(TypeTag.U16); - public static readonly Type S32 = new Type(TypeTag.S32); - public static readonly Type U32 = new Type(TypeTag.U32); - public static readonly Type S64 = new Type(TypeTag.S64); - public static readonly Type U64 = new Type(TypeTag.U64); - public static readonly Type F32 = new Type(TypeTag.F32); - public static readonly Type F64 = new Type(TypeTag.F64); - public static readonly Type AnyPointer = new Type(TypeTag.AnyPointer); - public static readonly Type StructPointer = new Type(TypeTag.StructPointer); - public static readonly Type ListPointer = new Type(TypeTag.ListPointer); - public static readonly Type CapabilityPointer = new Type(TypeTag.CapabilityPointer); - public static readonly Type Data = new Type(TypeTag.Data); - public static readonly Type Text = new Type(TypeTag.Text); - public static readonly Type AnyEnum = new Type(TypeTag.AnyEnum); - - public static Type List(Type elementType) - { - return new Type(TypeTag.List) - { - ElementType = elementType - }; - } - - public static Type FromDefinition(TypeDefinition def) - { - if (def.Tag == TypeTag.Unknown) - { - throw new InvalidOperationException("Oops, type definition is not yet valid, cannot create type"); - } - - return new Type(def.Tag) - { - Definition = def - }; - } - - public static Type FromParameter(GenericParameter genericParameter) - { - return new Type(TypeTag.AnyPointer) - { - Parameter = genericParameter - }; - } - } -} diff --git a/capnpc-csharp/Model/Value.cs b/capnpc-csharp/Model/Value.cs deleted file mode 100644 index 955e51a..0000000 --- a/capnpc-csharp/Model/Value.cs +++ /dev/null @@ -1,300 +0,0 @@ -using Capnp; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace CapnpC.Model -{ - class Value - { - public static Value Scalar(T scalar) - { - var value = new Value() - { - ScalarValue = scalar - }; - - if (typeof(T) == typeof(bool)) - value.Type = Types.Bool; - else if (typeof(T) == typeof(float)) - value.Type = Types.F32; - else if (typeof(T) == typeof(double)) - value.Type = Types.F64; - else if (typeof(T) == typeof(sbyte)) - value.Type = Types.S8; - else if (typeof(T) == typeof(byte)) - value.Type = Types.U8; - else if (typeof(T) == typeof(short)) - value.Type = Types.S16; - else if (typeof(T) == typeof(ushort)) - value.Type = Types.U16; - else if (typeof(T) == typeof(int)) - value.Type = Types.S32; - else if (typeof(T) == typeof(uint)) - value.Type = Types.U32; - else if (typeof(T) == typeof(long)) - value.Type = Types.S64; - else if (typeof(T) == typeof(ulong)) - value.Type = Types.U64; - else if (typeof(T) == typeof(string)) - value.Type = Types.Text; - else - throw new NotImplementedException(); - - return value; - } - - public Type Type { get; set; } - public object ScalarValue { get; set; } - public Capnp.DeserializerState RawValue { get; set; } - public List Items { get; } = new List(); - public int VoidListCount { get; set; } - public ushort DiscriminatorValue { get; private set; } - public List<(Field, Value)> Fields { get; } = new List<(Field, Value)>(); - - public Enumerant GetEnumerant() - { - if (Type.Tag != TypeTag.Enum) - throw new InvalidOperationException(); - - if (Type.Definition.Enumerants[0].Ordinal.HasValue) - return Type.Definition.Enumerants.Single(e => e.Ordinal == (ushort)ScalarValue); - else - return Type.Definition.Enumerants[(ushort)ScalarValue]; - } - - void DecodeStruct() - { - if (RawValue.Kind != Capnp.ObjectKind.Struct) - { - throw new NotSupportedException(); - } - - var def = Type.Definition; - - if (def.UnionInfo != null) - { - DiscriminatorValue = RawValue.ReadDataUShort(def.UnionInfo.TagOffset, ushort.MaxValue); - } - - foreach (var field in Type.Fields) - { - if (field.DiscValue.HasValue && field.DiscValue.Value != DiscriminatorValue) - continue; - - Value value = new Value() - { - Type = field.Type - }; - - switch (field.Type.Tag) - { - case TypeTag.AnyEnum: - value.ScalarValue = field.DefaultValue?.ScalarValue as ushort? ?? 0; - break; - - case TypeTag.AnyPointer: - value.RawValue = RawValue.StructReadPointer((int)field.Offset); - break; - - case TypeTag.Bool: - value.ScalarValue = RawValue.ReadDataBool(field.BitOffset.Value, (field.DefaultValue?.ScalarValue as bool?) ?? false); - break; - - case TypeTag.CapabilityPointer: - case TypeTag.Interface: - continue; - - case TypeTag.Data: - case TypeTag.Group: - case TypeTag.Struct: - case TypeTag.List: - case TypeTag.Text: - value.RawValue = RawValue.StructReadPointer((int)field.Offset); - value.Decode(); - break; - - case TypeTag.ListPointer: - case TypeTag.StructPointer: - value.RawValue = RawValue.StructReadPointer((int)field.Offset); - break; - - case TypeTag.Enum: - value.ScalarValue = field.DefaultValue?.ScalarValue as ushort? ?? ushort.MaxValue; - break; - - case TypeTag.F32: - value = Scalar(RawValue.ReadDataFloat(field.BitOffset.Value, (field.DefaultValue?.ScalarValue as float?) ?? 0.0f)); - break; - - case TypeTag.F64: - value = Scalar(RawValue.ReadDataDouble(field.BitOffset.Value, (field.DefaultValue?.ScalarValue as double?) ?? 0.0f)); - break; - - case TypeTag.S16: - value = Scalar(RawValue.ReadDataShort(field.BitOffset.Value, (field.DefaultValue?.ScalarValue as short?) ?? 0)); - break; - - case TypeTag.S32: - value = Scalar(RawValue.ReadDataInt(field.BitOffset.Value, (field.DefaultValue?.ScalarValue as int?) ?? 0)); - break; - - case TypeTag.S64: - value = Scalar(RawValue.ReadDataLong(field.BitOffset.Value, (field.DefaultValue?.ScalarValue as long?) ?? 0)); - break; - - case TypeTag.S8: - value = Scalar(RawValue.ReadDataSByte(field.BitOffset.Value, (field.DefaultValue?.ScalarValue as sbyte?) ?? 0)); - break; - - case TypeTag.U16: - value = Scalar(RawValue.ReadDataUShort(field.BitOffset.Value, (field.DefaultValue?.ScalarValue as ushort?) ?? 0)); - break; - - case TypeTag.U32: - value = Scalar(RawValue.ReadDataUInt(field.BitOffset.Value, (field.DefaultValue?.ScalarValue as uint?) ?? 0)); - break; - - case TypeTag.U64: - value = Scalar(RawValue.ReadDataULong(field.BitOffset.Value, (field.DefaultValue?.ScalarValue as ulong?) ?? 0)); - break; - - case TypeTag.U8: - value = Scalar(RawValue.ReadDataByte(field.BitOffset.Value, (field.DefaultValue?.ScalarValue as byte?) ?? 0)); - break; - - case TypeTag.Void: - continue; - - default: - throw new NotImplementedException(); - } - - Fields.Add((field, value)); - } - } - - void DecodeList() - { - switch (Type.Tag) - { - case TypeTag.Data: - Items.AddRange(RawValue.RequireList().CastByte().Select(Scalar)); - break; - - case TypeTag.List: - switch (Type.ElementType.Tag) - { - case TypeTag.AnyEnum: - case TypeTag.Enum: - Items.AddRange(RawValue.RequireList().CastUShort().Select(u => { - var v = Scalar(u); - v.Type = Type.ElementType; - return v; })); - break; - - case TypeTag.AnyPointer: - Items.AddRange(RawValue.RequireList().Cast(d => new Value() { Type = Type.ElementType, RawValue = d })); - break; - - case TypeTag.Bool: - Items.AddRange(RawValue.RequireList().CastBool().Select(Scalar)); - break; - - case TypeTag.Data: - case TypeTag.Group: - case TypeTag.Struct: - case TypeTag.List: - Items.AddRange(RawValue.RequireList().Cast(d => { - var v = new Value() { Type = Type.ElementType, RawValue = d }; - v.Decode(); - return v; - })); - break; - - case TypeTag.Text: - Items.AddRange(RawValue.RequireList().CastText2().Select(Scalar)); - break; - - case TypeTag.F32: - Items.AddRange(RawValue.RequireList().CastFloat().Select(Scalar)); - break; - - case TypeTag.F64: - Items.AddRange(RawValue.RequireList().CastDouble().Select(Scalar)); - break; - - case TypeTag.S8: - Items.AddRange(RawValue.RequireList().CastSByte().Select(Scalar)); - break; - - case TypeTag.S16: - Items.AddRange(RawValue.RequireList().CastShort().Select(Scalar)); - break; - - case TypeTag.S32: - Items.AddRange(RawValue.RequireList().CastInt().Select(Scalar)); - break; - - case TypeTag.S64: - Items.AddRange(RawValue.RequireList().CastLong().Select(Scalar)); - break; - - case TypeTag.Void: - VoidListCount = RawValue.RequireList().Count; - break; - - case TypeTag.U16: - Items.AddRange(RawValue.RequireList().CastUShort().Select(Scalar)); - break; - - case TypeTag.U32: - Items.AddRange(RawValue.RequireList().CastUInt().Select(Scalar)); - break; - - case TypeTag.U64: - Items.AddRange(RawValue.RequireList().CastULong().Select(Scalar)); - break; - - case TypeTag.U8: - Items.AddRange(RawValue.RequireList().CastByte().Select(Scalar)); - break; - - default: - throw new NotImplementedException(); - } - break; - - case TypeTag.ListPointer: - Items.AddRange(RawValue.RequireList().Cast(d => new Value() { Type = Type.ElementType, RawValue = d })); - break; - - case TypeTag.Text: - ScalarValue = RawValue.RequireList().CastText(); - break; - } - } - - public void Decode() - { - if (RawValue.Kind == ObjectKind.Nil) return; - - switch (Type.Tag) - { - case TypeTag.Group: - case TypeTag.Struct: - DecodeStruct(); - break; - - case TypeTag.List: - case TypeTag.ListPointer: - case TypeTag.Text: - case TypeTag.Data: - DecodeList(); - break; - } - - RawValue = default(Capnp.DeserializerState); - } - } -} diff --git a/capnpc-csharp/Program.cs b/capnpc-csharp/Program.cs index 3f71b4b..b8eccee 100644 --- a/capnpc-csharp/Program.cs +++ b/capnpc-csharp/Program.cs @@ -1,30 +1,14 @@ using Capnp; +using CapnpC.CSharp.Generator; using System; using System.IO; using System.Runtime.CompilerServices; - -[assembly: InternalsVisibleToAttribute("capnpc-csharp.tests")] +using System.Security; namespace CapnpC { internal class Program { - internal static void GenerateFromStream(Stream input) - { - WireFrame segments; - - using (input) - { - segments = Framing.ReadSegments(input); - } - - var dec = DeserializerState.CreateRoot(segments); - var reader = Schema.CodeGeneratorRequest.Reader.Create(dec); - var model = Model.SchemaModel.Create(reader); - var codeGen = new Generator.CodeGenerator(model, new Generator.GeneratorOptions()); - codeGen.Generate(); - } - static void Main(string[] args) { Stream input; @@ -41,13 +25,36 @@ namespace CapnpC input = Console.OpenStandardInput(); } - try + var result = CapnpCompilation.GenerateFromStream(input); + + if (result.IsSuccess) { - GenerateFromStream(input); + foreach (var generatedFile in result.GeneratedFiles) + { + if (generatedFile.IsSuccess) + { + string outputFile = generatedFile.CapnpFilePath + ".cs"; + + try + { + File.WriteAllText(outputFile, generatedFile.GeneratedContent); + } + catch (Exception exception) + { + Console.Error.WriteLine(exception.Message); + Environment.ExitCode = -1; + } + } + else + { + Console.Error.WriteLine($"Error generating {generatedFile.CapnpFilePath}: {generatedFile.Exception.Message}"); + Environment.ExitCode = -1; + } + } } - catch (Exception exception) + else { - Console.Error.WriteLine(exception.Message); + Console.Error.WriteLine(result.Exception.Message); Environment.ExitCode = -1; } } diff --git a/capnpc-csharp/Schema/SchemaSerialization.cs b/capnpc-csharp/Schema/SchemaSerialization.cs deleted file mode 100644 index a61281a..0000000 --- a/capnpc-csharp/Schema/SchemaSerialization.cs +++ /dev/null @@ -1,1577 +0,0 @@ -using Capnp; -using System; -using System.Collections.Generic; -using System.Text; - -namespace CapnpC.Schema -{ - namespace Superclass - { - public struct Reader - { - public DeserializerState State { get; } - - public Reader(DeserializerState ctx) - { - State = ctx; - } - - public static Reader Create(DeserializerState ctx) => new Reader(ctx); - - public ulong Id => State.ReadDataULong(0); - public Brand.Reader Brand => State.ReadStruct(0, Schema.Brand.Reader.Create); - } - - public class Writer: SerializerState - { - public Writer() - { - SetStruct(1, 1); - } - - public ulong Id - { - get => this.ReadDataULong(0); - set => this.WriteData(0, value); - } - - public Brand.Writer Brand - { - get => BuildPointer(0); - set => Link(0, value); - } - } - } - - namespace Method - { - public struct Reader - { - public DeserializerState State { get; } - - public Reader(DeserializerState ctx) - { - State = ctx; - } - - public static Reader Create(DeserializerState ctx) => new Reader(ctx); - - public string Name => State.ReadText(0); - public ushort CodeOrder => State.ReadDataUShort(0); - public IReadOnlyList ImplicitParameters => State.ReadListOfStructs(4, Node.Parameter.Reader.Create); - public ulong ParamStructType => State.ReadDataULong(64); - public Brand.Reader ParamBrand => State.ReadStruct(2, Brand.Reader.Create); - public ulong ResultStructType => State.ReadDataULong(128); - public Brand.Reader ResultBrand => State.ReadStruct(3, Brand.Reader.Create); - public IReadOnlyList Annotations => State.ReadListOfStructs(1, Annotation.Reader.Create); - } - - public class Writer: SerializerState - { - public Writer() - { - SetStruct(5, 3); - } - - public string Name - { - get => ReadText(0); - set => WriteText(0, value); - } - - public ushort CodeOrder - { - get => this.ReadDataUShort(0); - set => this.WriteData(0, value); - } - - public ListOfStructsSerializer ImplicitParameters - { - get => BuildPointer>(4); - set => Link(4, value); - } - - public ref ulong ParamStructType => ref this.RefData(8); - - public Brand.Writer ParamBrand - { - get => BuildPointer(2); - set => Link(2, value); - } - - public ulong ResultStructType - { - get => this.ReadDataULong(128); - set => this.WriteData(128, value); - } - - public Brand.Writer ResultBrand - { - get => BuildPointer(3); - set => Link(3, value); - } - - public ListOfStructsSerializer Annotations - { - get => BuildPointer>(1); - set => Link(1, value); - } - } - } - - namespace Type - { - public struct Reader - { - public DeserializerState State { get; } - - public Reader(DeserializerState ctx) - { - State = ctx; - } - - public static Reader Create(DeserializerState ctx) => new Reader(ctx); - - public ushort Tag => State.ReadDataUShort(0); - public bool IsVoid => Tag == 0; - public bool IsBool => Tag == 1; - public bool IsInt8 => Tag == 2; - public bool IsInt16 => Tag == 3; - public bool IsInt32 => Tag == 4; - public bool IsInt64 => Tag == 5; - public bool IsUInt8 => Tag == 6; - public bool IsUInt16 => Tag == 7; - public bool IsUInt32 => Tag == 8; - public bool IsUInt64 => Tag == 9; - public bool IsFloat32 => Tag == 10; - public bool IsFloat64 => Tag == 11; - public bool IsText => Tag == 12; - public bool IsData => Tag == 13; - public bool IsList => Tag == 14; - public Reader List_ElementType => IsList ? State.ReadStruct(0, Create) : default; - public bool IsEnum => Tag == 15; - public ulong Enum_TypeId => IsEnum ? State.ReadDataULong(64) : 0; - public Brand.Reader Enum_Brand => IsEnum ? State.ReadStruct(0, Brand.Reader.Create) : default; - public bool IsStruct => Tag == 16; - public ulong Struct_TypeId => IsStruct ? State.ReadDataULong(64) : 0; - public Brand.Reader Struct_Brand => IsStruct ? State.ReadStruct(0, Brand.Reader.Create) : default; - public bool IsInterface => Tag == 17; - public ulong Interface_TypeId => IsInterface ? State.ReadDataULong(64) : 0; - public Brand.Reader Interface_Brand => IsInterface ? State.ReadStruct(0, Brand.Reader.Create) : default; - public bool IsAnyPointer => Tag == 18; - public ushort AnyPointer_Tag => IsAnyPointer ? State.ReadDataUShort(64) : default; - public bool AnyPointer_IsUnconstrained => IsAnyPointer && AnyPointer_Tag == 0; - public ushort AnyPointer_Unconstrained_Tag => AnyPointer_IsUnconstrained ? State.ReadDataUShort(80) : (ushort)0; - public bool AnyPointer_Unconstrained_IsAnyKind => AnyPointer_IsUnconstrained && AnyPointer_Unconstrained_Tag == 0; - public bool AnyPointer_Unconstrained_IsStruct => AnyPointer_IsUnconstrained && AnyPointer_Unconstrained_Tag == 1; - public bool AnyPointer_Unconstrained_IsList => AnyPointer_IsUnconstrained && AnyPointer_Unconstrained_Tag == 2; - public bool AnyPointer_Unconstrained_IsCapability => AnyPointer_IsUnconstrained && AnyPointer_Unconstrained_Tag == 3; - public bool AnyPointer_IsParameter => IsAnyPointer && AnyPointer_Tag == 1; - public ulong AnyPointer_Parameter_ScopeId => AnyPointer_IsParameter ? State.ReadDataULong(128) : 0; - public ushort AnyPointer_Parameter_ParameterIndex => AnyPointer_IsParameter ? State.ReadDataUShort(80) : (ushort)0; - public bool AnyPointer_IsImplicitMethodParameter => AnyPointer_Tag == 2; - public ushort AnyPointer_ImplicitMethodParameter_ParameterIndex => AnyPointer_IsImplicitMethodParameter ? State.ReadDataUShort(80) : default; - } - - public class Writer: SerializerState - { - public Writer() - { - SetStruct(3, 1); - } - - public ref ushort Tag => ref this.RefData(0); - - public bool IsVoid - { - get => Tag == 0; - set => Tag = 0; - } - - public bool IsBool - { - get => Tag == 1; - set => Tag = 1; - } - - public bool IsInt8 - { - get => Tag == 2; - set => Tag = 2; - } - - public bool IsInt16 - { - get => Tag == 3; - set => Tag = 3; - } - - public bool IsInt32 - { - get => Tag == 4; - set => Tag = 4; - } - - public bool IsInt64 - { - get => Tag == 5; - set => Tag = 5; - } - - public bool IsUInt8 - { - get => Tag == 6; - set => Tag = 6; - } - - public bool IsUInt16 - { - get => Tag == 7; - set => Tag = 7; - } - - public bool IsUInt32 - { - get => Tag == 8; - set => Tag = 8; - } - - public bool IsUInt64 - { - get => Tag == 9; - set => Tag = 9; - } - - public bool IsFloat32 - { - get => Tag == 10; - set => Tag = 10; - } - - public bool IsFloat64 - { - get => Tag == 11; - set => Tag = 11; - } - - public bool IsText - { - get => Tag == 12; - set => Tag = 12; - } - - public bool IsData - { - get => Tag == 13; - set => Tag = 13; - } - - public bool IsList - { - get => Tag == 14; - set => Tag = 14; - } - - public Writer List_ElementType - { - get => IsList ? BuildPointer(0) : default; - set { Link(0, value); } - } - - public bool IsEnum - { - get => Tag == 15; - set => Tag = 15; - } - - public ulong Enum_TypeId - { - get => IsEnum ? this.ReadDataULong(64) : 0; - set { this.WriteData(64, value); } - } - - public Brand.Writer Enum_Brand - { - get => IsEnum ? BuildPointer(0) : default; - set => Link(0, value); - } - - public bool IsStruct - { - get => Tag == 16; - set => Tag = 16; - } - - public ulong Struct_TypeId - { - get => IsStruct ? this.ReadDataULong(64) : 0; - set => this.WriteData(64, value); - } - - public Brand.Writer Struct_Brand - { - get => IsStruct ? BuildPointer(0) : default; - set => Link(0, value); - } - - public bool IsInterface - { - get => Tag == 17; - set => Tag = 17; - } - - public ulong Interface_TypeId - { - get => IsStruct ? this.ReadDataULong(64) : 0; - set => this.WriteData(64, value); - } - - public Brand.Writer Interface_Brand - { - get => IsStruct ? BuildPointer(0) : default; - set => Link(0, value); - } - - public bool IsAnyPointer - { - get => Tag == 18; - set => Tag = 18; - } - - public ushort AnyPointer_Tag - { - get => IsAnyPointer ? this.ReadDataUShort(64) : default; - set => this.WriteData(64, value); - } - - public bool AnyPointer_IsUnconstrained - { - get => IsAnyPointer && AnyPointer_Tag == 0; - set => AnyPointer_Tag = 0; - } - - public ushort AnyPointer_Unconstrained_Tag - { - get => AnyPointer_IsUnconstrained ? this.ReadDataUShort(80) : (ushort)0; - set => this.WriteData(80, value); - } - - public bool AnyPointer_Unconstrained_IsAnyKind - { - get => AnyPointer_IsUnconstrained && AnyPointer_Unconstrained_Tag == 0; - set => AnyPointer_Unconstrained_Tag = 0; - } - - public bool AnyPointer_Unconstrained_IsStruct - { - get => AnyPointer_IsUnconstrained && AnyPointer_Unconstrained_Tag == 1; - set => AnyPointer_Unconstrained_Tag = 1; - } - - public bool AnyPointer_Unconstrained_IsList - { - get => AnyPointer_IsUnconstrained && AnyPointer_Unconstrained_Tag == 2; - set => AnyPointer_Unconstrained_Tag = 2; - } - - public bool AnyPointer_Unconstrained_IsCapability - { - get => AnyPointer_IsUnconstrained && AnyPointer_Unconstrained_Tag == 3; - set => AnyPointer_Unconstrained_Tag = 3; - } - - public bool AnyPointer_IsParameter - { - get => IsAnyPointer && AnyPointer_Tag == 1; - set => AnyPointer_Tag = 1; - } - - public ulong AnyPointer_Parameter_ScopeId - { - get => AnyPointer_IsParameter ? this.ReadDataULong(128) : 0; - set => this.WriteData(128, value); - } - - public ushort AnyPointer_Parameter_ParameterIndex - { - get => AnyPointer_IsParameter ? this.ReadDataUShort(80) : (ushort)0; - set => this.WriteData(80, value); - } - - public bool AnyPointer_IsImplicitMethodParameter - { - get => AnyPointer_Tag == 2; - set => AnyPointer_Tag = 2; - } - - public ushort AnyPointer_ImplicitMethodParameter_ParameterIndex - { - get => AnyPointer_IsImplicitMethodParameter ? this.ReadDataUShort(80) : default; - set => this.WriteData(80, value); - } - } - } - - namespace Brand - { - namespace Scope - { - public struct Reader - { - public DeserializerState State { get; } - - public Reader(DeserializerState ctx) - { - State = ctx; - } - - public static Reader Create(DeserializerState ctx) => new Reader(ctx); - - public ulong ScopeId => State.ReadDataULong(0); - public ushort Tag => State.ReadDataUShort(64); - public bool IsBind => Tag == 0; - public IReadOnlyList Bind => IsBind ? State.ReadListOfStructs(0, Binding.Reader.Create) : null; - public bool IsInherit => Tag == 1; - } - - public class Writer: SerializerState - { - public Writer() - { - SetStruct(2, 1); - } - - public ulong ScopeId - { - get => this.ReadDataULong(0); - set => this.WriteData(0, value); - } - - public ushort Tag - { - get => this.ReadDataUShort(64); - set => this.WriteData(64, value); - } - - public bool IsBind - { - get => Tag == 0; - set => Tag = 0; - } - - public ListOfStructsSerializer Bind - { - get => IsBind ? BuildPointer>(0) : default; - set => Link(0, value); - } - - public bool IsInherit - { - get => Tag == 1; - set => Tag = 1; - } - } - - namespace Binding - { - public struct Reader - { - public DeserializerState State { get; } - - public Reader(DeserializerState ctx) - { - State = ctx; - } - - public static Reader Create(DeserializerState ctx) => new Reader(ctx); - - public ushort Tag => State.ReadDataUShort(0); - public bool IsUnbound => Tag == 0; - public bool IsType => Tag == 1; - public Type.Reader Type => IsType ? State.ReadStruct(0, Schema.Type.Reader.Create) : default; - } - - public class Writer: SerializerState - { - public Writer() - { - SetStruct(1, 1); - } - - public ushort Tag - { - get => this.ReadDataUShort(0); - set => this.WriteData(0, value); - } - - public bool IsUnbound - { - get => Tag == 0; - set => Tag = 0; - } - - public bool IsType - { - get => Tag == 1; - set => Tag = 1; - } - - public Type.Writer Type - { - get => IsType ? BuildPointer(0) : default; - set => Link(0, value); - } - } - } - } - - public struct Reader - { - public DeserializerState State { get; } - - public Reader(DeserializerState ctx) - { - State = ctx; - } - - public static Reader Create(DeserializerState ctx) => new Reader(ctx); - - public IReadOnlyList Scopes => State.ReadListOfStructs(0, Scope.Reader.Create); - } - - public class Writer: SerializerState - { - public Writer() - { - SetStruct(0, 1); - } - - public ListOfStructsSerializer Scopes - { - get => BuildPointer>(0); - set => Link(0, value); - } - } - } - - namespace Value - { - public struct Reader - { - public DeserializerState State { get; } - - public Reader(DeserializerState ctx) - { - State = ctx; - } - - public static Reader Create(DeserializerState ctx) => new Reader(ctx); - - public ushort Tag => State.ReadDataUShort(0); - public bool IsVoid => Tag == 0; - public bool IsBool => Tag == 1; - public bool Bool => IsBool ? State.ReadDataBool(16) : default; - public bool IsInt8 => Tag == 2; - public sbyte Int8 => IsInt8 ? State.ReadDataSByte(16) : default; - public bool IsInt16 => Tag == 3; - public short Int16 => IsInt16 ? State.ReadDataShort(16) : default; - public bool IsInt32 => Tag == 4; - public int Int32 => IsInt32 ? State.ReadDataInt(32) : default; - public bool IsInt64 => Tag == 5; - public long Int64 => IsInt64 ? State.ReadDataLong(64) : default; - public bool IsUInt8 => Tag == 6; - public byte UInt8 => IsUInt8 ? State.ReadDataByte(16) : default; - public bool IsUInt16 => Tag == 7; - public ushort UInt16 => IsUInt16 ? State.ReadDataUShort(16) : default; - public bool IsUInt32 => Tag == 8; - public uint UInt32 => IsUInt32 ? State.ReadDataUInt(32) : default; - public bool IsUInt64 => Tag == 9; - public ulong UInt64 => IsUInt64 ? State.ReadDataULong(64) : default; - public bool IsFloat32 => Tag == 10; - public float Float32 => IsFloat32 ? State.ReadDataFloat(32) : default; - public bool IsFloat64 => Tag == 11; - public double Float64 => IsFloat64 ? State.ReadDataDouble(64) : default; - public bool IsText => Tag == 12; - public string Text => IsText ? State.ReadText(0) : default; - public bool IsData => Tag == 13; - public ListDeserializer Data => IsData ? State.ReadList(0) : default; - public bool IsList => Tag == 14; - public DeserializerState List => IsList ? State.StructReadPointer(0) : default; - public bool IsEnum => Tag == 15; - public ushort Enum => IsEnum ? State.ReadDataUShort(16) : default; - public bool IsStruct => Tag == 16; - public DeserializerState Struct => IsStruct ? State.StructReadPointer(0) : default; - public bool IsInterface => Tag == 17; - public bool IsAnyPointer => Tag == 18; - public DeserializerState AnyPointer => IsAnyPointer ? State.StructReadPointer(0) : default; - } - - public class Writer: SerializerState - { - public Writer() - { - SetStruct(2, 1); - } - - public ushort Tag - { - get => this.ReadDataUShort(0); - set => this.WriteData(0, value); - } - - public bool IsVoid - { - get => Tag == 0; - set => Tag = 0; - } - - public bool IsBool - { - get => Tag == 1; - set => Tag = 1; - } - - public bool Bool - { - get => IsBool ? this.ReadDataBool(16) : default; - set => this.WriteData(16, value); - } - - public bool IsInt8 - { - get => Tag == 2; - set => Tag = 2; - } - - public sbyte Int8 - { - get => IsInt8 ? this.ReadDataSByte(16) : default; - set => this.WriteData(16, value); - } - - public bool IsInt16 - { - get => Tag == 3; - set => Tag = 3; - } - - public short Int16 - { - get => IsInt16 ? this.ReadDataShort(16) : default; - set => this.WriteData(16, value); - } - - public bool IsInt32 - { - get => Tag == 4; - set => Tag = 4; - } - - public int Int32 - { - get => IsInt32 ? this.ReadDataInt(32) : default; - set => this.WriteData(32, value); - } - - public bool IsInt64 - { - get => Tag == 5; - set => Tag = 5; - } - - public long Int64 - { - get => IsInt64 ? this.ReadDataLong(64) : default; - set => this.WriteData(64, value); - } - - public bool IsUInt8 - { - get => Tag == 6; - set => Tag = 6; - } - - public byte UInt8 - { - get => IsUInt8 ? this.ReadDataByte(16) : default; - set => this.WriteData(16, value); - } - - public bool IsUInt16 - { - get => Tag == 7; - set => Tag = 7; - } - - public ushort UInt16 - { - get => IsUInt16 ? this.ReadDataUShort(16) : default; - set => this.WriteData(16, value); - } - - public bool IsUInt32 - { - get => Tag == 8; - set => Tag = 8; - } - - public uint UInt32 - { - get => IsUInt32 ? this.ReadDataUInt(32) : default; - set => this.WriteData(32, value); - } - - public bool IsUInt64 - { - get => Tag == 9; - set => Tag = 9; - } - - public ulong UInt64 - { - get => IsUInt64 ? this.ReadDataULong(64) : default; - set => this.WriteData(64, value); - } - - public bool IsFloat32 - { - get => Tag == 10; - set => Tag = 10; - } - - public float Float32 - { - get => IsFloat32 ? this.ReadDataFloat(32) : default; - set => this.WriteData(32, value); - } - - public bool IsFloat64 - { - get => Tag == 11; - set => Tag = 11; - } - - public double Float64 - { - get => IsFloat64 ? this.ReadDataDouble(64) : default; - set => this.WriteData(64, value); - } - - public bool IsText - { - get => Tag == 12; - set => Tag = 12; - } - - public string Text - { - get => IsText ? ReadText(0) : default; - set => WriteText(0, value); - } - - public bool IsData - { - get => Tag == 13; - set => Tag = 13; - } - - public SerializerState Data - { - get => IsData ? BuildPointer(0) : default; - set => Link(0, value); - } - - public bool IsList - { - get => Tag == 14; - set => Tag = 14; - } - - public SerializerState List - { - get => IsList ? BuildPointer(0) : default; - set => Link(0, value); - } - - public bool IsEnum - { - get => Tag == 15; - set => Tag = 15; - } - - public ushort Enum - { - get => IsEnum ? this.ReadDataUShort(16) : default; - set => this.WriteData(16, value); - } - - public bool IsStruct - { - get => Tag == 16; - set => Tag = 16; - } - - public SerializerState Struct - { - get => IsStruct ? BuildPointer(0) : default; - set => Link(0, value); - } - - public bool IsInterface - { - get => Tag == 17; - set => Tag = 17; - } - - public bool IsAnyPointer - { - get => Tag == 18; - set => Tag = 18; - } - - public SerializerState AnyPointer - { - get => IsAnyPointer ? BuildPointer(0) : default; - set => Link(0, value); - } - } - } - - namespace Annotation - { - public struct Reader - { - public DeserializerState State { get; } - - public Reader(DeserializerState ctx) - { - State = ctx; - } - - public static Reader Create(DeserializerState ctx) => new Reader(ctx); - - public ulong Id => State.ReadDataULong(0); - public Brand.Reader Brand => State.ReadStruct(1, Schema.Brand.Reader.Create); - public Value.Reader Value => State.ReadStruct(0, Schema.Value.Reader.Create); - } - - public class Writer: SerializerState - { - public Writer() - { - SetStruct(1, 2); - } - - public ref ulong Id => ref this.RefData(0); - - public Brand.Writer Brand - { - get => BuildPointer(1); - set => Link(1, value); - } - - public Value.Writer Value - { - get => BuildPointer(0); - set => Link(0, value); - } - } - } - - public enum ElementSize: ushort - { - Empty = 0, - Bit = 1, - Byte = 2, - TwoBytes = 3, - FourBytes = 4, - EightBytes = 5, - Pointer = 6, - InlineComposite = 7 - } - - namespace Field - { - public struct Reader - { - public DeserializerState State { get; } - - public Reader(DeserializerState ctx) - { - State = ctx; - } - - public static Reader Create(DeserializerState ctx) => new Reader(ctx); - - public string Name => State.ReadText(0); - public ushort CodeOrder => State.ReadDataUShort(0); - public IReadOnlyList Annotations => State.ReadListOfStructs(1, Annotation.Reader.Create); - public ushort DiscriminantValue => State.ReadDataUShort(16, 65535); - public ushort Tag => State.ReadDataUShort(64); - public bool IsSlot => Tag == 0; - public uint Slot_Offset => IsSlot ? State.ReadDataUInt(32) : default; - public Type.Reader Slot_Type => IsSlot ? State.ReadStruct(2, Type.Reader.Create) : default; - public Value.Reader Slot_DefaultValue => IsSlot ? State.ReadStruct(3, Value.Reader.Create) : default; - public bool Slot_HadExplicitDefault => IsSlot ? State.ReadDataBool(128) : default; - public bool IsGroup => Tag == 1; - public ulong Group_TypeId => IsGroup ? State.ReadDataULong(128) : default; - public ushort Ordinal_Tag => State.ReadDataUShort(80); - public bool Ordinal_IsImplicit => Ordinal_Tag == 0; - public bool Ordinal_IsExplicit => Ordinal_Tag == 1; - public ushort Ordinal_Explicit => Ordinal_IsExplicit ? State.ReadDataUShort(96) : default; - - public const ushort NoDiscriminant = 0xffff; - } - - public class Writer: SerializerState - { - public Writer() - { - SetStruct(3, 3); - } - - public string Name - { - get => ReadText(0); - set => WriteText(0, value); - } - - public ref ushort CodeOrder => ref this.RefData(0); - - public ListOfStructsSerializer Annotations - { - get => BuildPointer>(1); - set => Link(1, value); - } - - public ushort DiscriminantValue - { - get => this.ReadDataUShort(16, 65535); - set => this.WriteData(16, value, (ushort)65535); - } - - public ref ushort Tag => ref this.RefData(8); - - public bool IsSlot - { - get => Tag == 0; - set => Tag = 0; - } - - public uint Slot_Offset - { - get => IsSlot ? this.ReadDataUInt(32) : default; - set => this.WriteData(32, value); - } - - public Type.Writer Slot_Type - { - get => IsSlot ? BuildPointer(2) : default; - set => Link(2, value); - } - - public Value.Writer Slot_DefaultValue - { - get => IsSlot ? BuildPointer(3) : default; - set => Link(3, value); - } - - public bool Slot_HadExplicitDefault - { - get => IsSlot ? this.ReadDataBool(128) : default; - set => this.WriteData(128, value); - } - - public bool IsGroup - { - get => Tag == 1; - set => Tag = 1; - } - - public ref ulong Group_TypeId => ref this.RefData(2); - - public ref ushort Ordinal_Tag => ref this.RefData(5); - - public bool Ordinal_IsImplicit - { - get => Ordinal_Tag == 0; - set => Ordinal_Tag = 0; - } - - public bool Ordinal_IsExplicit - { - get => Ordinal_Tag == 1; - set => Ordinal_Tag = 1; - } - - public ref ushort Ordinal_Explicit => ref this.RefData(6); - } - } - - namespace Node - { - namespace Parameter - { - public struct Reader - { - public DeserializerState State { get; } - - public Reader(DeserializerState ctx) - { - State = ctx; - } - - public static Reader Create(DeserializerState ctx) => new Reader(ctx); - - public string Name => State.ReadText(0); - } - - public class Writer: SerializerState - { - public Writer() - { - SetStruct(0, 1); - } - - public string Name - { - get => ReadText(0); - set => WriteText(0, value); - } - } - } - - namespace NestedNode - { - public struct Reader - { - public DeserializerState State { get; } - - public Reader(DeserializerState ctx) - { - State = ctx; - } - - public static Reader Create(DeserializerState ctx) => new Reader(ctx); - - public string Name => State.ReadText(0); - public ulong Id => State.ReadDataULong(0); - } - - public class Writer: SerializerState - { - public Writer() - { - SetStruct(1, 1); - } - - public string Name - { - get => ReadText(0); - set => WriteText(0, value); - } - - public ref ulong Id => ref this.RefData(0); - } - } - - namespace SourceInfo - { - namespace Member - { - public struct Reader - { - public DeserializerState State { get; } - - public Reader(DeserializerState ctx) - { - State = ctx; - } - - public static Reader Create(DeserializerState ctx) => new Reader(ctx); - - public string DocComment => State.ReadText(0); - } - - public class Writer: SerializerState - { - public Writer() - { - SetStruct(0, 1); - } - - public string DocComment - { - get => ReadText(0); - set => WriteText(0, value); - } - } - } - - public struct Reader - { - public DeserializerState State { get; } - - public Reader(DeserializerState ctx) - { - State = ctx; - } - - public static Reader Create(DeserializerState ctx) => new Reader(ctx); - - public ulong Id => State.ReadDataULong(0); - public string DocComment => State.ReadText(0); - public IReadOnlyList Members => State.ReadListOfStructs(1, Member.Reader.Create); - } - - public class Writer: SerializerState - { - public Writer() - { - SetStruct(1, 2); - } - - public ref ulong Id => ref this.RefData(0); - - public string DocComment - { - get => ReadText(0); - set => WriteText(0, value); - } - - public ListOfStructsSerializer Members - { - get => BuildPointer>(1); - set => Link(1, value); - } - } - } - - public struct Reader - { - public DeserializerState State { get; } - - public Reader(DeserializerState ctx) - { - State = ctx; - } - - public static Reader Create(DeserializerState ctx) => new Reader(ctx); - - public ulong Id => State.ReadDataULong(0); - public string DisplayName => State.ReadText(0); - public uint DisplayNamePrefixLength => State.ReadDataUInt(64); - public ulong ScopeId => State.ReadDataULong(128); - public IReadOnlyList Parameters => State.ReadListOfStructs(5, Parameter.Reader.Create); - public bool IsGeneric => State.ReadDataBool(288); - public IReadOnlyList NestedNodes => State.ReadListOfStructs(1, NestedNode.Reader.Create); - public IReadOnlyList Annotations => State.ReadListOfStructs(2, Annotation.Reader.Create); - public ushort Tag => State.ReadDataUShort(96); - public bool IsFile => Tag == 0; - public bool IsStruct => Tag == 1; - public ushort Struct_DataWordCount => IsStruct ? State.ReadDataUShort(112) : default; - public ushort Struct_PointerCount => IsStruct ? State.ReadDataUShort(192) : default; - public ElementSize Struct_PreferredListEncoding => IsStruct ? (ElementSize)State.ReadDataUShort(208) : default; - public bool Struct_IsGroup => IsStruct ? State.ReadDataBool(224) : default; - public ushort Struct_DiscriminantCount => IsStruct ? State.ReadDataUShort(240) : default; - public uint Struct_DiscriminantOffset => IsStruct ? State.ReadDataUInt(256) : default; - public IReadOnlyList Fields => IsStruct ? State.ReadListOfStructs(3, Field.Reader.Create) : default; - public bool IsEnum => Tag == 2; - public IReadOnlyList Enumerants => IsEnum ? State.ReadListOfStructs(3, Field.Reader.Create) : default; - public bool IsInterface => Tag == 3; - public IReadOnlyList Interface_Methods => IsInterface ? State.ReadListOfStructs(3, Method.Reader.Create) : default; - public IReadOnlyList Interface_Superclasses => IsInterface ? State.ReadListOfStructs(4, Superclass.Reader.Create) : default; - public bool IsConst => Tag == 4; - public Type.Reader Const_Type => IsConst ? State.ReadStruct(3, Type.Reader.Create) : default; - public Value.Reader Const_Value => IsConst ? State.ReadStruct(4, Value.Reader.Create) : default; - public bool IsAnnotation => Tag == 5; - public Type.Reader Annotation_Type => IsAnnotation ? State.ReadStruct(3, Type.Reader.Create) : default; - public bool Annotation_TargetsFile => IsAnnotation ? State.ReadDataBool(112) : default; - public bool Annotation_TargetsConst => IsAnnotation ? State.ReadDataBool(113) : default; - public bool Annotation_TargetsEnum => IsAnnotation ? State.ReadDataBool(114) : default; - public bool Annotation_TargetsEnumerant => IsAnnotation ? State.ReadDataBool(115) : default; - public bool Annotation_TargetsStruct => IsAnnotation ? State.ReadDataBool(116) : default; - public bool Annotation_TargetsField => IsAnnotation ? State.ReadDataBool(117) : default; - public bool Annotation_TargetsUnion => IsAnnotation ? State.ReadDataBool(118) : default; - public bool Annotation_TargetsGroup => IsAnnotation ? State.ReadDataBool(119) : default; - public bool Annotation_TargetsInterface => IsAnnotation ? State.ReadDataBool(120) : default; - public bool Annotation_TargetsMethod => IsAnnotation ? State.ReadDataBool(121) : default; - public bool Annotation_TargetsParam => IsAnnotation ? State.ReadDataBool(122) : default; - public bool Annotation_TargetsAnnotation => IsAnnotation ? State.ReadDataBool(123) : default; - } - - public class Writer: SerializerState - { - public Writer() - { - SetStruct(5, 6); - } - - public ulong Id - { - get => this.ReadDataULong(0); - set => this.WriteData(0, value); - } - - public string DisplayName - { - get => ReadText(0); - set => WriteText(0, value); - } - - public ref uint DisplayNamePrefixLength => ref this.RefData(2); - - public ref ulong ScopeId => ref this.RefData(2); - - public ListOfStructsSerializer Parameters - { - get => BuildPointer>(5); - set => Link(5, value); - } - - public bool IsGeneric - { - get => this.ReadDataBool(288); - set => this.WriteData(288, value); - } - - public ListOfStructsSerializer NestedNodes - { - get => BuildPointer>(1); - set => Link(1, value); - } - - public ListOfStructsSerializer Annotations - { - get => BuildPointer>(2); - set => Link(2, value); - } - - public ref ushort Tag => ref this.RefData(6); - - public bool IsFile - { - get => Tag == 0; - set => Tag = 0; - } - - public bool IsStruct - { - get => Tag == 1; - set => Tag = 1; - } - - public ref ushort Struct_DataWordCount => ref this.RefData(7); - - public ref ushort Struct_PointerCount => ref this.RefData(12); - - public ref ElementSize Struct_PreferredListEncoding => ref this.RefData(13); - - public bool Struct_IsGroup - { - get => IsStruct ? this.ReadDataBool(224) : default; - set => this.WriteData(224, value); - } - - public ref ushort Struct_DiscriminantCount => ref this.RefData(15); - - public ref uint Struct_DiscriminantOffset => ref this.RefData(8); - - public ListOfStructsSerializer Fields - { - get => BuildPointer>(3); - set => Link(3, value); - } - - public bool IsEnum - { - get => Tag == 2; - set => Tag = 2; - } - - public ListOfStructsSerializer Enumerants - { - get => BuildPointer>(3); - set => Link(3, value); - } - - public bool IsInterface - { - get => Tag == 3; - set => Tag = 3; - } - - public ListOfStructsSerializer Interface_Methods - { - get => BuildPointer>(3); - set => Link(3, value); - } - - public ListOfStructsSerializer Interface_Superclasses - { - get => IsInterface ? BuildPointer>(4) : default; - set => Link(4, value); - } - - public bool IsConst - { - get => Tag == 4; - set => Tag = 4; - } - - public Type.Writer Const_Type - { - get => IsConst ? BuildPointer(3) : default; - set => Link(3, value); - } - - public Value.Writer Const_Value - { - get => IsConst ? BuildPointer(4) : default; - set => Link(4, value); - } - - public bool IsAnnotation - { - get => Tag == 5; - set => Tag = 5; - } - - public Type.Writer Annotation_Type - { - get => IsAnnotation ? BuildPointer(3) : default; - set => Link(3, value); - } - - public bool Annotation_TargetsFile - { - get => IsAnnotation ? this.ReadDataBool(112) : default; - set => this.WriteData(112, value); - } - - public bool Annotation_TargetsConst - { - get => IsAnnotation ? this.ReadDataBool(113) : default; - set => this.WriteData(113, value); - } - - public bool Annotation_TargetsEnum - { - get => IsAnnotation ? this.ReadDataBool(114) : default; - set => this.WriteData(114, value); - } - - public bool Annotation_TargetsEnumerant - { - get => IsAnnotation ? this.ReadDataBool(115) : default; - set => this.WriteData(115, value); - } - - public bool Annotation_TargetsStruct - { - get => IsAnnotation ? this.ReadDataBool(116) : default; - set => this.WriteData(116, value); - } - - public bool Annotation_TargetsField - { - get => IsAnnotation ? this.ReadDataBool(117) : default; - set => this.WriteData(117, value); - } - - public bool Annotation_TargetsUnion - { - get => IsAnnotation ? this.ReadDataBool(118) : default; - set => this.WriteData(118, value); - } - - public bool Annotation_TargetsGroup - { - get => IsAnnotation ? this.ReadDataBool(119) : default; - set => this.WriteData(119, value); - } - - public bool Annotation_TargetsInterface - { - get => IsAnnotation ? this.ReadDataBool(120) : default; - set => this.WriteData(120, value); - } - - public bool Annotation_TargetsMethod - { - get => IsAnnotation ? this.ReadDataBool(121) : default; - set => this.WriteData(121, value); - } - - public bool Annotation_TargetsParam - { - get => IsAnnotation ? this.ReadDataBool(122) : default; - set => this.WriteData(122, value); - } - - public bool Annotation_TargetsAnnotation - { - get => IsAnnotation ? this.ReadDataBool(123) : default; - set => this.WriteData(123, value); - } - } - } - - namespace CapnpVersion - { - public struct Reader - { - public DeserializerState State { get; } - - public Reader(DeserializerState ctx) - { - State = ctx; - } - - public static Reader Create(DeserializerState ctx) => new Reader(ctx); - - public ushort Major => State.ReadDataUShort(0); - public byte Minor => State.ReadDataByte(16); - public byte Micro => State.ReadDataByte(24); - } - - public class Writer: SerializerState - { - public Writer() - { - SetStruct(1, 0); - } - - public ref ushort Major => ref this.RefData(0); - public ref byte Minor => ref this.RefData(2); - public ref byte Micro => ref this.RefData(3); - } - } - - namespace CodeGeneratorRequest - { - namespace RequestedFile - { - namespace Import - { - public struct Reader - { - public DeserializerState State { get; } - - public Reader(DeserializerState ctx) - { - State = ctx; - } - - public static Reader Create(DeserializerState ctx) => new Reader(ctx); - - public ulong Id => State.ReadDataULong(0); - public string Name => State.ReadText(0); - } - - public class Writer: SerializerState - { - public Writer() - { - SetStruct(1, 1); - } - - public ref ulong Id => ref this.RefData(0); - - public string Name - { - get => ReadText(0); - set => WriteText(0, value); - } - } - } - - public struct Reader - { - public DeserializerState State { get; } - - public Reader(DeserializerState ctx) - { - State = ctx; - } - - public static Reader Create(DeserializerState ctx) => new Reader(ctx); - - public ulong Id => State.ReadDataULong(0); - public string Filename => State.ReadText(0); - public IReadOnlyList Imports => State.ReadListOfStructs(1, Import.Reader.Create); - } - - public class Writer: SerializerState - { - public Writer() - { - SetStruct(1, 2); - } - - public ref ulong Id => ref this.RefData(0); - - public string Filename - { - get => ReadText(0); - set => WriteText(0, value); - } - - public ListOfStructsSerializer Imports - { - get => BuildPointer>(1); - set => Link(1, value); - } - } - } - - public struct Reader - { - public DeserializerState State { get; } - - public Reader(DeserializerState ctx) - { - State = ctx; - } - - public static Reader Create(DeserializerState ctx) => new Reader(ctx); - - public CapnpVersion.Reader CapnpVersion => State.ReadStruct(2, Schema.CapnpVersion.Reader.Create); - public IReadOnlyList Nodes => State.ReadListOfStructs(0, Node.Reader.Create); - public IReadOnlyList SourceInfo => State.ReadListOfStructs(3, Node.SourceInfo.Reader.Create); - public IReadOnlyList RequestedFiles => State.ReadListOfStructs(1, RequestedFile.Reader.Create); - } - - public class Writer: SerializerState - { - public Writer() - { - SetStruct(0, 3); - } - - public CapnpVersion.Writer CapnpVersion - { - get => BuildPointer(2); - set => Link(2, value); - } - - public ListOfStructsSerializer Nodes - { - get => BuildPointer>(0); - set => Link(0, value); - } - - public ListOfStructsSerializer SourceInfo - { - get => BuildPointer>(3); - set => Link(3, value); - } - - public ListOfStructsSerializer RequestedFiles - { - get => BuildPointer>(1); - set => Link(1, value); - } - } - } -} diff --git a/capnpc-csharp/Schema/schema-with-offsets.capnp b/capnpc-csharp/Schema/schema-with-offsets.capnp deleted file mode 100644 index 45fe760..0000000 --- a/capnpc-csharp/Schema/schema-with-offsets.capnp +++ /dev/null @@ -1,235 +0,0 @@ -# schema.capnp -@0xa93fc509624c72d9; -$import "/capnp/c++.capnp".namespace("capnp::schema"); -struct Node @0xe682ab4cf923a417 { # 40 bytes, 6 ptrs - id @0 :UInt64; # bits[0, 64) - displayName @1 :Text; # ptr[0] - displayNamePrefixLength @2 :UInt32; # bits[64, 96) - scopeId @3 :UInt64; # bits[128, 192) - parameters @32 :List(Parameter); # ptr[5] - isGeneric @33 :Bool; # bits[288, 289) - nestedNodes @4 :List(NestedNode); # ptr[1] - annotations @5 :List(Annotation); # ptr[2] - union { # tag bits [96, 112) - file @6 :Void; # bits[0, 0), union tag = 0 - struct :group { # union tag = 1 - dataWordCount @7 :UInt16; # bits[112, 128) - pointerCount @8 :UInt16; # bits[192, 208) - preferredListEncoding @9 :ElementSize; # bits[208, 224) - isGroup @10 :Bool; # bits[224, 225) - discriminantCount @11 :UInt16; # bits[240, 256) - discriminantOffset @12 :UInt32; # bits[256, 288) - fields @13 :List(Field); # ptr[3] - } - enum :group { # union tag = 2 - enumerants @14 :List(Enumerant); # ptr[3] - } - interface :group { # union tag = 3 - methods @15 :List(Method); # ptr[3] - superclasses @31 :List(Superclass); # ptr[4] - } - const :group { # union tag = 4 - type @16 :Type; # ptr[3] - value @17 :Value; # ptr[4] - } - annotation :group { # union tag = 5 - type @18 :Type; # ptr[3] - targetsFile @19 :Bool; # bits[112, 113) - targetsConst @20 :Bool; # bits[113, 114) - targetsEnum @21 :Bool; # bits[114, 115) - targetsEnumerant @22 :Bool; # bits[115, 116) - targetsStruct @23 :Bool; # bits[116, 117) - targetsField @24 :Bool; # bits[117, 118) - targetsUnion @25 :Bool; # bits[118, 119) - targetsGroup @26 :Bool; # bits[119, 120) - targetsInterface @27 :Bool; # bits[120, 121) - targetsMethod @28 :Bool; # bits[121, 122) - targetsParam @29 :Bool; # bits[122, 123) - targetsAnnotation @30 :Bool; # bits[123, 124) - } - } - struct Parameter @0xb9521bccf10fa3b1 { # 0 bytes, 1 ptrs - name @0 :Text; # ptr[0] - } - struct NestedNode @0xdebf55bbfa0fc242 { # 8 bytes, 1 ptrs - name @0 :Text; # ptr[0] - id @1 :UInt64; # bits[0, 64) - } - struct SourceInfo @0xf38e1de3041357ae { # 8 bytes, 2 ptrs - id @0 :UInt64; # bits[0, 64) - docComment @1 :Text; # ptr[0] - members @2 :List(Member); # ptr[1] - struct Member @0xc2ba9038898e1fa2 { # 0 bytes, 1 ptrs - docComment @0 :Text; # ptr[0] - } - } -} -struct Field @0x9aad50a41f4af45f { # 24 bytes, 4 ptrs - name @0 :Text; # ptr[0] - codeOrder @1 :UInt16; # bits[0, 16) - annotations @2 :List(Annotation); # ptr[1] - discriminantValue @3 :UInt16 = 65535; # bits[16, 32) - union { # tag bits [64, 80) - slot :group { # union tag = 0 - offset @4 :UInt32; # bits[32, 64) - type @5 :Type; # ptr[2] - defaultValue @6 :Value; # ptr[3] - hadExplicitDefault @10 :Bool; # bits[128, 129) - } - group :group { # union tag = 1 - typeId @7 :UInt64; # bits[128, 192) - } - } - ordinal :group { - union { # tag bits [80, 96) - implicit @8 :Void; # bits[0, 0), union tag = 0 - explicit @9 :UInt16; # bits[96, 112), union tag = 1 - } - } - const noDiscriminant @0x97b14cbe7cfec712 :UInt16 = 65535; -} -struct Enumerant @0x978a7cebdc549a4d { # 8 bytes, 2 ptrs - name @0 :Text; # ptr[0] - codeOrder @1 :UInt16; # bits[0, 16) - annotations @2 :List(Annotation); # ptr[1] -} -struct Superclass @0xa9962a9ed0a4d7f8 { # 8 bytes, 1 ptrs - id @0 :UInt64; # bits[0, 64) - brand @1 :Brand; # ptr[0] -} -struct Method @0x9500cce23b334d80 { # 24 bytes, 5 ptrs - name @0 :Text; # ptr[0] - codeOrder @1 :UInt16; # bits[0, 16) - implicitParameters @7 :List(Node.Parameter); # ptr[4] - paramStructType @2 :UInt64; # bits[64, 128) - paramBrand @5 :Brand; # ptr[2] - resultStructType @3 :UInt64; # bits[128, 192) - resultBrand @6 :Brand; # ptr[3] - annotations @4 :List(Annotation); # ptr[1] -} -struct Type @0xd07378ede1f9cc60 { # 24 bytes, 1 ptrs - union { # tag bits [0, 16) - void @0 :Void; # bits[0, 0), union tag = 0 - bool @1 :Void; # bits[0, 0), union tag = 1 - int8 @2 :Void; # bits[0, 0), union tag = 2 - int16 @3 :Void; # bits[0, 0), union tag = 3 - int32 @4 :Void; # bits[0, 0), union tag = 4 - int64 @5 :Void; # bits[0, 0), union tag = 5 - uint8 @6 :Void; # bits[0, 0), union tag = 6 - uint16 @7 :Void; # bits[0, 0), union tag = 7 - uint32 @8 :Void; # bits[0, 0), union tag = 8 - uint64 @9 :Void; # bits[0, 0), union tag = 9 - float32 @10 :Void; # bits[0, 0), union tag = 10 - float64 @11 :Void; # bits[0, 0), union tag = 11 - text @12 :Void; # bits[0, 0), union tag = 12 - data @13 :Void; # bits[0, 0), union tag = 13 - list :group { # union tag = 14 - elementType @14 :Type; # ptr[0] - } - enum :group { # union tag = 15 - typeId @15 :UInt64; # bits[64, 128) - brand @21 :Brand; # ptr[0] - } - struct :group { # union tag = 16 - typeId @16 :UInt64; # bits[64, 128) - brand @22 :Brand; # ptr[0] - } - interface :group { # union tag = 17 - typeId @17 :UInt64; # bits[64, 128) - brand @23 :Brand; # ptr[0] - } - anyPointer :group { # union tag = 18 - union { # tag bits [64, 80) - unconstrained :group { # union tag = 0 - union { # tag bits [80, 96) - anyKind @18 :Void; # bits[0, 0), union tag = 0 - struct @25 :Void; # bits[0, 0), union tag = 1 - list @26 :Void; # bits[0, 0), union tag = 2 - capability @27 :Void; # bits[0, 0), union tag = 3 - } - } - parameter :group { # union tag = 1 - scopeId @19 :UInt64; # bits[128, 192) - parameterIndex @20 :UInt16; # bits[80, 96) - } - implicitMethodParameter :group { # union tag = 2 - parameterIndex @24 :UInt16; # bits[80, 96) - } - } - } - } -} -struct Brand @0x903455f06065422b { # 0 bytes, 1 ptrs - scopes @0 :List(Scope); # ptr[0] - struct Scope @0xabd73485a9636bc9 { # 16 bytes, 1 ptrs - scopeId @0 :UInt64; # bits[0, 64) - union { # tag bits [64, 80) - bind @1 :List(Binding); # ptr[0], union tag = 0 - inherit @2 :Void; # bits[0, 0), union tag = 1 - } - } - struct Binding @0xc863cd16969ee7fc { # 8 bytes, 1 ptrs - union { # tag bits [0, 16) - unbound @0 :Void; # bits[0, 0), union tag = 0 - type @1 :Type; # ptr[0], union tag = 1 - } - } -} -struct Value @0xce23dcd2d7b00c9b { # 16 bytes, 1 ptrs - union { # tag bits [0, 16) - void @0 :Void; # bits[0, 0), union tag = 0 - bool @1 :Bool; # bits[16, 17), union tag = 1 - int8 @2 :Int8; # bits[16, 24), union tag = 2 - int16 @3 :Int16; # bits[16, 32), union tag = 3 - int32 @4 :Int32; # bits[32, 64), union tag = 4 - int64 @5 :Int64; # bits[64, 128), union tag = 5 - uint8 @6 :UInt8; # bits[16, 24), union tag = 6 - uint16 @7 :UInt16; # bits[16, 32), union tag = 7 - uint32 @8 :UInt32; # bits[32, 64), union tag = 8 - uint64 @9 :UInt64; # bits[64, 128), union tag = 9 - float32 @10 :Float32; # bits[32, 64), union tag = 10 - float64 @11 :Float64; # bits[64, 128), union tag = 11 - text @12 :Text; # ptr[0], union tag = 12 - data @13 :Data; # ptr[0], union tag = 13 - list @14 :AnyPointer; # ptr[0], union tag = 14 - enum @15 :UInt16; # bits[16, 32), union tag = 15 - struct @16 :AnyPointer; # ptr[0], union tag = 16 - interface @17 :Void; # bits[0, 0), union tag = 17 - anyPointer @18 :AnyPointer; # ptr[0], union tag = 18 - } -} -struct Annotation @0xf1c8950dab257542 { # 8 bytes, 2 ptrs - id @0 :UInt64; # bits[0, 64) - brand @2 :Brand; # ptr[1] - value @1 :Value; # ptr[0] -} -enum ElementSize @0xd1958f7dba521926 { - empty @0; - bit @1; - byte @2; - twoBytes @3; - fourBytes @4; - eightBytes @5; - pointer @6; - inlineComposite @7; -} -struct CapnpVersion @0xd85d305b7d839963 { # 8 bytes, 0 ptrs - major @0 :UInt16; # bits[0, 16) - minor @1 :UInt8; # bits[16, 24) - micro @2 :UInt8; # bits[24, 32) -} -struct CodeGeneratorRequest @0xbfc546f6210ad7ce { # 0 bytes, 4 ptrs - capnpVersion @2 :CapnpVersion; # ptr[2] - nodes @0 :List(Node); # ptr[0] - sourceInfo @3 :List(Node.SourceInfo); # ptr[3] - requestedFiles @1 :List(RequestedFile); # ptr[1] - struct RequestedFile @0xcfea0eb02e810062 { # 8 bytes, 2 ptrs - id @0 :UInt64; # bits[0, 64) - filename @1 :Text; # ptr[0] - imports @2 :List(Import); # ptr[1] - struct Import @0xae504193122357e5 { # 8 bytes, 1 ptrs - id @0 :UInt64; # bits[0, 64) - name @1 :Text; # ptr[0] - } - } -} diff --git a/capnpc-csharp/capnpc-csharp.csproj b/capnpc-csharp/capnpc-csharp.csproj index 3e3531e..4c58994 100644 --- a/capnpc-csharp/capnpc-csharp.csproj +++ b/capnpc-csharp/capnpc-csharp.csproj @@ -27,6 +27,7 @@ + From 4fe85892447f4e6e73a19423fa7e0433891d6a9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6llner?= Date: Wed, 11 Sep 2019 22:20:29 +0200 Subject: [PATCH 05/22] CI integration of added projects --- appveyor.yml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 00636e7..0c0af27 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,8 +1,8 @@ version: '1.0.{build}' image: Visual Studio 2019 -branches: - only: - - master +# branches: +# only: +# - master cache: - c:\Tools\vcpkg\installed init: @@ -28,8 +28,10 @@ before_build: - cmd: dotnet restore ./Capnp.Net.Runtime.Core21/Capnp.Net.Runtime.Core21.csproj --verbosity m - cmd: dotnet restore ./Capnp.Net.Runtime.Tests/Capnp.Net.Runtime.Tests.Std20.csproj --verbosity m - cmd: dotnet restore ./Capnp.Net.Runtime.Tests.Core21/Capnp.Net.Runtime.Tests.Core21.csproj --verbosity m - - cmd: dotnet restore ./capnpc-csharp/capnpc-csharp.csproj --verbosity m + - cmd: dotnet restore ./CapnpC.CSharp.Generator/CapnpC.CSharp.Generator.csproj --verbosity m - cmd: dotnet restore ./CapnpC.CSharp.Generator.Tests/CapnpC.CSharp.Generator.Tests.csproj --verbosity m + - cmd: dotnet restore ./CapnpC.CSharp.MsBuild.Generation/CapnpC.CSharp.MsBuild.Generation.csproj --verbosity m + - cmd: dotnet restore ./CapnpC.CSharp.MsBuild.Generation.Tests/CapnpC.CSharp.MsBuild.Generation.Tests.csproj --verbosity m build_script: - cmd: msbuild ./Capnp.Net.sln /p:Configuration="Debug" - cmd: msbuild ./Capnp.Net.sln /p:Configuration="Release" @@ -42,6 +44,9 @@ artifacts: - path: Capnp.Net.Runtime\bin\Release\Capnp.Net.Runtime.$(appveyor_build_version).nupkg name: Capnp.Net.Runtime type: NuGetPackage + - path: CapnpC.CSharp.MsBuild.Generation\bin\Release\CapnpC.CSharp.MsBuild.Generation.$(appveyor_build_version).nupkg + name: CapnpC.CSharp.MsBuild.Generation + type: NuGetPackage - path: chocolatey\install\capnpc-csharp-win-x86.$(appveyor_build_version).nupkg name: capnpc-csharp-win-x86 type: NuGetPackage @@ -65,6 +70,7 @@ test_script: - cmd: choco uninstall capnpc-csharp-win-x86 -y - cmd: notinstalled-test - cmd: cd %APPVEYOR_BUILD_FOLDER% + - cmd: vstest.console /logger:Appveyor /inIsolation CapnpC.CSharp.MsBuild.Generation.Tests\bin\Release\netcoreapp2.2\CapnpC.CSharp.MsBuild.Generation.Tests.dll - cmd: vstest.console /logger:Appveyor /inIsolation Capnp.Net.Runtime.Tests\bin\Debug\netcoreapp2.2\Capnp.Net.Runtime.Tests.Std20.dll - cmd: vstest.console /logger:Appveyor /inIsolation Capnp.Net.Runtime.Tests\bin\Release\netcoreapp2.2\Capnp.Net.Runtime.Tests.Std20.dll - cmd: vstest.console /logger:Appveyor /inIsolation Capnp.Net.Runtime.Tests.Core21\bin\Debug\netcoreapp2.2\Capnp.Net.Runtime.Tests.Core21.dll From a4af71bceb33df85dd4fa12e4f82540eeda2a4c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6llner?= Date: Wed, 11 Sep 2019 22:43:39 +0200 Subject: [PATCH 06/22] Build configuration fixes --- CapnpC.CSharp.Generator.Tests/capnpc-csharp.tests.csproj | 4 ---- .../Capnpc.Csharp.MsBuild.Generation.csproj | 2 +- .../Capnpc.Csharp.MsBuild.Generation.nuspec | 6 +++--- 3 files changed, 4 insertions(+), 8 deletions(-) delete mode 100644 CapnpC.CSharp.Generator.Tests/capnpc-csharp.tests.csproj diff --git a/CapnpC.CSharp.Generator.Tests/capnpc-csharp.tests.csproj b/CapnpC.CSharp.Generator.Tests/capnpc-csharp.tests.csproj deleted file mode 100644 index 88a5509..0000000 --- a/CapnpC.CSharp.Generator.Tests/capnpc-csharp.tests.csproj +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.csproj b/Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.csproj index bbb9e95..6c20fd2 100644 --- a/Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.csproj +++ b/Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.csproj @@ -14,7 +14,7 @@ 1.0.0 $(MSBuildThisFileDirectory)CapnpC.CSharp.MsBuild.Generation.nuspec - version=$(Version) + version=$(Version);configuration=$(Configuration) true diff --git a/Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.nuspec b/Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.nuspec index d5073c9..e048bb9 100644 --- a/Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.nuspec +++ b/Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.nuspec @@ -21,9 +21,9 @@ - - - + + + From a9a5109986cc6c515d85c82bdff2dc77c496bc11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6llner?= Date: Wed, 11 Sep 2019 22:50:37 +0200 Subject: [PATCH 07/22] Forgot to restore capnpc-csharp --- appveyor.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/appveyor.yml b/appveyor.yml index 0c0af27..95693e1 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -32,6 +32,7 @@ before_build: - cmd: dotnet restore ./CapnpC.CSharp.Generator.Tests/CapnpC.CSharp.Generator.Tests.csproj --verbosity m - cmd: dotnet restore ./CapnpC.CSharp.MsBuild.Generation/CapnpC.CSharp.MsBuild.Generation.csproj --verbosity m - cmd: dotnet restore ./CapnpC.CSharp.MsBuild.Generation.Tests/CapnpC.CSharp.MsBuild.Generation.Tests.csproj --verbosity m + - cmd: dotnet restore ./capnpc-csharp/capnpc-csharp.csproj --verbosity m build_script: - cmd: msbuild ./Capnp.Net.sln /p:Configuration="Debug" - cmd: msbuild ./Capnp.Net.sln /p:Configuration="Release" From d34d3b72a75731142a16ecf47516f1dff42fdc58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6llner?= Date: Thu, 12 Sep 2019 22:08:00 +0200 Subject: [PATCH 08/22] Adapted compile-test.bat to new file naming --- install-test/compile-test.bat | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install-test/compile-test.bat b/install-test/compile-test.bat index 2162124..b93a2da 100644 --- a/install-test/compile-test.bat +++ b/install-test/compile-test.bat @@ -1,8 +1,8 @@ @echo off capnp compile -ocsharp -I%cd% .\capnp\schema.capnp if %ERRORLEVEL% neq 0 exit /b 1 -if exist .\capnp\schema.cs ( - del .\capnp\schema.cs +if exist .\capnp\schema.capnp.cs ( + del .\capnp\schema.capnp.cs ) else ( exit /b 2 ) From f73d6a257bb80650bdb39145dcaed69c984b9d5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6llner?= Date: Fri, 13 Sep 2019 21:29:55 +0200 Subject: [PATCH 09/22] test autom. fix --- appveyor.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/appveyor.yml b/appveyor.yml index 95693e1..d3add8a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -61,6 +61,7 @@ test_script: - cmd: choco install capnpc-csharp --source=".;https://chocolatey.org/api/v2" --force -y - cmd: cd %APPVEYOR_BUILD_FOLDER%\install-test - cmd: compile-test + - cmd: cd %APPVEYOR_BUILD_FOLDER% - cmd: vstest.console /logger:Appveyor /inIsolation CapnpC.CSharp.Generator.Tests\bin\Release\netcoreapp2.2\CapnpC.CSharp.Generator.Tests.dll - cmd: choco uninstall capnpc-csharp -y - cmd: notinstalled-test From 388209b3f2f662f9716abefd222efdcfc9af7148 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6llner?= Date: Fri, 13 Sep 2019 21:38:56 +0200 Subject: [PATCH 10/22] another test fix --- appveyor.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/appveyor.yml b/appveyor.yml index d3add8a..f7db4e5 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -64,6 +64,7 @@ test_script: - cmd: cd %APPVEYOR_BUILD_FOLDER% - cmd: vstest.console /logger:Appveyor /inIsolation CapnpC.CSharp.Generator.Tests\bin\Release\netcoreapp2.2\CapnpC.CSharp.Generator.Tests.dll - cmd: choco uninstall capnpc-csharp -y + - cmd: cd %APPVEYOR_BUILD_FOLDER%\install-test - cmd: notinstalled-test - cmd: cd %APPVEYOR_BUILD_FOLDER%\chocolatey\install - cmd: choco install capnpc-csharp-win-x86 --source=".;https://chocolatey.org/api/v2" --force -y From e9c65f6719e754b1be37517649c742b2bc31d190 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6llner?= Date: Sun, 15 Sep 2019 19:09:43 +0200 Subject: [PATCH 11/22] More WIP --- .gitignore | 5 + .../Capnp.Net.Runtime.Tests.Core21.csproj | 3 + .../Capnp.Net.Runtime.Tests.Std20.csproj | 3 + Capnp.Net.Runtime/Capnp.Net.Runtime.csproj | 10 +- Capnp.Net.sln | 2 +- .../CapnpC.CSharp.Generator.Tests.csproj | 3 + .../CapnpC.CSharp.Generator.csproj | 1 + CapnpC.CSharp.Generator/CapnpCompilation.cs | 7 +- ...npC.CSharp.MsBuild.Generation.Tests.csproj | 2 + .../CapnpCodeBehindGenerator.cs | 20 +- .../CapnpFileCodeBehindGenerator.cs | 18 +- .../Capnpc.Csharp.MsBuild.Generation.csproj | 16 +- .../GenerateCapnpFileCodeBehindTask.cs | 46 +- .../ICapnpCsharpGenerator.cs | 2 +- .../CPS/Buildsystem/Rules/CapnpFileType.xaml | 25 +- .../Capnpc.Csharp.MsBuild.Generation.props | 1 + MsBuildGenerationTest/AddressBook.capnp | 31 + .../MsBuildGenerationTest.csproj | 56 + .../MsBuildGenerationTest.sln | 25 + MsBuildGenerationTest/capnp/c++.capnp | 26 + .../capnp/compat/json-test.capnp | 116 ++ MsBuildGenerationTest/capnp/compat/json.capnp | 112 ++ MsBuildGenerationTest/capnp/persistent.capnp | 139 ++ .../capnp/rpc-twoparty.capnp | 169 ++ MsBuildGenerationTest/capnp/rpc.capnp | 1409 +++++++++++++++++ MsBuildGenerationTest/capnp/schema.capnp | 529 +++++++ MsBuildGenerationTest/capnp/test-import.capnp | 28 + .../capnp/test-import2.capnp | 32 + MsBuildGenerationTest/capnp/test.capnp | 969 ++++++++++++ .../capnp/testdata/annotated-json.binary | Bin 0 -> 544 bytes .../capnp/testdata/annotated.json | 22 + MsBuildGenerationTest/capnp/testdata/binary | Bin 0 -> 2816 bytes .../capnp/testdata/errors.capnp.nobuild | 161 ++ .../capnp/testdata/errors.txt | 60 + MsBuildGenerationTest/capnp/testdata/flat | Bin 0 -> 2808 bytes .../capnp/testdata/lists.binary | Bin 0 -> 1096 bytes MsBuildGenerationTest/capnp/testdata/packed | Bin 0 -> 831 bytes .../capnp/testdata/packedflat | Bin 0 -> 828 bytes .../capnp/testdata/pretty.json | 88 + .../capnp/testdata/pretty.txt | 187 +++ .../capnp/testdata/segmented | Bin 0 -> 5520 bytes .../capnp/testdata/segmented-packed | Bin 0 -> 1352 bytes .../capnp/testdata/short.json | 1 + .../capnp/testdata/short.txt | 1 + MsBuildGenerationTest/nuget.config | 10 + appveyor.yml | 4 +- capnpc-csharp/capnpc-csharp.csproj | 5 +- test.capnp.bin | 0 48 files changed, 4295 insertions(+), 49 deletions(-) create mode 100644 MsBuildGenerationTest/AddressBook.capnp create mode 100644 MsBuildGenerationTest/MsBuildGenerationTest.csproj create mode 100644 MsBuildGenerationTest/MsBuildGenerationTest.sln create mode 100644 MsBuildGenerationTest/capnp/c++.capnp create mode 100644 MsBuildGenerationTest/capnp/compat/json-test.capnp create mode 100644 MsBuildGenerationTest/capnp/compat/json.capnp create mode 100644 MsBuildGenerationTest/capnp/persistent.capnp create mode 100644 MsBuildGenerationTest/capnp/rpc-twoparty.capnp create mode 100644 MsBuildGenerationTest/capnp/rpc.capnp create mode 100644 MsBuildGenerationTest/capnp/schema.capnp create mode 100644 MsBuildGenerationTest/capnp/test-import.capnp create mode 100644 MsBuildGenerationTest/capnp/test-import2.capnp create mode 100644 MsBuildGenerationTest/capnp/test.capnp create mode 100644 MsBuildGenerationTest/capnp/testdata/annotated-json.binary create mode 100644 MsBuildGenerationTest/capnp/testdata/annotated.json create mode 100644 MsBuildGenerationTest/capnp/testdata/binary create mode 100644 MsBuildGenerationTest/capnp/testdata/errors.capnp.nobuild create mode 100644 MsBuildGenerationTest/capnp/testdata/errors.txt create mode 100644 MsBuildGenerationTest/capnp/testdata/flat create mode 100644 MsBuildGenerationTest/capnp/testdata/lists.binary create mode 100644 MsBuildGenerationTest/capnp/testdata/packed create mode 100644 MsBuildGenerationTest/capnp/testdata/packedflat create mode 100644 MsBuildGenerationTest/capnp/testdata/pretty.json create mode 100644 MsBuildGenerationTest/capnp/testdata/pretty.txt create mode 100644 MsBuildGenerationTest/capnp/testdata/segmented create mode 100644 MsBuildGenerationTest/capnp/testdata/segmented-packed create mode 100644 MsBuildGenerationTest/capnp/testdata/short.json create mode 100644 MsBuildGenerationTest/capnp/testdata/short.txt create mode 100644 MsBuildGenerationTest/nuget.config delete mode 100644 test.capnp.bin diff --git a/.gitignore b/.gitignore index cc27174..1f39135 100644 --- a/.gitignore +++ b/.gitignore @@ -332,3 +332,8 @@ ASALocalRun/ .mfractor/ .vscode/tasks.json .vscode/launch.json + +# Capnp code behind +.capnp.cs +/globalPackages +*.cs diff --git a/Capnp.Net.Runtime.Tests.Core21/Capnp.Net.Runtime.Tests.Core21.csproj b/Capnp.Net.Runtime.Tests.Core21/Capnp.Net.Runtime.Tests.Core21.csproj index d72aa67..d4a9e68 100644 --- a/Capnp.Net.Runtime.Tests.Core21/Capnp.Net.Runtime.Tests.Core21.csproj +++ b/Capnp.Net.Runtime.Tests.Core21/Capnp.Net.Runtime.Tests.Core21.csproj @@ -4,6 +4,8 @@ netcoreapp2.2 false + + Debug;Release @@ -31,6 +33,7 @@ + diff --git a/Capnp.Net.Runtime.Tests/Capnp.Net.Runtime.Tests.Std20.csproj b/Capnp.Net.Runtime.Tests/Capnp.Net.Runtime.Tests.Std20.csproj index 5048b1c..d722dd3 100644 --- a/Capnp.Net.Runtime.Tests/Capnp.Net.Runtime.Tests.Std20.csproj +++ b/Capnp.Net.Runtime.Tests/Capnp.Net.Runtime.Tests.Std20.csproj @@ -8,6 +8,8 @@ 7.1 Library + + Debug;Release @@ -15,6 +17,7 @@ + diff --git a/Capnp.Net.Runtime/Capnp.Net.Runtime.csproj b/Capnp.Net.Runtime/Capnp.Net.Runtime.csproj index ae162a8..90555c9 100644 --- a/Capnp.Net.Runtime/Capnp.Net.Runtime.csproj +++ b/Capnp.Net.Runtime/Capnp.Net.Runtime.csproj @@ -7,6 +7,7 @@ Capnp.Net.Runtime Capnp.Net.Runtime true + ..\bin\$(Configuration) Christian Köllner and contributors A Cap'n Proto implementation for .NET Standard & Core capnproto-dotnetcore @@ -17,17 +18,14 @@ MIT Git capnp "Cap'n Proto" RPC serialization cerealization - 1.0.0 + 1.0-local$([System.DateTime]::UtcNow.ToString(yyMMddHHmm)) + Debug;Release TRACE - - - - - + diff --git a/Capnp.Net.sln b/Capnp.Net.sln index 38c77ca..ff53c1c 100644 --- a/Capnp.Net.sln +++ b/Capnp.Net.sln @@ -17,7 +17,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CapnpC.CSharp.MsBuild.Gener EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CapnpC.CSharp.Generator", "CapnpC.CSharp.Generator\CapnpC.CSharp.Generator.csproj", "{C3A3BB49-356E-4762-A190-76D877BE18F7}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CapnpC.CSharp.MsBuild.Generation.Tests", "CapnpC.CSharp.MsBuild.Generation.Tests\CapnpC.CSharp.MsBuild.Generation.Tests.csproj", "{EF05AD68-DE31-448E-B88D-4144F928ED5D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CapnpC.CSharp.MsBuild.Generation.Tests", "CapnpC.CSharp.MsBuild.Generation.Tests\CapnpC.CSharp.MsBuild.Generation.Tests.csproj", "{EF05AD68-DE31-448E-B88D-4144F928ED5D}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/CapnpC.CSharp.Generator.Tests/CapnpC.CSharp.Generator.Tests.csproj b/CapnpC.CSharp.Generator.Tests/CapnpC.CSharp.Generator.Tests.csproj index 5228560..0f3fa11 100644 --- a/CapnpC.CSharp.Generator.Tests/CapnpC.CSharp.Generator.Tests.csproj +++ b/CapnpC.CSharp.Generator.Tests/CapnpC.CSharp.Generator.Tests.csproj @@ -5,6 +5,8 @@ CapnpC.CSharp.Generator.Tests false + + Debug;Release @@ -61,6 +63,7 @@ SpecFlowSingleFileGenerator CodeGenerator.feature.cs + diff --git a/CapnpC.CSharp.Generator/CapnpC.CSharp.Generator.csproj b/CapnpC.CSharp.Generator/CapnpC.CSharp.Generator.csproj index 377d454..e752fdf 100644 --- a/CapnpC.CSharp.Generator/CapnpC.CSharp.Generator.csproj +++ b/CapnpC.CSharp.Generator/CapnpC.CSharp.Generator.csproj @@ -2,6 +2,7 @@ netstandard2.0;netcoreapp2.1 + Debug;Release diff --git a/CapnpC.CSharp.Generator/CapnpCompilation.cs b/CapnpC.CSharp.Generator/CapnpCompilation.cs index ec4c342..3c01261 100644 --- a/CapnpC.CSharp.Generator/CapnpCompilation.cs +++ b/CapnpC.CSharp.Generator/CapnpCompilation.cs @@ -45,9 +45,10 @@ namespace CapnpC.CSharp.Generator /// Invokes "capnp.exe -o-" with given additional arguments and redirects the output to the C# generator backend. /// /// additional command line arguments + /// optional working directory /// generation result /// is null - public static GenerationResult InvokeCapnpAndGenerate(IEnumerable arguments) + public static GenerationResult InvokeCapnpAndGenerate(IEnumerable arguments, string workingDirectory = null) { if (arguments == null) throw new ArgumentNullException(nameof(arguments)); @@ -64,6 +65,10 @@ namespace CapnpC.CSharp.Generator compiler.StartInfo.UseShellExecute = false; compiler.StartInfo.RedirectStandardOutput = true; compiler.StartInfo.RedirectStandardError = true; + if (!string.IsNullOrWhiteSpace(workingDirectory)) + { + compiler.StartInfo.WorkingDirectory = workingDirectory; + } try { diff --git a/CapnpC.CSharp.MsBuild.Generation.Tests/CapnpC.CSharp.MsBuild.Generation.Tests.csproj b/CapnpC.CSharp.MsBuild.Generation.Tests/CapnpC.CSharp.MsBuild.Generation.Tests.csproj index fe274f1..4b48f59 100644 --- a/CapnpC.CSharp.MsBuild.Generation.Tests/CapnpC.CSharp.MsBuild.Generation.Tests.csproj +++ b/CapnpC.CSharp.MsBuild.Generation.Tests/CapnpC.CSharp.MsBuild.Generation.Tests.csproj @@ -4,6 +4,8 @@ netcoreapp2.2 false + + Debug;Release diff --git a/Capnpc.Csharp.MsBuild.Generation/CapnpCodeBehindGenerator.cs b/Capnpc.Csharp.MsBuild.Generation/CapnpCodeBehindGenerator.cs index 71c0592..6bc73be 100644 --- a/Capnpc.Csharp.MsBuild.Generation/CapnpCodeBehindGenerator.cs +++ b/Capnpc.Csharp.MsBuild.Generation/CapnpCodeBehindGenerator.cs @@ -13,8 +13,10 @@ namespace CapnpC.CSharp.MsBuild.Generation } - public CsFileGeneratorResult GenerateCodeBehindFile(string capnpFile) + public CsFileGeneratorResult GenerateCodeBehindFile(CapnpGenJob job) { + string capnpFile = job.CapnpPath; + // Works around a weird capnp.exe behavior: When the input file is empty, it will spit out an exception dump // instead of a parse error. But the parse error is nice because it contains a generated ID. We want the parse error! // Workaround: Generate a temporary file that contains a single line break (such that it is not empty...) @@ -27,7 +29,15 @@ namespace CapnpC.CSharp.MsBuild.Generation File.WriteAllText(tempFile, Environment.NewLine); try { - return GenerateCodeBehindFile(tempFile); + var jobCopy = new CapnpGenJob() + { + CapnpPath = tempFile, + WorkingDirectory = job.WorkingDirectory + }; + + jobCopy.AdditionalArguments.AddRange(job.AdditionalArguments); + + return GenerateCodeBehindFile(jobCopy); } finally { @@ -39,7 +49,11 @@ namespace CapnpC.CSharp.MsBuild.Generation { } - var result = CapnpCompilation.InvokeCapnpAndGenerate(new string[] { capnpFile }); + var args = new List(); + args.AddRange(job.AdditionalArguments); + args.Add(capnpFile); + + var result = CapnpCompilation.InvokeCapnpAndGenerate(args, job.WorkingDirectory); if (result.IsSuccess) { diff --git a/Capnpc.Csharp.MsBuild.Generation/CapnpFileCodeBehindGenerator.cs b/Capnpc.Csharp.MsBuild.Generation/CapnpFileCodeBehindGenerator.cs index 188830b..26af336 100644 --- a/Capnpc.Csharp.MsBuild.Generation/CapnpFileCodeBehindGenerator.cs +++ b/Capnpc.Csharp.MsBuild.Generation/CapnpFileCodeBehindGenerator.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Microsoft.Build.Framework; using Microsoft.Build.Utilities; namespace CapnpC.CSharp.MsBuild.Generation @@ -18,10 +19,8 @@ namespace CapnpC.CSharp.MsBuild.Generation public IEnumerable GenerateFilesForProject( string projectPath, - List capnpFiles, - string projectFolder, - string workingDirectory, - string additionalOptions) + List capnpFiles, + string projectFolder) { using (var capnpCodeBehindGenerator = new CapnpCodeBehindGenerator()) { @@ -34,9 +33,14 @@ namespace CapnpC.CSharp.MsBuild.Generation yield break; } - foreach (var capnpFile in capnpFiles) + foreach (var genJob in capnpFiles) { - var generatorResult = capnpCodeBehindGenerator.GenerateCodeBehindFile(capnpFile); + Log.LogMessage(MessageImportance.Normal, "Generate {0}, working dir = {1}, options = {2}", + genJob.CapnpPath, + genJob.WorkingDirectory, + string.Join(" ", genJob.AdditionalArguments)); + + var generatorResult = capnpCodeBehindGenerator.GenerateCodeBehindFile(genJob); if (!generatorResult.Success) { @@ -55,7 +59,7 @@ namespace CapnpC.CSharp.MsBuild.Generation subcategory: null, errorCode: null, helpKeyword: null, - file: capnpFile, + file: genJob.CapnpPath, lineNumber: message.Line, columnNumber: message.Column, endLineNumber: message.Line, diff --git a/Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.csproj b/Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.csproj index 6c20fd2..c45d18d 100644 --- a/Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.csproj +++ b/Capnpc.Csharp.MsBuild.Generation/Capnpc.Csharp.MsBuild.Generation.csproj @@ -11,19 +11,22 @@ $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb 1.0.0.0 1.0.0.0 - 1.0.0 - + 1.0-local$([System.DateTime]::UtcNow.ToString(yyMMddHHmm)) + $(MSBuildThisFileDirectory)CapnpC.CSharp.MsBuild.Generation.nuspec version=$(Version);configuration=$(Configuration) true + ..\bin\$(Configuration) + Debug;Release - + + @@ -41,7 +44,8 @@ - + + @@ -103,4 +107,8 @@ + + + + \ No newline at end of file diff --git a/Capnpc.Csharp.MsBuild.Generation/GenerateCapnpFileCodeBehindTask.cs b/Capnpc.Csharp.MsBuild.Generation/GenerateCapnpFileCodeBehindTask.cs index d29cf8d..459af9b 100644 --- a/Capnpc.Csharp.MsBuild.Generation/GenerateCapnpFileCodeBehindTask.cs +++ b/Capnpc.Csharp.MsBuild.Generation/GenerateCapnpFileCodeBehindTask.cs @@ -25,13 +25,43 @@ namespace CapnpC.CSharp.MsBuild.Generation public ITaskItem[] CapnpFiles { get; set; } - public string WorkingDirectory { get; set; } - - public string AdditionalOptions { get; set; } - [Output] public ITaskItem[] GeneratedFiles { get; private set; } + static CapnpGenJob ToGenJob(ITaskItem item) + { + var job = new CapnpGenJob() + { + CapnpPath = item.GetMetadata("FullPath"), + WorkingDirectory = item.GetMetadata("WorkingDirectory") + }; + + string importPaths = item.GetMetadata("ImportPaths"); + + if (!string.IsNullOrWhiteSpace(importPaths)) + { + job.AdditionalArguments.AddRange(importPaths.Split(new char[] { ';' }, + StringSplitOptions.RemoveEmptyEntries).Select(p => $"-I\"{p.TrimEnd('\\')}\"")); + } + + string sourcePrefix = item.GetMetadata("SourcePrefix"); + + if (!string.IsNullOrWhiteSpace(sourcePrefix)) + { + job.AdditionalArguments.Add(sourcePrefix); + } + + + string verbose = item.GetMetadata("Verbose"); + + if ("true".Equals(verbose, StringComparison.OrdinalIgnoreCase)) + { + job.AdditionalArguments.Add("--verbose"); + } + + return job; + } + public override bool Execute() { try @@ -56,16 +86,14 @@ namespace CapnpC.CSharp.MsBuild.Generation var generator = CodeBehindGenerator ?? new CapnpFileCodeBehindGenerator(Log); - Log.LogWithNameTag(Log.LogMessage, "Starting GenerateFeatureFileCodeBehind"); + Log.LogWithNameTag(Log.LogMessage, "Starting GenerateCapnpFileCodeBehind"); - var capnpFiles = CapnpFiles?.Select(i => i.ItemSpec).ToList() ?? new List(); + var capnpFiles = CapnpFiles?.Select(ToGenJob).ToList() ?? new List(); var generatedFiles = generator.GenerateFilesForProject( ProjectPath, capnpFiles, - ProjectFolder, - WorkingDirectory, - AdditionalOptions); + ProjectFolder); GeneratedFiles = generatedFiles.Select(file => new TaskItem { ItemSpec = file }).ToArray(); diff --git a/Capnpc.Csharp.MsBuild.Generation/ICapnpCsharpGenerator.cs b/Capnpc.Csharp.MsBuild.Generation/ICapnpCsharpGenerator.cs index de828fd..965b0ce 100644 --- a/Capnpc.Csharp.MsBuild.Generation/ICapnpCsharpGenerator.cs +++ b/Capnpc.Csharp.MsBuild.Generation/ICapnpCsharpGenerator.cs @@ -4,6 +4,6 @@ namespace CapnpC.CSharp.MsBuild.Generation { public interface ICapnpcCsharpGenerator { - IEnumerable GenerateFilesForProject(string projectPath, List capnpFiles, string projectFolder, string workingDirectory, string additionalOptions); + IEnumerable GenerateFilesForProject(string projectPath, List jobs, string projectFolder); } } \ No newline at end of file diff --git a/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/CapnpFileType.xaml b/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/CapnpFileType.xaml index 72e5c94..c938967 100644 --- a/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/CapnpFileType.xaml +++ b/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/CapnpFileType.xaml @@ -27,17 +27,20 @@ - + - - - - - - --> + + + + + + + \ No newline at end of file diff --git a/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.props b/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.props index bc41f4e..2d2682c 100644 --- a/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.props +++ b/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.props @@ -47,6 +47,7 @@ %(RelativeDir)%(Filename).capnp.cs $(UsingMicrosoftNETSdk) + $(ProjectDir) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/ProjectItemsSchema.xaml b/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/ProjectItemsSchema.xaml deleted file mode 100644 index 1cf7ddb..0000000 --- a/Capnpc.Csharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/ProjectItemsSchema.xaml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.props b/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.props deleted file mode 100644 index 2d2682c..0000000 --- a/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.props +++ /dev/null @@ -1,78 +0,0 @@ - - - - $(MSBuildThisFileDirectory)CPS\Buildsystem\CpsExtension.DesignTime.targets - - - - - - - false - $(CapnpcCsharp_UseHostCompilerIfAvailable) - - - - - false - false - - false - true - false - - <_CapnpcCsharpPropsImported Condition="'$(_CapnpcCsharpPropsImported)'==''">true - - - - - - - false - - - true - $(CapnpcCsharp_EnableDefaultCompileItems) - - $(DefaultItemExcludes);**/*.capnp - - - - - %(RelativeDir)%(Filename).capnp.cs - $(UsingMicrosoftNETSdk) - $(ProjectDir) - - - - - - - - - - - - - - - <_CapnpcCsharp_TaskFolder Condition=" '$(MSBuildRuntimeType)' == 'Core' And '$(_CapnpcCsharp_TaskFolder)' == ''">netcoreapp2.1 - <_CapnpcCsharp_TaskFolder Condition=" '$(MSBuildRuntimeType)' != 'Core' And '$(_CapnpcCsharp_TaskFolder)' == ''">net471 - <_CapnpcCsharp_TaskAssembly Condition=" '$(_CapnpcCsharp_TaskAssembly)' == '' ">..\tasks\$(_CapnpcCsharp_TaskFolder)\CapnpC.CSharp.MsBuild.Generation.dll - - - - - diff --git a/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.targets b/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.targets deleted file mode 100644 index 718f826..0000000 --- a/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.targets +++ /dev/null @@ -1,133 +0,0 @@ - - - - - - false - true - - - <_CapnpcCsharp_EnableDefaultCompileItems Condition="'$(CapnpcCsharp_EnableDefaultCompileItems)' == '' And '$(UsingMicrosoftNETSdk)' == 'true'">true - <_CapnpcCsharp_EnableDefaultCompileItems Condition="'$(CapnpcCsharp_EnableDefaultCompileItems)' == 'true' And '$(UsingMicrosoftNETSdk)' == 'true'">true - - - - - BeforeUpdateCapnpFilesInProject; - UpdateCapnpFilesInProject; - IncludeCodeBehindFilesInProject; - AfterUpdateCapnpFilesInProject; - $(BuildDependsOn) - - - CleanCapnpFilesInProject; - $(CleanDependsOn) - - - SwitchToForceGenerate; - $(RebuildDependsOn) - - - - - - - - - - - - - - - - - - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.tasks b/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.tasks deleted file mode 100644 index 9859d7b..0000000 --- a/Capnpc.Csharp.MsBuild.Generation/build/Capnpc.Csharp.MsBuild.Generation.tasks +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/Capnpc.Csharp.MsBuild.Generation/buildMultiTargeting/Capnpc.Csharp.MsBuild.Generation.props b/Capnpc.Csharp.MsBuild.Generation/buildMultiTargeting/Capnpc.Csharp.MsBuild.Generation.props deleted file mode 100644 index 62930dd..0000000 --- a/Capnpc.Csharp.MsBuild.Generation/buildMultiTargeting/Capnpc.Csharp.MsBuild.Generation.props +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file From a7f3c71960a813f963482a73a41937130f633dd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6llner?= Date: Sun, 15 Sep 2019 21:11:03 +0200 Subject: [PATCH 13/22] Fix casing problem, part II --- .../CapnpC.CSharp.MsBuild.Generation.csproj | 114 +++++++++++++++ .../CapnpC.CSharp.MsBuild.Generation.nuspec | 31 ++++ .../CpsExtension.DesignTime.targets | 15 ++ .../CPS/Buildsystem/Rules/CapnpFileType.xaml | 46 ++++++ .../Buildsystem/Rules/ProjectItemsSchema.xaml | 18 +++ .../CapnpC.CSharp.MsBuild.Generation.props | 78 ++++++++++ .../CapnpC.CSharp.MsBuild.Generation.targets | 133 ++++++++++++++++++ .../CapnpC.CSharp.MsBuild.Generation.tasks | 3 + .../CapnpC.CSharp.MsBuild.Generation.props | 5 + 9 files changed, 443 insertions(+) create mode 100644 CapnpC.CSharp.MsBuild.Generation/CapnpC.CSharp.MsBuild.Generation.csproj create mode 100644 CapnpC.CSharp.MsBuild.Generation/CapnpC.CSharp.MsBuild.Generation.nuspec create mode 100644 CapnpC.CSharp.MsBuild.Generation/build/CPS/Buildsystem/CpsExtension.DesignTime.targets create mode 100644 CapnpC.CSharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/CapnpFileType.xaml create mode 100644 CapnpC.CSharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/ProjectItemsSchema.xaml create mode 100644 CapnpC.CSharp.MsBuild.Generation/build/CapnpC.CSharp.MsBuild.Generation.props create mode 100644 CapnpC.CSharp.MsBuild.Generation/build/CapnpC.CSharp.MsBuild.Generation.targets create mode 100644 CapnpC.CSharp.MsBuild.Generation/build/CapnpC.CSharp.MsBuild.Generation.tasks create mode 100644 CapnpC.CSharp.MsBuild.Generation/buildMultiTargeting/CapnpC.CSharp.MsBuild.Generation.props diff --git a/CapnpC.CSharp.MsBuild.Generation/CapnpC.CSharp.MsBuild.Generation.csproj b/CapnpC.CSharp.MsBuild.Generation/CapnpC.CSharp.MsBuild.Generation.csproj new file mode 100644 index 0000000..c45d18d --- /dev/null +++ b/CapnpC.CSharp.MsBuild.Generation/CapnpC.CSharp.MsBuild.Generation.csproj @@ -0,0 +1,114 @@ + + + net471;netcoreapp2.1 + false + + true + true + + true + true + $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb + 1.0.0.0 + 1.0.0.0 + 1.0-local$([System.DateTime]::UtcNow.ToString(yyMMddHHmm)) + + $(MSBuildThisFileDirectory)CapnpC.CSharp.MsBuild.Generation.nuspec + version=$(Version);configuration=$(Configuration) + true + ..\bin\$(Configuration) + Debug;Release + + + + + + + + + + + + + + + All + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + + + + Microsoft.Build + + + Microsoft.Build.Framework + + + Microsoft.Build.Utilities.Core + + + + + + + Always + + + Always + + + Always + + + Always + + + Always + + + MSBuild:Compile + Always + + + MSBuild:Compile + Always + + + + + + + + \ No newline at end of file diff --git a/CapnpC.CSharp.MsBuild.Generation/CapnpC.CSharp.MsBuild.Generation.nuspec b/CapnpC.CSharp.MsBuild.Generation/CapnpC.CSharp.MsBuild.Generation.nuspec new file mode 100644 index 0000000..e048bb9 --- /dev/null +++ b/CapnpC.CSharp.MsBuild.Generation/CapnpC.CSharp.MsBuild.Generation.nuspec @@ -0,0 +1,31 @@ + + + + CapnpC.CSharp.MsBuild.Generation + $version$ + CapnpC.CSharp.MsBuild.Generation + Christian Köllner and contributors + Christian Köllner + Package to enable the .capnp -> .cs file generation during build time + Package to enable the .capnp -> .cs file generation during build time + en-US + https://github.com/c80k/capnproto-dotnetcore + false + MIT + capnproto csharp msbuild + Christian Köllner and contributors + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CapnpC.CSharp.MsBuild.Generation/build/CPS/Buildsystem/CpsExtension.DesignTime.targets b/CapnpC.CSharp.MsBuild.Generation/build/CPS/Buildsystem/CpsExtension.DesignTime.targets new file mode 100644 index 0000000..4f6883c --- /dev/null +++ b/CapnpC.CSharp.MsBuild.Generation/build/CPS/Buildsystem/CpsExtension.DesignTime.targets @@ -0,0 +1,15 @@ + + + + + $(MSBuildThisFileDirectory)Rules\ + + + + + + + File;BrowseObject + + + \ No newline at end of file diff --git a/CapnpC.CSharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/CapnpFileType.xaml b/CapnpC.CSharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/CapnpFileType.xaml new file mode 100644 index 0000000..c938967 --- /dev/null +++ b/CapnpC.CSharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/CapnpFileType.xaml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CapnpC.CSharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/ProjectItemsSchema.xaml b/CapnpC.CSharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/ProjectItemsSchema.xaml new file mode 100644 index 0000000..1cf7ddb --- /dev/null +++ b/CapnpC.CSharp.MsBuild.Generation/build/CPS/Buildsystem/Rules/ProjectItemsSchema.xaml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CapnpC.CSharp.MsBuild.Generation/build/CapnpC.CSharp.MsBuild.Generation.props b/CapnpC.CSharp.MsBuild.Generation/build/CapnpC.CSharp.MsBuild.Generation.props new file mode 100644 index 0000000..2d2682c --- /dev/null +++ b/CapnpC.CSharp.MsBuild.Generation/build/CapnpC.CSharp.MsBuild.Generation.props @@ -0,0 +1,78 @@ + + + + $(MSBuildThisFileDirectory)CPS\Buildsystem\CpsExtension.DesignTime.targets + + + + + + + false + $(CapnpcCsharp_UseHostCompilerIfAvailable) + + + + + false + false + + false + true + false + + <_CapnpcCsharpPropsImported Condition="'$(_CapnpcCsharpPropsImported)'==''">true + + + + + + + false + + + true + $(CapnpcCsharp_EnableDefaultCompileItems) + + $(DefaultItemExcludes);**/*.capnp + + + + + %(RelativeDir)%(Filename).capnp.cs + $(UsingMicrosoftNETSdk) + $(ProjectDir) + + + + + + + + + + + + + + + <_CapnpcCsharp_TaskFolder Condition=" '$(MSBuildRuntimeType)' == 'Core' And '$(_CapnpcCsharp_TaskFolder)' == ''">netcoreapp2.1 + <_CapnpcCsharp_TaskFolder Condition=" '$(MSBuildRuntimeType)' != 'Core' And '$(_CapnpcCsharp_TaskFolder)' == ''">net471 + <_CapnpcCsharp_TaskAssembly Condition=" '$(_CapnpcCsharp_TaskAssembly)' == '' ">..\tasks\$(_CapnpcCsharp_TaskFolder)\CapnpC.CSharp.MsBuild.Generation.dll + + + + + diff --git a/CapnpC.CSharp.MsBuild.Generation/build/CapnpC.CSharp.MsBuild.Generation.targets b/CapnpC.CSharp.MsBuild.Generation/build/CapnpC.CSharp.MsBuild.Generation.targets new file mode 100644 index 0000000..718f826 --- /dev/null +++ b/CapnpC.CSharp.MsBuild.Generation/build/CapnpC.CSharp.MsBuild.Generation.targets @@ -0,0 +1,133 @@ + + + + + + false + true + + + <_CapnpcCsharp_EnableDefaultCompileItems Condition="'$(CapnpcCsharp_EnableDefaultCompileItems)' == '' And '$(UsingMicrosoftNETSdk)' == 'true'">true + <_CapnpcCsharp_EnableDefaultCompileItems Condition="'$(CapnpcCsharp_EnableDefaultCompileItems)' == 'true' And '$(UsingMicrosoftNETSdk)' == 'true'">true + + + + + BeforeUpdateCapnpFilesInProject; + UpdateCapnpFilesInProject; + IncludeCodeBehindFilesInProject; + AfterUpdateCapnpFilesInProject; + $(BuildDependsOn) + + + CleanCapnpFilesInProject; + $(CleanDependsOn) + + + SwitchToForceGenerate; + $(RebuildDependsOn) + + + + + + + + + + + + + + + + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CapnpC.CSharp.MsBuild.Generation/build/CapnpC.CSharp.MsBuild.Generation.tasks b/CapnpC.CSharp.MsBuild.Generation/build/CapnpC.CSharp.MsBuild.Generation.tasks new file mode 100644 index 0000000..9859d7b --- /dev/null +++ b/CapnpC.CSharp.MsBuild.Generation/build/CapnpC.CSharp.MsBuild.Generation.tasks @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/CapnpC.CSharp.MsBuild.Generation/buildMultiTargeting/CapnpC.CSharp.MsBuild.Generation.props b/CapnpC.CSharp.MsBuild.Generation/buildMultiTargeting/CapnpC.CSharp.MsBuild.Generation.props new file mode 100644 index 0000000..62930dd --- /dev/null +++ b/CapnpC.CSharp.MsBuild.Generation/buildMultiTargeting/CapnpC.CSharp.MsBuild.Generation.props @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file From ede2441008ca82baae032770f2b24786b04475c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6llner?= Date: Sun, 15 Sep 2019 22:16:46 +0200 Subject: [PATCH 14/22] Fixes --- CapnpC.CSharp.MsBuild.Generation.Tests/TaskItemMock.cs | 7 ++++++- .../CapnpC.CSharp.MsBuild.Generation.csproj | 1 - 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CapnpC.CSharp.MsBuild.Generation.Tests/TaskItemMock.cs b/CapnpC.CSharp.MsBuild.Generation.Tests/TaskItemMock.cs index 6cf0f5a..dd6174c 100644 --- a/CapnpC.CSharp.MsBuild.Generation.Tests/TaskItemMock.cs +++ b/CapnpC.CSharp.MsBuild.Generation.Tests/TaskItemMock.cs @@ -23,7 +23,12 @@ namespace CapnpC.CSharp.MsBuild.Generation.Tests public string GetMetadata(string metadataName) { - return null; + if (metadataName == "FullPath") + { + return ItemSpec; + } + + return string.Empty; } public void RemoveMetadata(string metadataName) diff --git a/CapnpC.CSharp.MsBuild.Generation/CapnpC.CSharp.MsBuild.Generation.csproj b/CapnpC.CSharp.MsBuild.Generation/CapnpC.CSharp.MsBuild.Generation.csproj index c45d18d..f471873 100644 --- a/CapnpC.CSharp.MsBuild.Generation/CapnpC.CSharp.MsBuild.Generation.csproj +++ b/CapnpC.CSharp.MsBuild.Generation/CapnpC.CSharp.MsBuild.Generation.csproj @@ -26,7 +26,6 @@ - From edb30a7bcee721d372d94232cf6d09ce3a3b3572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6llner?= Date: Wed, 2 Oct 2019 14:36:31 +0200 Subject: [PATCH 15/22] Fixed broken .gitignore --- .gitignore | 1 - .../AssemblyAttributes.cs | 4 + .../CapnpCodeBehindGenerator.cs | 99 + .../CapnpFileCodeBehindGenerator.cs | 88 + .../CapnpGenJob.cs | 11 + .../CodeBehindWriter.cs | 38 + .../CsFileGeneratorResult.cs | 51 + .../FileSystemHelper.cs | 112 + .../GenerateCapnpFileCodeBehindTask.cs | 136 + .../Helper/LogExtensions.cs | 22 + .../ICapnpCsharpGenerator.cs | 9 + MsBuildGenerationTest/AddressBook.capnp.cs | 412 + MsBuildGenerationTest/Program.cs | 12 + MsBuildGenerationTest/capnp/c++.capnp.cs | 10 + .../capnp/compat/json-test.capnp.cs | 1559 ++ .../capnp/compat/json.capnp.cs | 536 + .../capnp/rpc-twoparty.capnp.cs | 393 + MsBuildGenerationTest/capnp/rpc.capnp.cs | 2641 +++ MsBuildGenerationTest/capnp/schema.capnp.cs | 4309 ++++ .../capnp/test-import.capnp.cs | 67 + .../capnp/test-import2.capnp.cs | 97 + MsBuildGenerationTest/capnp/test.capnp.cs | 16200 ++++++++++++++++ 22 files changed, 26806 insertions(+), 1 deletion(-) create mode 100644 CapnpC.CSharp.MsBuild.Generation/AssemblyAttributes.cs create mode 100644 CapnpC.CSharp.MsBuild.Generation/CapnpCodeBehindGenerator.cs create mode 100644 CapnpC.CSharp.MsBuild.Generation/CapnpFileCodeBehindGenerator.cs create mode 100644 CapnpC.CSharp.MsBuild.Generation/CapnpGenJob.cs create mode 100644 CapnpC.CSharp.MsBuild.Generation/CodeBehindWriter.cs create mode 100644 CapnpC.CSharp.MsBuild.Generation/CsFileGeneratorResult.cs create mode 100644 CapnpC.CSharp.MsBuild.Generation/FileSystemHelper.cs create mode 100644 CapnpC.CSharp.MsBuild.Generation/GenerateCapnpFileCodeBehindTask.cs create mode 100644 CapnpC.CSharp.MsBuild.Generation/Helper/LogExtensions.cs create mode 100644 CapnpC.CSharp.MsBuild.Generation/ICapnpCsharpGenerator.cs create mode 100644 MsBuildGenerationTest/AddressBook.capnp.cs create mode 100644 MsBuildGenerationTest/Program.cs create mode 100644 MsBuildGenerationTest/capnp/c++.capnp.cs create mode 100644 MsBuildGenerationTest/capnp/compat/json-test.capnp.cs create mode 100644 MsBuildGenerationTest/capnp/compat/json.capnp.cs create mode 100644 MsBuildGenerationTest/capnp/rpc-twoparty.capnp.cs create mode 100644 MsBuildGenerationTest/capnp/rpc.capnp.cs create mode 100644 MsBuildGenerationTest/capnp/schema.capnp.cs create mode 100644 MsBuildGenerationTest/capnp/test-import.capnp.cs create mode 100644 MsBuildGenerationTest/capnp/test-import2.capnp.cs create mode 100644 MsBuildGenerationTest/capnp/test.capnp.cs diff --git a/.gitignore b/.gitignore index 1f39135..4f734c3 100644 --- a/.gitignore +++ b/.gitignore @@ -336,4 +336,3 @@ ASALocalRun/ # Capnp code behind .capnp.cs /globalPackages -*.cs diff --git a/CapnpC.CSharp.MsBuild.Generation/AssemblyAttributes.cs b/CapnpC.CSharp.MsBuild.Generation/AssemblyAttributes.cs new file mode 100644 index 0000000..ff364dc --- /dev/null +++ b/CapnpC.CSharp.MsBuild.Generation/AssemblyAttributes.cs @@ -0,0 +1,4 @@ + +using System.Runtime.CompilerServices; +using System.Security; + diff --git a/CapnpC.CSharp.MsBuild.Generation/CapnpCodeBehindGenerator.cs b/CapnpC.CSharp.MsBuild.Generation/CapnpCodeBehindGenerator.cs new file mode 100644 index 0000000..6bc73be --- /dev/null +++ b/CapnpC.CSharp.MsBuild.Generation/CapnpCodeBehindGenerator.cs @@ -0,0 +1,99 @@ +using CapnpC.CSharp.Generator; +using System; +using System.Collections.Generic; +using System.IO; + +namespace CapnpC.CSharp.MsBuild.Generation +{ + public class CapnpCodeBehindGenerator : IDisposable + { + + public void InitializeProject(string projectPath) + { + } + + + public CsFileGeneratorResult GenerateCodeBehindFile(CapnpGenJob job) + { + string capnpFile = job.CapnpPath; + + // Works around a weird capnp.exe behavior: When the input file is empty, it will spit out an exception dump + // instead of a parse error. But the parse error is nice because it contains a generated ID. We want the parse error! + // Workaround: Generate a temporary file that contains a single line break (such that it is not empty...) + try + { + if (File.Exists(capnpFile) && new FileInfo(capnpFile).Length == 0) + { + string tempFile = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + ".capnp"); + + File.WriteAllText(tempFile, Environment.NewLine); + try + { + var jobCopy = new CapnpGenJob() + { + CapnpPath = tempFile, + WorkingDirectory = job.WorkingDirectory + }; + + jobCopy.AdditionalArguments.AddRange(job.AdditionalArguments); + + return GenerateCodeBehindFile(jobCopy); + } + finally + { + File.Delete(tempFile); + } + } + } + catch + { + } + + var args = new List(); + args.AddRange(job.AdditionalArguments); + args.Add(capnpFile); + + var result = CapnpCompilation.InvokeCapnpAndGenerate(args, job.WorkingDirectory); + + if (result.IsSuccess) + { + if (result.GeneratedFiles.Count == 1) + { + return new CsFileGeneratorResult( + result.GeneratedFiles[0], + capnpFile + ".cs", + result.Messages); + } + else + { + return new CsFileGeneratorResult( + "Code generation produced more than one file. This is not supported.", + result.Messages); + } + } + else + { + switch (result.ErrorCategory) + { + case CapnpProcessFailure.NotFound: + return new CsFileGeneratorResult("Unable to find capnp.exe - please install capnproto on your system first."); + + case CapnpProcessFailure.BadInput: + return new CsFileGeneratorResult("Invalid schema", result.Messages); + + case CapnpProcessFailure.BadOutput: + return new CsFileGeneratorResult( + "Internal error: capnp.exe produced a binary code generation request which was not understood by the backend", + result.Messages); + + default: + throw new NotSupportedException("Invalid error category"); + } + } + } + + public void Dispose() + { + } + } +} \ No newline at end of file diff --git a/CapnpC.CSharp.MsBuild.Generation/CapnpFileCodeBehindGenerator.cs b/CapnpC.CSharp.MsBuild.Generation/CapnpFileCodeBehindGenerator.cs new file mode 100644 index 0000000..26af336 --- /dev/null +++ b/CapnpC.CSharp.MsBuild.Generation/CapnpFileCodeBehindGenerator.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; + +namespace CapnpC.CSharp.MsBuild.Generation +{ + public class CapnpFileCodeBehindGenerator : ICapnpcCsharpGenerator + { + public CapnpFileCodeBehindGenerator(TaskLoggingHelper log) + { + Log = log ?? throw new ArgumentNullException(nameof(log)); + } + + public TaskLoggingHelper Log { get; } + + public IEnumerable GenerateFilesForProject( + string projectPath, + List capnpFiles, + string projectFolder) + { + using (var capnpCodeBehindGenerator = new CapnpCodeBehindGenerator()) + { + capnpCodeBehindGenerator.InitializeProject(projectPath); + + var codeBehindWriter = new CodeBehindWriter(null); + + if (capnpFiles == null) + { + yield break; + } + + foreach (var genJob in capnpFiles) + { + Log.LogMessage(MessageImportance.Normal, "Generate {0}, working dir = {1}, options = {2}", + genJob.CapnpPath, + genJob.WorkingDirectory, + string.Join(" ", genJob.AdditionalArguments)); + + var generatorResult = capnpCodeBehindGenerator.GenerateCodeBehindFile(genJob); + + if (!generatorResult.Success) + { + if (!string.IsNullOrEmpty(generatorResult.Error)) + { + Log.LogError("{0}", generatorResult.Error); + } + + if (generatorResult.Messages != null) + { + foreach (var message in generatorResult.Messages) + { + if (message.IsParseSuccess) + { + Log.LogError( + subcategory: null, + errorCode: null, + helpKeyword: null, + file: genJob.CapnpPath, + lineNumber: message.Line, + columnNumber: message.Column, + endLineNumber: message.Line, + endColumnNumber: message.EndColumn == 0 ? message.Column : message.EndColumn, + "{0}", + message.MessageText); + } + else + { + Log.LogError("{0}", message.FullMessage); + } + } + } + + continue; + } + + var resultedFile = codeBehindWriter.WriteCodeBehindFile(generatorResult.Filename, generatorResult); + + yield return FileSystemHelper.GetRelativePath(resultedFile, projectFolder); + } + } + + } + } +} diff --git a/CapnpC.CSharp.MsBuild.Generation/CapnpGenJob.cs b/CapnpC.CSharp.MsBuild.Generation/CapnpGenJob.cs new file mode 100644 index 0000000..0ac6201 --- /dev/null +++ b/CapnpC.CSharp.MsBuild.Generation/CapnpGenJob.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; + +namespace CapnpC.CSharp.MsBuild.Generation +{ + public class CapnpGenJob + { + public string CapnpPath { get; set; } + public string WorkingDirectory { get; set; } + public List AdditionalArguments { get; } = new List(); + } +} \ No newline at end of file diff --git a/CapnpC.CSharp.MsBuild.Generation/CodeBehindWriter.cs b/CapnpC.CSharp.MsBuild.Generation/CodeBehindWriter.cs new file mode 100644 index 0000000..3ff276b --- /dev/null +++ b/CapnpC.CSharp.MsBuild.Generation/CodeBehindWriter.cs @@ -0,0 +1,38 @@ +using System; +using System.IO; +using Microsoft.Build.Utilities; + +namespace CapnpC.CSharp.MsBuild.Generation +{ + public class CodeBehindWriter + { + public CodeBehindWriter(TaskLoggingHelper log) + { + Log = log; + } + + public TaskLoggingHelper Log { get; } + + public string WriteCodeBehindFile(string outputPath, CsFileGeneratorResult testFileGeneratorResult) + { + string directoryPath = Path.GetDirectoryName(outputPath) ?? throw new InvalidOperationException(); + Log?.LogWithNameTag(Log.LogMessage, directoryPath); + + Log?.LogWithNameTag(Log.LogMessage, $"Writing data to {outputPath}; path = {directoryPath}; generatedFilename = {testFileGeneratorResult.Filename}"); + + if (File.Exists(outputPath)) + { + if (!FileSystemHelper.FileCompareContent(outputPath, testFileGeneratorResult.GeneratedCode)) + { + File.WriteAllText(outputPath, testFileGeneratorResult.GeneratedCode); + } + } + else + { + File.WriteAllText(outputPath, testFileGeneratorResult.GeneratedCode); + } + + return outputPath; + } + } +} diff --git a/CapnpC.CSharp.MsBuild.Generation/CsFileGeneratorResult.cs b/CapnpC.CSharp.MsBuild.Generation/CsFileGeneratorResult.cs new file mode 100644 index 0000000..75961ac --- /dev/null +++ b/CapnpC.CSharp.MsBuild.Generation/CsFileGeneratorResult.cs @@ -0,0 +1,51 @@ +using CapnpC.CSharp.Generator; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace CapnpC.CSharp.MsBuild.Generation +{ + public class CsFileGeneratorResult + { + public CsFileGeneratorResult(FileGenerationResult generatorResult, string fileName, IReadOnlyList messages) + { + if (generatorResult == null) + { + throw new ArgumentNullException(nameof(generatorResult)); + } + + Filename = fileName ?? throw new ArgumentNullException(nameof(fileName)); + + Error = generatorResult.Exception?.Message; + GeneratedCode = generatorResult.GeneratedContent; + Messages = messages; + } + + public CsFileGeneratorResult(string error) + { + Error = error; + } + + public CsFileGeneratorResult(string error, IReadOnlyList messages) + { + Error = error; + Messages = messages; + } + + /// + /// The error, if any. + /// + public string Error { get; } + + /// + /// The generated code. + /// + public string GeneratedCode { get; } + + public IReadOnlyList Messages { get; } + + public bool Success => Error == null; + + public string Filename { get; } + } +} \ No newline at end of file diff --git a/CapnpC.CSharp.MsBuild.Generation/FileSystemHelper.cs b/CapnpC.CSharp.MsBuild.Generation/FileSystemHelper.cs new file mode 100644 index 0000000..d538531 --- /dev/null +++ b/CapnpC.CSharp.MsBuild.Generation/FileSystemHelper.cs @@ -0,0 +1,112 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Text; + +namespace CapnpC.CSharp.MsBuild.Generation +{ + public static class FileSystemHelper + { + public static void CopyFileToFolder(string filePath, string folderName) + { + File.Copy(filePath, Path.Combine(folderName, Path.GetFileName(filePath))); + } + + public static string GetRelativePath(string path, string basePath) + { + path = Path.GetFullPath(path); + basePath = Path.GetFullPath(basePath); + if (String.Equals(path, basePath, StringComparison.OrdinalIgnoreCase)) + return "."; // the "this folder" + + if (path.StartsWith(basePath + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase)) + return path.Substring(basePath.Length + 1); + + //handle different drives + string pathRoot = Path.GetPathRoot(path); + if (!String.Equals(pathRoot, Path.GetPathRoot(basePath), StringComparison.OrdinalIgnoreCase)) + return path; + + //handle ".." pathes + string[] pathParts = path.Substring(pathRoot.Length).Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); + string[] basePathParts = basePath.Substring(pathRoot.Length).Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); + + int commonFolderCount = 0; + while (commonFolderCount < pathParts.Length && commonFolderCount < basePathParts.Length && + String.Equals(pathParts[commonFolderCount], basePathParts[commonFolderCount], StringComparison.OrdinalIgnoreCase)) + commonFolderCount++; + + StringBuilder result = new StringBuilder(); + for (int i = 0; i < basePathParts.Length - commonFolderCount; i++) + { + result.Append(".."); + result.Append(Path.DirectorySeparatorChar); + } + + if (pathParts.Length - commonFolderCount == 0) + return result.ToString().TrimEnd(Path.DirectorySeparatorChar); + + result.Append(String.Join(Path.DirectorySeparatorChar.ToString(), pathParts, commonFolderCount, pathParts.Length - commonFolderCount)); + return result.ToString(); + } + + // This method accepts two strings the represent two files to + // compare. A return value of true indicates that the contents of the files + // are the same. A return value of any other value indicates that the + // files are not the same. + public static bool FileCompare(string filePath1, string filePath2) + { + int file1byte; + int file2byte; + + // Determine if the same file was referenced two times. + if (String.Equals(filePath1, filePath2, StringComparison.CurrentCultureIgnoreCase)) + { + // Return true to indicate that the files are the same. + return true; + } + + // Open the two files. + using (FileStream fs1 = new FileStream(filePath1, FileMode.Open, FileAccess.Read)) + { + using (FileStream fs2 = new FileStream(filePath2, FileMode.Open, FileAccess.Read)) + { + // Check the file sizes. If they are not the same, the files + // are not the same. + if (fs1.Length != fs2.Length) + { + // Return false to indicate files are different + return false; + } + + // Read and compare a byte from each file until either a + // non-matching set of bytes is found or until the end of + // file1 is reached. + do + { + // Read one byte from each file. + file1byte = fs1.ReadByte(); + file2byte = fs2.ReadByte(); + } while ((file1byte == file2byte) && (file1byte != -1)); + } + } + // Return the success of the comparison. "file1byte" is + // equal to "file2byte" at this point only if the files are + // the same. + return ((file1byte - file2byte) == 0); + } + + // This method accepts two strings the represent two files to + // compare. A return value of true indicates that the contents of the files + // are the same. A return value of any other value indicates that the + // files are not the same. + public static bool FileCompareContent(string filePath1, string fileContent) + { + var currentFileContent = File.ReadAllText(filePath1); + + return string.CompareOrdinal(currentFileContent, fileContent) == 0; + + } + } +} diff --git a/CapnpC.CSharp.MsBuild.Generation/GenerateCapnpFileCodeBehindTask.cs b/CapnpC.CSharp.MsBuild.Generation/GenerateCapnpFileCodeBehindTask.cs new file mode 100644 index 0000000..459af9b --- /dev/null +++ b/CapnpC.CSharp.MsBuild.Generation/GenerateCapnpFileCodeBehindTask.cs @@ -0,0 +1,136 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Resources; +using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; + +namespace CapnpC.CSharp.MsBuild.Generation +{ + public class GenerateCapnpFileCodeBehindTask : Task + { + public GenerateCapnpFileCodeBehindTask() + { + CodeBehindGenerator = new CapnpFileCodeBehindGenerator(Log); + } + + public ICapnpcCsharpGenerator CodeBehindGenerator { get; set; } + + [Required] + public string ProjectPath { get; set; } + + public string ProjectFolder => Path.GetDirectoryName(ProjectPath); + + public ITaskItem[] CapnpFiles { get; set; } + + [Output] + public ITaskItem[] GeneratedFiles { get; private set; } + + static CapnpGenJob ToGenJob(ITaskItem item) + { + var job = new CapnpGenJob() + { + CapnpPath = item.GetMetadata("FullPath"), + WorkingDirectory = item.GetMetadata("WorkingDirectory") + }; + + string importPaths = item.GetMetadata("ImportPaths"); + + if (!string.IsNullOrWhiteSpace(importPaths)) + { + job.AdditionalArguments.AddRange(importPaths.Split(new char[] { ';' }, + StringSplitOptions.RemoveEmptyEntries).Select(p => $"-I\"{p.TrimEnd('\\')}\"")); + } + + string sourcePrefix = item.GetMetadata("SourcePrefix"); + + if (!string.IsNullOrWhiteSpace(sourcePrefix)) + { + job.AdditionalArguments.Add(sourcePrefix); + } + + + string verbose = item.GetMetadata("Verbose"); + + if ("true".Equals(verbose, StringComparison.OrdinalIgnoreCase)) + { + job.AdditionalArguments.Add("--verbose"); + } + + return job; + } + + public override bool Execute() + { + try + { + try + { + var currentProcess = Process.GetCurrentProcess(); + + Log.LogWithNameTag(Log.LogMessage, $"process: {currentProcess.ProcessName}, pid: {currentProcess.Id}, CD: {Environment.CurrentDirectory}"); + + foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) + { + Log.LogWithNameTag(Log.LogMessage, " " + assembly.FullName); + } + } + catch (Exception e) + { + Log.LogWithNameTag(Log.LogMessage, $"Error when dumping process info: {e}"); + } + + AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; + + var generator = CodeBehindGenerator ?? new CapnpFileCodeBehindGenerator(Log); + + Log.LogWithNameTag(Log.LogMessage, "Starting GenerateCapnpFileCodeBehind"); + + var capnpFiles = CapnpFiles?.Select(ToGenJob).ToList() ?? new List(); + + var generatedFiles = generator.GenerateFilesForProject( + ProjectPath, + capnpFiles, + ProjectFolder); + + GeneratedFiles = generatedFiles.Select(file => new TaskItem { ItemSpec = file }).ToArray(); + + return !Log.HasLoggedErrors; + } + catch (Exception e) + { + if (e.InnerException != null) + { + if (e.InnerException is FileLoadException fle) + { + Log?.LogWithNameTag(Log.LogError, $"FileLoadException Filename: {fle.FileName}"); + Log?.LogWithNameTag(Log.LogError, $"FileLoadException FusionLog: {fle.FusionLog}"); + Log?.LogWithNameTag(Log.LogError, $"FileLoadException Message: {fle.Message}"); + } + + Log?.LogWithNameTag(Log.LogError, e.InnerException.ToString()); + } + + Log?.LogWithNameTag(Log.LogError, e.ToString()); + return false; + } + finally + { + AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve; + } + } + + private System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) + { + Log.LogWithNameTag(Log.LogMessage, args.Name); + + + return null; + } + + } + + +} \ No newline at end of file diff --git a/CapnpC.CSharp.MsBuild.Generation/Helper/LogExtensions.cs b/CapnpC.CSharp.MsBuild.Generation/Helper/LogExtensions.cs new file mode 100644 index 0000000..3203bea --- /dev/null +++ b/CapnpC.CSharp.MsBuild.Generation/Helper/LogExtensions.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Build.Utilities; + +namespace CapnpC.CSharp.MsBuild.Generation +{ + public static class LogExtensions + { + public static void LogWithNameTag( + this TaskLoggingHelper loggingHelper, + Action loggingMethod, + string message, + params object[] messageArgs) + { + string fullMessage = $"[Cap'n Proto] {message}"; + loggingMethod?.Invoke(fullMessage, messageArgs); + } + } +} diff --git a/CapnpC.CSharp.MsBuild.Generation/ICapnpCsharpGenerator.cs b/CapnpC.CSharp.MsBuild.Generation/ICapnpCsharpGenerator.cs new file mode 100644 index 0000000..965b0ce --- /dev/null +++ b/CapnpC.CSharp.MsBuild.Generation/ICapnpCsharpGenerator.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace CapnpC.CSharp.MsBuild.Generation +{ + public interface ICapnpcCsharpGenerator + { + IEnumerable GenerateFilesForProject(string projectPath, List jobs, string projectFolder); + } +} \ No newline at end of file diff --git a/MsBuildGenerationTest/AddressBook.capnp.cs b/MsBuildGenerationTest/AddressBook.capnp.cs new file mode 100644 index 0000000..ebffe97 --- /dev/null +++ b/MsBuildGenerationTest/AddressBook.capnp.cs @@ -0,0 +1,412 @@ +using Capnp; +using Capnp.Rpc; +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +namespace CapnpGen +{ + public class Person : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Id = reader.Id; + Name = reader.Name; + Email = reader.Email; + Phones = reader.Phones.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + Employment = CapnpSerializable.Create(reader.Employment); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Id = Id; + writer.Name = Name; + writer.Email = Email; + writer.Phones.Init(Phones, (_s1, _v1) => _v1?.serialize(_s1)); + Employment?.serialize(writer.Employment); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public uint Id + { + get; + set; + } + + public string Name + { + get; + set; + } + + public string Email + { + get; + set; + } + + public IReadOnlyList Phones + { + get; + set; + } + + public CapnpGen.Person.@employment Employment + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public uint Id => ctx.ReadDataUInt(0UL, 0U); + public string Name => ctx.ReadText(0, ""); + public string Email => ctx.ReadText(1, ""); + public IReadOnlyList Phones => ctx.ReadList(2).Cast(CapnpGen.Person.PhoneNumber.READER.create); + public @employment.READER Employment => new @employment.READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 4); + } + + public uint Id + { + get => this.ReadDataUInt(0UL, 0U); + set => this.WriteData(0UL, value, 0U); + } + + public string Name + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + + public string Email + { + get => this.ReadText(1, ""); + set => this.WriteText(1, value, ""); + } + + public ListOfStructsSerializer Phones + { + get => BuildPointer>(2); + set => Link(2, value); + } + + public @employment.WRITER Employment + { + get => Rewrap<@employment.WRITER>(); + } + } + + public class @employment : ICapnpSerializable + { + public enum WHICH : ushort + { + Unemployed = 0, + Employer = 1, + School = 2, + SelfEmployed = 3, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.Unemployed: + which = reader.which; + break; + case WHICH.Employer: + Employer = reader.Employer; + break; + case WHICH.School: + School = reader.School; + break; + case WHICH.SelfEmployed: + which = reader.which; + break; + } + + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.Unemployed: + break; + case WHICH.Employer: + _content = null; + break; + case WHICH.School: + _content = null; + break; + case WHICH.SelfEmployed: + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.Unemployed: + break; + case WHICH.Employer: + writer.Employer = Employer; + break; + case WHICH.School: + writer.School = School; + break; + case WHICH.SelfEmployed: + break; + } + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string Employer + { + get => _which == WHICH.Employer ? (string)_content : null; + set + { + _which = WHICH.Employer; + _content = value; + } + } + + public string School + { + get => _which == WHICH.School ? (string)_content : null; + set + { + _which = WHICH.School; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(32U, (ushort)0); + public string Employer => which == WHICH.Employer ? ctx.ReadText(3, "") : default; + public string School => which == WHICH.School ? ctx.ReadText(3, "") : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(32U, (ushort)0); + set => this.WriteData(32U, (ushort)value, (ushort)0); + } + + public string Employer + { + get => which == WHICH.Employer ? this.ReadText(3, "") : default; + set => this.WriteText(3, value, ""); + } + + public string School + { + get => which == WHICH.School ? this.ReadText(3, "") : default; + set => this.WriteText(3, value, ""); + } + } + } + + public class PhoneNumber : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Number = reader.Number; + TheType = reader.TheType; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Number = Number; + writer.TheType = TheType; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string Number + { + get; + set; + } + + public CapnpGen.Person.PhoneNumber.Type TheType + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string Number => ctx.ReadText(0, ""); + public CapnpGen.Person.PhoneNumber.Type TheType => (CapnpGen.Person.PhoneNumber.Type)ctx.ReadDataUShort(0UL, (ushort)0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public string Number + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + + public CapnpGen.Person.PhoneNumber.Type TheType + { + get => (CapnpGen.Person.PhoneNumber.Type)this.ReadDataUShort(0UL, (ushort)0); + set => this.WriteData(0UL, (ushort)value, (ushort)0); + } + } + + public enum Type : ushort + { + mobile, + home, + work + } + } + } + + public class AddressBook : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + People = reader.People.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.People.Init(People, (_s1, _v1) => _v1?.serialize(_s1)); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public IReadOnlyList People + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public IReadOnlyList People => ctx.ReadList(0).Cast(CapnpGen.Person.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public ListOfStructsSerializer People + { + get => BuildPointer>(0); + set => Link(0, value); + } + } + } +} \ No newline at end of file diff --git a/MsBuildGenerationTest/Program.cs b/MsBuildGenerationTest/Program.cs new file mode 100644 index 0000000..b07986b --- /dev/null +++ b/MsBuildGenerationTest/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace MsBuildGenerationTest +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + } + } +} diff --git a/MsBuildGenerationTest/capnp/c++.capnp.cs b/MsBuildGenerationTest/capnp/c++.capnp.cs new file mode 100644 index 0000000..e43c504 --- /dev/null +++ b/MsBuildGenerationTest/capnp/c++.capnp.cs @@ -0,0 +1,10 @@ +using Capnp; +using Capnp.Rpc; +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +namespace Capnp.Annotations +{ +} \ No newline at end of file diff --git a/MsBuildGenerationTest/capnp/compat/json-test.capnp.cs b/MsBuildGenerationTest/capnp/compat/json-test.capnp.cs new file mode 100644 index 0000000..c6366e6 --- /dev/null +++ b/MsBuildGenerationTest/capnp/compat/json-test.capnp.cs @@ -0,0 +1,1559 @@ +using Capnp; +using Capnp.Rpc; +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +namespace Capnp +{ + public class TestJsonAnnotations : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + SomeField = reader.SomeField; + AGroup = CapnpSerializable.Create(reader.AGroup); + PrefixedGroup = CapnpSerializable.Create(reader.PrefixedGroup); + AUnion = CapnpSerializable.Create(reader.AUnion); + Dependency = CapnpSerializable.Create(reader.Dependency); + SimpleGroup = CapnpSerializable.Create(reader.SimpleGroup); + Enums = reader.Enums; + InnerJson = CapnpSerializable.Create(reader.InnerJson); + CustomFieldHandler = reader.CustomFieldHandler; + TestBase64 = reader.TestBase64; + TestHex = reader.TestHex; + BUnion = CapnpSerializable.Create(reader.BUnion); + ExternalUnion = CapnpSerializable.Create(reader.ExternalUnion); + UnionWithVoid = CapnpSerializable.Create(reader.UnionWithVoid); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.SomeField = SomeField; + AGroup?.serialize(writer.AGroup); + PrefixedGroup?.serialize(writer.PrefixedGroup); + AUnion?.serialize(writer.AUnion); + Dependency?.serialize(writer.Dependency); + SimpleGroup?.serialize(writer.SimpleGroup); + writer.Enums.Init(Enums); + InnerJson?.serialize(writer.InnerJson); + writer.CustomFieldHandler = CustomFieldHandler; + writer.TestBase64.Init(TestBase64); + writer.TestHex.Init(TestHex); + BUnion?.serialize(writer.BUnion); + ExternalUnion?.serialize(writer.ExternalUnion); + UnionWithVoid?.serialize(writer.UnionWithVoid); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string SomeField + { + get; + set; + } + + public Capnp.TestJsonAnnotations.@aGroup AGroup + { + get; + set; + } + + public Capnp.TestJsonAnnotations.@prefixedGroup PrefixedGroup + { + get; + set; + } + + public Capnp.TestJsonAnnotations.@aUnion AUnion + { + get; + set; + } + + public Capnp.TestJsonAnnotations2 Dependency + { + get; + set; + } + + public Capnp.TestJsonAnnotations.@simpleGroup SimpleGroup + { + get; + set; + } + + public IReadOnlyList Enums + { + get; + set; + } + + public Capnp.Json.Value InnerJson + { + get; + set; + } + + public string CustomFieldHandler + { + get; + set; + } + + public IReadOnlyList TestBase64 + { + get; + set; + } + + public IReadOnlyList TestHex + { + get; + set; + } + + public Capnp.TestJsonAnnotations.@bUnion BUnion + { + get; + set; + } + + public Capnp.TestJsonAnnotations3 ExternalUnion + { + get; + set; + } + + public Capnp.TestJsonAnnotations.@unionWithVoid UnionWithVoid + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string SomeField => ctx.ReadText(0, ""); + public @aGroup.READER AGroup => new @aGroup.READER(ctx); + public @prefixedGroup.READER PrefixedGroup => new @prefixedGroup.READER(ctx); + public @aUnion.READER AUnion => new @aUnion.READER(ctx); + public Capnp.TestJsonAnnotations2.READER Dependency => ctx.ReadStruct(6, Capnp.TestJsonAnnotations2.READER.create); + public @simpleGroup.READER SimpleGroup => new @simpleGroup.READER(ctx); + public IReadOnlyList Enums => ctx.ReadList(8).CastEnums(_0 => (Capnp.TestJsonAnnotatedEnum)_0); + public Capnp.Json.Value.READER InnerJson => ctx.ReadStruct(9, Capnp.Json.Value.READER.create); + public string CustomFieldHandler => ctx.ReadText(10, ""); + public IReadOnlyList TestBase64 => ctx.ReadList(11).CastByte(); + public IReadOnlyList TestHex => ctx.ReadList(12).CastByte(); + public @bUnion.READER BUnion => new @bUnion.READER(ctx); + public Capnp.TestJsonAnnotations3.READER ExternalUnion => ctx.ReadStruct(14, Capnp.TestJsonAnnotations3.READER.create); + public @unionWithVoid.READER UnionWithVoid => new @unionWithVoid.READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(4, 16); + } + + public string SomeField + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + + public @aGroup.WRITER AGroup + { + get => Rewrap<@aGroup.WRITER>(); + } + + public @prefixedGroup.WRITER PrefixedGroup + { + get => Rewrap<@prefixedGroup.WRITER>(); + } + + public @aUnion.WRITER AUnion + { + get => Rewrap<@aUnion.WRITER>(); + } + + public Capnp.TestJsonAnnotations2.WRITER Dependency + { + get => BuildPointer(6); + set => Link(6, value); + } + + public @simpleGroup.WRITER SimpleGroup + { + get => Rewrap<@simpleGroup.WRITER>(); + } + + public ListOfPrimitivesSerializer Enums + { + get => BuildPointer>(8); + set => Link(8, value); + } + + public Capnp.Json.Value.WRITER InnerJson + { + get => BuildPointer(9); + set => Link(9, value); + } + + public string CustomFieldHandler + { + get => this.ReadText(10, ""); + set => this.WriteText(10, value, ""); + } + + public ListOfPrimitivesSerializer TestBase64 + { + get => BuildPointer>(11); + set => Link(11, value); + } + + public ListOfPrimitivesSerializer TestHex + { + get => BuildPointer>(12); + set => Link(12, value); + } + + public @bUnion.WRITER BUnion + { + get => Rewrap<@bUnion.WRITER>(); + } + + public Capnp.TestJsonAnnotations3.WRITER ExternalUnion + { + get => BuildPointer(14); + set => Link(14, value); + } + + public @unionWithVoid.WRITER UnionWithVoid + { + get => Rewrap<@unionWithVoid.WRITER>(); + } + } + + public class @aGroup : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + FlatFoo = reader.FlatFoo; + FlatBar = reader.FlatBar; + FlatBaz = CapnpSerializable.Create(reader.FlatBaz); + DoubleFlat = CapnpSerializable.Create(reader.DoubleFlat); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.FlatFoo = FlatFoo; + writer.FlatBar = FlatBar; + FlatBaz?.serialize(writer.FlatBaz); + DoubleFlat?.serialize(writer.DoubleFlat); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public uint FlatFoo + { + get; + set; + } + + public string FlatBar + { + get; + set; + } + + public Capnp.TestJsonAnnotations.@aGroup.@flatBaz FlatBaz + { + get; + set; + } + + public Capnp.TestJsonAnnotations.@aGroup.@doubleFlat DoubleFlat + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public uint FlatFoo => ctx.ReadDataUInt(0UL, 0U); + public string FlatBar => ctx.ReadText(1, ""); + public @flatBaz.READER FlatBaz => new @flatBaz.READER(ctx); + public @doubleFlat.READER DoubleFlat => new @doubleFlat.READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public uint FlatFoo + { + get => this.ReadDataUInt(0UL, 0U); + set => this.WriteData(0UL, value, 0U); + } + + public string FlatBar + { + get => this.ReadText(1, ""); + set => this.WriteText(1, value, ""); + } + + public @flatBaz.WRITER FlatBaz + { + get => Rewrap<@flatBaz.WRITER>(); + } + + public @doubleFlat.WRITER DoubleFlat + { + get => Rewrap<@doubleFlat.WRITER>(); + } + } + + public class @flatBaz : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Hello = reader.Hello; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Hello = Hello; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public bool Hello + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public bool Hello => ctx.ReadDataBool(32UL, false); + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public bool Hello + { + get => this.ReadDataBool(32UL, false); + set => this.WriteData(32UL, value, false); + } + } + } + + public class @doubleFlat : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + FlatQux = reader.FlatQux; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.FlatQux = FlatQux; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string FlatQux + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string FlatQux => ctx.ReadText(2, ""); + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public string FlatQux + { + get => this.ReadText(2, ""); + set => this.WriteText(2, value, ""); + } + } + } + } + + public class @prefixedGroup : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Foo = reader.Foo; + Bar = reader.Bar; + Baz = CapnpSerializable.Create(reader.Baz); + MorePrefix = CapnpSerializable.Create(reader.MorePrefix); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Foo = Foo; + writer.Bar = Bar; + Baz?.serialize(writer.Baz); + MorePrefix?.serialize(writer.MorePrefix); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string Foo + { + get; + set; + } + + public uint Bar + { + get; + set; + } + + public Capnp.TestJsonAnnotations.@prefixedGroup.@baz Baz + { + get; + set; + } + + public Capnp.TestJsonAnnotations.@prefixedGroup.@morePrefix MorePrefix + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string Foo => ctx.ReadText(3, ""); + public uint Bar => ctx.ReadDataUInt(64UL, 0U); + public @baz.READER Baz => new @baz.READER(ctx); + public @morePrefix.READER MorePrefix => new @morePrefix.READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public string Foo + { + get => this.ReadText(3, ""); + set => this.WriteText(3, value, ""); + } + + public uint Bar + { + get => this.ReadDataUInt(64UL, 0U); + set => this.WriteData(64UL, value, 0U); + } + + public @baz.WRITER Baz + { + get => Rewrap<@baz.WRITER>(); + } + + public @morePrefix.WRITER MorePrefix + { + get => Rewrap<@morePrefix.WRITER>(); + } + } + + public class @baz : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Hello = reader.Hello; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Hello = Hello; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public bool Hello + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public bool Hello => ctx.ReadDataBool(33UL, false); + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public bool Hello + { + get => this.ReadDataBool(33UL, false); + set => this.WriteData(33UL, value, false); + } + } + } + + public class @morePrefix : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Qux = reader.Qux; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Qux = Qux; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string Qux + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string Qux => ctx.ReadText(4, ""); + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public string Qux + { + get => this.ReadText(4, ""); + set => this.WriteText(4, value, ""); + } + } + } + } + + public class @aUnion : ICapnpSerializable + { + public enum WHICH : ushort + { + Foo = 0, + Bar = 1, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.Foo: + Foo = CapnpSerializable.Create(reader.Foo); + break; + case WHICH.Bar: + Bar = CapnpSerializable.Create(reader.Bar); + break; + } + + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.Foo: + _content = null; + break; + case WHICH.Bar: + _content = null; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.Foo: + Foo?.serialize(writer.Foo); + break; + case WHICH.Bar: + Bar?.serialize(writer.Bar); + break; + } + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnp.TestJsonAnnotations.@aUnion.@foo Foo + { + get => _which == WHICH.Foo ? (Capnp.TestJsonAnnotations.@aUnion.@foo)_content : null; + set + { + _which = WHICH.Foo; + _content = value; + } + } + + public Capnp.TestJsonAnnotations.@aUnion.@bar Bar + { + get => _which == WHICH.Bar ? (Capnp.TestJsonAnnotations.@aUnion.@bar)_content : null; + set + { + _which = WHICH.Bar; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(48U, (ushort)0); + public @foo.READER Foo => which == WHICH.Foo ? new @foo.READER(ctx) : default; + public @bar.READER Bar => which == WHICH.Bar ? new @bar.READER(ctx) : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(48U, (ushort)0); + set => this.WriteData(48U, (ushort)value, (ushort)0); + } + + public @foo.WRITER Foo + { + get => which == WHICH.Foo ? Rewrap<@foo.WRITER>() : default; + } + + public @bar.WRITER Bar + { + get => which == WHICH.Bar ? Rewrap<@bar.WRITER>() : default; + } + } + + public class @foo : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + FooMember = reader.FooMember; + MultiMember = reader.MultiMember; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.FooMember = FooMember; + writer.MultiMember = MultiMember; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string FooMember + { + get; + set; + } + + public uint MultiMember + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string FooMember => ctx.ReadText(5, ""); + public uint MultiMember => ctx.ReadDataUInt(96UL, 0U); + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public string FooMember + { + get => this.ReadText(5, ""); + set => this.WriteText(5, value, ""); + } + + public uint MultiMember + { + get => this.ReadDataUInt(96UL, 0U); + set => this.WriteData(96UL, value, 0U); + } + } + } + + public class @bar : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + BarMember = reader.BarMember; + MultiMember = reader.MultiMember; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.BarMember = BarMember; + writer.MultiMember = MultiMember; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public uint BarMember + { + get; + set; + } + + public string MultiMember + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public uint BarMember => ctx.ReadDataUInt(96UL, 0U); + public string MultiMember => ctx.ReadText(5, ""); + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public uint BarMember + { + get => this.ReadDataUInt(96UL, 0U); + set => this.WriteData(96UL, value, 0U); + } + + public string MultiMember + { + get => this.ReadText(5, ""); + set => this.WriteText(5, value, ""); + } + } + } + } + + public class @simpleGroup : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Grault = reader.Grault; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Grault = Grault; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string Grault + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string Grault => ctx.ReadText(7, ""); + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public string Grault + { + get => this.ReadText(7, ""); + set => this.WriteText(7, value, ""); + } + } + } + + public class @bUnion : ICapnpSerializable + { + public enum WHICH : ushort + { + Foo = 0, + Bar = 1, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.Foo: + Foo = reader.Foo; + break; + case WHICH.Bar: + Bar = reader.Bar; + break; + } + + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.Foo: + _content = null; + break; + case WHICH.Bar: + _content = 0; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.Foo: + writer.Foo = Foo; + break; + case WHICH.Bar: + writer.Bar = Bar.Value; + break; + } + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string Foo + { + get => _which == WHICH.Foo ? (string)_content : null; + set + { + _which = WHICH.Foo; + _content = value; + } + } + + public uint? Bar + { + get => _which == WHICH.Bar ? (uint? )_content : null; + set + { + _which = WHICH.Bar; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(128U, (ushort)0); + public string Foo => which == WHICH.Foo ? ctx.ReadText(13, "") : default; + public uint Bar => which == WHICH.Bar ? ctx.ReadDataUInt(160UL, 0U) : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(128U, (ushort)0); + set => this.WriteData(128U, (ushort)value, (ushort)0); + } + + public string Foo + { + get => which == WHICH.Foo ? this.ReadText(13, "") : default; + set => this.WriteText(13, value, ""); + } + + public uint Bar + { + get => which == WHICH.Bar ? this.ReadDataUInt(160UL, 0U) : default; + set => this.WriteData(160UL, value, 0U); + } + } + } + + public class @unionWithVoid : ICapnpSerializable + { + public enum WHICH : ushort + { + IntValue = 0, + VoidValue = 1, + TextValue = 2, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.IntValue: + IntValue = reader.IntValue; + break; + case WHICH.VoidValue: + which = reader.which; + break; + case WHICH.TextValue: + TextValue = reader.TextValue; + break; + } + + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.IntValue: + _content = 0; + break; + case WHICH.VoidValue: + break; + case WHICH.TextValue: + _content = null; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.IntValue: + writer.IntValue = IntValue.Value; + break; + case WHICH.VoidValue: + break; + case WHICH.TextValue: + writer.TextValue = TextValue; + break; + } + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public uint? IntValue + { + get => _which == WHICH.IntValue ? (uint? )_content : null; + set + { + _which = WHICH.IntValue; + _content = value; + } + } + + public string TextValue + { + get => _which == WHICH.TextValue ? (string)_content : null; + set + { + _which = WHICH.TextValue; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(144U, (ushort)0); + public uint IntValue => which == WHICH.IntValue ? ctx.ReadDataUInt(192UL, 0U) : default; + public string TextValue => which == WHICH.TextValue ? ctx.ReadText(15, "") : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(144U, (ushort)0); + set => this.WriteData(144U, (ushort)value, (ushort)0); + } + + public uint IntValue + { + get => which == WHICH.IntValue ? this.ReadDataUInt(192UL, 0U) : default; + set => this.WriteData(192UL, value, 0U); + } + + public string TextValue + { + get => which == WHICH.TextValue ? this.ReadText(15, "") : default; + set => this.WriteText(15, value, ""); + } + } + } + } + + public class TestJsonAnnotations2 : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Foo = reader.Foo; + Cycle = CapnpSerializable.Create(reader.Cycle); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Foo = Foo; + Cycle?.serialize(writer.Cycle); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string Foo + { + get; + set; + } + + public Capnp.TestJsonAnnotations Cycle + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string Foo => ctx.ReadText(0, ""); + public Capnp.TestJsonAnnotations.READER Cycle => ctx.ReadStruct(1, Capnp.TestJsonAnnotations.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 2); + } + + public string Foo + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + + public Capnp.TestJsonAnnotations.WRITER Cycle + { + get => BuildPointer(1); + set => Link(1, value); + } + } + } + + public class TestJsonAnnotations3 : ICapnpSerializable + { + public enum WHICH : ushort + { + Foo = 0, + Bar = 1, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.Foo: + Foo = reader.Foo; + break; + case WHICH.Bar: + Bar = CapnpSerializable.Create(reader.Bar); + break; + } + + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.Foo: + _content = 0; + break; + case WHICH.Bar: + _content = null; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.Foo: + writer.Foo = Foo.Value; + break; + case WHICH.Bar: + Bar?.serialize(writer.Bar); + break; + } + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public uint? Foo + { + get => _which == WHICH.Foo ? (uint? )_content : null; + set + { + _which = WHICH.Foo; + _content = value; + } + } + + public Capnp.TestFlattenedStruct Bar + { + get => _which == WHICH.Bar ? (Capnp.TestFlattenedStruct)_content : null; + set + { + _which = WHICH.Bar; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(32U, (ushort)0); + public uint Foo => which == WHICH.Foo ? ctx.ReadDataUInt(0UL, 0U) : default; + public Capnp.TestFlattenedStruct.READER Bar => which == WHICH.Bar ? ctx.ReadStruct(0, Capnp.TestFlattenedStruct.READER.create) : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(32U, (ushort)0); + set => this.WriteData(32U, (ushort)value, (ushort)0); + } + + public uint Foo + { + get => which == WHICH.Foo ? this.ReadDataUInt(0UL, 0U) : default; + set => this.WriteData(0UL, value, 0U); + } + + public Capnp.TestFlattenedStruct.WRITER Bar + { + get => which == WHICH.Bar ? BuildPointer(0) : default; + set => Link(0, value); + } + } + } + + public class TestFlattenedStruct : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Value = reader.Value; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Value = Value; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string Value + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string Value => ctx.ReadText(0, ""); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public string Value + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + } + } + + public enum TestJsonAnnotatedEnum : ushort + { + foo, + bar, + baz, + qux + } +} \ No newline at end of file diff --git a/MsBuildGenerationTest/capnp/compat/json.capnp.cs b/MsBuildGenerationTest/capnp/compat/json.capnp.cs new file mode 100644 index 0000000..062257f --- /dev/null +++ b/MsBuildGenerationTest/capnp/compat/json.capnp.cs @@ -0,0 +1,536 @@ +using Capnp; +using Capnp.Rpc; +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +namespace Capnp.Json +{ + public class Value : ICapnpSerializable + { + public enum WHICH : ushort + { + Null = 0, + Boolean = 1, + Number = 2, + String = 3, + Array = 4, + Object = 5, + TheCall = 6, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.Null: + which = reader.which; + break; + case WHICH.Boolean: + Boolean = reader.Boolean; + break; + case WHICH.Number: + Number = reader.Number; + break; + case WHICH.String: + String = reader.String; + break; + case WHICH.Array: + Array = reader.Array.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + break; + case WHICH.Object: + Object = reader.Object.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + break; + case WHICH.TheCall: + TheCall = CapnpSerializable.Create(reader.TheCall); + break; + } + + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.Null: + break; + case WHICH.Boolean: + _content = false; + break; + case WHICH.Number: + _content = 0; + break; + case WHICH.String: + _content = null; + break; + case WHICH.Array: + _content = null; + break; + case WHICH.Object: + _content = null; + break; + case WHICH.TheCall: + _content = null; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.Null: + break; + case WHICH.Boolean: + writer.Boolean = Boolean.Value; + break; + case WHICH.Number: + writer.Number = Number.Value; + break; + case WHICH.String: + writer.String = String; + break; + case WHICH.Array: + writer.Array.Init(Array, (_s1, _v1) => _v1?.serialize(_s1)); + break; + case WHICH.Object: + writer.Object.Init(Object, (_s1, _v1) => _v1?.serialize(_s1)); + break; + case WHICH.TheCall: + TheCall?.serialize(writer.TheCall); + break; + } + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public bool? Boolean + { + get => _which == WHICH.Boolean ? (bool? )_content : null; + set + { + _which = WHICH.Boolean; + _content = value; + } + } + + public double? Number + { + get => _which == WHICH.Number ? (double? )_content : null; + set + { + _which = WHICH.Number; + _content = value; + } + } + + public string String + { + get => _which == WHICH.String ? (string)_content : null; + set + { + _which = WHICH.String; + _content = value; + } + } + + public IReadOnlyList Array + { + get => _which == WHICH.Array ? (IReadOnlyList)_content : null; + set + { + _which = WHICH.Array; + _content = value; + } + } + + public IReadOnlyList Object + { + get => _which == WHICH.Object ? (IReadOnlyList)_content : null; + set + { + _which = WHICH.Object; + _content = value; + } + } + + public Capnp.Json.Value.Call TheCall + { + get => _which == WHICH.TheCall ? (Capnp.Json.Value.Call)_content : null; + set + { + _which = WHICH.TheCall; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(0U, (ushort)0); + public bool Boolean => which == WHICH.Boolean ? ctx.ReadDataBool(16UL, false) : default; + public double Number => which == WHICH.Number ? ctx.ReadDataDouble(64UL, 0) : default; + public string String => which == WHICH.String ? ctx.ReadText(0, "") : default; + public IReadOnlyList Array => which == WHICH.Array ? ctx.ReadList(0).Cast(Capnp.Json.Value.READER.create) : default; + public IReadOnlyList Object => which == WHICH.Object ? ctx.ReadList(0).Cast(Capnp.Json.Value.Field.READER.create) : default; + public Capnp.Json.Value.Call.READER TheCall => which == WHICH.TheCall ? ctx.ReadStruct(0, Capnp.Json.Value.Call.READER.create) : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(2, 1); + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(0U, (ushort)0); + set => this.WriteData(0U, (ushort)value, (ushort)0); + } + + public bool Boolean + { + get => which == WHICH.Boolean ? this.ReadDataBool(16UL, false) : default; + set => this.WriteData(16UL, value, false); + } + + public double Number + { + get => which == WHICH.Number ? this.ReadDataDouble(64UL, 0) : default; + set => this.WriteData(64UL, value, 0); + } + + public string String + { + get => which == WHICH.String ? this.ReadText(0, "") : default; + set => this.WriteText(0, value, ""); + } + + public ListOfStructsSerializer Array + { + get => which == WHICH.Array ? BuildPointer>(0) : default; + set => Link(0, value); + } + + public ListOfStructsSerializer Object + { + get => which == WHICH.Object ? BuildPointer>(0) : default; + set => Link(0, value); + } + + public Capnp.Json.Value.Call.WRITER TheCall + { + get => which == WHICH.TheCall ? BuildPointer(0) : default; + set => Link(0, value); + } + } + + public class Field : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Name = reader.Name; + Value = CapnpSerializable.Create(reader.Value); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Name = Name; + Value?.serialize(writer.Value); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string Name + { + get; + set; + } + + public Capnp.Json.Value Value + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string Name => ctx.ReadText(0, ""); + public Capnp.Json.Value.READER Value => ctx.ReadStruct(1, Capnp.Json.Value.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 2); + } + + public string Name + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + + public Capnp.Json.Value.WRITER Value + { + get => BuildPointer(1); + set => Link(1, value); + } + } + } + + public class Call : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Function = reader.Function; + Params = reader.Params.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Function = Function; + writer.Params.Init(Params, (_s1, _v1) => _v1?.serialize(_s1)); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string Function + { + get; + set; + } + + public IReadOnlyList Params + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string Function => ctx.ReadText(0, ""); + public IReadOnlyList Params => ctx.ReadList(1).Cast(Capnp.Json.Value.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 2); + } + + public string Function + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + + public ListOfStructsSerializer Params + { + get => BuildPointer>(1); + set => Link(1, value); + } + } + } + } + + public class FlattenOptions : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Prefix = reader.Prefix; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Prefix = Prefix; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + Prefix = Prefix ?? ""; + } + + public string Prefix + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string Prefix => ctx.ReadText(0, ""); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public string Prefix + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + } + } + + public class DiscriminatorOptions : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Name = reader.Name; + ValueName = reader.ValueName; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Name = Name; + writer.ValueName = ValueName; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string Name + { + get; + set; + } + + public string ValueName + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string Name => ctx.ReadText(0, ""); + public string ValueName => ctx.ReadText(1, ""); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 2); + } + + public string Name + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + + public string ValueName + { + get => this.ReadText(1, ""); + set => this.WriteText(1, value, ""); + } + } + } +} \ No newline at end of file diff --git a/MsBuildGenerationTest/capnp/rpc-twoparty.capnp.cs b/MsBuildGenerationTest/capnp/rpc-twoparty.capnp.cs new file mode 100644 index 0000000..4d66331 --- /dev/null +++ b/MsBuildGenerationTest/capnp/rpc-twoparty.capnp.cs @@ -0,0 +1,393 @@ +using Capnp; +using Capnp.Rpc; +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +namespace Capnp.Rpc.Twoparty +{ + public enum Side : ushort + { + server, + client + } + + public class VatId : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Side = reader.Side; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Side = Side; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnp.Rpc.Twoparty.Side Side + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnp.Rpc.Twoparty.Side Side => (Capnp.Rpc.Twoparty.Side)ctx.ReadDataUShort(0UL, (ushort)0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 0); + } + + public Capnp.Rpc.Twoparty.Side Side + { + get => (Capnp.Rpc.Twoparty.Side)this.ReadDataUShort(0UL, (ushort)0); + set => this.WriteData(0UL, (ushort)value, (ushort)0); + } + } + } + + public class ProvisionId : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + JoinId = reader.JoinId; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.JoinId = JoinId; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public uint JoinId + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public uint JoinId => ctx.ReadDataUInt(0UL, 0U); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 0); + } + + public uint JoinId + { + get => this.ReadDataUInt(0UL, 0U); + set => this.WriteData(0UL, value, 0U); + } + } + } + + public class RecipientId : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + public class ThirdPartyCapId : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + public class JoinKeyPart : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + JoinId = reader.JoinId; + PartCount = reader.PartCount; + PartNum = reader.PartNum; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.JoinId = JoinId; + writer.PartCount = PartCount; + writer.PartNum = PartNum; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public uint JoinId + { + get; + set; + } + + public ushort PartCount + { + get; + set; + } + + public ushort PartNum + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public uint JoinId => ctx.ReadDataUInt(0UL, 0U); + public ushort PartCount => ctx.ReadDataUShort(32UL, (ushort)0); + public ushort PartNum => ctx.ReadDataUShort(48UL, (ushort)0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 0); + } + + public uint JoinId + { + get => this.ReadDataUInt(0UL, 0U); + set => this.WriteData(0UL, value, 0U); + } + + public ushort PartCount + { + get => this.ReadDataUShort(32UL, (ushort)0); + set => this.WriteData(32UL, value, (ushort)0); + } + + public ushort PartNum + { + get => this.ReadDataUShort(48UL, (ushort)0); + set => this.WriteData(48UL, value, (ushort)0); + } + } + } + + public class JoinResult : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + JoinId = reader.JoinId; + Succeeded = reader.Succeeded; + Cap = CapnpSerializable.Create(reader.Cap); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.JoinId = JoinId; + writer.Succeeded = Succeeded; + writer.Cap.SetObject(Cap); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public uint JoinId + { + get; + set; + } + + public bool Succeeded + { + get; + set; + } + + public AnyPointer Cap + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public uint JoinId => ctx.ReadDataUInt(0UL, 0U); + public bool Succeeded => ctx.ReadDataBool(32UL, false); + public DeserializerState Cap => ctx.StructReadPointer(0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public uint JoinId + { + get => this.ReadDataUInt(0UL, 0U); + set => this.WriteData(0UL, value, 0U); + } + + public bool Succeeded + { + get => this.ReadDataBool(32UL, false); + set => this.WriteData(32UL, value, false); + } + + public DynamicSerializerState Cap + { + get => BuildPointer(0); + set => Link(0, value); + } + } + } +} \ No newline at end of file diff --git a/MsBuildGenerationTest/capnp/rpc.capnp.cs b/MsBuildGenerationTest/capnp/rpc.capnp.cs new file mode 100644 index 0000000..35b0269 --- /dev/null +++ b/MsBuildGenerationTest/capnp/rpc.capnp.cs @@ -0,0 +1,2641 @@ +using Capnp; +using Capnp.Rpc; +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +namespace Capnp.Rpc +{ + public class Message : ICapnpSerializable + { + public enum WHICH : ushort + { + Unimplemented = 0, + Abort = 1, + Call = 2, + Return = 3, + Finish = 4, + Resolve = 5, + Release = 6, + ObsoleteSave = 7, + Bootstrap = 8, + ObsoleteDelete = 9, + Provide = 10, + Accept = 11, + Join = 12, + Disembargo = 13, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.Unimplemented: + Unimplemented = CapnpSerializable.Create(reader.Unimplemented); + break; + case WHICH.Abort: + Abort = CapnpSerializable.Create(reader.Abort); + break; + case WHICH.Call: + Call = CapnpSerializable.Create(reader.Call); + break; + case WHICH.Return: + Return = CapnpSerializable.Create(reader.Return); + break; + case WHICH.Finish: + Finish = CapnpSerializable.Create(reader.Finish); + break; + case WHICH.Resolve: + Resolve = CapnpSerializable.Create(reader.Resolve); + break; + case WHICH.Release: + Release = CapnpSerializable.Create(reader.Release); + break; + case WHICH.ObsoleteSave: + ObsoleteSave = CapnpSerializable.Create(reader.ObsoleteSave); + break; + case WHICH.Bootstrap: + Bootstrap = CapnpSerializable.Create(reader.Bootstrap); + break; + case WHICH.ObsoleteDelete: + ObsoleteDelete = CapnpSerializable.Create(reader.ObsoleteDelete); + break; + case WHICH.Provide: + Provide = CapnpSerializable.Create(reader.Provide); + break; + case WHICH.Accept: + Accept = CapnpSerializable.Create(reader.Accept); + break; + case WHICH.Join: + Join = CapnpSerializable.Create(reader.Join); + break; + case WHICH.Disembargo: + Disembargo = CapnpSerializable.Create(reader.Disembargo); + break; + } + + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.Unimplemented: + _content = null; + break; + case WHICH.Abort: + _content = null; + break; + case WHICH.Call: + _content = null; + break; + case WHICH.Return: + _content = null; + break; + case WHICH.Finish: + _content = null; + break; + case WHICH.Resolve: + _content = null; + break; + case WHICH.Release: + _content = null; + break; + case WHICH.ObsoleteSave: + _content = null; + break; + case WHICH.Bootstrap: + _content = null; + break; + case WHICH.ObsoleteDelete: + _content = null; + break; + case WHICH.Provide: + _content = null; + break; + case WHICH.Accept: + _content = null; + break; + case WHICH.Join: + _content = null; + break; + case WHICH.Disembargo: + _content = null; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.Unimplemented: + Unimplemented?.serialize(writer.Unimplemented); + break; + case WHICH.Abort: + Abort?.serialize(writer.Abort); + break; + case WHICH.Call: + Call?.serialize(writer.Call); + break; + case WHICH.Return: + Return?.serialize(writer.Return); + break; + case WHICH.Finish: + Finish?.serialize(writer.Finish); + break; + case WHICH.Resolve: + Resolve?.serialize(writer.Resolve); + break; + case WHICH.Release: + Release?.serialize(writer.Release); + break; + case WHICH.ObsoleteSave: + writer.ObsoleteSave.SetObject(ObsoleteSave); + break; + case WHICH.Bootstrap: + Bootstrap?.serialize(writer.Bootstrap); + break; + case WHICH.ObsoleteDelete: + writer.ObsoleteDelete.SetObject(ObsoleteDelete); + break; + case WHICH.Provide: + Provide?.serialize(writer.Provide); + break; + case WHICH.Accept: + Accept?.serialize(writer.Accept); + break; + case WHICH.Join: + Join?.serialize(writer.Join); + break; + case WHICH.Disembargo: + Disembargo?.serialize(writer.Disembargo); + break; + } + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnp.Rpc.Message Unimplemented + { + get => _which == WHICH.Unimplemented ? (Capnp.Rpc.Message)_content : null; + set + { + _which = WHICH.Unimplemented; + _content = value; + } + } + + public Capnp.Rpc.Exception Abort + { + get => _which == WHICH.Abort ? (Capnp.Rpc.Exception)_content : null; + set + { + _which = WHICH.Abort; + _content = value; + } + } + + public Capnp.Rpc.Call Call + { + get => _which == WHICH.Call ? (Capnp.Rpc.Call)_content : null; + set + { + _which = WHICH.Call; + _content = value; + } + } + + public Capnp.Rpc.Return Return + { + get => _which == WHICH.Return ? (Capnp.Rpc.Return)_content : null; + set + { + _which = WHICH.Return; + _content = value; + } + } + + public Capnp.Rpc.Finish Finish + { + get => _which == WHICH.Finish ? (Capnp.Rpc.Finish)_content : null; + set + { + _which = WHICH.Finish; + _content = value; + } + } + + public Capnp.Rpc.Resolve Resolve + { + get => _which == WHICH.Resolve ? (Capnp.Rpc.Resolve)_content : null; + set + { + _which = WHICH.Resolve; + _content = value; + } + } + + public Capnp.Rpc.Release Release + { + get => _which == WHICH.Release ? (Capnp.Rpc.Release)_content : null; + set + { + _which = WHICH.Release; + _content = value; + } + } + + public AnyPointer ObsoleteSave + { + get => _which == WHICH.ObsoleteSave ? (AnyPointer)_content : null; + set + { + _which = WHICH.ObsoleteSave; + _content = value; + } + } + + public Capnp.Rpc.Bootstrap Bootstrap + { + get => _which == WHICH.Bootstrap ? (Capnp.Rpc.Bootstrap)_content : null; + set + { + _which = WHICH.Bootstrap; + _content = value; + } + } + + public AnyPointer ObsoleteDelete + { + get => _which == WHICH.ObsoleteDelete ? (AnyPointer)_content : null; + set + { + _which = WHICH.ObsoleteDelete; + _content = value; + } + } + + public Capnp.Rpc.Provide Provide + { + get => _which == WHICH.Provide ? (Capnp.Rpc.Provide)_content : null; + set + { + _which = WHICH.Provide; + _content = value; + } + } + + public Capnp.Rpc.Accept Accept + { + get => _which == WHICH.Accept ? (Capnp.Rpc.Accept)_content : null; + set + { + _which = WHICH.Accept; + _content = value; + } + } + + public Capnp.Rpc.Join Join + { + get => _which == WHICH.Join ? (Capnp.Rpc.Join)_content : null; + set + { + _which = WHICH.Join; + _content = value; + } + } + + public Capnp.Rpc.Disembargo Disembargo + { + get => _which == WHICH.Disembargo ? (Capnp.Rpc.Disembargo)_content : null; + set + { + _which = WHICH.Disembargo; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(0U, (ushort)0); + public Capnp.Rpc.Message.READER Unimplemented => which == WHICH.Unimplemented ? ctx.ReadStruct(0, Capnp.Rpc.Message.READER.create) : default; + public Capnp.Rpc.Exception.READER Abort => which == WHICH.Abort ? ctx.ReadStruct(0, Capnp.Rpc.Exception.READER.create) : default; + public Capnp.Rpc.Call.READER Call => which == WHICH.Call ? ctx.ReadStruct(0, Capnp.Rpc.Call.READER.create) : default; + public Capnp.Rpc.Return.READER Return => which == WHICH.Return ? ctx.ReadStruct(0, Capnp.Rpc.Return.READER.create) : default; + public Capnp.Rpc.Finish.READER Finish => which == WHICH.Finish ? ctx.ReadStruct(0, Capnp.Rpc.Finish.READER.create) : default; + public Capnp.Rpc.Resolve.READER Resolve => which == WHICH.Resolve ? ctx.ReadStruct(0, Capnp.Rpc.Resolve.READER.create) : default; + public Capnp.Rpc.Release.READER Release => which == WHICH.Release ? ctx.ReadStruct(0, Capnp.Rpc.Release.READER.create) : default; + public DeserializerState ObsoleteSave => which == WHICH.ObsoleteSave ? ctx.StructReadPointer(0) : default; + public Capnp.Rpc.Bootstrap.READER Bootstrap => which == WHICH.Bootstrap ? ctx.ReadStruct(0, Capnp.Rpc.Bootstrap.READER.create) : default; + public DeserializerState ObsoleteDelete => which == WHICH.ObsoleteDelete ? ctx.StructReadPointer(0) : default; + public Capnp.Rpc.Provide.READER Provide => which == WHICH.Provide ? ctx.ReadStruct(0, Capnp.Rpc.Provide.READER.create) : default; + public Capnp.Rpc.Accept.READER Accept => which == WHICH.Accept ? ctx.ReadStruct(0, Capnp.Rpc.Accept.READER.create) : default; + public Capnp.Rpc.Join.READER Join => which == WHICH.Join ? ctx.ReadStruct(0, Capnp.Rpc.Join.READER.create) : default; + public Capnp.Rpc.Disembargo.READER Disembargo => which == WHICH.Disembargo ? ctx.ReadStruct(0, Capnp.Rpc.Disembargo.READER.create) : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(0U, (ushort)0); + set => this.WriteData(0U, (ushort)value, (ushort)0); + } + + public Capnp.Rpc.Message.WRITER Unimplemented + { + get => which == WHICH.Unimplemented ? BuildPointer(0) : default; + set => Link(0, value); + } + + public Capnp.Rpc.Exception.WRITER Abort + { + get => which == WHICH.Abort ? BuildPointer(0) : default; + set => Link(0, value); + } + + public Capnp.Rpc.Call.WRITER Call + { + get => which == WHICH.Call ? BuildPointer(0) : default; + set => Link(0, value); + } + + public Capnp.Rpc.Return.WRITER Return + { + get => which == WHICH.Return ? BuildPointer(0) : default; + set => Link(0, value); + } + + public Capnp.Rpc.Finish.WRITER Finish + { + get => which == WHICH.Finish ? BuildPointer(0) : default; + set => Link(0, value); + } + + public Capnp.Rpc.Resolve.WRITER Resolve + { + get => which == WHICH.Resolve ? BuildPointer(0) : default; + set => Link(0, value); + } + + public Capnp.Rpc.Release.WRITER Release + { + get => which == WHICH.Release ? BuildPointer(0) : default; + set => Link(0, value); + } + + public DynamicSerializerState ObsoleteSave + { + get => which == WHICH.ObsoleteSave ? BuildPointer(0) : default; + set => Link(0, value); + } + + public Capnp.Rpc.Bootstrap.WRITER Bootstrap + { + get => which == WHICH.Bootstrap ? BuildPointer(0) : default; + set => Link(0, value); + } + + public DynamicSerializerState ObsoleteDelete + { + get => which == WHICH.ObsoleteDelete ? BuildPointer(0) : default; + set => Link(0, value); + } + + public Capnp.Rpc.Provide.WRITER Provide + { + get => which == WHICH.Provide ? BuildPointer(0) : default; + set => Link(0, value); + } + + public Capnp.Rpc.Accept.WRITER Accept + { + get => which == WHICH.Accept ? BuildPointer(0) : default; + set => Link(0, value); + } + + public Capnp.Rpc.Join.WRITER Join + { + get => which == WHICH.Join ? BuildPointer(0) : default; + set => Link(0, value); + } + + public Capnp.Rpc.Disembargo.WRITER Disembargo + { + get => which == WHICH.Disembargo ? BuildPointer(0) : default; + set => Link(0, value); + } + } + } + + public class Bootstrap : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + QuestionId = reader.QuestionId; + DeprecatedObjectId = CapnpSerializable.Create(reader.DeprecatedObjectId); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.QuestionId = QuestionId; + writer.DeprecatedObjectId.SetObject(DeprecatedObjectId); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public uint QuestionId + { + get; + set; + } + + public AnyPointer DeprecatedObjectId + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public uint QuestionId => ctx.ReadDataUInt(0UL, 0U); + public DeserializerState DeprecatedObjectId => ctx.StructReadPointer(0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public uint QuestionId + { + get => this.ReadDataUInt(0UL, 0U); + set => this.WriteData(0UL, value, 0U); + } + + public DynamicSerializerState DeprecatedObjectId + { + get => BuildPointer(0); + set => Link(0, value); + } + } + } + + public class Call : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + QuestionId = reader.QuestionId; + Target = CapnpSerializable.Create(reader.Target); + InterfaceId = reader.InterfaceId; + MethodId = reader.MethodId; + Params = CapnpSerializable.Create(reader.Params); + SendResultsTo = CapnpSerializable.Create(reader.SendResultsTo); + AllowThirdPartyTailCall = reader.AllowThirdPartyTailCall; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.QuestionId = QuestionId; + Target?.serialize(writer.Target); + writer.InterfaceId = InterfaceId; + writer.MethodId = MethodId; + Params?.serialize(writer.Params); + SendResultsTo?.serialize(writer.SendResultsTo); + writer.AllowThirdPartyTailCall = AllowThirdPartyTailCall; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public uint QuestionId + { + get; + set; + } + + public Capnp.Rpc.MessageTarget Target + { + get; + set; + } + + public ulong InterfaceId + { + get; + set; + } + + public ushort MethodId + { + get; + set; + } + + public Capnp.Rpc.Payload Params + { + get; + set; + } + + public Capnp.Rpc.Call.@sendResultsTo SendResultsTo + { + get; + set; + } + + public bool AllowThirdPartyTailCall + { + get; + set; + } + + = false; + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public uint QuestionId => ctx.ReadDataUInt(0UL, 0U); + public Capnp.Rpc.MessageTarget.READER Target => ctx.ReadStruct(0, Capnp.Rpc.MessageTarget.READER.create); + public ulong InterfaceId => ctx.ReadDataULong(64UL, 0UL); + public ushort MethodId => ctx.ReadDataUShort(32UL, (ushort)0); + public Capnp.Rpc.Payload.READER Params => ctx.ReadStruct(1, Capnp.Rpc.Payload.READER.create); + public @sendResultsTo.READER SendResultsTo => new @sendResultsTo.READER(ctx); + public bool AllowThirdPartyTailCall => ctx.ReadDataBool(128UL, false); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(3, 3); + } + + public uint QuestionId + { + get => this.ReadDataUInt(0UL, 0U); + set => this.WriteData(0UL, value, 0U); + } + + public Capnp.Rpc.MessageTarget.WRITER Target + { + get => BuildPointer(0); + set => Link(0, value); + } + + public ulong InterfaceId + { + get => this.ReadDataULong(64UL, 0UL); + set => this.WriteData(64UL, value, 0UL); + } + + public ushort MethodId + { + get => this.ReadDataUShort(32UL, (ushort)0); + set => this.WriteData(32UL, value, (ushort)0); + } + + public Capnp.Rpc.Payload.WRITER Params + { + get => BuildPointer(1); + set => Link(1, value); + } + + public @sendResultsTo.WRITER SendResultsTo + { + get => Rewrap<@sendResultsTo.WRITER>(); + } + + public bool AllowThirdPartyTailCall + { + get => this.ReadDataBool(128UL, false); + set => this.WriteData(128UL, value, false); + } + } + + public class @sendResultsTo : ICapnpSerializable + { + public enum WHICH : ushort + { + Caller = 0, + Yourself = 1, + ThirdParty = 2, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.Caller: + which = reader.which; + break; + case WHICH.Yourself: + which = reader.which; + break; + case WHICH.ThirdParty: + ThirdParty = CapnpSerializable.Create(reader.ThirdParty); + break; + } + + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.Caller: + break; + case WHICH.Yourself: + break; + case WHICH.ThirdParty: + _content = null; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.Caller: + break; + case WHICH.Yourself: + break; + case WHICH.ThirdParty: + writer.ThirdParty.SetObject(ThirdParty); + break; + } + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public AnyPointer ThirdParty + { + get => _which == WHICH.ThirdParty ? (AnyPointer)_content : null; + set + { + _which = WHICH.ThirdParty; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(48U, (ushort)0); + public DeserializerState ThirdParty => which == WHICH.ThirdParty ? ctx.StructReadPointer(2) : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(48U, (ushort)0); + set => this.WriteData(48U, (ushort)value, (ushort)0); + } + + public DynamicSerializerState ThirdParty + { + get => which == WHICH.ThirdParty ? BuildPointer(2) : default; + set => Link(2, value); + } + } + } + } + + public class Return : ICapnpSerializable + { + public enum WHICH : ushort + { + Results = 0, + Exception = 1, + Canceled = 2, + ResultsSentElsewhere = 3, + TakeFromOtherQuestion = 4, + AcceptFromThirdParty = 5, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.Results: + Results = CapnpSerializable.Create(reader.Results); + break; + case WHICH.Exception: + Exception = CapnpSerializable.Create(reader.Exception); + break; + case WHICH.Canceled: + which = reader.which; + break; + case WHICH.ResultsSentElsewhere: + which = reader.which; + break; + case WHICH.TakeFromOtherQuestion: + TakeFromOtherQuestion = reader.TakeFromOtherQuestion; + break; + case WHICH.AcceptFromThirdParty: + AcceptFromThirdParty = CapnpSerializable.Create(reader.AcceptFromThirdParty); + break; + } + + AnswerId = reader.AnswerId; + ReleaseParamCaps = reader.ReleaseParamCaps; + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.Results: + _content = null; + break; + case WHICH.Exception: + _content = null; + break; + case WHICH.Canceled: + break; + case WHICH.ResultsSentElsewhere: + break; + case WHICH.TakeFromOtherQuestion: + _content = 0; + break; + case WHICH.AcceptFromThirdParty: + _content = null; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.Results: + Results?.serialize(writer.Results); + break; + case WHICH.Exception: + Exception?.serialize(writer.Exception); + break; + case WHICH.Canceled: + break; + case WHICH.ResultsSentElsewhere: + break; + case WHICH.TakeFromOtherQuestion: + writer.TakeFromOtherQuestion = TakeFromOtherQuestion.Value; + break; + case WHICH.AcceptFromThirdParty: + writer.AcceptFromThirdParty.SetObject(AcceptFromThirdParty); + break; + } + + writer.AnswerId = AnswerId; + writer.ReleaseParamCaps = ReleaseParamCaps; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public uint AnswerId + { + get; + set; + } + + public bool ReleaseParamCaps + { + get; + set; + } + + = true; + public Capnp.Rpc.Payload Results + { + get => _which == WHICH.Results ? (Capnp.Rpc.Payload)_content : null; + set + { + _which = WHICH.Results; + _content = value; + } + } + + public Capnp.Rpc.Exception Exception + { + get => _which == WHICH.Exception ? (Capnp.Rpc.Exception)_content : null; + set + { + _which = WHICH.Exception; + _content = value; + } + } + + public uint? TakeFromOtherQuestion + { + get => _which == WHICH.TakeFromOtherQuestion ? (uint? )_content : null; + set + { + _which = WHICH.TakeFromOtherQuestion; + _content = value; + } + } + + public AnyPointer AcceptFromThirdParty + { + get => _which == WHICH.AcceptFromThirdParty ? (AnyPointer)_content : null; + set + { + _which = WHICH.AcceptFromThirdParty; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(48U, (ushort)0); + public uint AnswerId => ctx.ReadDataUInt(0UL, 0U); + public bool ReleaseParamCaps => ctx.ReadDataBool(32UL, true); + public Capnp.Rpc.Payload.READER Results => which == WHICH.Results ? ctx.ReadStruct(0, Capnp.Rpc.Payload.READER.create) : default; + public Capnp.Rpc.Exception.READER Exception => which == WHICH.Exception ? ctx.ReadStruct(0, Capnp.Rpc.Exception.READER.create) : default; + public uint TakeFromOtherQuestion => which == WHICH.TakeFromOtherQuestion ? ctx.ReadDataUInt(64UL, 0U) : default; + public DeserializerState AcceptFromThirdParty => which == WHICH.AcceptFromThirdParty ? ctx.StructReadPointer(0) : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(2, 1); + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(48U, (ushort)0); + set => this.WriteData(48U, (ushort)value, (ushort)0); + } + + public uint AnswerId + { + get => this.ReadDataUInt(0UL, 0U); + set => this.WriteData(0UL, value, 0U); + } + + public bool ReleaseParamCaps + { + get => this.ReadDataBool(32UL, true); + set => this.WriteData(32UL, value, true); + } + + public Capnp.Rpc.Payload.WRITER Results + { + get => which == WHICH.Results ? BuildPointer(0) : default; + set => Link(0, value); + } + + public Capnp.Rpc.Exception.WRITER Exception + { + get => which == WHICH.Exception ? BuildPointer(0) : default; + set => Link(0, value); + } + + public uint TakeFromOtherQuestion + { + get => which == WHICH.TakeFromOtherQuestion ? this.ReadDataUInt(64UL, 0U) : default; + set => this.WriteData(64UL, value, 0U); + } + + public DynamicSerializerState AcceptFromThirdParty + { + get => which == WHICH.AcceptFromThirdParty ? BuildPointer(0) : default; + set => Link(0, value); + } + } + } + + public class Finish : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + QuestionId = reader.QuestionId; + ReleaseResultCaps = reader.ReleaseResultCaps; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.QuestionId = QuestionId; + writer.ReleaseResultCaps = ReleaseResultCaps; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public uint QuestionId + { + get; + set; + } + + public bool ReleaseResultCaps + { + get; + set; + } + + = true; + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public uint QuestionId => ctx.ReadDataUInt(0UL, 0U); + public bool ReleaseResultCaps => ctx.ReadDataBool(32UL, true); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 0); + } + + public uint QuestionId + { + get => this.ReadDataUInt(0UL, 0U); + set => this.WriteData(0UL, value, 0U); + } + + public bool ReleaseResultCaps + { + get => this.ReadDataBool(32UL, true); + set => this.WriteData(32UL, value, true); + } + } + } + + public class Resolve : ICapnpSerializable + { + public enum WHICH : ushort + { + Cap = 0, + Exception = 1, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.Cap: + Cap = CapnpSerializable.Create(reader.Cap); + break; + case WHICH.Exception: + Exception = CapnpSerializable.Create(reader.Exception); + break; + } + + PromiseId = reader.PromiseId; + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.Cap: + _content = null; + break; + case WHICH.Exception: + _content = null; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.Cap: + Cap?.serialize(writer.Cap); + break; + case WHICH.Exception: + Exception?.serialize(writer.Exception); + break; + } + + writer.PromiseId = PromiseId; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public uint PromiseId + { + get; + set; + } + + public Capnp.Rpc.CapDescriptor Cap + { + get => _which == WHICH.Cap ? (Capnp.Rpc.CapDescriptor)_content : null; + set + { + _which = WHICH.Cap; + _content = value; + } + } + + public Capnp.Rpc.Exception Exception + { + get => _which == WHICH.Exception ? (Capnp.Rpc.Exception)_content : null; + set + { + _which = WHICH.Exception; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(32U, (ushort)0); + public uint PromiseId => ctx.ReadDataUInt(0UL, 0U); + public Capnp.Rpc.CapDescriptor.READER Cap => which == WHICH.Cap ? ctx.ReadStruct(0, Capnp.Rpc.CapDescriptor.READER.create) : default; + public Capnp.Rpc.Exception.READER Exception => which == WHICH.Exception ? ctx.ReadStruct(0, Capnp.Rpc.Exception.READER.create) : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(32U, (ushort)0); + set => this.WriteData(32U, (ushort)value, (ushort)0); + } + + public uint PromiseId + { + get => this.ReadDataUInt(0UL, 0U); + set => this.WriteData(0UL, value, 0U); + } + + public Capnp.Rpc.CapDescriptor.WRITER Cap + { + get => which == WHICH.Cap ? BuildPointer(0) : default; + set => Link(0, value); + } + + public Capnp.Rpc.Exception.WRITER Exception + { + get => which == WHICH.Exception ? BuildPointer(0) : default; + set => Link(0, value); + } + } + } + + public class Release : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Id = reader.Id; + ReferenceCount = reader.ReferenceCount; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Id = Id; + writer.ReferenceCount = ReferenceCount; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public uint Id + { + get; + set; + } + + public uint ReferenceCount + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public uint Id => ctx.ReadDataUInt(0UL, 0U); + public uint ReferenceCount => ctx.ReadDataUInt(32UL, 0U); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 0); + } + + public uint Id + { + get => this.ReadDataUInt(0UL, 0U); + set => this.WriteData(0UL, value, 0U); + } + + public uint ReferenceCount + { + get => this.ReadDataUInt(32UL, 0U); + set => this.WriteData(32UL, value, 0U); + } + } + } + + public class Disembargo : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Target = CapnpSerializable.Create(reader.Target); + Context = CapnpSerializable.Create(reader.Context); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + Target?.serialize(writer.Target); + Context?.serialize(writer.Context); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnp.Rpc.MessageTarget Target + { + get; + set; + } + + public Capnp.Rpc.Disembargo.@context Context + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnp.Rpc.MessageTarget.READER Target => ctx.ReadStruct(0, Capnp.Rpc.MessageTarget.READER.create); + public @context.READER Context => new @context.READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public Capnp.Rpc.MessageTarget.WRITER Target + { + get => BuildPointer(0); + set => Link(0, value); + } + + public @context.WRITER Context + { + get => Rewrap<@context.WRITER>(); + } + } + + public class @context : ICapnpSerializable + { + public enum WHICH : ushort + { + SenderLoopback = 0, + ReceiverLoopback = 1, + Accept = 2, + Provide = 3, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.SenderLoopback: + SenderLoopback = reader.SenderLoopback; + break; + case WHICH.ReceiverLoopback: + ReceiverLoopback = reader.ReceiverLoopback; + break; + case WHICH.Accept: + which = reader.which; + break; + case WHICH.Provide: + Provide = reader.Provide; + break; + } + + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.SenderLoopback: + _content = 0; + break; + case WHICH.ReceiverLoopback: + _content = 0; + break; + case WHICH.Accept: + break; + case WHICH.Provide: + _content = 0; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.SenderLoopback: + writer.SenderLoopback = SenderLoopback.Value; + break; + case WHICH.ReceiverLoopback: + writer.ReceiverLoopback = ReceiverLoopback.Value; + break; + case WHICH.Accept: + break; + case WHICH.Provide: + writer.Provide = Provide.Value; + break; + } + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public uint? SenderLoopback + { + get => _which == WHICH.SenderLoopback ? (uint? )_content : null; + set + { + _which = WHICH.SenderLoopback; + _content = value; + } + } + + public uint? ReceiverLoopback + { + get => _which == WHICH.ReceiverLoopback ? (uint? )_content : null; + set + { + _which = WHICH.ReceiverLoopback; + _content = value; + } + } + + public uint? Provide + { + get => _which == WHICH.Provide ? (uint? )_content : null; + set + { + _which = WHICH.Provide; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(32U, (ushort)0); + public uint SenderLoopback => which == WHICH.SenderLoopback ? ctx.ReadDataUInt(0UL, 0U) : default; + public uint ReceiverLoopback => which == WHICH.ReceiverLoopback ? ctx.ReadDataUInt(0UL, 0U) : default; + public uint Provide => which == WHICH.Provide ? ctx.ReadDataUInt(0UL, 0U) : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(32U, (ushort)0); + set => this.WriteData(32U, (ushort)value, (ushort)0); + } + + public uint SenderLoopback + { + get => which == WHICH.SenderLoopback ? this.ReadDataUInt(0UL, 0U) : default; + set => this.WriteData(0UL, value, 0U); + } + + public uint ReceiverLoopback + { + get => which == WHICH.ReceiverLoopback ? this.ReadDataUInt(0UL, 0U) : default; + set => this.WriteData(0UL, value, 0U); + } + + public uint Provide + { + get => which == WHICH.Provide ? this.ReadDataUInt(0UL, 0U) : default; + set => this.WriteData(0UL, value, 0U); + } + } + } + } + + public class Provide : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + QuestionId = reader.QuestionId; + Target = CapnpSerializable.Create(reader.Target); + Recipient = CapnpSerializable.Create(reader.Recipient); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.QuestionId = QuestionId; + Target?.serialize(writer.Target); + writer.Recipient.SetObject(Recipient); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public uint QuestionId + { + get; + set; + } + + public Capnp.Rpc.MessageTarget Target + { + get; + set; + } + + public AnyPointer Recipient + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public uint QuestionId => ctx.ReadDataUInt(0UL, 0U); + public Capnp.Rpc.MessageTarget.READER Target => ctx.ReadStruct(0, Capnp.Rpc.MessageTarget.READER.create); + public DeserializerState Recipient => ctx.StructReadPointer(1); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 2); + } + + public uint QuestionId + { + get => this.ReadDataUInt(0UL, 0U); + set => this.WriteData(0UL, value, 0U); + } + + public Capnp.Rpc.MessageTarget.WRITER Target + { + get => BuildPointer(0); + set => Link(0, value); + } + + public DynamicSerializerState Recipient + { + get => BuildPointer(1); + set => Link(1, value); + } + } + } + + public class Accept : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + QuestionId = reader.QuestionId; + Provision = CapnpSerializable.Create(reader.Provision); + Embargo = reader.Embargo; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.QuestionId = QuestionId; + writer.Provision.SetObject(Provision); + writer.Embargo = Embargo; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public uint QuestionId + { + get; + set; + } + + public AnyPointer Provision + { + get; + set; + } + + public bool Embargo + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public uint QuestionId => ctx.ReadDataUInt(0UL, 0U); + public DeserializerState Provision => ctx.StructReadPointer(0); + public bool Embargo => ctx.ReadDataBool(32UL, false); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public uint QuestionId + { + get => this.ReadDataUInt(0UL, 0U); + set => this.WriteData(0UL, value, 0U); + } + + public DynamicSerializerState Provision + { + get => BuildPointer(0); + set => Link(0, value); + } + + public bool Embargo + { + get => this.ReadDataBool(32UL, false); + set => this.WriteData(32UL, value, false); + } + } + } + + public class Join : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + QuestionId = reader.QuestionId; + Target = CapnpSerializable.Create(reader.Target); + KeyPart = CapnpSerializable.Create(reader.KeyPart); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.QuestionId = QuestionId; + Target?.serialize(writer.Target); + writer.KeyPart.SetObject(KeyPart); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public uint QuestionId + { + get; + set; + } + + public Capnp.Rpc.MessageTarget Target + { + get; + set; + } + + public AnyPointer KeyPart + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public uint QuestionId => ctx.ReadDataUInt(0UL, 0U); + public Capnp.Rpc.MessageTarget.READER Target => ctx.ReadStruct(0, Capnp.Rpc.MessageTarget.READER.create); + public DeserializerState KeyPart => ctx.StructReadPointer(1); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 2); + } + + public uint QuestionId + { + get => this.ReadDataUInt(0UL, 0U); + set => this.WriteData(0UL, value, 0U); + } + + public Capnp.Rpc.MessageTarget.WRITER Target + { + get => BuildPointer(0); + set => Link(0, value); + } + + public DynamicSerializerState KeyPart + { + get => BuildPointer(1); + set => Link(1, value); + } + } + } + + public class MessageTarget : ICapnpSerializable + { + public enum WHICH : ushort + { + ImportedCap = 0, + PromisedAnswer = 1, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.ImportedCap: + ImportedCap = reader.ImportedCap; + break; + case WHICH.PromisedAnswer: + PromisedAnswer = CapnpSerializable.Create(reader.PromisedAnswer); + break; + } + + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.ImportedCap: + _content = 0; + break; + case WHICH.PromisedAnswer: + _content = null; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.ImportedCap: + writer.ImportedCap = ImportedCap.Value; + break; + case WHICH.PromisedAnswer: + PromisedAnswer?.serialize(writer.PromisedAnswer); + break; + } + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public uint? ImportedCap + { + get => _which == WHICH.ImportedCap ? (uint? )_content : null; + set + { + _which = WHICH.ImportedCap; + _content = value; + } + } + + public Capnp.Rpc.PromisedAnswer PromisedAnswer + { + get => _which == WHICH.PromisedAnswer ? (Capnp.Rpc.PromisedAnswer)_content : null; + set + { + _which = WHICH.PromisedAnswer; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(32U, (ushort)0); + public uint ImportedCap => which == WHICH.ImportedCap ? ctx.ReadDataUInt(0UL, 0U) : default; + public Capnp.Rpc.PromisedAnswer.READER PromisedAnswer => which == WHICH.PromisedAnswer ? ctx.ReadStruct(0, Capnp.Rpc.PromisedAnswer.READER.create) : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(32U, (ushort)0); + set => this.WriteData(32U, (ushort)value, (ushort)0); + } + + public uint ImportedCap + { + get => which == WHICH.ImportedCap ? this.ReadDataUInt(0UL, 0U) : default; + set => this.WriteData(0UL, value, 0U); + } + + public Capnp.Rpc.PromisedAnswer.WRITER PromisedAnswer + { + get => which == WHICH.PromisedAnswer ? BuildPointer(0) : default; + set => Link(0, value); + } + } + } + + public class Payload : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Content = CapnpSerializable.Create(reader.Content); + CapTable = reader.CapTable.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Content.SetObject(Content); + writer.CapTable.Init(CapTable, (_s1, _v1) => _v1?.serialize(_s1)); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public AnyPointer Content + { + get; + set; + } + + public IReadOnlyList CapTable + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public DeserializerState Content => ctx.StructReadPointer(0); + public IReadOnlyList CapTable => ctx.ReadList(1).Cast(Capnp.Rpc.CapDescriptor.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 2); + } + + public DynamicSerializerState Content + { + get => BuildPointer(0); + set => Link(0, value); + } + + public ListOfStructsSerializer CapTable + { + get => BuildPointer>(1); + set => Link(1, value); + } + } + } + + public class CapDescriptor : ICapnpSerializable + { + public enum WHICH : ushort + { + None = 0, + SenderHosted = 1, + SenderPromise = 2, + ReceiverHosted = 3, + ReceiverAnswer = 4, + ThirdPartyHosted = 5, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.None: + which = reader.which; + break; + case WHICH.SenderHosted: + SenderHosted = reader.SenderHosted; + break; + case WHICH.SenderPromise: + SenderPromise = reader.SenderPromise; + break; + case WHICH.ReceiverHosted: + ReceiverHosted = reader.ReceiverHosted; + break; + case WHICH.ReceiverAnswer: + ReceiverAnswer = CapnpSerializable.Create(reader.ReceiverAnswer); + break; + case WHICH.ThirdPartyHosted: + ThirdPartyHosted = CapnpSerializable.Create(reader.ThirdPartyHosted); + break; + } + + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.None: + break; + case WHICH.SenderHosted: + _content = 0; + break; + case WHICH.SenderPromise: + _content = 0; + break; + case WHICH.ReceiverHosted: + _content = 0; + break; + case WHICH.ReceiverAnswer: + _content = null; + break; + case WHICH.ThirdPartyHosted: + _content = null; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.None: + break; + case WHICH.SenderHosted: + writer.SenderHosted = SenderHosted.Value; + break; + case WHICH.SenderPromise: + writer.SenderPromise = SenderPromise.Value; + break; + case WHICH.ReceiverHosted: + writer.ReceiverHosted = ReceiverHosted.Value; + break; + case WHICH.ReceiverAnswer: + ReceiverAnswer?.serialize(writer.ReceiverAnswer); + break; + case WHICH.ThirdPartyHosted: + ThirdPartyHosted?.serialize(writer.ThirdPartyHosted); + break; + } + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public uint? SenderHosted + { + get => _which == WHICH.SenderHosted ? (uint? )_content : null; + set + { + _which = WHICH.SenderHosted; + _content = value; + } + } + + public uint? SenderPromise + { + get => _which == WHICH.SenderPromise ? (uint? )_content : null; + set + { + _which = WHICH.SenderPromise; + _content = value; + } + } + + public uint? ReceiverHosted + { + get => _which == WHICH.ReceiverHosted ? (uint? )_content : null; + set + { + _which = WHICH.ReceiverHosted; + _content = value; + } + } + + public Capnp.Rpc.PromisedAnswer ReceiverAnswer + { + get => _which == WHICH.ReceiverAnswer ? (Capnp.Rpc.PromisedAnswer)_content : null; + set + { + _which = WHICH.ReceiverAnswer; + _content = value; + } + } + + public Capnp.Rpc.ThirdPartyCapDescriptor ThirdPartyHosted + { + get => _which == WHICH.ThirdPartyHosted ? (Capnp.Rpc.ThirdPartyCapDescriptor)_content : null; + set + { + _which = WHICH.ThirdPartyHosted; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(0U, (ushort)0); + public uint SenderHosted => which == WHICH.SenderHosted ? ctx.ReadDataUInt(32UL, 0U) : default; + public uint SenderPromise => which == WHICH.SenderPromise ? ctx.ReadDataUInt(32UL, 0U) : default; + public uint ReceiverHosted => which == WHICH.ReceiverHosted ? ctx.ReadDataUInt(32UL, 0U) : default; + public Capnp.Rpc.PromisedAnswer.READER ReceiverAnswer => which == WHICH.ReceiverAnswer ? ctx.ReadStruct(0, Capnp.Rpc.PromisedAnswer.READER.create) : default; + public Capnp.Rpc.ThirdPartyCapDescriptor.READER ThirdPartyHosted => which == WHICH.ThirdPartyHosted ? ctx.ReadStruct(0, Capnp.Rpc.ThirdPartyCapDescriptor.READER.create) : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(0U, (ushort)0); + set => this.WriteData(0U, (ushort)value, (ushort)0); + } + + public uint SenderHosted + { + get => which == WHICH.SenderHosted ? this.ReadDataUInt(32UL, 0U) : default; + set => this.WriteData(32UL, value, 0U); + } + + public uint SenderPromise + { + get => which == WHICH.SenderPromise ? this.ReadDataUInt(32UL, 0U) : default; + set => this.WriteData(32UL, value, 0U); + } + + public uint ReceiverHosted + { + get => which == WHICH.ReceiverHosted ? this.ReadDataUInt(32UL, 0U) : default; + set => this.WriteData(32UL, value, 0U); + } + + public Capnp.Rpc.PromisedAnswer.WRITER ReceiverAnswer + { + get => which == WHICH.ReceiverAnswer ? BuildPointer(0) : default; + set => Link(0, value); + } + + public Capnp.Rpc.ThirdPartyCapDescriptor.WRITER ThirdPartyHosted + { + get => which == WHICH.ThirdPartyHosted ? BuildPointer(0) : default; + set => Link(0, value); + } + } + } + + public class PromisedAnswer : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + QuestionId = reader.QuestionId; + Transform = reader.Transform.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.QuestionId = QuestionId; + writer.Transform.Init(Transform, (_s1, _v1) => _v1?.serialize(_s1)); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public uint QuestionId + { + get; + set; + } + + public IReadOnlyList Transform + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public uint QuestionId => ctx.ReadDataUInt(0UL, 0U); + public IReadOnlyList Transform => ctx.ReadList(0).Cast(Capnp.Rpc.PromisedAnswer.Op.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public uint QuestionId + { + get => this.ReadDataUInt(0UL, 0U); + set => this.WriteData(0UL, value, 0U); + } + + public ListOfStructsSerializer Transform + { + get => BuildPointer>(0); + set => Link(0, value); + } + } + + public class Op : ICapnpSerializable + { + public enum WHICH : ushort + { + Noop = 0, + GetPointerField = 1, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.Noop: + which = reader.which; + break; + case WHICH.GetPointerField: + GetPointerField = reader.GetPointerField; + break; + } + + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.Noop: + break; + case WHICH.GetPointerField: + _content = 0; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.Noop: + break; + case WHICH.GetPointerField: + writer.GetPointerField = GetPointerField.Value; + break; + } + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public ushort? GetPointerField + { + get => _which == WHICH.GetPointerField ? (ushort? )_content : null; + set + { + _which = WHICH.GetPointerField; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(0U, (ushort)0); + public ushort GetPointerField => which == WHICH.GetPointerField ? ctx.ReadDataUShort(16UL, (ushort)0) : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 0); + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(0U, (ushort)0); + set => this.WriteData(0U, (ushort)value, (ushort)0); + } + + public ushort GetPointerField + { + get => which == WHICH.GetPointerField ? this.ReadDataUShort(16UL, (ushort)0) : default; + set => this.WriteData(16UL, value, (ushort)0); + } + } + } + } + + public class ThirdPartyCapDescriptor : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Id = CapnpSerializable.Create(reader.Id); + VineId = reader.VineId; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Id.SetObject(Id); + writer.VineId = VineId; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public AnyPointer Id + { + get; + set; + } + + public uint VineId + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public DeserializerState Id => ctx.StructReadPointer(0); + public uint VineId => ctx.ReadDataUInt(0UL, 0U); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public DynamicSerializerState Id + { + get => BuildPointer(0); + set => Link(0, value); + } + + public uint VineId + { + get => this.ReadDataUInt(0UL, 0U); + set => this.WriteData(0UL, value, 0U); + } + } + } + + public class Exception : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Reason = reader.Reason; + ObsoleteIsCallersFault = reader.ObsoleteIsCallersFault; + ObsoleteDurability = reader.ObsoleteDurability; + TheType = reader.TheType; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Reason = Reason; + writer.ObsoleteIsCallersFault = ObsoleteIsCallersFault; + writer.ObsoleteDurability = ObsoleteDurability; + writer.TheType = TheType; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string Reason + { + get; + set; + } + + public bool ObsoleteIsCallersFault + { + get; + set; + } + + public ushort ObsoleteDurability + { + get; + set; + } + + public Capnp.Rpc.Exception.Type TheType + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string Reason => ctx.ReadText(0, ""); + public bool ObsoleteIsCallersFault => ctx.ReadDataBool(0UL, false); + public ushort ObsoleteDurability => ctx.ReadDataUShort(16UL, (ushort)0); + public Capnp.Rpc.Exception.Type TheType => (Capnp.Rpc.Exception.Type)ctx.ReadDataUShort(32UL, (ushort)0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public string Reason + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + + public bool ObsoleteIsCallersFault + { + get => this.ReadDataBool(0UL, false); + set => this.WriteData(0UL, value, false); + } + + public ushort ObsoleteDurability + { + get => this.ReadDataUShort(16UL, (ushort)0); + set => this.WriteData(16UL, value, (ushort)0); + } + + public Capnp.Rpc.Exception.Type TheType + { + get => (Capnp.Rpc.Exception.Type)this.ReadDataUShort(32UL, (ushort)0); + set => this.WriteData(32UL, (ushort)value, (ushort)0); + } + } + + public enum Type : ushort + { + failed, + overloaded, + disconnected, + unimplemented + } + } +} \ No newline at end of file diff --git a/MsBuildGenerationTest/capnp/schema.capnp.cs b/MsBuildGenerationTest/capnp/schema.capnp.cs new file mode 100644 index 0000000..63d6b35 --- /dev/null +++ b/MsBuildGenerationTest/capnp/schema.capnp.cs @@ -0,0 +1,4309 @@ +using Capnp; +using Capnp.Rpc; +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +namespace Capnp.Schema +{ + public class Node : ICapnpSerializable + { + public enum WHICH : ushort + { + File = 0, + Struct = 1, + Enum = 2, + Interface = 3, + Const = 4, + Annotation = 5, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.File: + which = reader.which; + break; + case WHICH.Struct: + Struct = CapnpSerializable.Create(reader.Struct); + break; + case WHICH.Enum: + Enum = CapnpSerializable.Create(reader.Enum); + break; + case WHICH.Interface: + Interface = CapnpSerializable.Create(reader.Interface); + break; + case WHICH.Const: + Const = CapnpSerializable.Create(reader.Const); + break; + case WHICH.Annotation: + Annotation = CapnpSerializable.Create(reader.Annotation); + break; + } + + Id = reader.Id; + DisplayName = reader.DisplayName; + DisplayNamePrefixLength = reader.DisplayNamePrefixLength; + ScopeId = reader.ScopeId; + NestedNodes = reader.NestedNodes.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + Annotations = reader.Annotations.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + Parameters = reader.Parameters.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + IsGeneric = reader.IsGeneric; + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.File: + break; + case WHICH.Struct: + _content = null; + break; + case WHICH.Enum: + _content = null; + break; + case WHICH.Interface: + _content = null; + break; + case WHICH.Const: + _content = null; + break; + case WHICH.Annotation: + _content = null; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.File: + break; + case WHICH.Struct: + Struct?.serialize(writer.Struct); + break; + case WHICH.Enum: + Enum?.serialize(writer.Enum); + break; + case WHICH.Interface: + Interface?.serialize(writer.Interface); + break; + case WHICH.Const: + Const?.serialize(writer.Const); + break; + case WHICH.Annotation: + Annotation?.serialize(writer.Annotation); + break; + } + + writer.Id = Id; + writer.DisplayName = DisplayName; + writer.DisplayNamePrefixLength = DisplayNamePrefixLength; + writer.ScopeId = ScopeId; + writer.NestedNodes.Init(NestedNodes, (_s1, _v1) => _v1?.serialize(_s1)); + writer.Annotations.Init(Annotations, (_s1, _v1) => _v1?.serialize(_s1)); + writer.Parameters.Init(Parameters, (_s1, _v1) => _v1?.serialize(_s1)); + writer.IsGeneric = IsGeneric; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public ulong Id + { + get; + set; + } + + public string DisplayName + { + get; + set; + } + + public uint DisplayNamePrefixLength + { + get; + set; + } + + public ulong ScopeId + { + get; + set; + } + + public IReadOnlyList NestedNodes + { + get; + set; + } + + public IReadOnlyList Annotations + { + get; + set; + } + + public Capnp.Schema.Node.@struct Struct + { + get => _which == WHICH.Struct ? (Capnp.Schema.Node.@struct)_content : null; + set + { + _which = WHICH.Struct; + _content = value; + } + } + + public Capnp.Schema.Node.@enum Enum + { + get => _which == WHICH.Enum ? (Capnp.Schema.Node.@enum)_content : null; + set + { + _which = WHICH.Enum; + _content = value; + } + } + + public Capnp.Schema.Node.@interface Interface + { + get => _which == WHICH.Interface ? (Capnp.Schema.Node.@interface)_content : null; + set + { + _which = WHICH.Interface; + _content = value; + } + } + + public Capnp.Schema.Node.@const Const + { + get => _which == WHICH.Const ? (Capnp.Schema.Node.@const)_content : null; + set + { + _which = WHICH.Const; + _content = value; + } + } + + public Capnp.Schema.Node.@annotation Annotation + { + get => _which == WHICH.Annotation ? (Capnp.Schema.Node.@annotation)_content : null; + set + { + _which = WHICH.Annotation; + _content = value; + } + } + + public IReadOnlyList Parameters + { + get; + set; + } + + public bool IsGeneric + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(96U, (ushort)0); + public ulong Id => ctx.ReadDataULong(0UL, 0UL); + public string DisplayName => ctx.ReadText(0, ""); + public uint DisplayNamePrefixLength => ctx.ReadDataUInt(64UL, 0U); + public ulong ScopeId => ctx.ReadDataULong(128UL, 0UL); + public IReadOnlyList NestedNodes => ctx.ReadList(1).Cast(Capnp.Schema.Node.NestedNode.READER.create); + public IReadOnlyList Annotations => ctx.ReadList(2).Cast(Capnp.Schema.Annotation.READER.create); + public @struct.READER Struct => which == WHICH.Struct ? new @struct.READER(ctx) : default; + public @enum.READER Enum => which == WHICH.Enum ? new @enum.READER(ctx) : default; + public @interface.READER Interface => which == WHICH.Interface ? new @interface.READER(ctx) : default; + public @const.READER Const => which == WHICH.Const ? new @const.READER(ctx) : default; + public @annotation.READER Annotation => which == WHICH.Annotation ? new @annotation.READER(ctx) : default; + public IReadOnlyList Parameters => ctx.ReadList(5).Cast(Capnp.Schema.Node.Parameter.READER.create); + public bool IsGeneric => ctx.ReadDataBool(288UL, false); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(5, 6); + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(96U, (ushort)0); + set => this.WriteData(96U, (ushort)value, (ushort)0); + } + + public ulong Id + { + get => this.ReadDataULong(0UL, 0UL); + set => this.WriteData(0UL, value, 0UL); + } + + public string DisplayName + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + + public uint DisplayNamePrefixLength + { + get => this.ReadDataUInt(64UL, 0U); + set => this.WriteData(64UL, value, 0U); + } + + public ulong ScopeId + { + get => this.ReadDataULong(128UL, 0UL); + set => this.WriteData(128UL, value, 0UL); + } + + public ListOfStructsSerializer NestedNodes + { + get => BuildPointer>(1); + set => Link(1, value); + } + + public ListOfStructsSerializer Annotations + { + get => BuildPointer>(2); + set => Link(2, value); + } + + public @struct.WRITER Struct + { + get => which == WHICH.Struct ? Rewrap<@struct.WRITER>() : default; + } + + public @enum.WRITER Enum + { + get => which == WHICH.Enum ? Rewrap<@enum.WRITER>() : default; + } + + public @interface.WRITER Interface + { + get => which == WHICH.Interface ? Rewrap<@interface.WRITER>() : default; + } + + public @const.WRITER Const + { + get => which == WHICH.Const ? Rewrap<@const.WRITER>() : default; + } + + public @annotation.WRITER Annotation + { + get => which == WHICH.Annotation ? Rewrap<@annotation.WRITER>() : default; + } + + public ListOfStructsSerializer Parameters + { + get => BuildPointer>(5); + set => Link(5, value); + } + + public bool IsGeneric + { + get => this.ReadDataBool(288UL, false); + set => this.WriteData(288UL, value, false); + } + } + + public class @struct : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + DataWordCount = reader.DataWordCount; + PointerCount = reader.PointerCount; + PreferredListEncoding = reader.PreferredListEncoding; + IsGroup = reader.IsGroup; + DiscriminantCount = reader.DiscriminantCount; + DiscriminantOffset = reader.DiscriminantOffset; + Fields = reader.Fields.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.DataWordCount = DataWordCount; + writer.PointerCount = PointerCount; + writer.PreferredListEncoding = PreferredListEncoding; + writer.IsGroup = IsGroup; + writer.DiscriminantCount = DiscriminantCount; + writer.DiscriminantOffset = DiscriminantOffset; + writer.Fields.Init(Fields, (_s1, _v1) => _v1?.serialize(_s1)); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public ushort DataWordCount + { + get; + set; + } + + public ushort PointerCount + { + get; + set; + } + + public Capnp.Schema.ElementSize PreferredListEncoding + { + get; + set; + } + + public bool IsGroup + { + get; + set; + } + + public ushort DiscriminantCount + { + get; + set; + } + + public uint DiscriminantOffset + { + get; + set; + } + + public IReadOnlyList Fields + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public ushort DataWordCount => ctx.ReadDataUShort(112UL, (ushort)0); + public ushort PointerCount => ctx.ReadDataUShort(192UL, (ushort)0); + public Capnp.Schema.ElementSize PreferredListEncoding => (Capnp.Schema.ElementSize)ctx.ReadDataUShort(208UL, (ushort)0); + public bool IsGroup => ctx.ReadDataBool(224UL, false); + public ushort DiscriminantCount => ctx.ReadDataUShort(240UL, (ushort)0); + public uint DiscriminantOffset => ctx.ReadDataUInt(256UL, 0U); + public IReadOnlyList Fields => ctx.ReadList(3).Cast(Capnp.Schema.Field.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public ushort DataWordCount + { + get => this.ReadDataUShort(112UL, (ushort)0); + set => this.WriteData(112UL, value, (ushort)0); + } + + public ushort PointerCount + { + get => this.ReadDataUShort(192UL, (ushort)0); + set => this.WriteData(192UL, value, (ushort)0); + } + + public Capnp.Schema.ElementSize PreferredListEncoding + { + get => (Capnp.Schema.ElementSize)this.ReadDataUShort(208UL, (ushort)0); + set => this.WriteData(208UL, (ushort)value, (ushort)0); + } + + public bool IsGroup + { + get => this.ReadDataBool(224UL, false); + set => this.WriteData(224UL, value, false); + } + + public ushort DiscriminantCount + { + get => this.ReadDataUShort(240UL, (ushort)0); + set => this.WriteData(240UL, value, (ushort)0); + } + + public uint DiscriminantOffset + { + get => this.ReadDataUInt(256UL, 0U); + set => this.WriteData(256UL, value, 0U); + } + + public ListOfStructsSerializer Fields + { + get => BuildPointer>(3); + set => Link(3, value); + } + } + } + + public class @enum : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Enumerants = reader.Enumerants.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Enumerants.Init(Enumerants, (_s1, _v1) => _v1?.serialize(_s1)); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public IReadOnlyList Enumerants + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public IReadOnlyList Enumerants => ctx.ReadList(3).Cast(Capnp.Schema.Enumerant.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public ListOfStructsSerializer Enumerants + { + get => BuildPointer>(3); + set => Link(3, value); + } + } + } + + public class @interface : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Methods = reader.Methods.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + Superclasses = reader.Superclasses.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Methods.Init(Methods, (_s1, _v1) => _v1?.serialize(_s1)); + writer.Superclasses.Init(Superclasses, (_s1, _v1) => _v1?.serialize(_s1)); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public IReadOnlyList Methods + { + get; + set; + } + + public IReadOnlyList Superclasses + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public IReadOnlyList Methods => ctx.ReadList(3).Cast(Capnp.Schema.Method.READER.create); + public IReadOnlyList Superclasses => ctx.ReadList(4).Cast(Capnp.Schema.Superclass.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public ListOfStructsSerializer Methods + { + get => BuildPointer>(3); + set => Link(3, value); + } + + public ListOfStructsSerializer Superclasses + { + get => BuildPointer>(4); + set => Link(4, value); + } + } + } + + public class @const : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Type = CapnpSerializable.Create(reader.Type); + Value = CapnpSerializable.Create(reader.Value); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + Type?.serialize(writer.Type); + Value?.serialize(writer.Value); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnp.Schema.Type Type + { + get; + set; + } + + public Capnp.Schema.Value Value + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnp.Schema.Type.READER Type => ctx.ReadStruct(3, Capnp.Schema.Type.READER.create); + public Capnp.Schema.Value.READER Value => ctx.ReadStruct(4, Capnp.Schema.Value.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public Capnp.Schema.Type.WRITER Type + { + get => BuildPointer(3); + set => Link(3, value); + } + + public Capnp.Schema.Value.WRITER Value + { + get => BuildPointer(4); + set => Link(4, value); + } + } + } + + public class @annotation : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Type = CapnpSerializable.Create(reader.Type); + TargetsFile = reader.TargetsFile; + TargetsConst = reader.TargetsConst; + TargetsEnum = reader.TargetsEnum; + TargetsEnumerant = reader.TargetsEnumerant; + TargetsStruct = reader.TargetsStruct; + TargetsField = reader.TargetsField; + TargetsUnion = reader.TargetsUnion; + TargetsGroup = reader.TargetsGroup; + TargetsInterface = reader.TargetsInterface; + TargetsMethod = reader.TargetsMethod; + TargetsParam = reader.TargetsParam; + TargetsAnnotation = reader.TargetsAnnotation; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + Type?.serialize(writer.Type); + writer.TargetsFile = TargetsFile; + writer.TargetsConst = TargetsConst; + writer.TargetsEnum = TargetsEnum; + writer.TargetsEnumerant = TargetsEnumerant; + writer.TargetsStruct = TargetsStruct; + writer.TargetsField = TargetsField; + writer.TargetsUnion = TargetsUnion; + writer.TargetsGroup = TargetsGroup; + writer.TargetsInterface = TargetsInterface; + writer.TargetsMethod = TargetsMethod; + writer.TargetsParam = TargetsParam; + writer.TargetsAnnotation = TargetsAnnotation; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnp.Schema.Type Type + { + get; + set; + } + + public bool TargetsFile + { + get; + set; + } + + public bool TargetsConst + { + get; + set; + } + + public bool TargetsEnum + { + get; + set; + } + + public bool TargetsEnumerant + { + get; + set; + } + + public bool TargetsStruct + { + get; + set; + } + + public bool TargetsField + { + get; + set; + } + + public bool TargetsUnion + { + get; + set; + } + + public bool TargetsGroup + { + get; + set; + } + + public bool TargetsInterface + { + get; + set; + } + + public bool TargetsMethod + { + get; + set; + } + + public bool TargetsParam + { + get; + set; + } + + public bool TargetsAnnotation + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnp.Schema.Type.READER Type => ctx.ReadStruct(3, Capnp.Schema.Type.READER.create); + public bool TargetsFile => ctx.ReadDataBool(112UL, false); + public bool TargetsConst => ctx.ReadDataBool(113UL, false); + public bool TargetsEnum => ctx.ReadDataBool(114UL, false); + public bool TargetsEnumerant => ctx.ReadDataBool(115UL, false); + public bool TargetsStruct => ctx.ReadDataBool(116UL, false); + public bool TargetsField => ctx.ReadDataBool(117UL, false); + public bool TargetsUnion => ctx.ReadDataBool(118UL, false); + public bool TargetsGroup => ctx.ReadDataBool(119UL, false); + public bool TargetsInterface => ctx.ReadDataBool(120UL, false); + public bool TargetsMethod => ctx.ReadDataBool(121UL, false); + public bool TargetsParam => ctx.ReadDataBool(122UL, false); + public bool TargetsAnnotation => ctx.ReadDataBool(123UL, false); + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public Capnp.Schema.Type.WRITER Type + { + get => BuildPointer(3); + set => Link(3, value); + } + + public bool TargetsFile + { + get => this.ReadDataBool(112UL, false); + set => this.WriteData(112UL, value, false); + } + + public bool TargetsConst + { + get => this.ReadDataBool(113UL, false); + set => this.WriteData(113UL, value, false); + } + + public bool TargetsEnum + { + get => this.ReadDataBool(114UL, false); + set => this.WriteData(114UL, value, false); + } + + public bool TargetsEnumerant + { + get => this.ReadDataBool(115UL, false); + set => this.WriteData(115UL, value, false); + } + + public bool TargetsStruct + { + get => this.ReadDataBool(116UL, false); + set => this.WriteData(116UL, value, false); + } + + public bool TargetsField + { + get => this.ReadDataBool(117UL, false); + set => this.WriteData(117UL, value, false); + } + + public bool TargetsUnion + { + get => this.ReadDataBool(118UL, false); + set => this.WriteData(118UL, value, false); + } + + public bool TargetsGroup + { + get => this.ReadDataBool(119UL, false); + set => this.WriteData(119UL, value, false); + } + + public bool TargetsInterface + { + get => this.ReadDataBool(120UL, false); + set => this.WriteData(120UL, value, false); + } + + public bool TargetsMethod + { + get => this.ReadDataBool(121UL, false); + set => this.WriteData(121UL, value, false); + } + + public bool TargetsParam + { + get => this.ReadDataBool(122UL, false); + set => this.WriteData(122UL, value, false); + } + + public bool TargetsAnnotation + { + get => this.ReadDataBool(123UL, false); + set => this.WriteData(123UL, value, false); + } + } + } + + public class Parameter : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Name = reader.Name; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Name = Name; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string Name + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string Name => ctx.ReadText(0, ""); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public string Name + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + } + } + + public class NestedNode : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Name = reader.Name; + Id = reader.Id; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Name = Name; + writer.Id = Id; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string Name + { + get; + set; + } + + public ulong Id + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string Name => ctx.ReadText(0, ""); + public ulong Id => ctx.ReadDataULong(0UL, 0UL); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public string Name + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + + public ulong Id + { + get => this.ReadDataULong(0UL, 0UL); + set => this.WriteData(0UL, value, 0UL); + } + } + } + + public class SourceInfo : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Id = reader.Id; + DocComment = reader.DocComment; + Members = reader.Members.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Id = Id; + writer.DocComment = DocComment; + writer.Members.Init(Members, (_s1, _v1) => _v1?.serialize(_s1)); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public ulong Id + { + get; + set; + } + + public string DocComment + { + get; + set; + } + + public IReadOnlyList Members + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public ulong Id => ctx.ReadDataULong(0UL, 0UL); + public string DocComment => ctx.ReadText(0, ""); + public IReadOnlyList Members => ctx.ReadList(1).Cast(Capnp.Schema.Node.SourceInfo.Member.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 2); + } + + public ulong Id + { + get => this.ReadDataULong(0UL, 0UL); + set => this.WriteData(0UL, value, 0UL); + } + + public string DocComment + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + + public ListOfStructsSerializer Members + { + get => BuildPointer>(1); + set => Link(1, value); + } + } + + public class Member : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + DocComment = reader.DocComment; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.DocComment = DocComment; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string DocComment + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string DocComment => ctx.ReadText(0, ""); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public string DocComment + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + } + } + } + } + + public class Field : ICapnpSerializable + { + public enum WHICH : ushort + { + Slot = 0, + Group = 1, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.Slot: + Slot = CapnpSerializable.Create(reader.Slot); + break; + case WHICH.Group: + Group = CapnpSerializable.Create(reader.Group); + break; + } + + Name = reader.Name; + CodeOrder = reader.CodeOrder; + Annotations = reader.Annotations.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + DiscriminantValue = reader.DiscriminantValue; + Ordinal = CapnpSerializable.Create(reader.Ordinal); + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.Slot: + _content = null; + break; + case WHICH.Group: + _content = null; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.Slot: + Slot?.serialize(writer.Slot); + break; + case WHICH.Group: + Group?.serialize(writer.Group); + break; + } + + writer.Name = Name; + writer.CodeOrder = CodeOrder; + writer.Annotations.Init(Annotations, (_s1, _v1) => _v1?.serialize(_s1)); + writer.DiscriminantValue = DiscriminantValue; + Ordinal?.serialize(writer.Ordinal); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string Name + { + get; + set; + } + + public ushort CodeOrder + { + get; + set; + } + + public IReadOnlyList Annotations + { + get; + set; + } + + public ushort DiscriminantValue + { + get; + set; + } + + = 65535; + public Capnp.Schema.Field.@slot Slot + { + get => _which == WHICH.Slot ? (Capnp.Schema.Field.@slot)_content : null; + set + { + _which = WHICH.Slot; + _content = value; + } + } + + public Capnp.Schema.Field.@group Group + { + get => _which == WHICH.Group ? (Capnp.Schema.Field.@group)_content : null; + set + { + _which = WHICH.Group; + _content = value; + } + } + + public Capnp.Schema.Field.@ordinal Ordinal + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(64U, (ushort)0); + public string Name => ctx.ReadText(0, ""); + public ushort CodeOrder => ctx.ReadDataUShort(0UL, (ushort)0); + public IReadOnlyList Annotations => ctx.ReadList(1).Cast(Capnp.Schema.Annotation.READER.create); + public ushort DiscriminantValue => ctx.ReadDataUShort(16UL, (ushort)65535); + public @slot.READER Slot => which == WHICH.Slot ? new @slot.READER(ctx) : default; + public @group.READER Group => which == WHICH.Group ? new @group.READER(ctx) : default; + public @ordinal.READER Ordinal => new @ordinal.READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(3, 4); + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(64U, (ushort)0); + set => this.WriteData(64U, (ushort)value, (ushort)0); + } + + public string Name + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + + public ushort CodeOrder + { + get => this.ReadDataUShort(0UL, (ushort)0); + set => this.WriteData(0UL, value, (ushort)0); + } + + public ListOfStructsSerializer Annotations + { + get => BuildPointer>(1); + set => Link(1, value); + } + + public ushort DiscriminantValue + { + get => this.ReadDataUShort(16UL, (ushort)65535); + set => this.WriteData(16UL, value, (ushort)65535); + } + + public @slot.WRITER Slot + { + get => which == WHICH.Slot ? Rewrap<@slot.WRITER>() : default; + } + + public @group.WRITER Group + { + get => which == WHICH.Group ? Rewrap<@group.WRITER>() : default; + } + + public @ordinal.WRITER Ordinal + { + get => Rewrap<@ordinal.WRITER>(); + } + } + + public class @slot : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Offset = reader.Offset; + Type = CapnpSerializable.Create(reader.Type); + DefaultValue = CapnpSerializable.Create(reader.DefaultValue); + HadExplicitDefault = reader.HadExplicitDefault; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Offset = Offset; + Type?.serialize(writer.Type); + DefaultValue?.serialize(writer.DefaultValue); + writer.HadExplicitDefault = HadExplicitDefault; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public uint Offset + { + get; + set; + } + + public Capnp.Schema.Type Type + { + get; + set; + } + + public Capnp.Schema.Value DefaultValue + { + get; + set; + } + + public bool HadExplicitDefault + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public uint Offset => ctx.ReadDataUInt(32UL, 0U); + public Capnp.Schema.Type.READER Type => ctx.ReadStruct(2, Capnp.Schema.Type.READER.create); + public Capnp.Schema.Value.READER DefaultValue => ctx.ReadStruct(3, Capnp.Schema.Value.READER.create); + public bool HadExplicitDefault => ctx.ReadDataBool(128UL, false); + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public uint Offset + { + get => this.ReadDataUInt(32UL, 0U); + set => this.WriteData(32UL, value, 0U); + } + + public Capnp.Schema.Type.WRITER Type + { + get => BuildPointer(2); + set => Link(2, value); + } + + public Capnp.Schema.Value.WRITER DefaultValue + { + get => BuildPointer(3); + set => Link(3, value); + } + + public bool HadExplicitDefault + { + get => this.ReadDataBool(128UL, false); + set => this.WriteData(128UL, value, false); + } + } + } + + public class @group : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + TypeId = reader.TypeId; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.TypeId = TypeId; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public ulong TypeId + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public ulong TypeId => ctx.ReadDataULong(128UL, 0UL); + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public ulong TypeId + { + get => this.ReadDataULong(128UL, 0UL); + set => this.WriteData(128UL, value, 0UL); + } + } + } + + public class @ordinal : ICapnpSerializable + { + public enum WHICH : ushort + { + Implicit = 0, + Explicit = 1, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.Implicit: + which = reader.which; + break; + case WHICH.Explicit: + Explicit = reader.Explicit; + break; + } + + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.Implicit: + break; + case WHICH.Explicit: + _content = 0; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.Implicit: + break; + case WHICH.Explicit: + writer.Explicit = Explicit.Value; + break; + } + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public ushort? Explicit + { + get => _which == WHICH.Explicit ? (ushort? )_content : null; + set + { + _which = WHICH.Explicit; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(80U, (ushort)0); + public ushort Explicit => which == WHICH.Explicit ? ctx.ReadDataUShort(96UL, (ushort)0) : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(80U, (ushort)0); + set => this.WriteData(80U, (ushort)value, (ushort)0); + } + + public ushort Explicit + { + get => which == WHICH.Explicit ? this.ReadDataUShort(96UL, (ushort)0) : default; + set => this.WriteData(96UL, value, (ushort)0); + } + } + } + } + + public class Enumerant : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Name = reader.Name; + CodeOrder = reader.CodeOrder; + Annotations = reader.Annotations.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Name = Name; + writer.CodeOrder = CodeOrder; + writer.Annotations.Init(Annotations, (_s1, _v1) => _v1?.serialize(_s1)); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string Name + { + get; + set; + } + + public ushort CodeOrder + { + get; + set; + } + + public IReadOnlyList Annotations + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string Name => ctx.ReadText(0, ""); + public ushort CodeOrder => ctx.ReadDataUShort(0UL, (ushort)0); + public IReadOnlyList Annotations => ctx.ReadList(1).Cast(Capnp.Schema.Annotation.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 2); + } + + public string Name + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + + public ushort CodeOrder + { + get => this.ReadDataUShort(0UL, (ushort)0); + set => this.WriteData(0UL, value, (ushort)0); + } + + public ListOfStructsSerializer Annotations + { + get => BuildPointer>(1); + set => Link(1, value); + } + } + } + + public class Superclass : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Id = reader.Id; + Brand = CapnpSerializable.Create(reader.Brand); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Id = Id; + Brand?.serialize(writer.Brand); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public ulong Id + { + get; + set; + } + + public Capnp.Schema.Brand Brand + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public ulong Id => ctx.ReadDataULong(0UL, 0UL); + public Capnp.Schema.Brand.READER Brand => ctx.ReadStruct(0, Capnp.Schema.Brand.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public ulong Id + { + get => this.ReadDataULong(0UL, 0UL); + set => this.WriteData(0UL, value, 0UL); + } + + public Capnp.Schema.Brand.WRITER Brand + { + get => BuildPointer(0); + set => Link(0, value); + } + } + } + + public class Method : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Name = reader.Name; + CodeOrder = reader.CodeOrder; + ParamStructType = reader.ParamStructType; + ResultStructType = reader.ResultStructType; + Annotations = reader.Annotations.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + ParamBrand = CapnpSerializable.Create(reader.ParamBrand); + ResultBrand = CapnpSerializable.Create(reader.ResultBrand); + ImplicitParameters = reader.ImplicitParameters.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Name = Name; + writer.CodeOrder = CodeOrder; + writer.ParamStructType = ParamStructType; + writer.ResultStructType = ResultStructType; + writer.Annotations.Init(Annotations, (_s1, _v1) => _v1?.serialize(_s1)); + ParamBrand?.serialize(writer.ParamBrand); + ResultBrand?.serialize(writer.ResultBrand); + writer.ImplicitParameters.Init(ImplicitParameters, (_s1, _v1) => _v1?.serialize(_s1)); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string Name + { + get; + set; + } + + public ushort CodeOrder + { + get; + set; + } + + public ulong ParamStructType + { + get; + set; + } + + public ulong ResultStructType + { + get; + set; + } + + public IReadOnlyList Annotations + { + get; + set; + } + + public Capnp.Schema.Brand ParamBrand + { + get; + set; + } + + public Capnp.Schema.Brand ResultBrand + { + get; + set; + } + + public IReadOnlyList ImplicitParameters + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string Name => ctx.ReadText(0, ""); + public ushort CodeOrder => ctx.ReadDataUShort(0UL, (ushort)0); + public ulong ParamStructType => ctx.ReadDataULong(64UL, 0UL); + public ulong ResultStructType => ctx.ReadDataULong(128UL, 0UL); + public IReadOnlyList Annotations => ctx.ReadList(1).Cast(Capnp.Schema.Annotation.READER.create); + public Capnp.Schema.Brand.READER ParamBrand => ctx.ReadStruct(2, Capnp.Schema.Brand.READER.create); + public Capnp.Schema.Brand.READER ResultBrand => ctx.ReadStruct(3, Capnp.Schema.Brand.READER.create); + public IReadOnlyList ImplicitParameters => ctx.ReadList(4).Cast(Capnp.Schema.Node.Parameter.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(3, 5); + } + + public string Name + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + + public ushort CodeOrder + { + get => this.ReadDataUShort(0UL, (ushort)0); + set => this.WriteData(0UL, value, (ushort)0); + } + + public ulong ParamStructType + { + get => this.ReadDataULong(64UL, 0UL); + set => this.WriteData(64UL, value, 0UL); + } + + public ulong ResultStructType + { + get => this.ReadDataULong(128UL, 0UL); + set => this.WriteData(128UL, value, 0UL); + } + + public ListOfStructsSerializer Annotations + { + get => BuildPointer>(1); + set => Link(1, value); + } + + public Capnp.Schema.Brand.WRITER ParamBrand + { + get => BuildPointer(2); + set => Link(2, value); + } + + public Capnp.Schema.Brand.WRITER ResultBrand + { + get => BuildPointer(3); + set => Link(3, value); + } + + public ListOfStructsSerializer ImplicitParameters + { + get => BuildPointer>(4); + set => Link(4, value); + } + } + } + + public class Type : ICapnpSerializable + { + public enum WHICH : ushort + { + Void = 0, + Bool = 1, + Int8 = 2, + Int16 = 3, + Int32 = 4, + Int64 = 5, + Uint8 = 6, + Uint16 = 7, + Uint32 = 8, + Uint64 = 9, + Float32 = 10, + Float64 = 11, + Text = 12, + Data = 13, + List = 14, + Enum = 15, + Struct = 16, + Interface = 17, + AnyPointer = 18, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.Void: + which = reader.which; + break; + case WHICH.Bool: + which = reader.which; + break; + case WHICH.Int8: + which = reader.which; + break; + case WHICH.Int16: + which = reader.which; + break; + case WHICH.Int32: + which = reader.which; + break; + case WHICH.Int64: + which = reader.which; + break; + case WHICH.Uint8: + which = reader.which; + break; + case WHICH.Uint16: + which = reader.which; + break; + case WHICH.Uint32: + which = reader.which; + break; + case WHICH.Uint64: + which = reader.which; + break; + case WHICH.Float32: + which = reader.which; + break; + case WHICH.Float64: + which = reader.which; + break; + case WHICH.Text: + which = reader.which; + break; + case WHICH.Data: + which = reader.which; + break; + case WHICH.List: + List = CapnpSerializable.Create(reader.List); + break; + case WHICH.Enum: + Enum = CapnpSerializable.Create(reader.Enum); + break; + case WHICH.Struct: + Struct = CapnpSerializable.Create(reader.Struct); + break; + case WHICH.Interface: + Interface = CapnpSerializable.Create(reader.Interface); + break; + case WHICH.AnyPointer: + AnyPointer = CapnpSerializable.Create(reader.AnyPointer); + break; + } + + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.Void: + break; + case WHICH.Bool: + break; + case WHICH.Int8: + break; + case WHICH.Int16: + break; + case WHICH.Int32: + break; + case WHICH.Int64: + break; + case WHICH.Uint8: + break; + case WHICH.Uint16: + break; + case WHICH.Uint32: + break; + case WHICH.Uint64: + break; + case WHICH.Float32: + break; + case WHICH.Float64: + break; + case WHICH.Text: + break; + case WHICH.Data: + break; + case WHICH.List: + _content = null; + break; + case WHICH.Enum: + _content = null; + break; + case WHICH.Struct: + _content = null; + break; + case WHICH.Interface: + _content = null; + break; + case WHICH.AnyPointer: + _content = null; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.Void: + break; + case WHICH.Bool: + break; + case WHICH.Int8: + break; + case WHICH.Int16: + break; + case WHICH.Int32: + break; + case WHICH.Int64: + break; + case WHICH.Uint8: + break; + case WHICH.Uint16: + break; + case WHICH.Uint32: + break; + case WHICH.Uint64: + break; + case WHICH.Float32: + break; + case WHICH.Float64: + break; + case WHICH.Text: + break; + case WHICH.Data: + break; + case WHICH.List: + List?.serialize(writer.List); + break; + case WHICH.Enum: + Enum?.serialize(writer.Enum); + break; + case WHICH.Struct: + Struct?.serialize(writer.Struct); + break; + case WHICH.Interface: + Interface?.serialize(writer.Interface); + break; + case WHICH.AnyPointer: + AnyPointer?.serialize(writer.AnyPointer); + break; + } + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnp.Schema.Type.@list List + { + get => _which == WHICH.List ? (Capnp.Schema.Type.@list)_content : null; + set + { + _which = WHICH.List; + _content = value; + } + } + + public Capnp.Schema.Type.@enum Enum + { + get => _which == WHICH.Enum ? (Capnp.Schema.Type.@enum)_content : null; + set + { + _which = WHICH.Enum; + _content = value; + } + } + + public Capnp.Schema.Type.@struct Struct + { + get => _which == WHICH.Struct ? (Capnp.Schema.Type.@struct)_content : null; + set + { + _which = WHICH.Struct; + _content = value; + } + } + + public Capnp.Schema.Type.@interface Interface + { + get => _which == WHICH.Interface ? (Capnp.Schema.Type.@interface)_content : null; + set + { + _which = WHICH.Interface; + _content = value; + } + } + + public Capnp.Schema.Type.@anyPointer AnyPointer + { + get => _which == WHICH.AnyPointer ? (Capnp.Schema.Type.@anyPointer)_content : null; + set + { + _which = WHICH.AnyPointer; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(0U, (ushort)0); + public @list.READER List => which == WHICH.List ? new @list.READER(ctx) : default; + public @enum.READER Enum => which == WHICH.Enum ? new @enum.READER(ctx) : default; + public @struct.READER Struct => which == WHICH.Struct ? new @struct.READER(ctx) : default; + public @interface.READER Interface => which == WHICH.Interface ? new @interface.READER(ctx) : default; + public @anyPointer.READER AnyPointer => which == WHICH.AnyPointer ? new @anyPointer.READER(ctx) : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(3, 1); + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(0U, (ushort)0); + set => this.WriteData(0U, (ushort)value, (ushort)0); + } + + public @list.WRITER List + { + get => which == WHICH.List ? Rewrap<@list.WRITER>() : default; + } + + public @enum.WRITER Enum + { + get => which == WHICH.Enum ? Rewrap<@enum.WRITER>() : default; + } + + public @struct.WRITER Struct + { + get => which == WHICH.Struct ? Rewrap<@struct.WRITER>() : default; + } + + public @interface.WRITER Interface + { + get => which == WHICH.Interface ? Rewrap<@interface.WRITER>() : default; + } + + public @anyPointer.WRITER AnyPointer + { + get => which == WHICH.AnyPointer ? Rewrap<@anyPointer.WRITER>() : default; + } + } + + public class @list : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + ElementType = CapnpSerializable.Create(reader.ElementType); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + ElementType?.serialize(writer.ElementType); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnp.Schema.Type ElementType + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnp.Schema.Type.READER ElementType => ctx.ReadStruct(0, Capnp.Schema.Type.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public Capnp.Schema.Type.WRITER ElementType + { + get => BuildPointer(0); + set => Link(0, value); + } + } + } + + public class @enum : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + TypeId = reader.TypeId; + Brand = CapnpSerializable.Create(reader.Brand); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.TypeId = TypeId; + Brand?.serialize(writer.Brand); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public ulong TypeId + { + get; + set; + } + + public Capnp.Schema.Brand Brand + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public ulong TypeId => ctx.ReadDataULong(64UL, 0UL); + public Capnp.Schema.Brand.READER Brand => ctx.ReadStruct(0, Capnp.Schema.Brand.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public ulong TypeId + { + get => this.ReadDataULong(64UL, 0UL); + set => this.WriteData(64UL, value, 0UL); + } + + public Capnp.Schema.Brand.WRITER Brand + { + get => BuildPointer(0); + set => Link(0, value); + } + } + } + + public class @struct : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + TypeId = reader.TypeId; + Brand = CapnpSerializable.Create(reader.Brand); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.TypeId = TypeId; + Brand?.serialize(writer.Brand); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public ulong TypeId + { + get; + set; + } + + public Capnp.Schema.Brand Brand + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public ulong TypeId => ctx.ReadDataULong(64UL, 0UL); + public Capnp.Schema.Brand.READER Brand => ctx.ReadStruct(0, Capnp.Schema.Brand.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public ulong TypeId + { + get => this.ReadDataULong(64UL, 0UL); + set => this.WriteData(64UL, value, 0UL); + } + + public Capnp.Schema.Brand.WRITER Brand + { + get => BuildPointer(0); + set => Link(0, value); + } + } + } + + public class @interface : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + TypeId = reader.TypeId; + Brand = CapnpSerializable.Create(reader.Brand); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.TypeId = TypeId; + Brand?.serialize(writer.Brand); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public ulong TypeId + { + get; + set; + } + + public Capnp.Schema.Brand Brand + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public ulong TypeId => ctx.ReadDataULong(64UL, 0UL); + public Capnp.Schema.Brand.READER Brand => ctx.ReadStruct(0, Capnp.Schema.Brand.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public ulong TypeId + { + get => this.ReadDataULong(64UL, 0UL); + set => this.WriteData(64UL, value, 0UL); + } + + public Capnp.Schema.Brand.WRITER Brand + { + get => BuildPointer(0); + set => Link(0, value); + } + } + } + + public class @anyPointer : ICapnpSerializable + { + public enum WHICH : ushort + { + Unconstrained = 0, + Parameter = 1, + ImplicitMethodParameter = 2, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.Unconstrained: + Unconstrained = CapnpSerializable.Create(reader.Unconstrained); + break; + case WHICH.Parameter: + Parameter = CapnpSerializable.Create(reader.Parameter); + break; + case WHICH.ImplicitMethodParameter: + ImplicitMethodParameter = CapnpSerializable.Create(reader.ImplicitMethodParameter); + break; + } + + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.Unconstrained: + _content = null; + break; + case WHICH.Parameter: + _content = null; + break; + case WHICH.ImplicitMethodParameter: + _content = null; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.Unconstrained: + Unconstrained?.serialize(writer.Unconstrained); + break; + case WHICH.Parameter: + Parameter?.serialize(writer.Parameter); + break; + case WHICH.ImplicitMethodParameter: + ImplicitMethodParameter?.serialize(writer.ImplicitMethodParameter); + break; + } + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnp.Schema.Type.@anyPointer.@unconstrained Unconstrained + { + get => _which == WHICH.Unconstrained ? (Capnp.Schema.Type.@anyPointer.@unconstrained)_content : null; + set + { + _which = WHICH.Unconstrained; + _content = value; + } + } + + public Capnp.Schema.Type.@anyPointer.@parameter Parameter + { + get => _which == WHICH.Parameter ? (Capnp.Schema.Type.@anyPointer.@parameter)_content : null; + set + { + _which = WHICH.Parameter; + _content = value; + } + } + + public Capnp.Schema.Type.@anyPointer.@implicitMethodParameter ImplicitMethodParameter + { + get => _which == WHICH.ImplicitMethodParameter ? (Capnp.Schema.Type.@anyPointer.@implicitMethodParameter)_content : null; + set + { + _which = WHICH.ImplicitMethodParameter; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(64U, (ushort)0); + public @unconstrained.READER Unconstrained => which == WHICH.Unconstrained ? new @unconstrained.READER(ctx) : default; + public @parameter.READER Parameter => which == WHICH.Parameter ? new @parameter.READER(ctx) : default; + public @implicitMethodParameter.READER ImplicitMethodParameter => which == WHICH.ImplicitMethodParameter ? new @implicitMethodParameter.READER(ctx) : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(64U, (ushort)0); + set => this.WriteData(64U, (ushort)value, (ushort)0); + } + + public @unconstrained.WRITER Unconstrained + { + get => which == WHICH.Unconstrained ? Rewrap<@unconstrained.WRITER>() : default; + } + + public @parameter.WRITER Parameter + { + get => which == WHICH.Parameter ? Rewrap<@parameter.WRITER>() : default; + } + + public @implicitMethodParameter.WRITER ImplicitMethodParameter + { + get => which == WHICH.ImplicitMethodParameter ? Rewrap<@implicitMethodParameter.WRITER>() : default; + } + } + + public class @unconstrained : ICapnpSerializable + { + public enum WHICH : ushort + { + AnyKind = 0, + Struct = 1, + List = 2, + Capability = 3, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.AnyKind: + which = reader.which; + break; + case WHICH.Struct: + which = reader.which; + break; + case WHICH.List: + which = reader.which; + break; + case WHICH.Capability: + which = reader.which; + break; + } + + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.AnyKind: + break; + case WHICH.Struct: + break; + case WHICH.List: + break; + case WHICH.Capability: + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.AnyKind: + break; + case WHICH.Struct: + break; + case WHICH.List: + break; + case WHICH.Capability: + break; + } + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(80U, (ushort)0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(80U, (ushort)0); + set => this.WriteData(80U, (ushort)value, (ushort)0); + } + } + } + + public class @parameter : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + ScopeId = reader.ScopeId; + ParameterIndex = reader.ParameterIndex; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.ScopeId = ScopeId; + writer.ParameterIndex = ParameterIndex; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public ulong ScopeId + { + get; + set; + } + + public ushort ParameterIndex + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public ulong ScopeId => ctx.ReadDataULong(128UL, 0UL); + public ushort ParameterIndex => ctx.ReadDataUShort(80UL, (ushort)0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public ulong ScopeId + { + get => this.ReadDataULong(128UL, 0UL); + set => this.WriteData(128UL, value, 0UL); + } + + public ushort ParameterIndex + { + get => this.ReadDataUShort(80UL, (ushort)0); + set => this.WriteData(80UL, value, (ushort)0); + } + } + } + + public class @implicitMethodParameter : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + ParameterIndex = reader.ParameterIndex; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.ParameterIndex = ParameterIndex; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public ushort ParameterIndex + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public ushort ParameterIndex => ctx.ReadDataUShort(80UL, (ushort)0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public ushort ParameterIndex + { + get => this.ReadDataUShort(80UL, (ushort)0); + set => this.WriteData(80UL, value, (ushort)0); + } + } + } + } + } + + public class Brand : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Scopes = reader.Scopes.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Scopes.Init(Scopes, (_s1, _v1) => _v1?.serialize(_s1)); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public IReadOnlyList Scopes + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public IReadOnlyList Scopes => ctx.ReadList(0).Cast(Capnp.Schema.Brand.Scope.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public ListOfStructsSerializer Scopes + { + get => BuildPointer>(0); + set => Link(0, value); + } + } + + public class Scope : ICapnpSerializable + { + public enum WHICH : ushort + { + Bind = 0, + Inherit = 1, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.Bind: + Bind = reader.Bind.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + break; + case WHICH.Inherit: + which = reader.which; + break; + } + + ScopeId = reader.ScopeId; + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.Bind: + _content = null; + break; + case WHICH.Inherit: + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.Bind: + writer.Bind.Init(Bind, (_s1, _v1) => _v1?.serialize(_s1)); + break; + case WHICH.Inherit: + break; + } + + writer.ScopeId = ScopeId; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public ulong ScopeId + { + get; + set; + } + + public IReadOnlyList Bind + { + get => _which == WHICH.Bind ? (IReadOnlyList)_content : null; + set + { + _which = WHICH.Bind; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(64U, (ushort)0); + public ulong ScopeId => ctx.ReadDataULong(0UL, 0UL); + public IReadOnlyList Bind => which == WHICH.Bind ? ctx.ReadList(0).Cast(Capnp.Schema.Brand.Binding.READER.create) : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(2, 1); + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(64U, (ushort)0); + set => this.WriteData(64U, (ushort)value, (ushort)0); + } + + public ulong ScopeId + { + get => this.ReadDataULong(0UL, 0UL); + set => this.WriteData(0UL, value, 0UL); + } + + public ListOfStructsSerializer Bind + { + get => which == WHICH.Bind ? BuildPointer>(0) : default; + set => Link(0, value); + } + } + } + + public class Binding : ICapnpSerializable + { + public enum WHICH : ushort + { + Unbound = 0, + Type = 1, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.Unbound: + which = reader.which; + break; + case WHICH.Type: + Type = CapnpSerializable.Create(reader.Type); + break; + } + + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.Unbound: + break; + case WHICH.Type: + _content = null; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.Unbound: + break; + case WHICH.Type: + Type?.serialize(writer.Type); + break; + } + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnp.Schema.Type Type + { + get => _which == WHICH.Type ? (Capnp.Schema.Type)_content : null; + set + { + _which = WHICH.Type; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(0U, (ushort)0); + public Capnp.Schema.Type.READER Type => which == WHICH.Type ? ctx.ReadStruct(0, Capnp.Schema.Type.READER.create) : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(0U, (ushort)0); + set => this.WriteData(0U, (ushort)value, (ushort)0); + } + + public Capnp.Schema.Type.WRITER Type + { + get => which == WHICH.Type ? BuildPointer(0) : default; + set => Link(0, value); + } + } + } + } + + public class Value : ICapnpSerializable + { + public enum WHICH : ushort + { + Void = 0, + Bool = 1, + Int8 = 2, + Int16 = 3, + Int32 = 4, + Int64 = 5, + Uint8 = 6, + Uint16 = 7, + Uint32 = 8, + Uint64 = 9, + Float32 = 10, + Float64 = 11, + Text = 12, + Data = 13, + List = 14, + Enum = 15, + Struct = 16, + Interface = 17, + AnyPointer = 18, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.Void: + which = reader.which; + break; + case WHICH.Bool: + Bool = reader.Bool; + break; + case WHICH.Int8: + Int8 = reader.Int8; + break; + case WHICH.Int16: + Int16 = reader.Int16; + break; + case WHICH.Int32: + Int32 = reader.Int32; + break; + case WHICH.Int64: + Int64 = reader.Int64; + break; + case WHICH.Uint8: + Uint8 = reader.Uint8; + break; + case WHICH.Uint16: + Uint16 = reader.Uint16; + break; + case WHICH.Uint32: + Uint32 = reader.Uint32; + break; + case WHICH.Uint64: + Uint64 = reader.Uint64; + break; + case WHICH.Float32: + Float32 = reader.Float32; + break; + case WHICH.Float64: + Float64 = reader.Float64; + break; + case WHICH.Text: + Text = reader.Text; + break; + case WHICH.Data: + Data = reader.Data; + break; + case WHICH.List: + List = CapnpSerializable.Create(reader.List); + break; + case WHICH.Enum: + Enum = reader.Enum; + break; + case WHICH.Struct: + Struct = CapnpSerializable.Create(reader.Struct); + break; + case WHICH.Interface: + which = reader.which; + break; + case WHICH.AnyPointer: + AnyPointer = CapnpSerializable.Create(reader.AnyPointer); + break; + } + + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.Void: + break; + case WHICH.Bool: + _content = false; + break; + case WHICH.Int8: + _content = 0; + break; + case WHICH.Int16: + _content = 0; + break; + case WHICH.Int32: + _content = 0; + break; + case WHICH.Int64: + _content = 0; + break; + case WHICH.Uint8: + _content = 0; + break; + case WHICH.Uint16: + _content = 0; + break; + case WHICH.Uint32: + _content = 0; + break; + case WHICH.Uint64: + _content = 0; + break; + case WHICH.Float32: + _content = 0F; + break; + case WHICH.Float64: + _content = 0; + break; + case WHICH.Text: + _content = null; + break; + case WHICH.Data: + _content = null; + break; + case WHICH.List: + _content = null; + break; + case WHICH.Enum: + _content = 0; + break; + case WHICH.Struct: + _content = null; + break; + case WHICH.Interface: + break; + case WHICH.AnyPointer: + _content = null; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.Void: + break; + case WHICH.Bool: + writer.Bool = Bool.Value; + break; + case WHICH.Int8: + writer.Int8 = Int8.Value; + break; + case WHICH.Int16: + writer.Int16 = Int16.Value; + break; + case WHICH.Int32: + writer.Int32 = Int32.Value; + break; + case WHICH.Int64: + writer.Int64 = Int64.Value; + break; + case WHICH.Uint8: + writer.Uint8 = Uint8.Value; + break; + case WHICH.Uint16: + writer.Uint16 = Uint16.Value; + break; + case WHICH.Uint32: + writer.Uint32 = Uint32.Value; + break; + case WHICH.Uint64: + writer.Uint64 = Uint64.Value; + break; + case WHICH.Float32: + writer.Float32 = Float32.Value; + break; + case WHICH.Float64: + writer.Float64 = Float64.Value; + break; + case WHICH.Text: + writer.Text = Text; + break; + case WHICH.Data: + writer.Data.Init(Data); + break; + case WHICH.List: + writer.List.SetObject(List); + break; + case WHICH.Enum: + writer.Enum = Enum.Value; + break; + case WHICH.Struct: + writer.Struct.SetObject(Struct); + break; + case WHICH.Interface: + break; + case WHICH.AnyPointer: + writer.AnyPointer.SetObject(AnyPointer); + break; + } + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public bool? Bool + { + get => _which == WHICH.Bool ? (bool? )_content : null; + set + { + _which = WHICH.Bool; + _content = value; + } + } + + public sbyte? Int8 + { + get => _which == WHICH.Int8 ? (sbyte? )_content : null; + set + { + _which = WHICH.Int8; + _content = value; + } + } + + public short? Int16 + { + get => _which == WHICH.Int16 ? (short? )_content : null; + set + { + _which = WHICH.Int16; + _content = value; + } + } + + public int? Int32 + { + get => _which == WHICH.Int32 ? (int? )_content : null; + set + { + _which = WHICH.Int32; + _content = value; + } + } + + public long? Int64 + { + get => _which == WHICH.Int64 ? (long? )_content : null; + set + { + _which = WHICH.Int64; + _content = value; + } + } + + public byte? Uint8 + { + get => _which == WHICH.Uint8 ? (byte? )_content : null; + set + { + _which = WHICH.Uint8; + _content = value; + } + } + + public ushort? Uint16 + { + get => _which == WHICH.Uint16 ? (ushort? )_content : null; + set + { + _which = WHICH.Uint16; + _content = value; + } + } + + public uint? Uint32 + { + get => _which == WHICH.Uint32 ? (uint? )_content : null; + set + { + _which = WHICH.Uint32; + _content = value; + } + } + + public ulong? Uint64 + { + get => _which == WHICH.Uint64 ? (ulong? )_content : null; + set + { + _which = WHICH.Uint64; + _content = value; + } + } + + public float? Float32 + { + get => _which == WHICH.Float32 ? (float? )_content : null; + set + { + _which = WHICH.Float32; + _content = value; + } + } + + public double? Float64 + { + get => _which == WHICH.Float64 ? (double? )_content : null; + set + { + _which = WHICH.Float64; + _content = value; + } + } + + public string Text + { + get => _which == WHICH.Text ? (string)_content : null; + set + { + _which = WHICH.Text; + _content = value; + } + } + + public IReadOnlyList Data + { + get => _which == WHICH.Data ? (IReadOnlyList)_content : null; + set + { + _which = WHICH.Data; + _content = value; + } + } + + public AnyPointer List + { + get => _which == WHICH.List ? (AnyPointer)_content : null; + set + { + _which = WHICH.List; + _content = value; + } + } + + public ushort? Enum + { + get => _which == WHICH.Enum ? (ushort? )_content : null; + set + { + _which = WHICH.Enum; + _content = value; + } + } + + public AnyPointer Struct + { + get => _which == WHICH.Struct ? (AnyPointer)_content : null; + set + { + _which = WHICH.Struct; + _content = value; + } + } + + public AnyPointer AnyPointer + { + get => _which == WHICH.AnyPointer ? (AnyPointer)_content : null; + set + { + _which = WHICH.AnyPointer; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(0U, (ushort)0); + public bool Bool => which == WHICH.Bool ? ctx.ReadDataBool(16UL, false) : default; + public sbyte Int8 => which == WHICH.Int8 ? ctx.ReadDataSByte(16UL, (sbyte)0) : default; + public short Int16 => which == WHICH.Int16 ? ctx.ReadDataShort(16UL, (short)0) : default; + public int Int32 => which == WHICH.Int32 ? ctx.ReadDataInt(32UL, 0) : default; + public long Int64 => which == WHICH.Int64 ? ctx.ReadDataLong(64UL, 0L) : default; + public byte Uint8 => which == WHICH.Uint8 ? ctx.ReadDataByte(16UL, (byte)0) : default; + public ushort Uint16 => which == WHICH.Uint16 ? ctx.ReadDataUShort(16UL, (ushort)0) : default; + public uint Uint32 => which == WHICH.Uint32 ? ctx.ReadDataUInt(32UL, 0U) : default; + public ulong Uint64 => which == WHICH.Uint64 ? ctx.ReadDataULong(64UL, 0UL) : default; + public float Float32 => which == WHICH.Float32 ? ctx.ReadDataFloat(32UL, 0F) : default; + public double Float64 => which == WHICH.Float64 ? ctx.ReadDataDouble(64UL, 0) : default; + public string Text => which == WHICH.Text ? ctx.ReadText(0, "") : default; + public IReadOnlyList Data => which == WHICH.Data ? ctx.ReadList(0).CastByte() : default; + public DeserializerState List => which == WHICH.List ? ctx.StructReadPointer(0) : default; + public ushort Enum => which == WHICH.Enum ? ctx.ReadDataUShort(16UL, (ushort)0) : default; + public DeserializerState Struct => which == WHICH.Struct ? ctx.StructReadPointer(0) : default; + public DeserializerState AnyPointer => which == WHICH.AnyPointer ? ctx.StructReadPointer(0) : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(2, 1); + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(0U, (ushort)0); + set => this.WriteData(0U, (ushort)value, (ushort)0); + } + + public bool Bool + { + get => which == WHICH.Bool ? this.ReadDataBool(16UL, false) : default; + set => this.WriteData(16UL, value, false); + } + + public sbyte Int8 + { + get => which == WHICH.Int8 ? this.ReadDataSByte(16UL, (sbyte)0) : default; + set => this.WriteData(16UL, value, (sbyte)0); + } + + public short Int16 + { + get => which == WHICH.Int16 ? this.ReadDataShort(16UL, (short)0) : default; + set => this.WriteData(16UL, value, (short)0); + } + + public int Int32 + { + get => which == WHICH.Int32 ? this.ReadDataInt(32UL, 0) : default; + set => this.WriteData(32UL, value, 0); + } + + public long Int64 + { + get => which == WHICH.Int64 ? this.ReadDataLong(64UL, 0L) : default; + set => this.WriteData(64UL, value, 0L); + } + + public byte Uint8 + { + get => which == WHICH.Uint8 ? this.ReadDataByte(16UL, (byte)0) : default; + set => this.WriteData(16UL, value, (byte)0); + } + + public ushort Uint16 + { + get => which == WHICH.Uint16 ? this.ReadDataUShort(16UL, (ushort)0) : default; + set => this.WriteData(16UL, value, (ushort)0); + } + + public uint Uint32 + { + get => which == WHICH.Uint32 ? this.ReadDataUInt(32UL, 0U) : default; + set => this.WriteData(32UL, value, 0U); + } + + public ulong Uint64 + { + get => which == WHICH.Uint64 ? this.ReadDataULong(64UL, 0UL) : default; + set => this.WriteData(64UL, value, 0UL); + } + + public float Float32 + { + get => which == WHICH.Float32 ? this.ReadDataFloat(32UL, 0F) : default; + set => this.WriteData(32UL, value, 0F); + } + + public double Float64 + { + get => which == WHICH.Float64 ? this.ReadDataDouble(64UL, 0) : default; + set => this.WriteData(64UL, value, 0); + } + + public string Text + { + get => which == WHICH.Text ? this.ReadText(0, "") : default; + set => this.WriteText(0, value, ""); + } + + public ListOfPrimitivesSerializer Data + { + get => which == WHICH.Data ? BuildPointer>(0) : default; + set => Link(0, value); + } + + public DynamicSerializerState List + { + get => which == WHICH.List ? BuildPointer(0) : default; + set => Link(0, value); + } + + public ushort Enum + { + get => which == WHICH.Enum ? this.ReadDataUShort(16UL, (ushort)0) : default; + set => this.WriteData(16UL, value, (ushort)0); + } + + public DynamicSerializerState Struct + { + get => which == WHICH.Struct ? BuildPointer(0) : default; + set => Link(0, value); + } + + public DynamicSerializerState AnyPointer + { + get => which == WHICH.AnyPointer ? BuildPointer(0) : default; + set => Link(0, value); + } + } + } + + public class Annotation : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Id = reader.Id; + Value = CapnpSerializable.Create(reader.Value); + Brand = CapnpSerializable.Create(reader.Brand); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Id = Id; + Value?.serialize(writer.Value); + Brand?.serialize(writer.Brand); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public ulong Id + { + get; + set; + } + + public Capnp.Schema.Value Value + { + get; + set; + } + + public Capnp.Schema.Brand Brand + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public ulong Id => ctx.ReadDataULong(0UL, 0UL); + public Capnp.Schema.Value.READER Value => ctx.ReadStruct(0, Capnp.Schema.Value.READER.create); + public Capnp.Schema.Brand.READER Brand => ctx.ReadStruct(1, Capnp.Schema.Brand.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 2); + } + + public ulong Id + { + get => this.ReadDataULong(0UL, 0UL); + set => this.WriteData(0UL, value, 0UL); + } + + public Capnp.Schema.Value.WRITER Value + { + get => BuildPointer(0); + set => Link(0, value); + } + + public Capnp.Schema.Brand.WRITER Brand + { + get => BuildPointer(1); + set => Link(1, value); + } + } + } + + public enum ElementSize : ushort + { + empty, + bit, + @byte, + twoBytes, + fourBytes, + eightBytes, + pointer, + inlineComposite + } + + public class CapnpVersion : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Major = reader.Major; + Minor = reader.Minor; + Micro = reader.Micro; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Major = Major; + writer.Minor = Minor; + writer.Micro = Micro; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public ushort Major + { + get; + set; + } + + public byte Minor + { + get; + set; + } + + public byte Micro + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public ushort Major => ctx.ReadDataUShort(0UL, (ushort)0); + public byte Minor => ctx.ReadDataByte(16UL, (byte)0); + public byte Micro => ctx.ReadDataByte(24UL, (byte)0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 0); + } + + public ushort Major + { + get => this.ReadDataUShort(0UL, (ushort)0); + set => this.WriteData(0UL, value, (ushort)0); + } + + public byte Minor + { + get => this.ReadDataByte(16UL, (byte)0); + set => this.WriteData(16UL, value, (byte)0); + } + + public byte Micro + { + get => this.ReadDataByte(24UL, (byte)0); + set => this.WriteData(24UL, value, (byte)0); + } + } + } + + public class CodeGeneratorRequest : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Nodes = reader.Nodes.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + RequestedFiles = reader.RequestedFiles.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + CapnpVersion = CapnpSerializable.Create(reader.CapnpVersion); + SourceInfo = reader.SourceInfo.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Nodes.Init(Nodes, (_s1, _v1) => _v1?.serialize(_s1)); + writer.RequestedFiles.Init(RequestedFiles, (_s1, _v1) => _v1?.serialize(_s1)); + CapnpVersion?.serialize(writer.CapnpVersion); + writer.SourceInfo.Init(SourceInfo, (_s1, _v1) => _v1?.serialize(_s1)); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public IReadOnlyList Nodes + { + get; + set; + } + + public IReadOnlyList RequestedFiles + { + get; + set; + } + + public Capnp.Schema.CapnpVersion CapnpVersion + { + get; + set; + } + + public IReadOnlyList SourceInfo + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public IReadOnlyList Nodes => ctx.ReadList(0).Cast(Capnp.Schema.Node.READER.create); + public IReadOnlyList RequestedFiles => ctx.ReadList(1).Cast(Capnp.Schema.CodeGeneratorRequest.RequestedFile.READER.create); + public Capnp.Schema.CapnpVersion.READER CapnpVersion => ctx.ReadStruct(2, Capnp.Schema.CapnpVersion.READER.create); + public IReadOnlyList SourceInfo => ctx.ReadList(3).Cast(Capnp.Schema.Node.SourceInfo.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 4); + } + + public ListOfStructsSerializer Nodes + { + get => BuildPointer>(0); + set => Link(0, value); + } + + public ListOfStructsSerializer RequestedFiles + { + get => BuildPointer>(1); + set => Link(1, value); + } + + public Capnp.Schema.CapnpVersion.WRITER CapnpVersion + { + get => BuildPointer(2); + set => Link(2, value); + } + + public ListOfStructsSerializer SourceInfo + { + get => BuildPointer>(3); + set => Link(3, value); + } + } + + public class RequestedFile : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Id = reader.Id; + Filename = reader.Filename; + Imports = reader.Imports.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Id = Id; + writer.Filename = Filename; + writer.Imports.Init(Imports, (_s1, _v1) => _v1?.serialize(_s1)); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public ulong Id + { + get; + set; + } + + public string Filename + { + get; + set; + } + + public IReadOnlyList Imports + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public ulong Id => ctx.ReadDataULong(0UL, 0UL); + public string Filename => ctx.ReadText(0, ""); + public IReadOnlyList Imports => ctx.ReadList(1).Cast(Capnp.Schema.CodeGeneratorRequest.RequestedFile.Import.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 2); + } + + public ulong Id + { + get => this.ReadDataULong(0UL, 0UL); + set => this.WriteData(0UL, value, 0UL); + } + + public string Filename + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + + public ListOfStructsSerializer Imports + { + get => BuildPointer>(1); + set => Link(1, value); + } + } + + public class Import : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Id = reader.Id; + Name = reader.Name; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Id = Id; + writer.Name = Name; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public ulong Id + { + get; + set; + } + + public string Name + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public ulong Id => ctx.ReadDataULong(0UL, 0UL); + public string Name => ctx.ReadText(0, ""); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public ulong Id + { + get => this.ReadDataULong(0UL, 0UL); + set => this.WriteData(0UL, value, 0UL); + } + + public string Name + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + } + } + } + } +} \ No newline at end of file diff --git a/MsBuildGenerationTest/capnp/test-import.capnp.cs b/MsBuildGenerationTest/capnp/test-import.capnp.cs new file mode 100644 index 0000000..3fc5b54 --- /dev/null +++ b/MsBuildGenerationTest/capnp/test-import.capnp.cs @@ -0,0 +1,67 @@ +using Capnp; +using Capnp.Rpc; +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +namespace CapnpGen +{ + public class TestImport : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Field = CapnpSerializable.Create(reader.Field); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + Field?.serialize(writer.Field); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.TestAllTypes Field + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnproto_test.Capnp.Test.TestAllTypes.READER Field => ctx.ReadStruct(0, Capnproto_test.Capnp.Test.TestAllTypes.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public Capnproto_test.Capnp.Test.TestAllTypes.WRITER Field + { + get => BuildPointer(0); + set => Link(0, value); + } + } + } +} \ No newline at end of file diff --git a/MsBuildGenerationTest/capnp/test-import2.capnp.cs b/MsBuildGenerationTest/capnp/test-import2.capnp.cs new file mode 100644 index 0000000..534bba9 --- /dev/null +++ b/MsBuildGenerationTest/capnp/test-import2.capnp.cs @@ -0,0 +1,97 @@ +using Capnp; +using Capnp.Rpc; +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +namespace CapnpGen +{ + public class TestImport2 : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Foo = CapnpSerializable.Create(reader.Foo); + Bar = CapnpSerializable.Create(reader.Bar); + Baz = CapnpSerializable.Create(reader.Baz); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + Foo?.serialize(writer.Foo); + Bar?.serialize(writer.Bar); + Baz?.serialize(writer.Baz); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.TestAllTypes Foo + { + get; + set; + } + + public Capnp.Schema.Node Bar + { + get; + set; + } + + public CapnpGen.TestImport Baz + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnproto_test.Capnp.Test.TestAllTypes.READER Foo => ctx.ReadStruct(0, Capnproto_test.Capnp.Test.TestAllTypes.READER.create); + public Capnp.Schema.Node.READER Bar => ctx.ReadStruct(1, Capnp.Schema.Node.READER.create); + public CapnpGen.TestImport.READER Baz => ctx.ReadStruct(2, CapnpGen.TestImport.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 3); + } + + public Capnproto_test.Capnp.Test.TestAllTypes.WRITER Foo + { + get => BuildPointer(0); + set => Link(0, value); + } + + public Capnp.Schema.Node.WRITER Bar + { + get => BuildPointer(1); + set => Link(1, value); + } + + public CapnpGen.TestImport.WRITER Baz + { + get => BuildPointer(2); + set => Link(2, value); + } + } + } +} \ No newline at end of file diff --git a/MsBuildGenerationTest/capnp/test.capnp.cs b/MsBuildGenerationTest/capnp/test.capnp.cs new file mode 100644 index 0000000..d20da0b --- /dev/null +++ b/MsBuildGenerationTest/capnp/test.capnp.cs @@ -0,0 +1,16200 @@ +using Capnp; +using Capnp.Rpc; +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +namespace Capnproto_test.Capnp.Test +{ + public enum TestEnum : ushort + { + foo, + bar, + baz, + qux, + quux, + corge, + grault, + garply + } + + public class TestAllTypes : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + BoolField = reader.BoolField; + Int8Field = reader.Int8Field; + Int16Field = reader.Int16Field; + Int32Field = reader.Int32Field; + Int64Field = reader.Int64Field; + UInt8Field = reader.UInt8Field; + UInt16Field = reader.UInt16Field; + UInt32Field = reader.UInt32Field; + UInt64Field = reader.UInt64Field; + Float32Field = reader.Float32Field; + Float64Field = reader.Float64Field; + TextField = reader.TextField; + DataField = reader.DataField; + StructField = CapnpSerializable.Create(reader.StructField); + EnumField = reader.EnumField; + VoidList = reader.VoidList; + BoolList = reader.BoolList; + Int8List = reader.Int8List; + Int16List = reader.Int16List; + Int32List = reader.Int32List; + Int64List = reader.Int64List; + UInt8List = reader.UInt8List; + UInt16List = reader.UInt16List; + UInt32List = reader.UInt32List; + UInt64List = reader.UInt64List; + Float32List = reader.Float32List; + Float64List = reader.Float64List; + TextList = reader.TextList; + DataList = reader.DataList; + StructList = reader.StructList.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + EnumList = reader.EnumList; + InterfaceList = reader.InterfaceList; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.BoolField = BoolField; + writer.Int8Field = Int8Field; + writer.Int16Field = Int16Field; + writer.Int32Field = Int32Field; + writer.Int64Field = Int64Field; + writer.UInt8Field = UInt8Field; + writer.UInt16Field = UInt16Field; + writer.UInt32Field = UInt32Field; + writer.UInt64Field = UInt64Field; + writer.Float32Field = Float32Field; + writer.Float64Field = Float64Field; + writer.TextField = TextField; + writer.DataField.Init(DataField); + StructField?.serialize(writer.StructField); + writer.EnumField = EnumField; + writer.VoidList.Init(VoidList); + writer.BoolList.Init(BoolList); + writer.Int8List.Init(Int8List); + writer.Int16List.Init(Int16List); + writer.Int32List.Init(Int32List); + writer.Int64List.Init(Int64List); + writer.UInt8List.Init(UInt8List); + writer.UInt16List.Init(UInt16List); + writer.UInt32List.Init(UInt32List); + writer.UInt64List.Init(UInt64List); + writer.Float32List.Init(Float32List); + writer.Float64List.Init(Float64List); + writer.TextList.Init(TextList); + writer.DataList.Init(DataList, (_s1, _v1) => _s1.Init(_v1)); + writer.StructList.Init(StructList, (_s1, _v1) => _v1?.serialize(_s1)); + writer.EnumList.Init(EnumList); + writer.InterfaceList.Init(InterfaceList); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public bool BoolField + { + get; + set; + } + + public sbyte Int8Field + { + get; + set; + } + + public short Int16Field + { + get; + set; + } + + public int Int32Field + { + get; + set; + } + + public long Int64Field + { + get; + set; + } + + public byte UInt8Field + { + get; + set; + } + + public ushort UInt16Field + { + get; + set; + } + + public uint UInt32Field + { + get; + set; + } + + public ulong UInt64Field + { + get; + set; + } + + public float Float32Field + { + get; + set; + } + + public double Float64Field + { + get; + set; + } + + public string TextField + { + get; + set; + } + + public IReadOnlyList DataField + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestAllTypes StructField + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestEnum EnumField + { + get; + set; + } + + public int VoidList + { + get; + set; + } + + public IReadOnlyList BoolList + { + get; + set; + } + + public IReadOnlyList Int8List + { + get; + set; + } + + public IReadOnlyList Int16List + { + get; + set; + } + + public IReadOnlyList Int32List + { + get; + set; + } + + public IReadOnlyList Int64List + { + get; + set; + } + + public IReadOnlyList UInt8List + { + get; + set; + } + + public IReadOnlyList UInt16List + { + get; + set; + } + + public IReadOnlyList UInt32List + { + get; + set; + } + + public IReadOnlyList UInt64List + { + get; + set; + } + + public IReadOnlyList Float32List + { + get; + set; + } + + public IReadOnlyList Float64List + { + get; + set; + } + + public IReadOnlyList TextList + { + get; + set; + } + + public IReadOnlyList> DataList + { + get; + set; + } + + public IReadOnlyList StructList + { + get; + set; + } + + public IReadOnlyList EnumList + { + get; + set; + } + + public int InterfaceList + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public bool BoolField => ctx.ReadDataBool(0UL, false); + public sbyte Int8Field => ctx.ReadDataSByte(8UL, (sbyte)0); + public short Int16Field => ctx.ReadDataShort(16UL, (short)0); + public int Int32Field => ctx.ReadDataInt(32UL, 0); + public long Int64Field => ctx.ReadDataLong(64UL, 0L); + public byte UInt8Field => ctx.ReadDataByte(128UL, (byte)0); + public ushort UInt16Field => ctx.ReadDataUShort(144UL, (ushort)0); + public uint UInt32Field => ctx.ReadDataUInt(160UL, 0U); + public ulong UInt64Field => ctx.ReadDataULong(192UL, 0UL); + public float Float32Field => ctx.ReadDataFloat(256UL, 0F); + public double Float64Field => ctx.ReadDataDouble(320UL, 0); + public string TextField => ctx.ReadText(0, ""); + public IReadOnlyList DataField => ctx.ReadList(1).CastByte(); + public Capnproto_test.Capnp.Test.TestAllTypes.READER StructField => ctx.ReadStruct(2, Capnproto_test.Capnp.Test.TestAllTypes.READER.create); + public Capnproto_test.Capnp.Test.TestEnum EnumField => (Capnproto_test.Capnp.Test.TestEnum)ctx.ReadDataUShort(288UL, (ushort)0); + public int VoidList => ctx.ReadList(3).Count; + public IReadOnlyList BoolList => ctx.ReadList(4).CastBool(); + public IReadOnlyList Int8List => ctx.ReadList(5).CastSByte(); + public IReadOnlyList Int16List => ctx.ReadList(6).CastShort(); + public IReadOnlyList Int32List => ctx.ReadList(7).CastInt(); + public IReadOnlyList Int64List => ctx.ReadList(8).CastLong(); + public IReadOnlyList UInt8List => ctx.ReadList(9).CastByte(); + public IReadOnlyList UInt16List => ctx.ReadList(10).CastUShort(); + public IReadOnlyList UInt32List => ctx.ReadList(11).CastUInt(); + public IReadOnlyList UInt64List => ctx.ReadList(12).CastULong(); + public IReadOnlyList Float32List => ctx.ReadList(13).CastFloat(); + public IReadOnlyList Float64List => ctx.ReadList(14).CastDouble(); + public IReadOnlyList TextList => ctx.ReadList(15).CastText2(); + public IReadOnlyList> DataList => ctx.ReadList(16).CastData(); + public IReadOnlyList StructList => ctx.ReadList(17).Cast(Capnproto_test.Capnp.Test.TestAllTypes.READER.create); + public IReadOnlyList EnumList => ctx.ReadList(18).CastEnums(_0 => (Capnproto_test.Capnp.Test.TestEnum)_0); + public int InterfaceList => ctx.ReadList(19).Count; + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(6, 20); + } + + public bool BoolField + { + get => this.ReadDataBool(0UL, false); + set => this.WriteData(0UL, value, false); + } + + public sbyte Int8Field + { + get => this.ReadDataSByte(8UL, (sbyte)0); + set => this.WriteData(8UL, value, (sbyte)0); + } + + public short Int16Field + { + get => this.ReadDataShort(16UL, (short)0); + set => this.WriteData(16UL, value, (short)0); + } + + public int Int32Field + { + get => this.ReadDataInt(32UL, 0); + set => this.WriteData(32UL, value, 0); + } + + public long Int64Field + { + get => this.ReadDataLong(64UL, 0L); + set => this.WriteData(64UL, value, 0L); + } + + public byte UInt8Field + { + get => this.ReadDataByte(128UL, (byte)0); + set => this.WriteData(128UL, value, (byte)0); + } + + public ushort UInt16Field + { + get => this.ReadDataUShort(144UL, (ushort)0); + set => this.WriteData(144UL, value, (ushort)0); + } + + public uint UInt32Field + { + get => this.ReadDataUInt(160UL, 0U); + set => this.WriteData(160UL, value, 0U); + } + + public ulong UInt64Field + { + get => this.ReadDataULong(192UL, 0UL); + set => this.WriteData(192UL, value, 0UL); + } + + public float Float32Field + { + get => this.ReadDataFloat(256UL, 0F); + set => this.WriteData(256UL, value, 0F); + } + + public double Float64Field + { + get => this.ReadDataDouble(320UL, 0); + set => this.WriteData(320UL, value, 0); + } + + public string TextField + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + + public ListOfPrimitivesSerializer DataField + { + get => BuildPointer>(1); + set => Link(1, value); + } + + public Capnproto_test.Capnp.Test.TestAllTypes.WRITER StructField + { + get => BuildPointer(2); + set => Link(2, value); + } + + public Capnproto_test.Capnp.Test.TestEnum EnumField + { + get => (Capnproto_test.Capnp.Test.TestEnum)this.ReadDataUShort(288UL, (ushort)0); + set => this.WriteData(288UL, (ushort)value, (ushort)0); + } + + public ListOfEmptySerializer VoidList + { + get => BuildPointer(3); + set => Link(3, value); + } + + public ListOfBitsSerializer BoolList + { + get => BuildPointer(4); + set => Link(4, value); + } + + public ListOfPrimitivesSerializer Int8List + { + get => BuildPointer>(5); + set => Link(5, value); + } + + public ListOfPrimitivesSerializer Int16List + { + get => BuildPointer>(6); + set => Link(6, value); + } + + public ListOfPrimitivesSerializer Int32List + { + get => BuildPointer>(7); + set => Link(7, value); + } + + public ListOfPrimitivesSerializer Int64List + { + get => BuildPointer>(8); + set => Link(8, value); + } + + public ListOfPrimitivesSerializer UInt8List + { + get => BuildPointer>(9); + set => Link(9, value); + } + + public ListOfPrimitivesSerializer UInt16List + { + get => BuildPointer>(10); + set => Link(10, value); + } + + public ListOfPrimitivesSerializer UInt32List + { + get => BuildPointer>(11); + set => Link(11, value); + } + + public ListOfPrimitivesSerializer UInt64List + { + get => BuildPointer>(12); + set => Link(12, value); + } + + public ListOfPrimitivesSerializer Float32List + { + get => BuildPointer>(13); + set => Link(13, value); + } + + public ListOfPrimitivesSerializer Float64List + { + get => BuildPointer>(14); + set => Link(14, value); + } + + public ListOfTextSerializer TextList + { + get => BuildPointer(15); + set => Link(15, value); + } + + public ListOfPointersSerializer> DataList + { + get => BuildPointer>>(16); + set => Link(16, value); + } + + public ListOfStructsSerializer StructList + { + get => BuildPointer>(17); + set => Link(17, value); + } + + public ListOfPrimitivesSerializer EnumList + { + get => BuildPointer>(18); + set => Link(18, value); + } + + public ListOfEmptySerializer InterfaceList + { + get => BuildPointer(19); + set => Link(19, value); + } + } + } + + public class TestDefaults : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + BoolField = reader.BoolField; + Int8Field = reader.Int8Field; + Int16Field = reader.Int16Field; + Int32Field = reader.Int32Field; + Int64Field = reader.Int64Field; + UInt8Field = reader.UInt8Field; + UInt16Field = reader.UInt16Field; + UInt32Field = reader.UInt32Field; + UInt64Field = reader.UInt64Field; + Float32Field = reader.Float32Field; + Float64Field = reader.Float64Field; + TextField = reader.TextField; + DataField = reader.DataField; + StructField = CapnpSerializable.Create(reader.StructField); + EnumField = reader.EnumField; + VoidList = reader.VoidList; + BoolList = reader.BoolList; + Int8List = reader.Int8List; + Int16List = reader.Int16List; + Int32List = reader.Int32List; + Int64List = reader.Int64List; + UInt8List = reader.UInt8List; + UInt16List = reader.UInt16List; + UInt32List = reader.UInt32List; + UInt64List = reader.UInt64List; + Float32List = reader.Float32List; + Float64List = reader.Float64List; + TextList = reader.TextList; + DataList = reader.DataList; + StructList = reader.StructList.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + EnumList = reader.EnumList; + InterfaceList = reader.InterfaceList; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.BoolField = BoolField; + writer.Int8Field = Int8Field; + writer.Int16Field = Int16Field; + writer.Int32Field = Int32Field; + writer.Int64Field = Int64Field; + writer.UInt8Field = UInt8Field; + writer.UInt16Field = UInt16Field; + writer.UInt32Field = UInt32Field; + writer.UInt64Field = UInt64Field; + writer.Float32Field = Float32Field; + writer.Float64Field = Float64Field; + writer.TextField = TextField; + writer.DataField.Init(DataField); + StructField?.serialize(writer.StructField); + writer.EnumField = EnumField; + writer.VoidList.Init(VoidList); + writer.BoolList.Init(BoolList); + writer.Int8List.Init(Int8List); + writer.Int16List.Init(Int16List); + writer.Int32List.Init(Int32List); + writer.Int64List.Init(Int64List); + writer.UInt8List.Init(UInt8List); + writer.UInt16List.Init(UInt16List); + writer.UInt32List.Init(UInt32List); + writer.UInt64List.Init(UInt64List); + writer.Float32List.Init(Float32List); + writer.Float64List.Init(Float64List); + writer.TextList.Init(TextList); + writer.DataList.Init(DataList, (_s1, _v1) => _s1.Init(_v1)); + writer.StructList.Init(StructList, (_s1, _v1) => _v1?.serialize(_s1)); + writer.EnumList.Init(EnumList); + writer.InterfaceList.Init(InterfaceList); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + TextField = TextField ?? "foo"; + DataField = DataField ?? new byte[]{98, 97, 114}; + StructField = StructField ?? new Capnproto_test.Capnp.Test.TestAllTypes() + {BoolField = true, Int8Field = -12, Int16Field = 3456, Int32Field = -78901234, Int64Field = 56789012345678L, UInt8Field = 90, UInt16Field = 1234, UInt32Field = 56789012U, UInt64Field = 345678901234567890UL, Float32Field = -1.25E-10F, Float64Field = 345, TextField = "baz", DataField = new byte[]{113, 117, 120}, StructField = new Capnproto_test.Capnp.Test.TestAllTypes() + {BoolField = false, Int8Field = 0, Int16Field = 0, Int32Field = 0, Int64Field = 0L, UInt8Field = 0, UInt16Field = 0, UInt32Field = 0U, UInt64Field = 0UL, Float32Field = 0F, Float64Field = 0, TextField = "nested", DataField = new byte[]{}, StructField = new Capnproto_test.Capnp.Test.TestAllTypes() + {BoolField = false, Int8Field = 0, Int16Field = 0, Int32Field = 0, Int64Field = 0L, UInt8Field = 0, UInt16Field = 0, UInt32Field = 0U, UInt64Field = 0UL, Float32Field = 0F, Float64Field = 0, TextField = "really nested", DataField = new byte[]{}, StructField = new Capnproto_test.Capnp.Test.TestAllTypes() + {}, EnumField = Capnproto_test.Capnp.Test.TestEnum.foo, VoidList = 0, BoolList = new bool[]{}, Int8List = new sbyte[]{}, Int16List = new short[]{}, Int32List = new int[]{}, Int64List = new long[]{}, UInt8List = new byte[]{}, UInt16List = new ushort[]{}, UInt32List = new uint[]{}, UInt64List = new ulong[]{}, Float32List = new float[]{}, Float64List = new double[]{}, TextList = new string[]{}, DataList = new IReadOnlyList[]{}, StructList = new Capnproto_test.Capnp.Test.TestAllTypes[]{}, EnumList = new Capnproto_test.Capnp.Test.TestEnum[]{}, InterfaceList = 0}, EnumField = Capnproto_test.Capnp.Test.TestEnum.foo, VoidList = 0, BoolList = new bool[]{}, Int8List = new sbyte[]{}, Int16List = new short[]{}, Int32List = new int[]{}, Int64List = new long[]{}, UInt8List = new byte[]{}, UInt16List = new ushort[]{}, UInt32List = new uint[]{}, UInt64List = new ulong[]{}, Float32List = new float[]{}, Float64List = new double[]{}, TextList = new string[]{}, DataList = new IReadOnlyList[]{}, StructList = new Capnproto_test.Capnp.Test.TestAllTypes[]{}, EnumList = new Capnproto_test.Capnp.Test.TestEnum[]{}, InterfaceList = 0}, EnumField = Capnproto_test.Capnp.Test.TestEnum.foo, VoidList = 3, BoolList = new bool[]{false, true, false, true, true}, Int8List = new sbyte[]{12, -34, -128, 127}, Int16List = new short[]{1234, -5678, -32768, 32767}, Int32List = new int[]{12345678, -90123456, -2147483648, 2147483647}, Int64List = new long[]{123456789012345L, -678901234567890L, -9223372036854775808L, 9223372036854775807L}, UInt8List = new byte[]{12, 34, 0, 255}, UInt16List = new ushort[]{1234, 5678, 0, 65535}, UInt32List = new uint[]{12345678U, 90123456U, 0U, 4294967295U}, UInt64List = new ulong[]{123456789012345UL, 678901234567890UL, 0UL, 18446744073709551615UL}, Float32List = new float[]{0F, 1234567F, 1E+37F, -1E+37F, 1E-37F, -1E-37F}, Float64List = new double[]{0, 123456789012345, 1E+306, -1E+306, 1E-306, -1E-306}, TextList = new string[]{"quux", "corge", "grault"}, DataList = new IReadOnlyList[]{new byte[]{103, 97, 114, 112, 108, 121}, new byte[]{119, 97, 108, 100, 111}, new byte[]{102, 114, 101, 100}}, StructList = new Capnproto_test.Capnp.Test.TestAllTypes[]{new Capnproto_test.Capnp.Test.TestAllTypes() + {BoolField = false, Int8Field = 0, Int16Field = 0, Int32Field = 0, Int64Field = 0L, UInt8Field = 0, UInt16Field = 0, UInt32Field = 0U, UInt64Field = 0UL, Float32Field = 0F, Float64Field = 0, TextField = "x structlist 1", DataField = new byte[]{}, StructField = new Capnproto_test.Capnp.Test.TestAllTypes() + {}, EnumField = Capnproto_test.Capnp.Test.TestEnum.foo, VoidList = 0, BoolList = new bool[]{}, Int8List = new sbyte[]{}, Int16List = new short[]{}, Int32List = new int[]{}, Int64List = new long[]{}, UInt8List = new byte[]{}, UInt16List = new ushort[]{}, UInt32List = new uint[]{}, UInt64List = new ulong[]{}, Float32List = new float[]{}, Float64List = new double[]{}, TextList = new string[]{}, DataList = new IReadOnlyList[]{}, StructList = new Capnproto_test.Capnp.Test.TestAllTypes[]{}, EnumList = new Capnproto_test.Capnp.Test.TestEnum[]{}, InterfaceList = 0}, new Capnproto_test.Capnp.Test.TestAllTypes() + {BoolField = false, Int8Field = 0, Int16Field = 0, Int32Field = 0, Int64Field = 0L, UInt8Field = 0, UInt16Field = 0, UInt32Field = 0U, UInt64Field = 0UL, Float32Field = 0F, Float64Field = 0, TextField = "x structlist 2", DataField = new byte[]{}, StructField = new Capnproto_test.Capnp.Test.TestAllTypes() + {}, EnumField = Capnproto_test.Capnp.Test.TestEnum.foo, VoidList = 0, BoolList = new bool[]{}, Int8List = new sbyte[]{}, Int16List = new short[]{}, Int32List = new int[]{}, Int64List = new long[]{}, UInt8List = new byte[]{}, UInt16List = new ushort[]{}, UInt32List = new uint[]{}, UInt64List = new ulong[]{}, Float32List = new float[]{}, Float64List = new double[]{}, TextList = new string[]{}, DataList = new IReadOnlyList[]{}, StructList = new Capnproto_test.Capnp.Test.TestAllTypes[]{}, EnumList = new Capnproto_test.Capnp.Test.TestEnum[]{}, InterfaceList = 0}, new Capnproto_test.Capnp.Test.TestAllTypes() + {BoolField = false, Int8Field = 0, Int16Field = 0, Int32Field = 0, Int64Field = 0L, UInt8Field = 0, UInt16Field = 0, UInt32Field = 0U, UInt64Field = 0UL, Float32Field = 0F, Float64Field = 0, TextField = "x structlist 3", DataField = new byte[]{}, StructField = new Capnproto_test.Capnp.Test.TestAllTypes() + {}, EnumField = Capnproto_test.Capnp.Test.TestEnum.foo, VoidList = 0, BoolList = new bool[]{}, Int8List = new sbyte[]{}, Int16List = new short[]{}, Int32List = new int[]{}, Int64List = new long[]{}, UInt8List = new byte[]{}, UInt16List = new ushort[]{}, UInt32List = new uint[]{}, UInt64List = new ulong[]{}, Float32List = new float[]{}, Float64List = new double[]{}, TextList = new string[]{}, DataList = new IReadOnlyList[]{}, StructList = new Capnproto_test.Capnp.Test.TestAllTypes[]{}, EnumList = new Capnproto_test.Capnp.Test.TestEnum[]{}, InterfaceList = 0}}, EnumList = new Capnproto_test.Capnp.Test.TestEnum[]{Capnproto_test.Capnp.Test.TestEnum.qux, Capnproto_test.Capnp.Test.TestEnum.bar, Capnproto_test.Capnp.Test.TestEnum.grault}, InterfaceList = 0}; + BoolList = BoolList ?? new bool[]{true, false, false, true}; + Int8List = Int8List ?? new sbyte[]{111, -111}; + Int16List = Int16List ?? new short[]{11111, -11111}; + Int32List = Int32List ?? new int[]{111111111, -111111111}; + Int64List = Int64List ?? new long[]{1111111111111111111L, -1111111111111111111L}; + UInt8List = UInt8List ?? new byte[]{111, 222}; + UInt16List = UInt16List ?? new ushort[]{33333, 44444}; + UInt32List = UInt32List ?? new uint[]{3333333333U}; + UInt64List = UInt64List ?? new ulong[]{11111111111111111111UL}; + Float32List = Float32List ?? new float[]{5555.5F, float.PositiveInfinity, float.NegativeInfinity, float.NaN}; + Float64List = Float64List ?? new double[]{7777.75, double.PositiveInfinity, double.NegativeInfinity, double.NaN}; + TextList = TextList ?? new string[]{"plugh", "xyzzy", "thud"}; + DataList = DataList ?? new IReadOnlyList[]{new byte[]{111, 111, 112, 115}, new byte[]{101, 120, 104, 97, 117, 115, 116, 101, 100}, new byte[]{114, 102, 99, 51, 48, 57, 50}}; + StructList = StructList ?? new Capnproto_test.Capnp.Test.TestAllTypes[]{new Capnproto_test.Capnp.Test.TestAllTypes() + {BoolField = false, Int8Field = 0, Int16Field = 0, Int32Field = 0, Int64Field = 0L, UInt8Field = 0, UInt16Field = 0, UInt32Field = 0U, UInt64Field = 0UL, Float32Field = 0F, Float64Field = 0, TextField = "structlist 1", DataField = new byte[]{}, StructField = new Capnproto_test.Capnp.Test.TestAllTypes() + {}, EnumField = Capnproto_test.Capnp.Test.TestEnum.foo, VoidList = 0, BoolList = new bool[]{}, Int8List = new sbyte[]{}, Int16List = new short[]{}, Int32List = new int[]{}, Int64List = new long[]{}, UInt8List = new byte[]{}, UInt16List = new ushort[]{}, UInt32List = new uint[]{}, UInt64List = new ulong[]{}, Float32List = new float[]{}, Float64List = new double[]{}, TextList = new string[]{}, DataList = new IReadOnlyList[]{}, StructList = new Capnproto_test.Capnp.Test.TestAllTypes[]{}, EnumList = new Capnproto_test.Capnp.Test.TestEnum[]{}, InterfaceList = 0}, new Capnproto_test.Capnp.Test.TestAllTypes() + {BoolField = false, Int8Field = 0, Int16Field = 0, Int32Field = 0, Int64Field = 0L, UInt8Field = 0, UInt16Field = 0, UInt32Field = 0U, UInt64Field = 0UL, Float32Field = 0F, Float64Field = 0, TextField = "structlist 2", DataField = new byte[]{}, StructField = new Capnproto_test.Capnp.Test.TestAllTypes() + {}, EnumField = Capnproto_test.Capnp.Test.TestEnum.foo, VoidList = 0, BoolList = new bool[]{}, Int8List = new sbyte[]{}, Int16List = new short[]{}, Int32List = new int[]{}, Int64List = new long[]{}, UInt8List = new byte[]{}, UInt16List = new ushort[]{}, UInt32List = new uint[]{}, UInt64List = new ulong[]{}, Float32List = new float[]{}, Float64List = new double[]{}, TextList = new string[]{}, DataList = new IReadOnlyList[]{}, StructList = new Capnproto_test.Capnp.Test.TestAllTypes[]{}, EnumList = new Capnproto_test.Capnp.Test.TestEnum[]{}, InterfaceList = 0}, new Capnproto_test.Capnp.Test.TestAllTypes() + {BoolField = false, Int8Field = 0, Int16Field = 0, Int32Field = 0, Int64Field = 0L, UInt8Field = 0, UInt16Field = 0, UInt32Field = 0U, UInt64Field = 0UL, Float32Field = 0F, Float64Field = 0, TextField = "structlist 3", DataField = new byte[]{}, StructField = new Capnproto_test.Capnp.Test.TestAllTypes() + {}, EnumField = Capnproto_test.Capnp.Test.TestEnum.foo, VoidList = 0, BoolList = new bool[]{}, Int8List = new sbyte[]{}, Int16List = new short[]{}, Int32List = new int[]{}, Int64List = new long[]{}, UInt8List = new byte[]{}, UInt16List = new ushort[]{}, UInt32List = new uint[]{}, UInt64List = new ulong[]{}, Float32List = new float[]{}, Float64List = new double[]{}, TextList = new string[]{}, DataList = new IReadOnlyList[]{}, StructList = new Capnproto_test.Capnp.Test.TestAllTypes[]{}, EnumList = new Capnproto_test.Capnp.Test.TestEnum[]{}, InterfaceList = 0}}; + EnumList = EnumList ?? new Capnproto_test.Capnp.Test.TestEnum[]{Capnproto_test.Capnp.Test.TestEnum.foo, Capnproto_test.Capnp.Test.TestEnum.garply}; + } + + public bool BoolField + { + get; + set; + } + + = true; + public sbyte Int8Field + { + get; + set; + } + + = -123; + public short Int16Field + { + get; + set; + } + + = -12345; + public int Int32Field + { + get; + set; + } + + = -12345678; + public long Int64Field + { + get; + set; + } + + = -123456789012345L; + public byte UInt8Field + { + get; + set; + } + + = 234; + public ushort UInt16Field + { + get; + set; + } + + = 45678; + public uint UInt32Field + { + get; + set; + } + + = 3456789012U; + public ulong UInt64Field + { + get; + set; + } + + = 12345678901234567890UL; + public float Float32Field + { + get; + set; + } + + = 1234.5F; + public double Float64Field + { + get; + set; + } + + = -1.23E+47; + public string TextField + { + get; + set; + } + + public IReadOnlyList DataField + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestAllTypes StructField + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestEnum EnumField + { + get; + set; + } + + = Capnproto_test.Capnp.Test.TestEnum.corge; + public int VoidList + { + get; + set; + } + + = 6; + public IReadOnlyList BoolList + { + get; + set; + } + + public IReadOnlyList Int8List + { + get; + set; + } + + public IReadOnlyList Int16List + { + get; + set; + } + + public IReadOnlyList Int32List + { + get; + set; + } + + public IReadOnlyList Int64List + { + get; + set; + } + + public IReadOnlyList UInt8List + { + get; + set; + } + + public IReadOnlyList UInt16List + { + get; + set; + } + + public IReadOnlyList UInt32List + { + get; + set; + } + + public IReadOnlyList UInt64List + { + get; + set; + } + + public IReadOnlyList Float32List + { + get; + set; + } + + public IReadOnlyList Float64List + { + get; + set; + } + + public IReadOnlyList TextList + { + get; + set; + } + + public IReadOnlyList> DataList + { + get; + set; + } + + public IReadOnlyList StructList + { + get; + set; + } + + public IReadOnlyList EnumList + { + get; + set; + } + + public int InterfaceList + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public bool BoolField => ctx.ReadDataBool(0UL, true); + public sbyte Int8Field => ctx.ReadDataSByte(8UL, (sbyte)-123); + public short Int16Field => ctx.ReadDataShort(16UL, (short)-12345); + public int Int32Field => ctx.ReadDataInt(32UL, -12345678); + public long Int64Field => ctx.ReadDataLong(64UL, -123456789012345L); + public byte UInt8Field => ctx.ReadDataByte(128UL, (byte)234); + public ushort UInt16Field => ctx.ReadDataUShort(144UL, (ushort)45678); + public uint UInt32Field => ctx.ReadDataUInt(160UL, 3456789012U); + public ulong UInt64Field => ctx.ReadDataULong(192UL, 12345678901234567890UL); + public float Float32Field => ctx.ReadDataFloat(256UL, 1234.5F); + public double Float64Field => ctx.ReadDataDouble(320UL, -1.23E+47); + public string TextField => ctx.ReadText(0, "foo"); + public IReadOnlyList DataField => ctx.ReadList(1).CastByte(); + public Capnproto_test.Capnp.Test.TestAllTypes.READER StructField => ctx.ReadStruct(2, Capnproto_test.Capnp.Test.TestAllTypes.READER.create); + public Capnproto_test.Capnp.Test.TestEnum EnumField => (Capnproto_test.Capnp.Test.TestEnum)ctx.ReadDataUShort(288UL, (ushort)5); + public int VoidList => ctx.ReadList(3).Count; + public IReadOnlyList BoolList => ctx.ReadList(4).CastBool(); + public IReadOnlyList Int8List => ctx.ReadList(5).CastSByte(); + public IReadOnlyList Int16List => ctx.ReadList(6).CastShort(); + public IReadOnlyList Int32List => ctx.ReadList(7).CastInt(); + public IReadOnlyList Int64List => ctx.ReadList(8).CastLong(); + public IReadOnlyList UInt8List => ctx.ReadList(9).CastByte(); + public IReadOnlyList UInt16List => ctx.ReadList(10).CastUShort(); + public IReadOnlyList UInt32List => ctx.ReadList(11).CastUInt(); + public IReadOnlyList UInt64List => ctx.ReadList(12).CastULong(); + public IReadOnlyList Float32List => ctx.ReadList(13).CastFloat(); + public IReadOnlyList Float64List => ctx.ReadList(14).CastDouble(); + public IReadOnlyList TextList => ctx.ReadList(15).CastText2(); + public IReadOnlyList> DataList => ctx.ReadList(16).CastData(); + public IReadOnlyList StructList => ctx.ReadList(17).Cast(Capnproto_test.Capnp.Test.TestAllTypes.READER.create); + public IReadOnlyList EnumList => ctx.ReadList(18).CastEnums(_0 => (Capnproto_test.Capnp.Test.TestEnum)_0); + public int InterfaceList => ctx.ReadList(19).Count; + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(6, 20); + } + + public bool BoolField + { + get => this.ReadDataBool(0UL, true); + set => this.WriteData(0UL, value, true); + } + + public sbyte Int8Field + { + get => this.ReadDataSByte(8UL, (sbyte)-123); + set => this.WriteData(8UL, value, (sbyte)-123); + } + + public short Int16Field + { + get => this.ReadDataShort(16UL, (short)-12345); + set => this.WriteData(16UL, value, (short)-12345); + } + + public int Int32Field + { + get => this.ReadDataInt(32UL, -12345678); + set => this.WriteData(32UL, value, -12345678); + } + + public long Int64Field + { + get => this.ReadDataLong(64UL, -123456789012345L); + set => this.WriteData(64UL, value, -123456789012345L); + } + + public byte UInt8Field + { + get => this.ReadDataByte(128UL, (byte)234); + set => this.WriteData(128UL, value, (byte)234); + } + + public ushort UInt16Field + { + get => this.ReadDataUShort(144UL, (ushort)45678); + set => this.WriteData(144UL, value, (ushort)45678); + } + + public uint UInt32Field + { + get => this.ReadDataUInt(160UL, 3456789012U); + set => this.WriteData(160UL, value, 3456789012U); + } + + public ulong UInt64Field + { + get => this.ReadDataULong(192UL, 12345678901234567890UL); + set => this.WriteData(192UL, value, 12345678901234567890UL); + } + + public float Float32Field + { + get => this.ReadDataFloat(256UL, 1234.5F); + set => this.WriteData(256UL, value, 1234.5F); + } + + public double Float64Field + { + get => this.ReadDataDouble(320UL, -1.23E+47); + set => this.WriteData(320UL, value, -1.23E+47); + } + + public string TextField + { + get => this.ReadText(0, "foo"); + set => this.WriteText(0, value, "foo"); + } + + public ListOfPrimitivesSerializer DataField + { + get => BuildPointer>(1); + set => Link(1, value); + } + + public Capnproto_test.Capnp.Test.TestAllTypes.WRITER StructField + { + get => BuildPointer(2); + set => Link(2, value); + } + + public Capnproto_test.Capnp.Test.TestEnum EnumField + { + get => (Capnproto_test.Capnp.Test.TestEnum)this.ReadDataUShort(288UL, (ushort)5); + set => this.WriteData(288UL, (ushort)value, (ushort)5); + } + + public ListOfEmptySerializer VoidList + { + get => BuildPointer(3); + set => Link(3, value); + } + + public ListOfBitsSerializer BoolList + { + get => BuildPointer(4); + set => Link(4, value); + } + + public ListOfPrimitivesSerializer Int8List + { + get => BuildPointer>(5); + set => Link(5, value); + } + + public ListOfPrimitivesSerializer Int16List + { + get => BuildPointer>(6); + set => Link(6, value); + } + + public ListOfPrimitivesSerializer Int32List + { + get => BuildPointer>(7); + set => Link(7, value); + } + + public ListOfPrimitivesSerializer Int64List + { + get => BuildPointer>(8); + set => Link(8, value); + } + + public ListOfPrimitivesSerializer UInt8List + { + get => BuildPointer>(9); + set => Link(9, value); + } + + public ListOfPrimitivesSerializer UInt16List + { + get => BuildPointer>(10); + set => Link(10, value); + } + + public ListOfPrimitivesSerializer UInt32List + { + get => BuildPointer>(11); + set => Link(11, value); + } + + public ListOfPrimitivesSerializer UInt64List + { + get => BuildPointer>(12); + set => Link(12, value); + } + + public ListOfPrimitivesSerializer Float32List + { + get => BuildPointer>(13); + set => Link(13, value); + } + + public ListOfPrimitivesSerializer Float64List + { + get => BuildPointer>(14); + set => Link(14, value); + } + + public ListOfTextSerializer TextList + { + get => BuildPointer(15); + set => Link(15, value); + } + + public ListOfPointersSerializer> DataList + { + get => BuildPointer>>(16); + set => Link(16, value); + } + + public ListOfStructsSerializer StructList + { + get => BuildPointer>(17); + set => Link(17, value); + } + + public ListOfPrimitivesSerializer EnumList + { + get => BuildPointer>(18); + set => Link(18, value); + } + + public ListOfEmptySerializer InterfaceList + { + get => BuildPointer(19); + set => Link(19, value); + } + } + } + + public class TestAnyPointer : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + AnyPointerField = CapnpSerializable.Create(reader.AnyPointerField); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.AnyPointerField.SetObject(AnyPointerField); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public AnyPointer AnyPointerField + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public DeserializerState AnyPointerField => ctx.StructReadPointer(0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public DynamicSerializerState AnyPointerField + { + get => BuildPointer(0); + set => Link(0, value); + } + } + } + + public class TestAnyOthers : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + AnyStructField = CapnpSerializable.Create(reader.AnyStructField); + AnyListField = reader.AnyListField.ToReadOnlyList(_ => (object)_); + CapabilityField = reader.CapabilityField; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.AnyStructField.SetObject(AnyStructField); + writer.AnyListField.SetObject(AnyListField); + writer.CapabilityField = CapabilityField; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public AnyPointer AnyStructField + { + get; + set; + } + + public IReadOnlyList AnyListField + { + get; + set; + } + + public BareProxy CapabilityField + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public DeserializerState AnyStructField => ctx.StructReadPointer(0); + public IReadOnlyList AnyListField => (IReadOnlyList)ctx.ReadList(1); + public BareProxy CapabilityField => ctx.ReadCap(2); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 3); + } + + public DynamicSerializerState AnyStructField + { + get => BuildPointer(0); + set => Link(0, value); + } + + public DynamicSerializerState AnyListField + { + get => BuildPointer(1); + set => Link(1, value); + } + + public BareProxy CapabilityField + { + get => ReadCap(2); + set => LinkObject(2, value); + } + } + } + + public class TestOutOfOrder : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Qux = reader.Qux; + Grault = reader.Grault; + Bar = reader.Bar; + Foo = reader.Foo; + Corge = reader.Corge; + Waldo = reader.Waldo; + Quux = reader.Quux; + Garply = reader.Garply; + Baz = reader.Baz; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Qux = Qux; + writer.Grault = Grault; + writer.Bar = Bar; + writer.Foo = Foo; + writer.Corge = Corge; + writer.Waldo = Waldo; + writer.Quux = Quux; + writer.Garply = Garply; + writer.Baz = Baz; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string Qux + { + get; + set; + } + + public string Grault + { + get; + set; + } + + public string Bar + { + get; + set; + } + + public string Foo + { + get; + set; + } + + public string Corge + { + get; + set; + } + + public string Waldo + { + get; + set; + } + + public string Quux + { + get; + set; + } + + public string Garply + { + get; + set; + } + + public string Baz + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string Qux => ctx.ReadText(0, ""); + public string Grault => ctx.ReadText(1, ""); + public string Bar => ctx.ReadText(2, ""); + public string Foo => ctx.ReadText(3, ""); + public string Corge => ctx.ReadText(4, ""); + public string Waldo => ctx.ReadText(5, ""); + public string Quux => ctx.ReadText(6, ""); + public string Garply => ctx.ReadText(7, ""); + public string Baz => ctx.ReadText(8, ""); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 9); + } + + public string Qux + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + + public string Grault + { + get => this.ReadText(1, ""); + set => this.WriteText(1, value, ""); + } + + public string Bar + { + get => this.ReadText(2, ""); + set => this.WriteText(2, value, ""); + } + + public string Foo + { + get => this.ReadText(3, ""); + set => this.WriteText(3, value, ""); + } + + public string Corge + { + get => this.ReadText(4, ""); + set => this.WriteText(4, value, ""); + } + + public string Waldo + { + get => this.ReadText(5, ""); + set => this.WriteText(5, value, ""); + } + + public string Quux + { + get => this.ReadText(6, ""); + set => this.WriteText(6, value, ""); + } + + public string Garply + { + get => this.ReadText(7, ""); + set => this.WriteText(7, value, ""); + } + + public string Baz + { + get => this.ReadText(8, ""); + set => this.WriteText(8, value, ""); + } + } + } + + public class TestUnion : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Union0 = CapnpSerializable.Create(reader.Union0); + Union1 = CapnpSerializable.Create(reader.Union1); + Union2 = CapnpSerializable.Create(reader.Union2); + Union3 = CapnpSerializable.Create(reader.Union3); + Bit0 = reader.Bit0; + Bit2 = reader.Bit2; + Bit3 = reader.Bit3; + Bit4 = reader.Bit4; + Bit5 = reader.Bit5; + Bit6 = reader.Bit6; + Bit7 = reader.Bit7; + Byte0 = reader.Byte0; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + Union0?.serialize(writer.Union0); + Union1?.serialize(writer.Union1); + Union2?.serialize(writer.Union2); + Union3?.serialize(writer.Union3); + writer.Bit0 = Bit0; + writer.Bit2 = Bit2; + writer.Bit3 = Bit3; + writer.Bit4 = Bit4; + writer.Bit5 = Bit5; + writer.Bit6 = Bit6; + writer.Bit7 = Bit7; + writer.Byte0 = Byte0; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.TestUnion.@union0 Union0 + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestUnion.@union1 Union1 + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestUnion.@union2 Union2 + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestUnion.@union3 Union3 + { + get; + set; + } + + public bool Bit0 + { + get; + set; + } + + public bool Bit2 + { + get; + set; + } + + public bool Bit3 + { + get; + set; + } + + public bool Bit4 + { + get; + set; + } + + public bool Bit5 + { + get; + set; + } + + public bool Bit6 + { + get; + set; + } + + public bool Bit7 + { + get; + set; + } + + public byte Byte0 + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public @union0.READER Union0 => new @union0.READER(ctx); + public @union1.READER Union1 => new @union1.READER(ctx); + public @union2.READER Union2 => new @union2.READER(ctx); + public @union3.READER Union3 => new @union3.READER(ctx); + public bool Bit0 => ctx.ReadDataBool(128UL, false); + public bool Bit2 => ctx.ReadDataBool(130UL, false); + public bool Bit3 => ctx.ReadDataBool(131UL, false); + public bool Bit4 => ctx.ReadDataBool(132UL, false); + public bool Bit5 => ctx.ReadDataBool(133UL, false); + public bool Bit6 => ctx.ReadDataBool(134UL, false); + public bool Bit7 => ctx.ReadDataBool(135UL, false); + public byte Byte0 => ctx.ReadDataByte(280UL, (byte)0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(8, 2); + } + + public @union0.WRITER Union0 + { + get => Rewrap<@union0.WRITER>(); + } + + public @union1.WRITER Union1 + { + get => Rewrap<@union1.WRITER>(); + } + + public @union2.WRITER Union2 + { + get => Rewrap<@union2.WRITER>(); + } + + public @union3.WRITER Union3 + { + get => Rewrap<@union3.WRITER>(); + } + + public bool Bit0 + { + get => this.ReadDataBool(128UL, false); + set => this.WriteData(128UL, value, false); + } + + public bool Bit2 + { + get => this.ReadDataBool(130UL, false); + set => this.WriteData(130UL, value, false); + } + + public bool Bit3 + { + get => this.ReadDataBool(131UL, false); + set => this.WriteData(131UL, value, false); + } + + public bool Bit4 + { + get => this.ReadDataBool(132UL, false); + set => this.WriteData(132UL, value, false); + } + + public bool Bit5 + { + get => this.ReadDataBool(133UL, false); + set => this.WriteData(133UL, value, false); + } + + public bool Bit6 + { + get => this.ReadDataBool(134UL, false); + set => this.WriteData(134UL, value, false); + } + + public bool Bit7 + { + get => this.ReadDataBool(135UL, false); + set => this.WriteData(135UL, value, false); + } + + public byte Byte0 + { + get => this.ReadDataByte(280UL, (byte)0); + set => this.WriteData(280UL, value, (byte)0); + } + } + + public class @union0 : ICapnpSerializable + { + public enum WHICH : ushort + { + U0f0s0 = 0, + U0f0s1 = 1, + U0f0s8 = 2, + U0f0s16 = 3, + U0f0s32 = 4, + U0f0s64 = 5, + U0f0sp = 6, + U0f1s0 = 7, + U0f1s1 = 8, + U0f1s8 = 9, + U0f1s16 = 10, + U0f1s32 = 11, + U0f1s64 = 12, + U0f1sp = 13, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.U0f0s0: + which = reader.which; + break; + case WHICH.U0f0s1: + U0f0s1 = reader.U0f0s1; + break; + case WHICH.U0f0s8: + U0f0s8 = reader.U0f0s8; + break; + case WHICH.U0f0s16: + U0f0s16 = reader.U0f0s16; + break; + case WHICH.U0f0s32: + U0f0s32 = reader.U0f0s32; + break; + case WHICH.U0f0s64: + U0f0s64 = reader.U0f0s64; + break; + case WHICH.U0f0sp: + U0f0sp = reader.U0f0sp; + break; + case WHICH.U0f1s0: + which = reader.which; + break; + case WHICH.U0f1s1: + U0f1s1 = reader.U0f1s1; + break; + case WHICH.U0f1s8: + U0f1s8 = reader.U0f1s8; + break; + case WHICH.U0f1s16: + U0f1s16 = reader.U0f1s16; + break; + case WHICH.U0f1s32: + U0f1s32 = reader.U0f1s32; + break; + case WHICH.U0f1s64: + U0f1s64 = reader.U0f1s64; + break; + case WHICH.U0f1sp: + U0f1sp = reader.U0f1sp; + break; + } + + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.U0f0s0: + break; + case WHICH.U0f0s1: + _content = false; + break; + case WHICH.U0f0s8: + _content = 0; + break; + case WHICH.U0f0s16: + _content = 0; + break; + case WHICH.U0f0s32: + _content = 0; + break; + case WHICH.U0f0s64: + _content = 0; + break; + case WHICH.U0f0sp: + _content = null; + break; + case WHICH.U0f1s0: + break; + case WHICH.U0f1s1: + _content = false; + break; + case WHICH.U0f1s8: + _content = 0; + break; + case WHICH.U0f1s16: + _content = 0; + break; + case WHICH.U0f1s32: + _content = 0; + break; + case WHICH.U0f1s64: + _content = 0; + break; + case WHICH.U0f1sp: + _content = null; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.U0f0s0: + break; + case WHICH.U0f0s1: + writer.U0f0s1 = U0f0s1.Value; + break; + case WHICH.U0f0s8: + writer.U0f0s8 = U0f0s8.Value; + break; + case WHICH.U0f0s16: + writer.U0f0s16 = U0f0s16.Value; + break; + case WHICH.U0f0s32: + writer.U0f0s32 = U0f0s32.Value; + break; + case WHICH.U0f0s64: + writer.U0f0s64 = U0f0s64.Value; + break; + case WHICH.U0f0sp: + writer.U0f0sp = U0f0sp; + break; + case WHICH.U0f1s0: + break; + case WHICH.U0f1s1: + writer.U0f1s1 = U0f1s1.Value; + break; + case WHICH.U0f1s8: + writer.U0f1s8 = U0f1s8.Value; + break; + case WHICH.U0f1s16: + writer.U0f1s16 = U0f1s16.Value; + break; + case WHICH.U0f1s32: + writer.U0f1s32 = U0f1s32.Value; + break; + case WHICH.U0f1s64: + writer.U0f1s64 = U0f1s64.Value; + break; + case WHICH.U0f1sp: + writer.U0f1sp = U0f1sp; + break; + } + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public bool? U0f0s1 + { + get => _which == WHICH.U0f0s1 ? (bool? )_content : null; + set + { + _which = WHICH.U0f0s1; + _content = value; + } + } + + public sbyte? U0f0s8 + { + get => _which == WHICH.U0f0s8 ? (sbyte? )_content : null; + set + { + _which = WHICH.U0f0s8; + _content = value; + } + } + + public short? U0f0s16 + { + get => _which == WHICH.U0f0s16 ? (short? )_content : null; + set + { + _which = WHICH.U0f0s16; + _content = value; + } + } + + public int? U0f0s32 + { + get => _which == WHICH.U0f0s32 ? (int? )_content : null; + set + { + _which = WHICH.U0f0s32; + _content = value; + } + } + + public long? U0f0s64 + { + get => _which == WHICH.U0f0s64 ? (long? )_content : null; + set + { + _which = WHICH.U0f0s64; + _content = value; + } + } + + public string U0f0sp + { + get => _which == WHICH.U0f0sp ? (string)_content : null; + set + { + _which = WHICH.U0f0sp; + _content = value; + } + } + + public bool? U0f1s1 + { + get => _which == WHICH.U0f1s1 ? (bool? )_content : null; + set + { + _which = WHICH.U0f1s1; + _content = value; + } + } + + public sbyte? U0f1s8 + { + get => _which == WHICH.U0f1s8 ? (sbyte? )_content : null; + set + { + _which = WHICH.U0f1s8; + _content = value; + } + } + + public short? U0f1s16 + { + get => _which == WHICH.U0f1s16 ? (short? )_content : null; + set + { + _which = WHICH.U0f1s16; + _content = value; + } + } + + public int? U0f1s32 + { + get => _which == WHICH.U0f1s32 ? (int? )_content : null; + set + { + _which = WHICH.U0f1s32; + _content = value; + } + } + + public long? U0f1s64 + { + get => _which == WHICH.U0f1s64 ? (long? )_content : null; + set + { + _which = WHICH.U0f1s64; + _content = value; + } + } + + public string U0f1sp + { + get => _which == WHICH.U0f1sp ? (string)_content : null; + set + { + _which = WHICH.U0f1sp; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(0U, (ushort)0); + public bool U0f0s1 => which == WHICH.U0f0s1 ? ctx.ReadDataBool(64UL, false) : default; + public sbyte U0f0s8 => which == WHICH.U0f0s8 ? ctx.ReadDataSByte(64UL, (sbyte)0) : default; + public short U0f0s16 => which == WHICH.U0f0s16 ? ctx.ReadDataShort(64UL, (short)0) : default; + public int U0f0s32 => which == WHICH.U0f0s32 ? ctx.ReadDataInt(64UL, 0) : default; + public long U0f0s64 => which == WHICH.U0f0s64 ? ctx.ReadDataLong(64UL, 0L) : default; + public string U0f0sp => which == WHICH.U0f0sp ? ctx.ReadText(0, "") : default; + public bool U0f1s1 => which == WHICH.U0f1s1 ? ctx.ReadDataBool(64UL, false) : default; + public sbyte U0f1s8 => which == WHICH.U0f1s8 ? ctx.ReadDataSByte(64UL, (sbyte)0) : default; + public short U0f1s16 => which == WHICH.U0f1s16 ? ctx.ReadDataShort(64UL, (short)0) : default; + public int U0f1s32 => which == WHICH.U0f1s32 ? ctx.ReadDataInt(64UL, 0) : default; + public long U0f1s64 => which == WHICH.U0f1s64 ? ctx.ReadDataLong(64UL, 0L) : default; + public string U0f1sp => which == WHICH.U0f1sp ? ctx.ReadText(0, "") : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(0U, (ushort)0); + set => this.WriteData(0U, (ushort)value, (ushort)0); + } + + public bool U0f0s1 + { + get => which == WHICH.U0f0s1 ? this.ReadDataBool(64UL, false) : default; + set => this.WriteData(64UL, value, false); + } + + public sbyte U0f0s8 + { + get => which == WHICH.U0f0s8 ? this.ReadDataSByte(64UL, (sbyte)0) : default; + set => this.WriteData(64UL, value, (sbyte)0); + } + + public short U0f0s16 + { + get => which == WHICH.U0f0s16 ? this.ReadDataShort(64UL, (short)0) : default; + set => this.WriteData(64UL, value, (short)0); + } + + public int U0f0s32 + { + get => which == WHICH.U0f0s32 ? this.ReadDataInt(64UL, 0) : default; + set => this.WriteData(64UL, value, 0); + } + + public long U0f0s64 + { + get => which == WHICH.U0f0s64 ? this.ReadDataLong(64UL, 0L) : default; + set => this.WriteData(64UL, value, 0L); + } + + public string U0f0sp + { + get => which == WHICH.U0f0sp ? this.ReadText(0, "") : default; + set => this.WriteText(0, value, ""); + } + + public bool U0f1s1 + { + get => which == WHICH.U0f1s1 ? this.ReadDataBool(64UL, false) : default; + set => this.WriteData(64UL, value, false); + } + + public sbyte U0f1s8 + { + get => which == WHICH.U0f1s8 ? this.ReadDataSByte(64UL, (sbyte)0) : default; + set => this.WriteData(64UL, value, (sbyte)0); + } + + public short U0f1s16 + { + get => which == WHICH.U0f1s16 ? this.ReadDataShort(64UL, (short)0) : default; + set => this.WriteData(64UL, value, (short)0); + } + + public int U0f1s32 + { + get => which == WHICH.U0f1s32 ? this.ReadDataInt(64UL, 0) : default; + set => this.WriteData(64UL, value, 0); + } + + public long U0f1s64 + { + get => which == WHICH.U0f1s64 ? this.ReadDataLong(64UL, 0L) : default; + set => this.WriteData(64UL, value, 0L); + } + + public string U0f1sp + { + get => which == WHICH.U0f1sp ? this.ReadText(0, "") : default; + set => this.WriteText(0, value, ""); + } + } + } + + public class @union1 : ICapnpSerializable + { + public enum WHICH : ushort + { + U1f0s0 = 0, + U1f0s1 = 1, + U1f1s1 = 2, + U1f0s8 = 3, + U1f1s8 = 4, + U1f0s16 = 5, + U1f1s16 = 6, + U1f0s32 = 7, + U1f1s32 = 8, + U1f0s64 = 9, + U1f1s64 = 10, + U1f0sp = 11, + U1f1sp = 12, + U1f2s0 = 13, + U1f2s1 = 14, + U1f2s8 = 15, + U1f2s16 = 16, + U1f2s32 = 17, + U1f2s64 = 18, + U1f2sp = 19, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.U1f0s0: + which = reader.which; + break; + case WHICH.U1f0s1: + U1f0s1 = reader.U1f0s1; + break; + case WHICH.U1f1s1: + U1f1s1 = reader.U1f1s1; + break; + case WHICH.U1f0s8: + U1f0s8 = reader.U1f0s8; + break; + case WHICH.U1f1s8: + U1f1s8 = reader.U1f1s8; + break; + case WHICH.U1f0s16: + U1f0s16 = reader.U1f0s16; + break; + case WHICH.U1f1s16: + U1f1s16 = reader.U1f1s16; + break; + case WHICH.U1f0s32: + U1f0s32 = reader.U1f0s32; + break; + case WHICH.U1f1s32: + U1f1s32 = reader.U1f1s32; + break; + case WHICH.U1f0s64: + U1f0s64 = reader.U1f0s64; + break; + case WHICH.U1f1s64: + U1f1s64 = reader.U1f1s64; + break; + case WHICH.U1f0sp: + U1f0sp = reader.U1f0sp; + break; + case WHICH.U1f1sp: + U1f1sp = reader.U1f1sp; + break; + case WHICH.U1f2s0: + which = reader.which; + break; + case WHICH.U1f2s1: + U1f2s1 = reader.U1f2s1; + break; + case WHICH.U1f2s8: + U1f2s8 = reader.U1f2s8; + break; + case WHICH.U1f2s16: + U1f2s16 = reader.U1f2s16; + break; + case WHICH.U1f2s32: + U1f2s32 = reader.U1f2s32; + break; + case WHICH.U1f2s64: + U1f2s64 = reader.U1f2s64; + break; + case WHICH.U1f2sp: + U1f2sp = reader.U1f2sp; + break; + } + + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.U1f0s0: + break; + case WHICH.U1f0s1: + _content = false; + break; + case WHICH.U1f1s1: + _content = false; + break; + case WHICH.U1f0s8: + _content = 0; + break; + case WHICH.U1f1s8: + _content = 0; + break; + case WHICH.U1f0s16: + _content = 0; + break; + case WHICH.U1f1s16: + _content = 0; + break; + case WHICH.U1f0s32: + _content = 0; + break; + case WHICH.U1f1s32: + _content = 0; + break; + case WHICH.U1f0s64: + _content = 0; + break; + case WHICH.U1f1s64: + _content = 0; + break; + case WHICH.U1f0sp: + _content = null; + break; + case WHICH.U1f1sp: + _content = null; + break; + case WHICH.U1f2s0: + break; + case WHICH.U1f2s1: + _content = false; + break; + case WHICH.U1f2s8: + _content = 0; + break; + case WHICH.U1f2s16: + _content = 0; + break; + case WHICH.U1f2s32: + _content = 0; + break; + case WHICH.U1f2s64: + _content = 0; + break; + case WHICH.U1f2sp: + _content = null; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.U1f0s0: + break; + case WHICH.U1f0s1: + writer.U1f0s1 = U1f0s1.Value; + break; + case WHICH.U1f1s1: + writer.U1f1s1 = U1f1s1.Value; + break; + case WHICH.U1f0s8: + writer.U1f0s8 = U1f0s8.Value; + break; + case WHICH.U1f1s8: + writer.U1f1s8 = U1f1s8.Value; + break; + case WHICH.U1f0s16: + writer.U1f0s16 = U1f0s16.Value; + break; + case WHICH.U1f1s16: + writer.U1f1s16 = U1f1s16.Value; + break; + case WHICH.U1f0s32: + writer.U1f0s32 = U1f0s32.Value; + break; + case WHICH.U1f1s32: + writer.U1f1s32 = U1f1s32.Value; + break; + case WHICH.U1f0s64: + writer.U1f0s64 = U1f0s64.Value; + break; + case WHICH.U1f1s64: + writer.U1f1s64 = U1f1s64.Value; + break; + case WHICH.U1f0sp: + writer.U1f0sp = U1f0sp; + break; + case WHICH.U1f1sp: + writer.U1f1sp = U1f1sp; + break; + case WHICH.U1f2s0: + break; + case WHICH.U1f2s1: + writer.U1f2s1 = U1f2s1.Value; + break; + case WHICH.U1f2s8: + writer.U1f2s8 = U1f2s8.Value; + break; + case WHICH.U1f2s16: + writer.U1f2s16 = U1f2s16.Value; + break; + case WHICH.U1f2s32: + writer.U1f2s32 = U1f2s32.Value; + break; + case WHICH.U1f2s64: + writer.U1f2s64 = U1f2s64.Value; + break; + case WHICH.U1f2sp: + writer.U1f2sp = U1f2sp; + break; + } + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public bool? U1f0s1 + { + get => _which == WHICH.U1f0s1 ? (bool? )_content : null; + set + { + _which = WHICH.U1f0s1; + _content = value; + } + } + + public bool? U1f1s1 + { + get => _which == WHICH.U1f1s1 ? (bool? )_content : null; + set + { + _which = WHICH.U1f1s1; + _content = value; + } + } + + public sbyte? U1f0s8 + { + get => _which == WHICH.U1f0s8 ? (sbyte? )_content : null; + set + { + _which = WHICH.U1f0s8; + _content = value; + } + } + + public sbyte? U1f1s8 + { + get => _which == WHICH.U1f1s8 ? (sbyte? )_content : null; + set + { + _which = WHICH.U1f1s8; + _content = value; + } + } + + public short? U1f0s16 + { + get => _which == WHICH.U1f0s16 ? (short? )_content : null; + set + { + _which = WHICH.U1f0s16; + _content = value; + } + } + + public short? U1f1s16 + { + get => _which == WHICH.U1f1s16 ? (short? )_content : null; + set + { + _which = WHICH.U1f1s16; + _content = value; + } + } + + public int? U1f0s32 + { + get => _which == WHICH.U1f0s32 ? (int? )_content : null; + set + { + _which = WHICH.U1f0s32; + _content = value; + } + } + + public int? U1f1s32 + { + get => _which == WHICH.U1f1s32 ? (int? )_content : null; + set + { + _which = WHICH.U1f1s32; + _content = value; + } + } + + public long? U1f0s64 + { + get => _which == WHICH.U1f0s64 ? (long? )_content : null; + set + { + _which = WHICH.U1f0s64; + _content = value; + } + } + + public long? U1f1s64 + { + get => _which == WHICH.U1f1s64 ? (long? )_content : null; + set + { + _which = WHICH.U1f1s64; + _content = value; + } + } + + public string U1f0sp + { + get => _which == WHICH.U1f0sp ? (string)_content : null; + set + { + _which = WHICH.U1f0sp; + _content = value; + } + } + + public string U1f1sp + { + get => _which == WHICH.U1f1sp ? (string)_content : null; + set + { + _which = WHICH.U1f1sp; + _content = value; + } + } + + public bool? U1f2s1 + { + get => _which == WHICH.U1f2s1 ? (bool? )_content : null; + set + { + _which = WHICH.U1f2s1; + _content = value; + } + } + + public sbyte? U1f2s8 + { + get => _which == WHICH.U1f2s8 ? (sbyte? )_content : null; + set + { + _which = WHICH.U1f2s8; + _content = value; + } + } + + public short? U1f2s16 + { + get => _which == WHICH.U1f2s16 ? (short? )_content : null; + set + { + _which = WHICH.U1f2s16; + _content = value; + } + } + + public int? U1f2s32 + { + get => _which == WHICH.U1f2s32 ? (int? )_content : null; + set + { + _which = WHICH.U1f2s32; + _content = value; + } + } + + public long? U1f2s64 + { + get => _which == WHICH.U1f2s64 ? (long? )_content : null; + set + { + _which = WHICH.U1f2s64; + _content = value; + } + } + + public string U1f2sp + { + get => _which == WHICH.U1f2sp ? (string)_content : null; + set + { + _which = WHICH.U1f2sp; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(16U, (ushort)0); + public bool U1f0s1 => which == WHICH.U1f0s1 ? ctx.ReadDataBool(129UL, false) : default; + public bool U1f1s1 => which == WHICH.U1f1s1 ? ctx.ReadDataBool(129UL, false) : default; + public sbyte U1f0s8 => which == WHICH.U1f0s8 ? ctx.ReadDataSByte(136UL, (sbyte)0) : default; + public sbyte U1f1s8 => which == WHICH.U1f1s8 ? ctx.ReadDataSByte(136UL, (sbyte)0) : default; + public short U1f0s16 => which == WHICH.U1f0s16 ? ctx.ReadDataShort(144UL, (short)0) : default; + public short U1f1s16 => which == WHICH.U1f1s16 ? ctx.ReadDataShort(144UL, (short)0) : default; + public int U1f0s32 => which == WHICH.U1f0s32 ? ctx.ReadDataInt(160UL, 0) : default; + public int U1f1s32 => which == WHICH.U1f1s32 ? ctx.ReadDataInt(160UL, 0) : default; + public long U1f0s64 => which == WHICH.U1f0s64 ? ctx.ReadDataLong(192UL, 0L) : default; + public long U1f1s64 => which == WHICH.U1f1s64 ? ctx.ReadDataLong(192UL, 0L) : default; + public string U1f0sp => which == WHICH.U1f0sp ? ctx.ReadText(1, "") : default; + public string U1f1sp => which == WHICH.U1f1sp ? ctx.ReadText(1, "") : default; + public bool U1f2s1 => which == WHICH.U1f2s1 ? ctx.ReadDataBool(129UL, false) : default; + public sbyte U1f2s8 => which == WHICH.U1f2s8 ? ctx.ReadDataSByte(136UL, (sbyte)0) : default; + public short U1f2s16 => which == WHICH.U1f2s16 ? ctx.ReadDataShort(144UL, (short)0) : default; + public int U1f2s32 => which == WHICH.U1f2s32 ? ctx.ReadDataInt(160UL, 0) : default; + public long U1f2s64 => which == WHICH.U1f2s64 ? ctx.ReadDataLong(192UL, 0L) : default; + public string U1f2sp => which == WHICH.U1f2sp ? ctx.ReadText(1, "") : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(16U, (ushort)0); + set => this.WriteData(16U, (ushort)value, (ushort)0); + } + + public bool U1f0s1 + { + get => which == WHICH.U1f0s1 ? this.ReadDataBool(129UL, false) : default; + set => this.WriteData(129UL, value, false); + } + + public bool U1f1s1 + { + get => which == WHICH.U1f1s1 ? this.ReadDataBool(129UL, false) : default; + set => this.WriteData(129UL, value, false); + } + + public sbyte U1f0s8 + { + get => which == WHICH.U1f0s8 ? this.ReadDataSByte(136UL, (sbyte)0) : default; + set => this.WriteData(136UL, value, (sbyte)0); + } + + public sbyte U1f1s8 + { + get => which == WHICH.U1f1s8 ? this.ReadDataSByte(136UL, (sbyte)0) : default; + set => this.WriteData(136UL, value, (sbyte)0); + } + + public short U1f0s16 + { + get => which == WHICH.U1f0s16 ? this.ReadDataShort(144UL, (short)0) : default; + set => this.WriteData(144UL, value, (short)0); + } + + public short U1f1s16 + { + get => which == WHICH.U1f1s16 ? this.ReadDataShort(144UL, (short)0) : default; + set => this.WriteData(144UL, value, (short)0); + } + + public int U1f0s32 + { + get => which == WHICH.U1f0s32 ? this.ReadDataInt(160UL, 0) : default; + set => this.WriteData(160UL, value, 0); + } + + public int U1f1s32 + { + get => which == WHICH.U1f1s32 ? this.ReadDataInt(160UL, 0) : default; + set => this.WriteData(160UL, value, 0); + } + + public long U1f0s64 + { + get => which == WHICH.U1f0s64 ? this.ReadDataLong(192UL, 0L) : default; + set => this.WriteData(192UL, value, 0L); + } + + public long U1f1s64 + { + get => which == WHICH.U1f1s64 ? this.ReadDataLong(192UL, 0L) : default; + set => this.WriteData(192UL, value, 0L); + } + + public string U1f0sp + { + get => which == WHICH.U1f0sp ? this.ReadText(1, "") : default; + set => this.WriteText(1, value, ""); + } + + public string U1f1sp + { + get => which == WHICH.U1f1sp ? this.ReadText(1, "") : default; + set => this.WriteText(1, value, ""); + } + + public bool U1f2s1 + { + get => which == WHICH.U1f2s1 ? this.ReadDataBool(129UL, false) : default; + set => this.WriteData(129UL, value, false); + } + + public sbyte U1f2s8 + { + get => which == WHICH.U1f2s8 ? this.ReadDataSByte(136UL, (sbyte)0) : default; + set => this.WriteData(136UL, value, (sbyte)0); + } + + public short U1f2s16 + { + get => which == WHICH.U1f2s16 ? this.ReadDataShort(144UL, (short)0) : default; + set => this.WriteData(144UL, value, (short)0); + } + + public int U1f2s32 + { + get => which == WHICH.U1f2s32 ? this.ReadDataInt(160UL, 0) : default; + set => this.WriteData(160UL, value, 0); + } + + public long U1f2s64 + { + get => which == WHICH.U1f2s64 ? this.ReadDataLong(192UL, 0L) : default; + set => this.WriteData(192UL, value, 0L); + } + + public string U1f2sp + { + get => which == WHICH.U1f2sp ? this.ReadText(1, "") : default; + set => this.WriteText(1, value, ""); + } + } + } + + public class @union2 : ICapnpSerializable + { + public enum WHICH : ushort + { + U2f0s1 = 0, + U2f0s8 = 1, + U2f0s16 = 2, + U2f0s32 = 3, + U2f0s64 = 4, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.U2f0s1: + U2f0s1 = reader.U2f0s1; + break; + case WHICH.U2f0s8: + U2f0s8 = reader.U2f0s8; + break; + case WHICH.U2f0s16: + U2f0s16 = reader.U2f0s16; + break; + case WHICH.U2f0s32: + U2f0s32 = reader.U2f0s32; + break; + case WHICH.U2f0s64: + U2f0s64 = reader.U2f0s64; + break; + } + + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.U2f0s1: + _content = false; + break; + case WHICH.U2f0s8: + _content = 0; + break; + case WHICH.U2f0s16: + _content = 0; + break; + case WHICH.U2f0s32: + _content = 0; + break; + case WHICH.U2f0s64: + _content = 0; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.U2f0s1: + writer.U2f0s1 = U2f0s1.Value; + break; + case WHICH.U2f0s8: + writer.U2f0s8 = U2f0s8.Value; + break; + case WHICH.U2f0s16: + writer.U2f0s16 = U2f0s16.Value; + break; + case WHICH.U2f0s32: + writer.U2f0s32 = U2f0s32.Value; + break; + case WHICH.U2f0s64: + writer.U2f0s64 = U2f0s64.Value; + break; + } + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public bool? U2f0s1 + { + get => _which == WHICH.U2f0s1 ? (bool? )_content : null; + set + { + _which = WHICH.U2f0s1; + _content = value; + } + } + + public sbyte? U2f0s8 + { + get => _which == WHICH.U2f0s8 ? (sbyte? )_content : null; + set + { + _which = WHICH.U2f0s8; + _content = value; + } + } + + public short? U2f0s16 + { + get => _which == WHICH.U2f0s16 ? (short? )_content : null; + set + { + _which = WHICH.U2f0s16; + _content = value; + } + } + + public int? U2f0s32 + { + get => _which == WHICH.U2f0s32 ? (int? )_content : null; + set + { + _which = WHICH.U2f0s32; + _content = value; + } + } + + public long? U2f0s64 + { + get => _which == WHICH.U2f0s64 ? (long? )_content : null; + set + { + _which = WHICH.U2f0s64; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(32U, (ushort)0); + public bool U2f0s1 => which == WHICH.U2f0s1 ? ctx.ReadDataBool(256UL, false) : default; + public sbyte U2f0s8 => which == WHICH.U2f0s8 ? ctx.ReadDataSByte(264UL, (sbyte)0) : default; + public short U2f0s16 => which == WHICH.U2f0s16 ? ctx.ReadDataShort(288UL, (short)0) : default; + public int U2f0s32 => which == WHICH.U2f0s32 ? ctx.ReadDataInt(320UL, 0) : default; + public long U2f0s64 => which == WHICH.U2f0s64 ? ctx.ReadDataLong(384UL, 0L) : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(32U, (ushort)0); + set => this.WriteData(32U, (ushort)value, (ushort)0); + } + + public bool U2f0s1 + { + get => which == WHICH.U2f0s1 ? this.ReadDataBool(256UL, false) : default; + set => this.WriteData(256UL, value, false); + } + + public sbyte U2f0s8 + { + get => which == WHICH.U2f0s8 ? this.ReadDataSByte(264UL, (sbyte)0) : default; + set => this.WriteData(264UL, value, (sbyte)0); + } + + public short U2f0s16 + { + get => which == WHICH.U2f0s16 ? this.ReadDataShort(288UL, (short)0) : default; + set => this.WriteData(288UL, value, (short)0); + } + + public int U2f0s32 + { + get => which == WHICH.U2f0s32 ? this.ReadDataInt(320UL, 0) : default; + set => this.WriteData(320UL, value, 0); + } + + public long U2f0s64 + { + get => which == WHICH.U2f0s64 ? this.ReadDataLong(384UL, 0L) : default; + set => this.WriteData(384UL, value, 0L); + } + } + } + + public class @union3 : ICapnpSerializable + { + public enum WHICH : ushort + { + U3f0s1 = 0, + U3f0s8 = 1, + U3f0s16 = 2, + U3f0s32 = 3, + U3f0s64 = 4, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.U3f0s1: + U3f0s1 = reader.U3f0s1; + break; + case WHICH.U3f0s8: + U3f0s8 = reader.U3f0s8; + break; + case WHICH.U3f0s16: + U3f0s16 = reader.U3f0s16; + break; + case WHICH.U3f0s32: + U3f0s32 = reader.U3f0s32; + break; + case WHICH.U3f0s64: + U3f0s64 = reader.U3f0s64; + break; + } + + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.U3f0s1: + _content = false; + break; + case WHICH.U3f0s8: + _content = 0; + break; + case WHICH.U3f0s16: + _content = 0; + break; + case WHICH.U3f0s32: + _content = 0; + break; + case WHICH.U3f0s64: + _content = 0; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.U3f0s1: + writer.U3f0s1 = U3f0s1.Value; + break; + case WHICH.U3f0s8: + writer.U3f0s8 = U3f0s8.Value; + break; + case WHICH.U3f0s16: + writer.U3f0s16 = U3f0s16.Value; + break; + case WHICH.U3f0s32: + writer.U3f0s32 = U3f0s32.Value; + break; + case WHICH.U3f0s64: + writer.U3f0s64 = U3f0s64.Value; + break; + } + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public bool? U3f0s1 + { + get => _which == WHICH.U3f0s1 ? (bool? )_content : null; + set + { + _which = WHICH.U3f0s1; + _content = value; + } + } + + public sbyte? U3f0s8 + { + get => _which == WHICH.U3f0s8 ? (sbyte? )_content : null; + set + { + _which = WHICH.U3f0s8; + _content = value; + } + } + + public short? U3f0s16 + { + get => _which == WHICH.U3f0s16 ? (short? )_content : null; + set + { + _which = WHICH.U3f0s16; + _content = value; + } + } + + public int? U3f0s32 + { + get => _which == WHICH.U3f0s32 ? (int? )_content : null; + set + { + _which = WHICH.U3f0s32; + _content = value; + } + } + + public long? U3f0s64 + { + get => _which == WHICH.U3f0s64 ? (long? )_content : null; + set + { + _which = WHICH.U3f0s64; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(48U, (ushort)0); + public bool U3f0s1 => which == WHICH.U3f0s1 ? ctx.ReadDataBool(257UL, false) : default; + public sbyte U3f0s8 => which == WHICH.U3f0s8 ? ctx.ReadDataSByte(272UL, (sbyte)0) : default; + public short U3f0s16 => which == WHICH.U3f0s16 ? ctx.ReadDataShort(304UL, (short)0) : default; + public int U3f0s32 => which == WHICH.U3f0s32 ? ctx.ReadDataInt(352UL, 0) : default; + public long U3f0s64 => which == WHICH.U3f0s64 ? ctx.ReadDataLong(448UL, 0L) : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(48U, (ushort)0); + set => this.WriteData(48U, (ushort)value, (ushort)0); + } + + public bool U3f0s1 + { + get => which == WHICH.U3f0s1 ? this.ReadDataBool(257UL, false) : default; + set => this.WriteData(257UL, value, false); + } + + public sbyte U3f0s8 + { + get => which == WHICH.U3f0s8 ? this.ReadDataSByte(272UL, (sbyte)0) : default; + set => this.WriteData(272UL, value, (sbyte)0); + } + + public short U3f0s16 + { + get => which == WHICH.U3f0s16 ? this.ReadDataShort(304UL, (short)0) : default; + set => this.WriteData(304UL, value, (short)0); + } + + public int U3f0s32 + { + get => which == WHICH.U3f0s32 ? this.ReadDataInt(352UL, 0) : default; + set => this.WriteData(352UL, value, 0); + } + + public long U3f0s64 + { + get => which == WHICH.U3f0s64 ? this.ReadDataLong(448UL, 0L) : default; + set => this.WriteData(448UL, value, 0L); + } + } + } + } + + public class TestUnnamedUnion : ICapnpSerializable + { + public enum WHICH : ushort + { + Foo = 0, + Bar = 1, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.Foo: + Foo = reader.Foo; + break; + case WHICH.Bar: + Bar = reader.Bar; + break; + } + + Before = reader.Before; + Middle = reader.Middle; + After = reader.After; + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.Foo: + _content = 0; + break; + case WHICH.Bar: + _content = 0; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.Foo: + writer.Foo = Foo.Value; + break; + case WHICH.Bar: + writer.Bar = Bar.Value; + break; + } + + writer.Before = Before; + writer.Middle = Middle; + writer.After = After; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string Before + { + get; + set; + } + + public ushort? Foo + { + get => _which == WHICH.Foo ? (ushort? )_content : null; + set + { + _which = WHICH.Foo; + _content = value; + } + } + + public ushort Middle + { + get; + set; + } + + public uint? Bar + { + get => _which == WHICH.Bar ? (uint? )_content : null; + set + { + _which = WHICH.Bar; + _content = value; + } + } + + public string After + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(32U, (ushort)0); + public string Before => ctx.ReadText(0, ""); + public ushort Foo => which == WHICH.Foo ? ctx.ReadDataUShort(0UL, (ushort)0) : default; + public ushort Middle => ctx.ReadDataUShort(16UL, (ushort)0); + public uint Bar => which == WHICH.Bar ? ctx.ReadDataUInt(64UL, 0U) : default; + public string After => ctx.ReadText(1, ""); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(2, 2); + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(32U, (ushort)0); + set => this.WriteData(32U, (ushort)value, (ushort)0); + } + + public string Before + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + + public ushort Foo + { + get => which == WHICH.Foo ? this.ReadDataUShort(0UL, (ushort)0) : default; + set => this.WriteData(0UL, value, (ushort)0); + } + + public ushort Middle + { + get => this.ReadDataUShort(16UL, (ushort)0); + set => this.WriteData(16UL, value, (ushort)0); + } + + public uint Bar + { + get => which == WHICH.Bar ? this.ReadDataUInt(64UL, 0U) : default; + set => this.WriteData(64UL, value, 0U); + } + + public string After + { + get => this.ReadText(1, ""); + set => this.WriteText(1, value, ""); + } + } + } + + public class TestUnionInUnion : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Outer = CapnpSerializable.Create(reader.Outer); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + Outer?.serialize(writer.Outer); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.TestUnionInUnion.@outer Outer + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public @outer.READER Outer => new @outer.READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(2, 0); + } + + public @outer.WRITER Outer + { + get => Rewrap<@outer.WRITER>(); + } + } + + public class @outer : ICapnpSerializable + { + public enum WHICH : ushort + { + Inner = 0, + Baz = 1, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.Inner: + Inner = CapnpSerializable.Create(reader.Inner); + break; + case WHICH.Baz: + Baz = reader.Baz; + break; + } + + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.Inner: + _content = null; + break; + case WHICH.Baz: + _content = 0; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.Inner: + Inner?.serialize(writer.Inner); + break; + case WHICH.Baz: + writer.Baz = Baz.Value; + break; + } + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.TestUnionInUnion.@outer.@inner Inner + { + get => _which == WHICH.Inner ? (Capnproto_test.Capnp.Test.TestUnionInUnion.@outer.@inner)_content : null; + set + { + _which = WHICH.Inner; + _content = value; + } + } + + public int? Baz + { + get => _which == WHICH.Baz ? (int? )_content : null; + set + { + _which = WHICH.Baz; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(64U, (ushort)0); + public @inner.READER Inner => which == WHICH.Inner ? new @inner.READER(ctx) : default; + public int Baz => which == WHICH.Baz ? ctx.ReadDataInt(0UL, 0) : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(64U, (ushort)0); + set => this.WriteData(64U, (ushort)value, (ushort)0); + } + + public @inner.WRITER Inner + { + get => which == WHICH.Inner ? Rewrap<@inner.WRITER>() : default; + } + + public int Baz + { + get => which == WHICH.Baz ? this.ReadDataInt(0UL, 0) : default; + set => this.WriteData(0UL, value, 0); + } + } + + public class @inner : ICapnpSerializable + { + public enum WHICH : ushort + { + Foo = 0, + Bar = 1, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.Foo: + Foo = reader.Foo; + break; + case WHICH.Bar: + Bar = reader.Bar; + break; + } + + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.Foo: + _content = 0; + break; + case WHICH.Bar: + _content = 0; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.Foo: + writer.Foo = Foo.Value; + break; + case WHICH.Bar: + writer.Bar = Bar.Value; + break; + } + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public int? Foo + { + get => _which == WHICH.Foo ? (int? )_content : null; + set + { + _which = WHICH.Foo; + _content = value; + } + } + + public int? Bar + { + get => _which == WHICH.Bar ? (int? )_content : null; + set + { + _which = WHICH.Bar; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(32U, (ushort)0); + public int Foo => which == WHICH.Foo ? ctx.ReadDataInt(0UL, 0) : default; + public int Bar => which == WHICH.Bar ? ctx.ReadDataInt(0UL, 0) : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(32U, (ushort)0); + set => this.WriteData(32U, (ushort)value, (ushort)0); + } + + public int Foo + { + get => which == WHICH.Foo ? this.ReadDataInt(0UL, 0) : default; + set => this.WriteData(0UL, value, 0); + } + + public int Bar + { + get => which == WHICH.Bar ? this.ReadDataInt(0UL, 0) : default; + set => this.WriteData(0UL, value, 0); + } + } + } + } + } + + public class TestGroups : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Groups = CapnpSerializable.Create(reader.Groups); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + Groups?.serialize(writer.Groups); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.TestGroups.@groups Groups + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public @groups.READER Groups => new @groups.READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(2, 2); + } + + public @groups.WRITER Groups + { + get => Rewrap<@groups.WRITER>(); + } + } + + public class @groups : ICapnpSerializable + { + public enum WHICH : ushort + { + Foo = 0, + Baz = 1, + Bar = 2, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.Foo: + Foo = CapnpSerializable.Create(reader.Foo); + break; + case WHICH.Baz: + Baz = CapnpSerializable.Create(reader.Baz); + break; + case WHICH.Bar: + Bar = CapnpSerializable.Create(reader.Bar); + break; + } + + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.Foo: + _content = null; + break; + case WHICH.Baz: + _content = null; + break; + case WHICH.Bar: + _content = null; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.Foo: + Foo?.serialize(writer.Foo); + break; + case WHICH.Baz: + Baz?.serialize(writer.Baz); + break; + case WHICH.Bar: + Bar?.serialize(writer.Bar); + break; + } + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.TestGroups.@groups.@foo Foo + { + get => _which == WHICH.Foo ? (Capnproto_test.Capnp.Test.TestGroups.@groups.@foo)_content : null; + set + { + _which = WHICH.Foo; + _content = value; + } + } + + public Capnproto_test.Capnp.Test.TestGroups.@groups.@baz Baz + { + get => _which == WHICH.Baz ? (Capnproto_test.Capnp.Test.TestGroups.@groups.@baz)_content : null; + set + { + _which = WHICH.Baz; + _content = value; + } + } + + public Capnproto_test.Capnp.Test.TestGroups.@groups.@bar Bar + { + get => _which == WHICH.Bar ? (Capnproto_test.Capnp.Test.TestGroups.@groups.@bar)_content : null; + set + { + _which = WHICH.Bar; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(32U, (ushort)0); + public @foo.READER Foo => which == WHICH.Foo ? new @foo.READER(ctx) : default; + public @baz.READER Baz => which == WHICH.Baz ? new @baz.READER(ctx) : default; + public @bar.READER Bar => which == WHICH.Bar ? new @bar.READER(ctx) : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(32U, (ushort)0); + set => this.WriteData(32U, (ushort)value, (ushort)0); + } + + public @foo.WRITER Foo + { + get => which == WHICH.Foo ? Rewrap<@foo.WRITER>() : default; + } + + public @baz.WRITER Baz + { + get => which == WHICH.Baz ? Rewrap<@baz.WRITER>() : default; + } + + public @bar.WRITER Bar + { + get => which == WHICH.Bar ? Rewrap<@bar.WRITER>() : default; + } + } + + public class @foo : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Corge = reader.Corge; + Grault = reader.Grault; + Garply = reader.Garply; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Corge = Corge; + writer.Grault = Grault; + writer.Garply = Garply; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public int Corge + { + get; + set; + } + + public long Grault + { + get; + set; + } + + public string Garply + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public int Corge => ctx.ReadDataInt(0UL, 0); + public long Grault => ctx.ReadDataLong(64UL, 0L); + public string Garply => ctx.ReadText(0, ""); + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public int Corge + { + get => this.ReadDataInt(0UL, 0); + set => this.WriteData(0UL, value, 0); + } + + public long Grault + { + get => this.ReadDataLong(64UL, 0L); + set => this.WriteData(64UL, value, 0L); + } + + public string Garply + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + } + } + + public class @baz : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Corge = reader.Corge; + Grault = reader.Grault; + Garply = reader.Garply; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Corge = Corge; + writer.Grault = Grault; + writer.Garply = Garply; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public int Corge + { + get; + set; + } + + public string Grault + { + get; + set; + } + + public string Garply + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public int Corge => ctx.ReadDataInt(0UL, 0); + public string Grault => ctx.ReadText(0, ""); + public string Garply => ctx.ReadText(1, ""); + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public int Corge + { + get => this.ReadDataInt(0UL, 0); + set => this.WriteData(0UL, value, 0); + } + + public string Grault + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + + public string Garply + { + get => this.ReadText(1, ""); + set => this.WriteText(1, value, ""); + } + } + } + + public class @bar : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Corge = reader.Corge; + Grault = reader.Grault; + Garply = reader.Garply; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Corge = Corge; + writer.Grault = Grault; + writer.Garply = Garply; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public int Corge + { + get; + set; + } + + public string Grault + { + get; + set; + } + + public long Garply + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public int Corge => ctx.ReadDataInt(0UL, 0); + public string Grault => ctx.ReadText(0, ""); + public long Garply => ctx.ReadDataLong(64UL, 0L); + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public int Corge + { + get => this.ReadDataInt(0UL, 0); + set => this.WriteData(0UL, value, 0); + } + + public string Grault + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + + public long Garply + { + get => this.ReadDataLong(64UL, 0L); + set => this.WriteData(64UL, value, 0L); + } + } + } + } + } + + public class TestInterleavedGroups : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Group1 = CapnpSerializable.Create(reader.Group1); + Group2 = CapnpSerializable.Create(reader.Group2); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + Group1?.serialize(writer.Group1); + Group2?.serialize(writer.Group2); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.TestInterleavedGroups.@group1 Group1 + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestInterleavedGroups.@group2 Group2 + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public @group1.READER Group1 => new @group1.READER(ctx); + public @group2.READER Group2 => new @group2.READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(6, 6); + } + + public @group1.WRITER Group1 + { + get => Rewrap<@group1.WRITER>(); + } + + public @group2.WRITER Group2 + { + get => Rewrap<@group2.WRITER>(); + } + } + + public class @group1 : ICapnpSerializable + { + public enum WHICH : ushort + { + Qux = 0, + Corge = 1, + Fred = 2, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.Qux: + Qux = reader.Qux; + break; + case WHICH.Corge: + Corge = CapnpSerializable.Create(reader.Corge); + break; + case WHICH.Fred: + Fred = reader.Fred; + break; + } + + Foo = reader.Foo; + Bar = reader.Bar; + Waldo = reader.Waldo; + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.Qux: + _content = 0; + break; + case WHICH.Corge: + _content = null; + break; + case WHICH.Fred: + _content = null; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.Qux: + writer.Qux = Qux.Value; + break; + case WHICH.Corge: + Corge?.serialize(writer.Corge); + break; + case WHICH.Fred: + writer.Fred = Fred; + break; + } + + writer.Foo = Foo; + writer.Bar = Bar; + writer.Waldo = Waldo; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public uint Foo + { + get; + set; + } + + public ulong Bar + { + get; + set; + } + + public ushort? Qux + { + get => _which == WHICH.Qux ? (ushort? )_content : null; + set + { + _which = WHICH.Qux; + _content = value; + } + } + + public Capnproto_test.Capnp.Test.TestInterleavedGroups.@group1.@corge Corge + { + get => _which == WHICH.Corge ? (Capnproto_test.Capnp.Test.TestInterleavedGroups.@group1.@corge)_content : null; + set + { + _which = WHICH.Corge; + _content = value; + } + } + + public string Waldo + { + get; + set; + } + + public string Fred + { + get => _which == WHICH.Fred ? (string)_content : null; + set + { + _which = WHICH.Fred; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(224U, (ushort)0); + public uint Foo => ctx.ReadDataUInt(0UL, 0U); + public ulong Bar => ctx.ReadDataULong(64UL, 0UL); + public ushort Qux => which == WHICH.Qux ? ctx.ReadDataUShort(192UL, (ushort)0) : default; + public @corge.READER Corge => which == WHICH.Corge ? new @corge.READER(ctx) : default; + public string Waldo => ctx.ReadText(0, ""); + public string Fred => which == WHICH.Fred ? ctx.ReadText(2, "") : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(224U, (ushort)0); + set => this.WriteData(224U, (ushort)value, (ushort)0); + } + + public uint Foo + { + get => this.ReadDataUInt(0UL, 0U); + set => this.WriteData(0UL, value, 0U); + } + + public ulong Bar + { + get => this.ReadDataULong(64UL, 0UL); + set => this.WriteData(64UL, value, 0UL); + } + + public ushort Qux + { + get => which == WHICH.Qux ? this.ReadDataUShort(192UL, (ushort)0) : default; + set => this.WriteData(192UL, value, (ushort)0); + } + + public @corge.WRITER Corge + { + get => which == WHICH.Corge ? Rewrap<@corge.WRITER>() : default; + } + + public string Waldo + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + + public string Fred + { + get => which == WHICH.Fred ? this.ReadText(2, "") : default; + set => this.WriteText(2, value, ""); + } + } + + public class @corge : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Grault = reader.Grault; + Garply = reader.Garply; + Plugh = reader.Plugh; + Xyzzy = reader.Xyzzy; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Grault = Grault; + writer.Garply = Garply; + writer.Plugh = Plugh; + writer.Xyzzy = Xyzzy; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public ulong Grault + { + get; + set; + } + + public ushort Garply + { + get; + set; + } + + public string Plugh + { + get; + set; + } + + public string Xyzzy + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public ulong Grault => ctx.ReadDataULong(256UL, 0UL); + public ushort Garply => ctx.ReadDataUShort(192UL, (ushort)0); + public string Plugh => ctx.ReadText(2, ""); + public string Xyzzy => ctx.ReadText(4, ""); + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public ulong Grault + { + get => this.ReadDataULong(256UL, 0UL); + set => this.WriteData(256UL, value, 0UL); + } + + public ushort Garply + { + get => this.ReadDataUShort(192UL, (ushort)0); + set => this.WriteData(192UL, value, (ushort)0); + } + + public string Plugh + { + get => this.ReadText(2, ""); + set => this.WriteText(2, value, ""); + } + + public string Xyzzy + { + get => this.ReadText(4, ""); + set => this.WriteText(4, value, ""); + } + } + } + } + + public class @group2 : ICapnpSerializable + { + public enum WHICH : ushort + { + Qux = 0, + Corge = 1, + Fred = 2, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.Qux: + Qux = reader.Qux; + break; + case WHICH.Corge: + Corge = CapnpSerializable.Create(reader.Corge); + break; + case WHICH.Fred: + Fred = reader.Fred; + break; + } + + Foo = reader.Foo; + Bar = reader.Bar; + Waldo = reader.Waldo; + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.Qux: + _content = 0; + break; + case WHICH.Corge: + _content = null; + break; + case WHICH.Fred: + _content = null; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.Qux: + writer.Qux = Qux.Value; + break; + case WHICH.Corge: + Corge?.serialize(writer.Corge); + break; + case WHICH.Fred: + writer.Fred = Fred; + break; + } + + writer.Foo = Foo; + writer.Bar = Bar; + writer.Waldo = Waldo; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public uint Foo + { + get; + set; + } + + public ulong Bar + { + get; + set; + } + + public ushort? Qux + { + get => _which == WHICH.Qux ? (ushort? )_content : null; + set + { + _which = WHICH.Qux; + _content = value; + } + } + + public Capnproto_test.Capnp.Test.TestInterleavedGroups.@group2.@corge Corge + { + get => _which == WHICH.Corge ? (Capnproto_test.Capnp.Test.TestInterleavedGroups.@group2.@corge)_content : null; + set + { + _which = WHICH.Corge; + _content = value; + } + } + + public string Waldo + { + get; + set; + } + + public string Fred + { + get => _which == WHICH.Fred ? (string)_content : null; + set + { + _which = WHICH.Fred; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(240U, (ushort)0); + public uint Foo => ctx.ReadDataUInt(32UL, 0U); + public ulong Bar => ctx.ReadDataULong(128UL, 0UL); + public ushort Qux => which == WHICH.Qux ? ctx.ReadDataUShort(208UL, (ushort)0) : default; + public @corge.READER Corge => which == WHICH.Corge ? new @corge.READER(ctx) : default; + public string Waldo => ctx.ReadText(1, ""); + public string Fred => which == WHICH.Fred ? ctx.ReadText(3, "") : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(240U, (ushort)0); + set => this.WriteData(240U, (ushort)value, (ushort)0); + } + + public uint Foo + { + get => this.ReadDataUInt(32UL, 0U); + set => this.WriteData(32UL, value, 0U); + } + + public ulong Bar + { + get => this.ReadDataULong(128UL, 0UL); + set => this.WriteData(128UL, value, 0UL); + } + + public ushort Qux + { + get => which == WHICH.Qux ? this.ReadDataUShort(208UL, (ushort)0) : default; + set => this.WriteData(208UL, value, (ushort)0); + } + + public @corge.WRITER Corge + { + get => which == WHICH.Corge ? Rewrap<@corge.WRITER>() : default; + } + + public string Waldo + { + get => this.ReadText(1, ""); + set => this.WriteText(1, value, ""); + } + + public string Fred + { + get => which == WHICH.Fred ? this.ReadText(3, "") : default; + set => this.WriteText(3, value, ""); + } + } + + public class @corge : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Grault = reader.Grault; + Garply = reader.Garply; + Plugh = reader.Plugh; + Xyzzy = reader.Xyzzy; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Grault = Grault; + writer.Garply = Garply; + writer.Plugh = Plugh; + writer.Xyzzy = Xyzzy; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public ulong Grault + { + get; + set; + } + + public ushort Garply + { + get; + set; + } + + public string Plugh + { + get; + set; + } + + public string Xyzzy + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public ulong Grault => ctx.ReadDataULong(320UL, 0UL); + public ushort Garply => ctx.ReadDataUShort(208UL, (ushort)0); + public string Plugh => ctx.ReadText(3, ""); + public string Xyzzy => ctx.ReadText(5, ""); + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public ulong Grault + { + get => this.ReadDataULong(320UL, 0UL); + set => this.WriteData(320UL, value, 0UL); + } + + public ushort Garply + { + get => this.ReadDataUShort(208UL, (ushort)0); + set => this.WriteData(208UL, value, (ushort)0); + } + + public string Plugh + { + get => this.ReadText(3, ""); + set => this.WriteText(3, value, ""); + } + + public string Xyzzy + { + get => this.ReadText(5, ""); + set => this.WriteText(5, value, ""); + } + } + } + } + } + + public class TestUnionDefaults : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + S16s8s64s8Set = CapnpSerializable.Create(reader.S16s8s64s8Set); + S0sps1s32Set = CapnpSerializable.Create(reader.S0sps1s32Set); + Unnamed1 = CapnpSerializable.Create(reader.Unnamed1); + Unnamed2 = CapnpSerializable.Create(reader.Unnamed2); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + S16s8s64s8Set?.serialize(writer.S16s8s64s8Set); + S0sps1s32Set?.serialize(writer.S0sps1s32Set); + Unnamed1?.serialize(writer.Unnamed1); + Unnamed2?.serialize(writer.Unnamed2); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + S16s8s64s8Set = S16s8s64s8Set ?? new Capnproto_test.Capnp.Test.TestUnion() + {Union0 = new Capnproto_test.Capnp.Test.TestUnion.@union0() + {}, Union1 = new Capnproto_test.Capnp.Test.TestUnion.@union1() + {}, Union2 = new Capnproto_test.Capnp.Test.TestUnion.@union2() + {}, Union3 = new Capnproto_test.Capnp.Test.TestUnion.@union3() + {}, Bit0 = false, Bit2 = false, Bit3 = false, Bit4 = false, Bit5 = false, Bit6 = false, Bit7 = false, Byte0 = 0}; + S0sps1s32Set = S0sps1s32Set ?? new Capnproto_test.Capnp.Test.TestUnion() + {Union0 = new Capnproto_test.Capnp.Test.TestUnion.@union0() + {}, Union1 = new Capnproto_test.Capnp.Test.TestUnion.@union1() + {}, Union2 = new Capnproto_test.Capnp.Test.TestUnion.@union2() + {}, Union3 = new Capnproto_test.Capnp.Test.TestUnion.@union3() + {}, Bit0 = false, Bit2 = false, Bit3 = false, Bit4 = false, Bit5 = false, Bit6 = false, Bit7 = false, Byte0 = 0}; + Unnamed1 = Unnamed1 ?? new Capnproto_test.Capnp.Test.TestUnnamedUnion() + {Before = null, Middle = 0, After = null}; + Unnamed2 = Unnamed2 ?? new Capnproto_test.Capnp.Test.TestUnnamedUnion() + {Before = "foo", Middle = 0, After = "bar"}; + } + + public Capnproto_test.Capnp.Test.TestUnion S16s8s64s8Set + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestUnion S0sps1s32Set + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestUnnamedUnion Unnamed1 + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestUnnamedUnion Unnamed2 + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnproto_test.Capnp.Test.TestUnion.READER S16s8s64s8Set => ctx.ReadStruct(0, Capnproto_test.Capnp.Test.TestUnion.READER.create); + public Capnproto_test.Capnp.Test.TestUnion.READER S0sps1s32Set => ctx.ReadStruct(1, Capnproto_test.Capnp.Test.TestUnion.READER.create); + public Capnproto_test.Capnp.Test.TestUnnamedUnion.READER Unnamed1 => ctx.ReadStruct(2, Capnproto_test.Capnp.Test.TestUnnamedUnion.READER.create); + public Capnproto_test.Capnp.Test.TestUnnamedUnion.READER Unnamed2 => ctx.ReadStruct(3, Capnproto_test.Capnp.Test.TestUnnamedUnion.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 4); + } + + public Capnproto_test.Capnp.Test.TestUnion.WRITER S16s8s64s8Set + { + get => BuildPointer(0); + set => Link(0, value); + } + + public Capnproto_test.Capnp.Test.TestUnion.WRITER S0sps1s32Set + { + get => BuildPointer(1); + set => Link(1, value); + } + + public Capnproto_test.Capnp.Test.TestUnnamedUnion.WRITER Unnamed1 + { + get => BuildPointer(2); + set => Link(2, value); + } + + public Capnproto_test.Capnp.Test.TestUnnamedUnion.WRITER Unnamed2 + { + get => BuildPointer(3); + set => Link(3, value); + } + } + } + + public class TestNestedTypes : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + TheNestedStruct = CapnpSerializable.Create(reader.TheNestedStruct); + OuterNestedEnum = reader.OuterNestedEnum; + InnerNestedEnum = reader.InnerNestedEnum; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + TheNestedStruct?.serialize(writer.TheNestedStruct); + writer.OuterNestedEnum = OuterNestedEnum; + writer.InnerNestedEnum = InnerNestedEnum; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.TestNestedTypes.NestedStruct TheNestedStruct + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestNestedTypes.NestedEnum OuterNestedEnum + { + get; + set; + } + + = Capnproto_test.Capnp.Test.TestNestedTypes.NestedEnum.bar; + public Capnproto_test.Capnp.Test.TestNestedTypes.NestedStruct.NestedEnum InnerNestedEnum + { + get; + set; + } + + = Capnproto_test.Capnp.Test.TestNestedTypes.NestedStruct.NestedEnum.quux; + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnproto_test.Capnp.Test.TestNestedTypes.NestedStruct.READER TheNestedStruct => ctx.ReadStruct(0, Capnproto_test.Capnp.Test.TestNestedTypes.NestedStruct.READER.create); + public Capnproto_test.Capnp.Test.TestNestedTypes.NestedEnum OuterNestedEnum => (Capnproto_test.Capnp.Test.TestNestedTypes.NestedEnum)ctx.ReadDataUShort(0UL, (ushort)1); + public Capnproto_test.Capnp.Test.TestNestedTypes.NestedStruct.NestedEnum InnerNestedEnum => (Capnproto_test.Capnp.Test.TestNestedTypes.NestedStruct.NestedEnum)ctx.ReadDataUShort(16UL, (ushort)2); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public Capnproto_test.Capnp.Test.TestNestedTypes.NestedStruct.WRITER TheNestedStruct + { + get => BuildPointer(0); + set => Link(0, value); + } + + public Capnproto_test.Capnp.Test.TestNestedTypes.NestedEnum OuterNestedEnum + { + get => (Capnproto_test.Capnp.Test.TestNestedTypes.NestedEnum)this.ReadDataUShort(0UL, (ushort)1); + set => this.WriteData(0UL, (ushort)value, (ushort)1); + } + + public Capnproto_test.Capnp.Test.TestNestedTypes.NestedStruct.NestedEnum InnerNestedEnum + { + get => (Capnproto_test.Capnp.Test.TestNestedTypes.NestedStruct.NestedEnum)this.ReadDataUShort(16UL, (ushort)2); + set => this.WriteData(16UL, (ushort)value, (ushort)2); + } + } + + public enum NestedEnum : ushort + { + foo, + bar + } + + public class NestedStruct : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + OuterNestedEnum = reader.OuterNestedEnum; + InnerNestedEnum = reader.InnerNestedEnum; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.OuterNestedEnum = OuterNestedEnum; + writer.InnerNestedEnum = InnerNestedEnum; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.TestNestedTypes.NestedEnum OuterNestedEnum + { + get; + set; + } + + = Capnproto_test.Capnp.Test.TestNestedTypes.NestedEnum.bar; + public Capnproto_test.Capnp.Test.TestNestedTypes.NestedStruct.NestedEnum InnerNestedEnum + { + get; + set; + } + + = Capnproto_test.Capnp.Test.TestNestedTypes.NestedStruct.NestedEnum.quux; + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnproto_test.Capnp.Test.TestNestedTypes.NestedEnum OuterNestedEnum => (Capnproto_test.Capnp.Test.TestNestedTypes.NestedEnum)ctx.ReadDataUShort(0UL, (ushort)1); + public Capnproto_test.Capnp.Test.TestNestedTypes.NestedStruct.NestedEnum InnerNestedEnum => (Capnproto_test.Capnp.Test.TestNestedTypes.NestedStruct.NestedEnum)ctx.ReadDataUShort(16UL, (ushort)2); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 0); + } + + public Capnproto_test.Capnp.Test.TestNestedTypes.NestedEnum OuterNestedEnum + { + get => (Capnproto_test.Capnp.Test.TestNestedTypes.NestedEnum)this.ReadDataUShort(0UL, (ushort)1); + set => this.WriteData(0UL, (ushort)value, (ushort)1); + } + + public Capnproto_test.Capnp.Test.TestNestedTypes.NestedStruct.NestedEnum InnerNestedEnum + { + get => (Capnproto_test.Capnp.Test.TestNestedTypes.NestedStruct.NestedEnum)this.ReadDataUShort(16UL, (ushort)2); + set => this.WriteData(16UL, (ushort)value, (ushort)2); + } + } + + public enum NestedEnum : ushort + { + baz, + qux, + quux + } + } + } + + public class TestUsing : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + InnerNestedEnum = reader.InnerNestedEnum; + OuterNestedEnum = reader.OuterNestedEnum; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.InnerNestedEnum = InnerNestedEnum; + writer.OuterNestedEnum = OuterNestedEnum; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.TestNestedTypes.NestedStruct.NestedEnum InnerNestedEnum + { + get; + set; + } + + = Capnproto_test.Capnp.Test.TestNestedTypes.NestedStruct.NestedEnum.quux; + public Capnproto_test.Capnp.Test.TestNestedTypes.NestedEnum OuterNestedEnum + { + get; + set; + } + + = Capnproto_test.Capnp.Test.TestNestedTypes.NestedEnum.bar; + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnproto_test.Capnp.Test.TestNestedTypes.NestedStruct.NestedEnum InnerNestedEnum => (Capnproto_test.Capnp.Test.TestNestedTypes.NestedStruct.NestedEnum)ctx.ReadDataUShort(0UL, (ushort)2); + public Capnproto_test.Capnp.Test.TestNestedTypes.NestedEnum OuterNestedEnum => (Capnproto_test.Capnp.Test.TestNestedTypes.NestedEnum)ctx.ReadDataUShort(16UL, (ushort)1); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 0); + } + + public Capnproto_test.Capnp.Test.TestNestedTypes.NestedStruct.NestedEnum InnerNestedEnum + { + get => (Capnproto_test.Capnp.Test.TestNestedTypes.NestedStruct.NestedEnum)this.ReadDataUShort(0UL, (ushort)2); + set => this.WriteData(0UL, (ushort)value, (ushort)2); + } + + public Capnproto_test.Capnp.Test.TestNestedTypes.NestedEnum OuterNestedEnum + { + get => (Capnproto_test.Capnp.Test.TestNestedTypes.NestedEnum)this.ReadDataUShort(16UL, (ushort)1); + set => this.WriteData(16UL, (ushort)value, (ushort)1); + } + } + } + + public class TestLists : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + List0 = reader.List0.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + List1 = reader.List1.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + List8 = reader.List8.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + List16 = reader.List16.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + List32 = reader.List32.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + List64 = reader.List64.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + ListP = reader.ListP.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + Int32ListList = reader.Int32ListList; + TextListList = reader.TextListList; + StructListList = reader.StructListList.ToReadOnlyList(_2 => _2.ToReadOnlyList(_ => CapnpSerializable.Create(_))); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.List0.Init(List0, (_s1, _v1) => _v1?.serialize(_s1)); + writer.List1.Init(List1, (_s1, _v1) => _v1?.serialize(_s1)); + writer.List8.Init(List8, (_s1, _v1) => _v1?.serialize(_s1)); + writer.List16.Init(List16, (_s1, _v1) => _v1?.serialize(_s1)); + writer.List32.Init(List32, (_s1, _v1) => _v1?.serialize(_s1)); + writer.List64.Init(List64, (_s1, _v1) => _v1?.serialize(_s1)); + writer.ListP.Init(ListP, (_s1, _v1) => _v1?.serialize(_s1)); + writer.Int32ListList.Init(Int32ListList, (_s2, _v2) => _s2.Init(_v2)); + writer.TextListList.Init(TextListList, (_s2, _v2) => _s2.Init(_v2)); + writer.StructListList.Init(StructListList, (_s2, _v2) => _s2.Init(_v2, (_s1, _v1) => _v1?.serialize(_s1))); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public IReadOnlyList List0 + { + get; + set; + } + + public IReadOnlyList List1 + { + get; + set; + } + + public IReadOnlyList List8 + { + get; + set; + } + + public IReadOnlyList List16 + { + get; + set; + } + + public IReadOnlyList List32 + { + get; + set; + } + + public IReadOnlyList List64 + { + get; + set; + } + + public IReadOnlyList ListP + { + get; + set; + } + + public IReadOnlyList> Int32ListList + { + get; + set; + } + + public IReadOnlyList> TextListList + { + get; + set; + } + + public IReadOnlyList> StructListList + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public IReadOnlyList List0 => ctx.ReadList(0).Cast(Capnproto_test.Capnp.Test.TestLists.Struct0.READER.create); + public IReadOnlyList List1 => ctx.ReadList(1).Cast(Capnproto_test.Capnp.Test.TestLists.Struct1.READER.create); + public IReadOnlyList List8 => ctx.ReadList(2).Cast(Capnproto_test.Capnp.Test.TestLists.Struct8.READER.create); + public IReadOnlyList List16 => ctx.ReadList(3).Cast(Capnproto_test.Capnp.Test.TestLists.Struct16.READER.create); + public IReadOnlyList List32 => ctx.ReadList(4).Cast(Capnproto_test.Capnp.Test.TestLists.Struct32.READER.create); + public IReadOnlyList List64 => ctx.ReadList(5).Cast(Capnproto_test.Capnp.Test.TestLists.Struct64.READER.create); + public IReadOnlyList ListP => ctx.ReadList(6).Cast(Capnproto_test.Capnp.Test.TestLists.StructP.READER.create); + public IReadOnlyList> Int32ListList => ctx.ReadList(7).Cast(_0 => _0.RequireList().CastInt()); + public IReadOnlyList> TextListList => ctx.ReadList(8).Cast(_0 => _0.RequireList().CastText2()); + public IReadOnlyList> StructListList => ctx.ReadList(9).Cast(_0 => _0.RequireList().Cast(Capnproto_test.Capnp.Test.TestAllTypes.READER.create)); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 10); + } + + public ListOfStructsSerializer List0 + { + get => BuildPointer>(0); + set => Link(0, value); + } + + public ListOfStructsSerializer List1 + { + get => BuildPointer>(1); + set => Link(1, value); + } + + public ListOfStructsSerializer List8 + { + get => BuildPointer>(2); + set => Link(2, value); + } + + public ListOfStructsSerializer List16 + { + get => BuildPointer>(3); + set => Link(3, value); + } + + public ListOfStructsSerializer List32 + { + get => BuildPointer>(4); + set => Link(4, value); + } + + public ListOfStructsSerializer List64 + { + get => BuildPointer>(5); + set => Link(5, value); + } + + public ListOfStructsSerializer ListP + { + get => BuildPointer>(6); + set => Link(6, value); + } + + public ListOfPointersSerializer> Int32ListList + { + get => BuildPointer>>(7); + set => Link(7, value); + } + + public ListOfPointersSerializer TextListList + { + get => BuildPointer>(8); + set => Link(8, value); + } + + public ListOfPointersSerializer> StructListList + { + get => BuildPointer>>(9); + set => Link(9, value); + } + } + + public class Struct0 : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + public class Struct1 : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + F = reader.F; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.F = F; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public bool F + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public bool F => ctx.ReadDataBool(0UL, false); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 0); + } + + public bool F + { + get => this.ReadDataBool(0UL, false); + set => this.WriteData(0UL, value, false); + } + } + } + + public class Struct8 : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + F = reader.F; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.F = F; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public byte F + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public byte F => ctx.ReadDataByte(0UL, (byte)0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 0); + } + + public byte F + { + get => this.ReadDataByte(0UL, (byte)0); + set => this.WriteData(0UL, value, (byte)0); + } + } + } + + public class Struct16 : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + F = reader.F; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.F = F; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public ushort F + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public ushort F => ctx.ReadDataUShort(0UL, (ushort)0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 0); + } + + public ushort F + { + get => this.ReadDataUShort(0UL, (ushort)0); + set => this.WriteData(0UL, value, (ushort)0); + } + } + } + + public class Struct32 : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + F = reader.F; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.F = F; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public uint F + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public uint F => ctx.ReadDataUInt(0UL, 0U); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 0); + } + + public uint F + { + get => this.ReadDataUInt(0UL, 0U); + set => this.WriteData(0UL, value, 0U); + } + } + } + + public class Struct64 : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + F = reader.F; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.F = F; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public ulong F + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public ulong F => ctx.ReadDataULong(0UL, 0UL); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 0); + } + + public ulong F + { + get => this.ReadDataULong(0UL, 0UL); + set => this.WriteData(0UL, value, 0UL); + } + } + } + + public class StructP : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + F = reader.F; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.F = F; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string F + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string F => ctx.ReadText(0, ""); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public string F + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + } + } + + public class Struct0c : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Pad = reader.Pad; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Pad = Pad; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string Pad + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string Pad => ctx.ReadText(0, ""); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public string Pad + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + } + } + + public class Struct1c : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + F = reader.F; + Pad = reader.Pad; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.F = F; + writer.Pad = Pad; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public bool F + { + get; + set; + } + + public string Pad + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public bool F => ctx.ReadDataBool(0UL, false); + public string Pad => ctx.ReadText(0, ""); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public bool F + { + get => this.ReadDataBool(0UL, false); + set => this.WriteData(0UL, value, false); + } + + public string Pad + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + } + } + + public class Struct8c : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + F = reader.F; + Pad = reader.Pad; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.F = F; + writer.Pad = Pad; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public byte F + { + get; + set; + } + + public string Pad + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public byte F => ctx.ReadDataByte(0UL, (byte)0); + public string Pad => ctx.ReadText(0, ""); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public byte F + { + get => this.ReadDataByte(0UL, (byte)0); + set => this.WriteData(0UL, value, (byte)0); + } + + public string Pad + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + } + } + + public class Struct16c : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + F = reader.F; + Pad = reader.Pad; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.F = F; + writer.Pad = Pad; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public ushort F + { + get; + set; + } + + public string Pad + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public ushort F => ctx.ReadDataUShort(0UL, (ushort)0); + public string Pad => ctx.ReadText(0, ""); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public ushort F + { + get => this.ReadDataUShort(0UL, (ushort)0); + set => this.WriteData(0UL, value, (ushort)0); + } + + public string Pad + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + } + } + + public class Struct32c : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + F = reader.F; + Pad = reader.Pad; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.F = F; + writer.Pad = Pad; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public uint F + { + get; + set; + } + + public string Pad + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public uint F => ctx.ReadDataUInt(0UL, 0U); + public string Pad => ctx.ReadText(0, ""); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public uint F + { + get => this.ReadDataUInt(0UL, 0U); + set => this.WriteData(0UL, value, 0U); + } + + public string Pad + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + } + } + + public class Struct64c : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + F = reader.F; + Pad = reader.Pad; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.F = F; + writer.Pad = Pad; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public ulong F + { + get; + set; + } + + public string Pad + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public ulong F => ctx.ReadDataULong(0UL, 0UL); + public string Pad => ctx.ReadText(0, ""); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public ulong F + { + get => this.ReadDataULong(0UL, 0UL); + set => this.WriteData(0UL, value, 0UL); + } + + public string Pad + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + } + } + + public class StructPc : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + F = reader.F; + Pad = reader.Pad; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.F = F; + writer.Pad = Pad; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string F + { + get; + set; + } + + public ulong Pad + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string F => ctx.ReadText(0, ""); + public ulong Pad => ctx.ReadDataULong(0UL, 0UL); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public string F + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + + public ulong Pad + { + get => this.ReadDataULong(0UL, 0UL); + set => this.WriteData(0UL, value, 0UL); + } + } + } + } + + public class TestFieldZeroIsBit : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Bit = reader.Bit; + SecondBit = reader.SecondBit; + ThirdField = reader.ThirdField; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Bit = Bit; + writer.SecondBit = SecondBit; + writer.ThirdField = ThirdField; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public bool Bit + { + get; + set; + } + + public bool SecondBit + { + get; + set; + } + + = true; + public byte ThirdField + { + get; + set; + } + + = 123; + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public bool Bit => ctx.ReadDataBool(0UL, false); + public bool SecondBit => ctx.ReadDataBool(1UL, true); + public byte ThirdField => ctx.ReadDataByte(8UL, (byte)123); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 0); + } + + public bool Bit + { + get => this.ReadDataBool(0UL, false); + set => this.WriteData(0UL, value, false); + } + + public bool SecondBit + { + get => this.ReadDataBool(1UL, true); + set => this.WriteData(1UL, value, true); + } + + public byte ThirdField + { + get => this.ReadDataByte(8UL, (byte)123); + set => this.WriteData(8UL, value, (byte)123); + } + } + } + + public class TestListDefaults : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Lists = CapnpSerializable.Create(reader.Lists); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + Lists?.serialize(writer.Lists); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + Lists = Lists ?? new Capnproto_test.Capnp.Test.TestLists() + {List0 = new Capnproto_test.Capnp.Test.TestLists.Struct0[]{new Capnproto_test.Capnp.Test.TestLists.Struct0() + {}, new Capnproto_test.Capnp.Test.TestLists.Struct0() + {}}, List1 = new Capnproto_test.Capnp.Test.TestLists.Struct1[]{new Capnproto_test.Capnp.Test.TestLists.Struct1() + {F = true}, new Capnproto_test.Capnp.Test.TestLists.Struct1() + {F = false}, new Capnproto_test.Capnp.Test.TestLists.Struct1() + {F = true}, new Capnproto_test.Capnp.Test.TestLists.Struct1() + {F = true}}, List8 = new Capnproto_test.Capnp.Test.TestLists.Struct8[]{new Capnproto_test.Capnp.Test.TestLists.Struct8() + {F = 123}, new Capnproto_test.Capnp.Test.TestLists.Struct8() + {F = 45}}, List16 = new Capnproto_test.Capnp.Test.TestLists.Struct16[]{new Capnproto_test.Capnp.Test.TestLists.Struct16() + {F = 12345}, new Capnproto_test.Capnp.Test.TestLists.Struct16() + {F = 6789}}, List32 = new Capnproto_test.Capnp.Test.TestLists.Struct32[]{new Capnproto_test.Capnp.Test.TestLists.Struct32() + {F = 123456789U}, new Capnproto_test.Capnp.Test.TestLists.Struct32() + {F = 234567890U}}, List64 = new Capnproto_test.Capnp.Test.TestLists.Struct64[]{new Capnproto_test.Capnp.Test.TestLists.Struct64() + {F = 1234567890123456UL}, new Capnproto_test.Capnp.Test.TestLists.Struct64() + {F = 2345678901234567UL}}, ListP = new Capnproto_test.Capnp.Test.TestLists.StructP[]{new Capnproto_test.Capnp.Test.TestLists.StructP() + {F = "foo"}, new Capnproto_test.Capnp.Test.TestLists.StructP() + {F = "bar"}}, Int32ListList = new IReadOnlyList[]{new int[]{1, 2, 3}, new int[]{4, 5}, new int[]{12341234}}, TextListList = new IReadOnlyList[]{new string[]{"foo", "bar"}, new string[]{"baz"}, new string[]{"qux", "corge"}}, StructListList = new IReadOnlyList[]{new Capnproto_test.Capnp.Test.TestAllTypes[]{new Capnproto_test.Capnp.Test.TestAllTypes() + {BoolField = false, Int8Field = 0, Int16Field = 0, Int32Field = 123, Int64Field = 0L, UInt8Field = 0, UInt16Field = 0, UInt32Field = 0U, UInt64Field = 0UL, Float32Field = 0F, Float64Field = 0, TextField = null, DataField = new byte[]{}, StructField = new Capnproto_test.Capnp.Test.TestAllTypes() + {}, EnumField = Capnproto_test.Capnp.Test.TestEnum.foo, VoidList = 0, BoolList = new bool[]{}, Int8List = new sbyte[]{}, Int16List = new short[]{}, Int32List = new int[]{}, Int64List = new long[]{}, UInt8List = new byte[]{}, UInt16List = new ushort[]{}, UInt32List = new uint[]{}, UInt64List = new ulong[]{}, Float32List = new float[]{}, Float64List = new double[]{}, TextList = new string[]{}, DataList = new IReadOnlyList[]{}, StructList = new Capnproto_test.Capnp.Test.TestAllTypes[]{}, EnumList = new Capnproto_test.Capnp.Test.TestEnum[]{}, InterfaceList = 0}, new Capnproto_test.Capnp.Test.TestAllTypes() + {BoolField = false, Int8Field = 0, Int16Field = 0, Int32Field = 456, Int64Field = 0L, UInt8Field = 0, UInt16Field = 0, UInt32Field = 0U, UInt64Field = 0UL, Float32Field = 0F, Float64Field = 0, TextField = null, DataField = new byte[]{}, StructField = new Capnproto_test.Capnp.Test.TestAllTypes() + {}, EnumField = Capnproto_test.Capnp.Test.TestEnum.foo, VoidList = 0, BoolList = new bool[]{}, Int8List = new sbyte[]{}, Int16List = new short[]{}, Int32List = new int[]{}, Int64List = new long[]{}, UInt8List = new byte[]{}, UInt16List = new ushort[]{}, UInt32List = new uint[]{}, UInt64List = new ulong[]{}, Float32List = new float[]{}, Float64List = new double[]{}, TextList = new string[]{}, DataList = new IReadOnlyList[]{}, StructList = new Capnproto_test.Capnp.Test.TestAllTypes[]{}, EnumList = new Capnproto_test.Capnp.Test.TestEnum[]{}, InterfaceList = 0}}, new Capnproto_test.Capnp.Test.TestAllTypes[]{new Capnproto_test.Capnp.Test.TestAllTypes() + {BoolField = false, Int8Field = 0, Int16Field = 0, Int32Field = 789, Int64Field = 0L, UInt8Field = 0, UInt16Field = 0, UInt32Field = 0U, UInt64Field = 0UL, Float32Field = 0F, Float64Field = 0, TextField = null, DataField = new byte[]{}, StructField = new Capnproto_test.Capnp.Test.TestAllTypes() + {}, EnumField = Capnproto_test.Capnp.Test.TestEnum.foo, VoidList = 0, BoolList = new bool[]{}, Int8List = new sbyte[]{}, Int16List = new short[]{}, Int32List = new int[]{}, Int64List = new long[]{}, UInt8List = new byte[]{}, UInt16List = new ushort[]{}, UInt32List = new uint[]{}, UInt64List = new ulong[]{}, Float32List = new float[]{}, Float64List = new double[]{}, TextList = new string[]{}, DataList = new IReadOnlyList[]{}, StructList = new Capnproto_test.Capnp.Test.TestAllTypes[]{}, EnumList = new Capnproto_test.Capnp.Test.TestEnum[]{}, InterfaceList = 0}}}}; + } + + public Capnproto_test.Capnp.Test.TestLists Lists + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnproto_test.Capnp.Test.TestLists.READER Lists => ctx.ReadStruct(0, Capnproto_test.Capnp.Test.TestLists.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public Capnproto_test.Capnp.Test.TestLists.WRITER Lists + { + get => BuildPointer(0); + set => Link(0, value); + } + } + } + + public class TestLateUnion : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Foo = reader.Foo; + Bar = reader.Bar; + Baz = reader.Baz; + TheUnion = CapnpSerializable.Create(reader.TheUnion); + AnotherUnion = CapnpSerializable.Create(reader.AnotherUnion); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Foo = Foo; + writer.Bar = Bar; + writer.Baz = Baz; + TheUnion?.serialize(writer.TheUnion); + AnotherUnion?.serialize(writer.AnotherUnion); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public int Foo + { + get; + set; + } + + public string Bar + { + get; + set; + } + + public short Baz + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestLateUnion.@theUnion TheUnion + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestLateUnion.@anotherUnion AnotherUnion + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public int Foo => ctx.ReadDataInt(0UL, 0); + public string Bar => ctx.ReadText(0, ""); + public short Baz => ctx.ReadDataShort(32UL, (short)0); + public @theUnion.READER TheUnion => new @theUnion.READER(ctx); + public @anotherUnion.READER AnotherUnion => new @anotherUnion.READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(3, 3); + } + + public int Foo + { + get => this.ReadDataInt(0UL, 0); + set => this.WriteData(0UL, value, 0); + } + + public string Bar + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + + public short Baz + { + get => this.ReadDataShort(32UL, (short)0); + set => this.WriteData(32UL, value, (short)0); + } + + public @theUnion.WRITER TheUnion + { + get => Rewrap<@theUnion.WRITER>(); + } + + public @anotherUnion.WRITER AnotherUnion + { + get => Rewrap<@anotherUnion.WRITER>(); + } + } + + public class @theUnion : ICapnpSerializable + { + public enum WHICH : ushort + { + Qux = 0, + Corge = 1, + Grault = 2, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.Qux: + Qux = reader.Qux; + break; + case WHICH.Corge: + Corge = reader.Corge; + break; + case WHICH.Grault: + Grault = reader.Grault; + break; + } + + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.Qux: + _content = null; + break; + case WHICH.Corge: + _content = null; + break; + case WHICH.Grault: + _content = 0F; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.Qux: + writer.Qux = Qux; + break; + case WHICH.Corge: + writer.Corge.Init(Corge); + break; + case WHICH.Grault: + writer.Grault = Grault.Value; + break; + } + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string Qux + { + get => _which == WHICH.Qux ? (string)_content : null; + set + { + _which = WHICH.Qux; + _content = value; + } + } + + public IReadOnlyList Corge + { + get => _which == WHICH.Corge ? (IReadOnlyList)_content : null; + set + { + _which = WHICH.Corge; + _content = value; + } + } + + public float? Grault + { + get => _which == WHICH.Grault ? (float? )_content : null; + set + { + _which = WHICH.Grault; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(48U, (ushort)0); + public string Qux => which == WHICH.Qux ? ctx.ReadText(1, "") : default; + public IReadOnlyList Corge => which == WHICH.Corge ? ctx.ReadList(1).CastInt() : default; + public float Grault => which == WHICH.Grault ? ctx.ReadDataFloat(64UL, 0F) : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(48U, (ushort)0); + set => this.WriteData(48U, (ushort)value, (ushort)0); + } + + public string Qux + { + get => which == WHICH.Qux ? this.ReadText(1, "") : default; + set => this.WriteText(1, value, ""); + } + + public ListOfPrimitivesSerializer Corge + { + get => which == WHICH.Corge ? BuildPointer>(1) : default; + set => Link(1, value); + } + + public float Grault + { + get => which == WHICH.Grault ? this.ReadDataFloat(64UL, 0F) : default; + set => this.WriteData(64UL, value, 0F); + } + } + } + + public class @anotherUnion : ICapnpSerializable + { + public enum WHICH : ushort + { + Qux = 0, + Corge = 1, + Grault = 2, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.Qux: + Qux = reader.Qux; + break; + case WHICH.Corge: + Corge = reader.Corge; + break; + case WHICH.Grault: + Grault = reader.Grault; + break; + } + + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.Qux: + _content = null; + break; + case WHICH.Corge: + _content = null; + break; + case WHICH.Grault: + _content = 0F; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.Qux: + writer.Qux = Qux; + break; + case WHICH.Corge: + writer.Corge.Init(Corge); + break; + case WHICH.Grault: + writer.Grault = Grault.Value; + break; + } + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string Qux + { + get => _which == WHICH.Qux ? (string)_content : null; + set + { + _which = WHICH.Qux; + _content = value; + } + } + + public IReadOnlyList Corge + { + get => _which == WHICH.Corge ? (IReadOnlyList)_content : null; + set + { + _which = WHICH.Corge; + _content = value; + } + } + + public float? Grault + { + get => _which == WHICH.Grault ? (float? )_content : null; + set + { + _which = WHICH.Grault; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(96U, (ushort)0); + public string Qux => which == WHICH.Qux ? ctx.ReadText(2, "") : default; + public IReadOnlyList Corge => which == WHICH.Corge ? ctx.ReadList(2).CastInt() : default; + public float Grault => which == WHICH.Grault ? ctx.ReadDataFloat(128UL, 0F) : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(96U, (ushort)0); + set => this.WriteData(96U, (ushort)value, (ushort)0); + } + + public string Qux + { + get => which == WHICH.Qux ? this.ReadText(2, "") : default; + set => this.WriteText(2, value, ""); + } + + public ListOfPrimitivesSerializer Corge + { + get => which == WHICH.Corge ? BuildPointer>(2) : default; + set => Link(2, value); + } + + public float Grault + { + get => which == WHICH.Grault ? this.ReadDataFloat(128UL, 0F) : default; + set => this.WriteData(128UL, value, 0F); + } + } + } + } + + public class TestOldVersion : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Old1 = reader.Old1; + Old2 = reader.Old2; + Old3 = CapnpSerializable.Create(reader.Old3); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Old1 = Old1; + writer.Old2 = Old2; + Old3?.serialize(writer.Old3); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public long Old1 + { + get; + set; + } + + public string Old2 + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestOldVersion Old3 + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public long Old1 => ctx.ReadDataLong(0UL, 0L); + public string Old2 => ctx.ReadText(0, ""); + public Capnproto_test.Capnp.Test.TestOldVersion.READER Old3 => ctx.ReadStruct(1, Capnproto_test.Capnp.Test.TestOldVersion.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 2); + } + + public long Old1 + { + get => this.ReadDataLong(0UL, 0L); + set => this.WriteData(0UL, value, 0L); + } + + public string Old2 + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + + public Capnproto_test.Capnp.Test.TestOldVersion.WRITER Old3 + { + get => BuildPointer(1); + set => Link(1, value); + } + } + } + + public class TestNewVersion : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Old1 = reader.Old1; + Old2 = reader.Old2; + Old3 = CapnpSerializable.Create(reader.Old3); + New1 = reader.New1; + New2 = reader.New2; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Old1 = Old1; + writer.Old2 = Old2; + Old3?.serialize(writer.Old3); + writer.New1 = New1; + writer.New2 = New2; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + New2 = New2 ?? "baz"; + } + + public long Old1 + { + get; + set; + } + + public string Old2 + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestNewVersion Old3 + { + get; + set; + } + + public long New1 + { + get; + set; + } + + = 987L; + public string New2 + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public long Old1 => ctx.ReadDataLong(0UL, 0L); + public string Old2 => ctx.ReadText(0, ""); + public Capnproto_test.Capnp.Test.TestNewVersion.READER Old3 => ctx.ReadStruct(1, Capnproto_test.Capnp.Test.TestNewVersion.READER.create); + public long New1 => ctx.ReadDataLong(64UL, 987L); + public string New2 => ctx.ReadText(2, "baz"); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(2, 3); + } + + public long Old1 + { + get => this.ReadDataLong(0UL, 0L); + set => this.WriteData(0UL, value, 0L); + } + + public string Old2 + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + + public Capnproto_test.Capnp.Test.TestNewVersion.WRITER Old3 + { + get => BuildPointer(1); + set => Link(1, value); + } + + public long New1 + { + get => this.ReadDataLong(64UL, 987L); + set => this.WriteData(64UL, value, 987L); + } + + public string New2 + { + get => this.ReadText(2, "baz"); + set => this.WriteText(2, value, "baz"); + } + } + } + + public class TestOldUnionVersion : ICapnpSerializable + { + public enum WHICH : ushort + { + A = 0, + B = 1, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.A: + which = reader.which; + break; + case WHICH.B: + B = reader.B; + break; + } + + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.A: + break; + case WHICH.B: + _content = 0; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.A: + break; + case WHICH.B: + writer.B = B.Value; + break; + } + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public ulong? B + { + get => _which == WHICH.B ? (ulong? )_content : null; + set + { + _which = WHICH.B; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(0U, (ushort)0); + public ulong B => which == WHICH.B ? ctx.ReadDataULong(64UL, 0UL) : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(2, 0); + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(0U, (ushort)0); + set => this.WriteData(0U, (ushort)value, (ushort)0); + } + + public ulong B + { + get => which == WHICH.B ? this.ReadDataULong(64UL, 0UL) : default; + set => this.WriteData(64UL, value, 0UL); + } + } + } + + public class TestNewUnionVersion : ICapnpSerializable + { + public enum WHICH : ushort + { + A = 0, + B = 1, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.A: + A = CapnpSerializable.Create(reader.A); + break; + case WHICH.B: + B = reader.B; + break; + } + + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.A: + _content = null; + break; + case WHICH.B: + _content = 0; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.A: + A?.serialize(writer.A); + break; + case WHICH.B: + writer.B = B.Value; + break; + } + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.TestNewUnionVersion.@a A + { + get => _which == WHICH.A ? (Capnproto_test.Capnp.Test.TestNewUnionVersion.@a)_content : null; + set + { + _which = WHICH.A; + _content = value; + } + } + + public ulong? B + { + get => _which == WHICH.B ? (ulong? )_content : null; + set + { + _which = WHICH.B; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(0U, (ushort)0); + public @a.READER A => which == WHICH.A ? new @a.READER(ctx) : default; + public ulong B => which == WHICH.B ? ctx.ReadDataULong(64UL, 0UL) : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(3, 0); + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(0U, (ushort)0); + set => this.WriteData(0U, (ushort)value, (ushort)0); + } + + public @a.WRITER A + { + get => which == WHICH.A ? Rewrap<@a.WRITER>() : default; + } + + public ulong B + { + get => which == WHICH.B ? this.ReadDataULong(64UL, 0UL) : default; + set => this.WriteData(64UL, value, 0UL); + } + } + + public class @a : ICapnpSerializable + { + public enum WHICH : ushort + { + A0 = 0, + A1 = 1, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.A0: + which = reader.which; + break; + case WHICH.A1: + A1 = reader.A1; + break; + } + + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.A0: + break; + case WHICH.A1: + _content = 0; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.A0: + break; + case WHICH.A1: + writer.A1 = A1.Value; + break; + } + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public ulong? A1 + { + get => _which == WHICH.A1 ? (ulong? )_content : null; + set + { + _which = WHICH.A1; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(64U, (ushort)0); + public ulong A1 => which == WHICH.A1 ? ctx.ReadDataULong(128UL, 0UL) : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(64U, (ushort)0); + set => this.WriteData(64U, (ushort)value, (ushort)0); + } + + public ulong A1 + { + get => which == WHICH.A1 ? this.ReadDataULong(128UL, 0UL) : default; + set => this.WriteData(128UL, value, 0UL); + } + } + } + } + + public class TestStructUnion : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Un = CapnpSerializable.Create(reader.Un); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + Un?.serialize(writer.Un); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.TestStructUnion.@un Un + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public @un.READER Un => new @un.READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public @un.WRITER Un + { + get => Rewrap<@un.WRITER>(); + } + } + + public class @un : ICapnpSerializable + { + public enum WHICH : ushort + { + Struct = 0, + Object = 1, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.Struct: + Struct = CapnpSerializable.Create(reader.Struct); + break; + case WHICH.Object: + Object = CapnpSerializable.Create(reader.Object); + break; + } + + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.Struct: + _content = null; + break; + case WHICH.Object: + _content = null; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.Struct: + Struct?.serialize(writer.Struct); + break; + case WHICH.Object: + Object?.serialize(writer.Object); + break; + } + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.TestStructUnion.SomeStruct Struct + { + get => _which == WHICH.Struct ? (Capnproto_test.Capnp.Test.TestStructUnion.SomeStruct)_content : null; + set + { + _which = WHICH.Struct; + _content = value; + } + } + + public Capnproto_test.Capnp.Test.TestAnyPointer Object + { + get => _which == WHICH.Object ? (Capnproto_test.Capnp.Test.TestAnyPointer)_content : null; + set + { + _which = WHICH.Object; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(0U, (ushort)0); + public Capnproto_test.Capnp.Test.TestStructUnion.SomeStruct.READER Struct => which == WHICH.Struct ? ctx.ReadStruct(0, Capnproto_test.Capnp.Test.TestStructUnion.SomeStruct.READER.create) : default; + public Capnproto_test.Capnp.Test.TestAnyPointer.READER Object => which == WHICH.Object ? ctx.ReadStruct(0, Capnproto_test.Capnp.Test.TestAnyPointer.READER.create) : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(0U, (ushort)0); + set => this.WriteData(0U, (ushort)value, (ushort)0); + } + + public Capnproto_test.Capnp.Test.TestStructUnion.SomeStruct.WRITER Struct + { + get => which == WHICH.Struct ? BuildPointer(0) : default; + set => Link(0, value); + } + + public Capnproto_test.Capnp.Test.TestAnyPointer.WRITER Object + { + get => which == WHICH.Object ? BuildPointer(0) : default; + set => Link(0, value); + } + } + } + + public class SomeStruct : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + SomeText = reader.SomeText; + MoreText = reader.MoreText; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.SomeText = SomeText; + writer.MoreText = MoreText; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string SomeText + { + get; + set; + } + + public string MoreText + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string SomeText => ctx.ReadText(0, ""); + public string MoreText => ctx.ReadText(1, ""); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 2); + } + + public string SomeText + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + + public string MoreText + { + get => this.ReadText(1, ""); + set => this.WriteText(1, value, ""); + } + } + } + } + + public class TestPrintInlineStructs : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + SomeText = reader.SomeText; + StructList = reader.StructList.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.SomeText = SomeText; + writer.StructList.Init(StructList, (_s1, _v1) => _v1?.serialize(_s1)); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string SomeText + { + get; + set; + } + + public IReadOnlyList StructList + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string SomeText => ctx.ReadText(0, ""); + public IReadOnlyList StructList => ctx.ReadList(1).Cast(Capnproto_test.Capnp.Test.TestPrintInlineStructs.InlineStruct.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 2); + } + + public string SomeText + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + + public ListOfStructsSerializer StructList + { + get => BuildPointer>(1); + set => Link(1, value); + } + } + + public class InlineStruct : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Int32Field = reader.Int32Field; + TextField = reader.TextField; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Int32Field = Int32Field; + writer.TextField = TextField; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public int Int32Field + { + get; + set; + } + + public string TextField + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public int Int32Field => ctx.ReadDataInt(0UL, 0); + public string TextField => ctx.ReadText(0, ""); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public int Int32Field + { + get => this.ReadDataInt(0UL, 0); + set => this.WriteData(0UL, value, 0); + } + + public string TextField + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + } + } + } + + public class TestWholeFloatDefault : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Field = reader.Field; + BigField = reader.BigField; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Field = Field; + writer.BigField = BigField; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public float Field + { + get; + set; + } + + = 123F; + public float BigField + { + get; + set; + } + + = 2E+30F; + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public float Field => ctx.ReadDataFloat(0UL, 123F); + public float BigField => ctx.ReadDataFloat(32UL, 2E+30F); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 0); + } + + public float Field + { + get => this.ReadDataFloat(0UL, 123F); + set => this.WriteData(0UL, value, 123F); + } + + public float BigField + { + get => this.ReadDataFloat(32UL, 2E+30F); + set => this.WriteData(32UL, value, 2E+30F); + } + } + } + + public class TestGenerics : ICapnpSerializable where TFoo : class where TBar : class + { + public enum WHICH : ushort + { + Uv = 0, + Ug = 1, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.Uv: + which = reader.which; + break; + case WHICH.Ug: + Ug = CapnpSerializable.Create.@ug>(reader.Ug); + break; + } + + Foo = CapnpSerializable.Create(reader.Foo); + Rev = CapnpSerializable.Create>(reader.Rev); + List = reader.List.ToReadOnlyList(_ => CapnpSerializable.Create.Inner>(_)); + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.Uv: + break; + case WHICH.Ug: + _content = null; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.Uv: + break; + case WHICH.Ug: + Ug?.serialize(writer.Ug); + break; + } + + writer.Foo.SetObject(Foo); + Rev?.serialize(writer.Rev); + writer.List.Init(List, (_s1, _v1) => _v1?.serialize(_s1)); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public TFoo Foo + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestGenerics Rev + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestGenerics.@ug Ug + { + get => _which == WHICH.Ug ? (Capnproto_test.Capnp.Test.TestGenerics.@ug)_content : null; + set + { + _which = WHICH.Ug; + _content = value; + } + } + + public IReadOnlyList.Inner> List + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(0U, (ushort)0); + public DeserializerState Foo => ctx.StructReadPointer(0); + public Capnproto_test.Capnp.Test.TestGenerics.READER Rev => ctx.ReadStruct(1, Capnproto_test.Capnp.Test.TestGenerics.READER.create); + public @ug.READER Ug => which == WHICH.Ug ? new @ug.READER(ctx) : default; + public IReadOnlyList.Inner.READER> List => ctx.ReadList(2).Cast(Capnproto_test.Capnp.Test.TestGenerics.Inner.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 3); + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(0U, (ushort)0); + set => this.WriteData(0U, (ushort)value, (ushort)0); + } + + public DynamicSerializerState Foo + { + get => BuildPointer(0); + set => Link(0, value); + } + + public Capnproto_test.Capnp.Test.TestGenerics.WRITER Rev + { + get => BuildPointer.WRITER>(1); + set => Link(1, value); + } + + public @ug.WRITER Ug + { + get => which == WHICH.Ug ? Rewrap<@ug.WRITER>() : default; + } + + public ListOfStructsSerializer.Inner.WRITER> List + { + get => BuildPointer.Inner.WRITER>>(2); + set => Link(2, value); + } + } + + public class @ug : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Ugfoo = reader.Ugfoo; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Ugfoo = Ugfoo; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public int Ugfoo + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public int Ugfoo => ctx.ReadDataInt(32UL, 0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public int Ugfoo + { + get => this.ReadDataInt(32UL, 0); + set => this.WriteData(32UL, value, 0); + } + } + } + + public class Inner : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Foo = CapnpSerializable.Create(reader.Foo); + Bar = CapnpSerializable.Create(reader.Bar); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Foo.SetObject(Foo); + writer.Bar.SetObject(Bar); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public TFoo Foo + { + get; + set; + } + + public TBar Bar + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public DeserializerState Foo => ctx.StructReadPointer(0); + public DeserializerState Bar => ctx.StructReadPointer(1); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 2); + } + + public DynamicSerializerState Foo + { + get => BuildPointer(0); + set => Link(0, value); + } + + public DynamicSerializerState Bar + { + get => BuildPointer(1); + set => Link(1, value); + } + } + } + + public class Inner2 : ICapnpSerializable where TBaz : class + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Bar = CapnpSerializable.Create(reader.Bar); + Baz = CapnpSerializable.Create(reader.Baz); + InnerBound = CapnpSerializable.Create.Inner>(reader.InnerBound); + InnerUnbound = CapnpSerializable.Create.Inner>(reader.InnerUnbound); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Bar.SetObject(Bar); + writer.Baz.SetObject(Baz); + InnerBound?.serialize(writer.InnerBound); + InnerUnbound?.serialize(writer.InnerUnbound); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public TBar Bar + { + get; + set; + } + + public TBaz Baz + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestGenerics.Inner InnerBound + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestGenerics.Inner InnerUnbound + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public DeserializerState Bar => ctx.StructReadPointer(0); + public DeserializerState Baz => ctx.StructReadPointer(1); + public Capnproto_test.Capnp.Test.TestGenerics.Inner.READER InnerBound => ctx.ReadStruct(2, Capnproto_test.Capnp.Test.TestGenerics.Inner.READER.create); + public Capnproto_test.Capnp.Test.TestGenerics.Inner.READER InnerUnbound => ctx.ReadStruct(3, Capnproto_test.Capnp.Test.TestGenerics.Inner.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 4); + } + + public DynamicSerializerState Bar + { + get => BuildPointer(0); + set => Link(0, value); + } + + public DynamicSerializerState Baz + { + get => BuildPointer(1); + set => Link(1, value); + } + + public Capnproto_test.Capnp.Test.TestGenerics.Inner.WRITER InnerBound + { + get => BuildPointer.Inner.WRITER>(2); + set => Link(2, value); + } + + public Capnproto_test.Capnp.Test.TestGenerics.Inner.WRITER InnerUnbound + { + get => BuildPointer.Inner.WRITER>(3); + set => Link(3, value); + } + } + + public class DeepNest : ICapnpSerializable where TQux : class + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Foo = CapnpSerializable.Create(reader.Foo); + Bar = CapnpSerializable.Create(reader.Bar); + Baz = CapnpSerializable.Create(reader.Baz); + Qux = CapnpSerializable.Create(reader.Qux); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Foo.SetObject(Foo); + writer.Bar.SetObject(Bar); + writer.Baz.SetObject(Baz); + writer.Qux.SetObject(Qux); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public TFoo Foo + { + get; + set; + } + + public TBar Bar + { + get; + set; + } + + public TBaz Baz + { + get; + set; + } + + public TQux Qux + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public DeserializerState Foo => ctx.StructReadPointer(0); + public DeserializerState Bar => ctx.StructReadPointer(1); + public DeserializerState Baz => ctx.StructReadPointer(2); + public DeserializerState Qux => ctx.StructReadPointer(3); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 4); + } + + public DynamicSerializerState Foo + { + get => BuildPointer(0); + set => Link(0, value); + } + + public DynamicSerializerState Bar + { + get => BuildPointer(1); + set => Link(1, value); + } + + public DynamicSerializerState Baz + { + get => BuildPointer(2); + set => Link(2, value); + } + + public DynamicSerializerState Qux + { + get => BuildPointer(3); + set => Link(3, value); + } + } + + [Proxy(typeof(DeepNestInterfaceProxy<>)), Skeleton(typeof(DeepNestInterfaceSkeleton<>))] + public interface IDeepNestInterface : IDisposable + { + Task Call(CancellationToken cancellationToken_ = default); + } + + public class DeepNestInterfaceProxy : Proxy, IDeepNestInterface where TQuux : class + { + public async Task Call(CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc.Inner2.DeepNest.DeepNestInterface.Params_call.WRITER>(); + var arg_ = new Capnproto_test.Capnp.Test.TestGenerics.Inner2.DeepNest.DeepNestInterface.Params_call() + {}; + arg_.serialize(in_); + var d_ = await Call(9816138025992274567UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create.Inner2.DeepNest.DeepNestInterface.Result_call>(d_); + return; + } + } + + public class DeepNestInterfaceSkeleton : Skeleton> where TQuux : class + { + public DeepNestInterfaceSkeleton() + { + SetMethodTable(Call); + } + + public override ulong InterfaceId => 9816138025992274567UL; + async Task Call(DeserializerState d_, CancellationToken cancellationToken_) + { + await Impl.Call(cancellationToken_); + var s_ = SerializerState.CreateForRpc.Inner2.DeepNest.DeepNestInterface.Result_call.WRITER>(); + return s_; + } + } + + public static class DeepNestInterface + where TQuux : class + { + public class Params_call : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + public class Result_call : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + } + } + } + + [Proxy(typeof(InterfaceProxy<>)), Skeleton(typeof(InterfaceSkeleton<>))] + public interface IInterface : IDisposable + { + Task<(TQux, Capnproto_test.Capnp.Test.TestGenerics)> Call(Capnproto_test.Capnp.Test.TestGenerics.Inner2 arg_, CancellationToken cancellationToken_ = default); + } + + public class InterfaceProxy : Proxy, IInterface where TQux : class + { + public Task<(TQux, Capnproto_test.Capnp.Test.TestGenerics)> Call(Capnproto_test.Capnp.Test.TestGenerics.Inner2 arg_, CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc.Inner2.WRITER>(); + arg_.serialize(in_); + return Impatient.MakePipelineAware(Call(14548678385738242652UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => + { + var r_ = CapnpSerializable.Create.Interface.Result_call>(d_); + return (r_.Qux, r_.Gen); + } + + ); + } + } + + public class InterfaceSkeleton : Skeleton> where TQux : class + { + public InterfaceSkeleton() + { + SetMethodTable(Call); + } + + public override ulong InterfaceId => 14548678385738242652UL; + Task Call(DeserializerState d_, CancellationToken cancellationToken_) + { + return Impatient.MaybeTailCall(Impl.Call(CapnpSerializable.Create.Inner2>(d_), cancellationToken_), (qux, gen) => + { + var s_ = SerializerState.CreateForRpc.Interface.Result_call.WRITER>(); + var r_ = new Capnproto_test.Capnp.Test.TestGenerics.Interface.Result_call{Qux = qux, Gen = gen}; + r_.serialize(s_); + return s_; + } + + ); + } + } + + public static class Interface + where TQux : class + { + public class Result_call : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Qux = CapnpSerializable.Create(reader.Qux); + Gen = CapnpSerializable.Create>(reader.Gen); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Qux.SetObject(Qux); + Gen?.serialize(writer.Gen); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public TQux Qux + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestGenerics Gen + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public DeserializerState Qux => ctx.StructReadPointer(0); + public Capnproto_test.Capnp.Test.TestGenerics.READER Gen => ctx.ReadStruct(1, Capnproto_test.Capnp.Test.TestGenerics.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 2); + } + + public DynamicSerializerState Qux + { + get => BuildPointer(0); + set => Link(0, value); + } + + public Capnproto_test.Capnp.Test.TestGenerics.WRITER Gen + { + get => BuildPointer.WRITER>(1); + set => Link(1, value); + } + } + } + } + + public class UseAliases : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Foo = CapnpSerializable.Create(reader.Foo); + Inner = CapnpSerializable.Create.Inner>(reader.Inner); + Inner2 = CapnpSerializable.Create.Inner2>(reader.Inner2); + Inner2Bind = CapnpSerializable.Create.Inner2>(reader.Inner2Bind); + Inner2Text = CapnpSerializable.Create.Inner2>(reader.Inner2Text); + RevFoo = CapnpSerializable.Create(reader.RevFoo); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Foo.SetObject(Foo); + Inner?.serialize(writer.Inner); + Inner2?.serialize(writer.Inner2); + Inner2Bind?.serialize(writer.Inner2Bind); + Inner2Text?.serialize(writer.Inner2Text); + writer.RevFoo.SetObject(RevFoo); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public TFoo Foo + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestGenerics.Inner Inner + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestGenerics.Inner2 Inner2 + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestGenerics.Inner2 Inner2Bind + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestGenerics.Inner2 Inner2Text + { + get; + set; + } + + public TBar RevFoo + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public DeserializerState Foo => ctx.StructReadPointer(0); + public Capnproto_test.Capnp.Test.TestGenerics.Inner.READER Inner => ctx.ReadStruct(1, Capnproto_test.Capnp.Test.TestGenerics.Inner.READER.create); + public Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER Inner2 => ctx.ReadStruct(2, Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER.create); + public Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER Inner2Bind => ctx.ReadStruct(3, Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER.create); + public Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER Inner2Text => ctx.ReadStruct(4, Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER.create); + public DeserializerState RevFoo => ctx.StructReadPointer(5); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 6); + } + + public DynamicSerializerState Foo + { + get => BuildPointer(0); + set => Link(0, value); + } + + public Capnproto_test.Capnp.Test.TestGenerics.Inner.WRITER Inner + { + get => BuildPointer.Inner.WRITER>(1); + set => Link(1, value); + } + + public Capnproto_test.Capnp.Test.TestGenerics.Inner2.WRITER Inner2 + { + get => BuildPointer.Inner2.WRITER>(2); + set => Link(2, value); + } + + public Capnproto_test.Capnp.Test.TestGenerics.Inner2.WRITER Inner2Bind + { + get => BuildPointer.Inner2.WRITER>(3); + set => Link(3, value); + } + + public Capnproto_test.Capnp.Test.TestGenerics.Inner2.WRITER Inner2Text + { + get => BuildPointer.Inner2.WRITER>(4); + set => Link(4, value); + } + + public DynamicSerializerState RevFoo + { + get => BuildPointer(5); + set => Link(5, value); + } + } + } + } + + public class TestGenericsWrapper : ICapnpSerializable where TFoo : class where TBar : class + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Value = CapnpSerializable.Create>(reader.Value); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + Value?.serialize(writer.Value); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.TestGenerics Value + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnproto_test.Capnp.Test.TestGenerics.READER Value => ctx.ReadStruct(0, Capnproto_test.Capnp.Test.TestGenerics.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public Capnproto_test.Capnp.Test.TestGenerics.WRITER Value + { + get => BuildPointer.WRITER>(0); + set => Link(0, value); + } + } + } + + public class TestGenericsWrapper2 : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Value = CapnpSerializable.Create>(reader.Value); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + Value?.serialize(writer.Value); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.TestGenericsWrapper Value + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnproto_test.Capnp.Test.TestGenericsWrapper.READER Value => ctx.ReadStruct(0, Capnproto_test.Capnp.Test.TestGenericsWrapper.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public Capnproto_test.Capnp.Test.TestGenericsWrapper.WRITER Value + { + get => BuildPointer.WRITER>(0); + set => Link(0, value); + } + } + } + + [Proxy(typeof(TestImplicitMethodParamsProxy)), Skeleton(typeof(TestImplicitMethodParamsSkeleton))] + public interface ITestImplicitMethodParams : IDisposable + { + Task> Call(TT foo, TU bar, CancellationToken cancellationToken_ = default) + where TT : class where TU : class; + } + + public class TestImplicitMethodParamsProxy : Proxy, ITestImplicitMethodParams + { + public Task> Call(TT foo, TU bar, CancellationToken cancellationToken_ = default) + where TT : class where TU : class + { + var in_ = SerializerState.CreateForRpc.WRITER>(); + var arg_ = new Capnproto_test.Capnp.Test.TestImplicitMethodParams.Params_call() + {Foo = foo, Bar = bar}; + arg_.serialize(in_); + return Impatient.MakePipelineAware(Call(10058534285777328794UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => + { + var r_ = CapnpSerializable.Create>(d_); + return r_; + } + + ); + } + } + + public class TestImplicitMethodParamsSkeleton : Skeleton + { + public TestImplicitMethodParamsSkeleton() + { + SetMethodTable(Call); + } + + public override ulong InterfaceId => 10058534285777328794UL; + Task Call(DeserializerState d_, CancellationToken cancellationToken_) + where TT : class where TU : class + { + var in_ = CapnpSerializable.Create>(d_); + return Impatient.MaybeTailCall(Impl.Call(in_.Foo, in_.Bar, cancellationToken_), r_ => + { + var s_ = SerializerState.CreateForRpc.WRITER>(); + r_.serialize(s_); + return s_; + } + + ); + } + } + + public static class TestImplicitMethodParams + { + public class Params_call : ICapnpSerializable where TT : class where TU : class + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Foo = CapnpSerializable.Create(reader.Foo); + Bar = CapnpSerializable.Create(reader.Bar); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Foo.SetObject(Foo); + writer.Bar.SetObject(Bar); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public TT Foo + { + get; + set; + } + + public TU Bar + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public DeserializerState Foo => ctx.StructReadPointer(0); + public DeserializerState Bar => ctx.StructReadPointer(1); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 2); + } + + public DynamicSerializerState Foo + { + get => BuildPointer(0); + set => Link(0, value); + } + + public DynamicSerializerState Bar + { + get => BuildPointer(1); + set => Link(1, value); + } + } + } + } + + [Proxy(typeof(TestImplicitMethodParamsInGenericProxy<>)), Skeleton(typeof(TestImplicitMethodParamsInGenericSkeleton<>))] + public interface ITestImplicitMethodParamsInGeneric : IDisposable + { + Task> Call(TT foo, TU bar, CancellationToken cancellationToken_ = default) + where TT : class where TU : class; + } + + public class TestImplicitMethodParamsInGenericProxy : Proxy, ITestImplicitMethodParamsInGeneric where TV : class + { + public Task> Call(TT foo, TU bar, CancellationToken cancellationToken_ = default) + where TT : class where TU : class + { + var in_ = SerializerState.CreateForRpc.Params_call.WRITER>(); + var arg_ = new Capnproto_test.Capnp.Test.TestImplicitMethodParamsInGeneric.Params_call() + {Foo = foo, Bar = bar}; + arg_.serialize(in_); + return Impatient.MakePipelineAware(Call(16112979978201007305UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => + { + var r_ = CapnpSerializable.Create>(d_); + return r_; + } + + ); + } + } + + public class TestImplicitMethodParamsInGenericSkeleton : Skeleton> where TV : class + { + public TestImplicitMethodParamsInGenericSkeleton() + { + SetMethodTable(Call); + } + + public override ulong InterfaceId => 16112979978201007305UL; + Task Call(DeserializerState d_, CancellationToken cancellationToken_) + where TT : class where TU : class + { + var in_ = CapnpSerializable.Create.Params_call>(d_); + return Impatient.MaybeTailCall(Impl.Call(in_.Foo, in_.Bar, cancellationToken_), r_ => + { + var s_ = SerializerState.CreateForRpc.WRITER>(); + r_.serialize(s_); + return s_; + } + + ); + } + } + + public static class TestImplicitMethodParamsInGeneric + where TV : class + { + public class Params_call : ICapnpSerializable where TT : class where TU : class + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Foo = CapnpSerializable.Create(reader.Foo); + Bar = CapnpSerializable.Create(reader.Bar); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Foo.SetObject(Foo); + writer.Bar.SetObject(Bar); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public TT Foo + { + get; + set; + } + + public TU Bar + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public DeserializerState Foo => ctx.StructReadPointer(0); + public DeserializerState Bar => ctx.StructReadPointer(1); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 2); + } + + public DynamicSerializerState Foo + { + get => BuildPointer(0); + set => Link(0, value); + } + + public DynamicSerializerState Bar + { + get => BuildPointer(1); + set => Link(1, value); + } + } + } + } + + public class TestGenericsUnion : ICapnpSerializable where TFoo : class where TBar : class + { + public enum WHICH : ushort + { + Foo = 0, + Bar = 1, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.Foo: + Foo = CapnpSerializable.Create(reader.Foo); + break; + case WHICH.Bar: + Bar = CapnpSerializable.Create(reader.Bar); + break; + } + + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.Foo: + _content = null; + break; + case WHICH.Bar: + _content = null; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.Foo: + writer.Foo.SetObject(Foo); + break; + case WHICH.Bar: + writer.Bar.SetObject(Bar); + break; + } + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public TFoo Foo + { + get => _which == WHICH.Foo ? (TFoo)_content : null; + set + { + _which = WHICH.Foo; + _content = value; + } + } + + public TBar Bar + { + get => _which == WHICH.Bar ? (TBar)_content : null; + set + { + _which = WHICH.Bar; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(0U, (ushort)0); + public DeserializerState Foo => which == WHICH.Foo ? ctx.StructReadPointer(0) : default; + public DeserializerState Bar => which == WHICH.Bar ? ctx.StructReadPointer(0) : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(0U, (ushort)0); + set => this.WriteData(0U, (ushort)value, (ushort)0); + } + + public DynamicSerializerState Foo + { + get => which == WHICH.Foo ? BuildPointer(0) : default; + set => Link(0, value); + } + + public DynamicSerializerState Bar + { + get => which == WHICH.Bar ? BuildPointer(0) : default; + set => Link(0, value); + } + } + } + + public class TestUseGenerics : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Basic = CapnpSerializable.Create>(reader.Basic); + Inner = CapnpSerializable.Create.Inner>(reader.Inner); + Inner2 = CapnpSerializable.Create.Inner2>(reader.Inner2); + Unspecified = CapnpSerializable.Create>(reader.Unspecified); + UnspecifiedInner = CapnpSerializable.Create.Inner2>(reader.UnspecifiedInner); + Default = CapnpSerializable.Create>(reader.Default); + DefaultInner = CapnpSerializable.Create.Inner>(reader.DefaultInner); + DefaultUser = CapnpSerializable.Create(reader.DefaultUser); + Wrapper = CapnpSerializable.Create>(reader.Wrapper); + DefaultWrapper = CapnpSerializable.Create>(reader.DefaultWrapper); + DefaultWrapper2 = CapnpSerializable.Create(reader.DefaultWrapper2); + AliasFoo = CapnpSerializable.Create(reader.AliasFoo); + AliasInner = CapnpSerializable.Create.Inner>(reader.AliasInner); + AliasInner2 = CapnpSerializable.Create.Inner2>(reader.AliasInner2); + AliasInner2Bind = CapnpSerializable.Create.Inner2>>(reader.AliasInner2Bind); + AliasInner2Text = CapnpSerializable.Create.Inner2>(reader.AliasInner2Text); + AliasRev = reader.AliasRev; + UseAliases = CapnpSerializable.Create>.UseAliases>(reader.UseAliases); + Cap = CapnpSerializable.Create>(reader.Cap); + GenericCap = reader.GenericCap; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + Basic?.serialize(writer.Basic); + Inner?.serialize(writer.Inner); + Inner2?.serialize(writer.Inner2); + Unspecified?.serialize(writer.Unspecified); + UnspecifiedInner?.serialize(writer.UnspecifiedInner); + Default?.serialize(writer.Default); + DefaultInner?.serialize(writer.DefaultInner); + DefaultUser?.serialize(writer.DefaultUser); + Wrapper?.serialize(writer.Wrapper); + DefaultWrapper?.serialize(writer.DefaultWrapper); + DefaultWrapper2?.serialize(writer.DefaultWrapper2); + AliasFoo?.serialize(writer.AliasFoo); + AliasInner?.serialize(writer.AliasInner); + AliasInner2?.serialize(writer.AliasInner2); + AliasInner2Bind?.serialize(writer.AliasInner2Bind); + AliasInner2Text?.serialize(writer.AliasInner2Text); + writer.AliasRev = AliasRev; + UseAliases?.serialize(writer.UseAliases); + Cap?.serialize(writer.Cap); + writer.GenericCap = GenericCap; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + Default = Default ?? new Capnproto_test.Capnp.Test.TestGenerics() + {Foo = new Capnproto_test.Capnp.Test.TestAllTypes() + {BoolField = false, Int8Field = 0, Int16Field = 123, Int32Field = 0, Int64Field = 0L, UInt8Field = 0, UInt16Field = 0, UInt32Field = 0U, UInt64Field = 0UL, Float32Field = 0F, Float64Field = 0, TextField = null, DataField = new byte[]{}, StructField = new Capnproto_test.Capnp.Test.TestAllTypes() + {}, EnumField = Capnproto_test.Capnp.Test.TestEnum.foo, VoidList = 0, BoolList = new bool[]{}, Int8List = new sbyte[]{}, Int16List = new short[]{}, Int32List = new int[]{}, Int64List = new long[]{}, UInt8List = new byte[]{}, UInt16List = new ushort[]{}, UInt32List = new uint[]{}, UInt64List = new ulong[]{}, Float32List = new float[]{}, Float64List = new double[]{}, TextList = new string[]{}, DataList = new IReadOnlyList[]{}, StructList = new Capnproto_test.Capnp.Test.TestAllTypes[]{}, EnumList = new Capnproto_test.Capnp.Test.TestEnum[]{}, InterfaceList = 0}, Rev = new Capnproto_test.Capnp.Test.TestGenerics() + {Foo = "text", Rev = new Capnproto_test.Capnp.Test.TestGenerics() + {Foo = new Capnproto_test.Capnp.Test.TestAllTypes() + {BoolField = false, Int8Field = 0, Int16Field = 321, Int32Field = 0, Int64Field = 0L, UInt8Field = 0, UInt16Field = 0, UInt32Field = 0U, UInt64Field = 0UL, Float32Field = 0F, Float64Field = 0, TextField = null, DataField = new byte[]{}, StructField = new Capnproto_test.Capnp.Test.TestAllTypes() + {}, EnumField = Capnproto_test.Capnp.Test.TestEnum.foo, VoidList = 0, BoolList = new bool[]{}, Int8List = new sbyte[]{}, Int16List = new short[]{}, Int32List = new int[]{}, Int64List = new long[]{}, UInt8List = new byte[]{}, UInt16List = new ushort[]{}, UInt32List = new uint[]{}, UInt64List = new ulong[]{}, Float32List = new float[]{}, Float64List = new double[]{}, TextList = new string[]{}, DataList = new IReadOnlyList[]{}, StructList = new Capnproto_test.Capnp.Test.TestAllTypes[]{}, EnumList = new Capnproto_test.Capnp.Test.TestEnum[]{}, InterfaceList = 0}, Rev = new Capnproto_test.Capnp.Test.TestGenerics() + {}, List = new Capnproto_test.Capnp.Test.TestGenerics.Inner[]{}}, List = new Capnproto_test.Capnp.Test.TestGenerics.Inner[]{}}, List = new Capnproto_test.Capnp.Test.TestGenerics.Inner[]{}}; + DefaultInner = DefaultInner ?? new Capnproto_test.Capnp.Test.TestGenerics.Inner() + {Foo = new Capnproto_test.Capnp.Test.TestAllTypes() + {BoolField = false, Int8Field = 0, Int16Field = 123, Int32Field = 0, Int64Field = 0L, UInt8Field = 0, UInt16Field = 0, UInt32Field = 0U, UInt64Field = 0UL, Float32Field = 0F, Float64Field = 0, TextField = null, DataField = new byte[]{}, StructField = new Capnproto_test.Capnp.Test.TestAllTypes() + {}, EnumField = Capnproto_test.Capnp.Test.TestEnum.foo, VoidList = 0, BoolList = new bool[]{}, Int8List = new sbyte[]{}, Int16List = new short[]{}, Int32List = new int[]{}, Int64List = new long[]{}, UInt8List = new byte[]{}, UInt16List = new ushort[]{}, UInt32List = new uint[]{}, UInt64List = new ulong[]{}, Float32List = new float[]{}, Float64List = new double[]{}, TextList = new string[]{}, DataList = new IReadOnlyList[]{}, StructList = new Capnproto_test.Capnp.Test.TestAllTypes[]{}, EnumList = new Capnproto_test.Capnp.Test.TestEnum[]{}, InterfaceList = 0}, Bar = "text"}; + DefaultUser = DefaultUser ?? new Capnproto_test.Capnp.Test.TestUseGenerics() + {Basic = new Capnproto_test.Capnp.Test.TestGenerics() + {Foo = new Capnproto_test.Capnp.Test.TestAllTypes() + {BoolField = false, Int8Field = 0, Int16Field = 123, Int32Field = 0, Int64Field = 0L, UInt8Field = 0, UInt16Field = 0, UInt32Field = 0U, UInt64Field = 0UL, Float32Field = 0F, Float64Field = 0, TextField = null, DataField = new byte[]{}, StructField = new Capnproto_test.Capnp.Test.TestAllTypes() + {}, EnumField = Capnproto_test.Capnp.Test.TestEnum.foo, VoidList = 0, BoolList = new bool[]{}, Int8List = new sbyte[]{}, Int16List = new short[]{}, Int32List = new int[]{}, Int64List = new long[]{}, UInt8List = new byte[]{}, UInt16List = new ushort[]{}, UInt32List = new uint[]{}, UInt64List = new ulong[]{}, Float32List = new float[]{}, Float64List = new double[]{}, TextList = new string[]{}, DataList = new IReadOnlyList[]{}, StructList = new Capnproto_test.Capnp.Test.TestAllTypes[]{}, EnumList = new Capnproto_test.Capnp.Test.TestEnum[]{}, InterfaceList = 0}, Rev = new Capnproto_test.Capnp.Test.TestGenerics() + {}, List = new Capnproto_test.Capnp.Test.TestGenerics.Inner[]{}}, Inner = new Capnproto_test.Capnp.Test.TestGenerics.Inner() + {}, Inner2 = new Capnproto_test.Capnp.Test.TestGenerics.Inner2() + {}, Unspecified = new Capnproto_test.Capnp.Test.TestGenerics() + {}, UnspecifiedInner = new Capnproto_test.Capnp.Test.TestGenerics.Inner2() + {}, Default = new Capnproto_test.Capnp.Test.TestGenerics() + {}, DefaultInner = new Capnproto_test.Capnp.Test.TestGenerics.Inner() + {}, DefaultUser = new Capnproto_test.Capnp.Test.TestUseGenerics() + {}, Wrapper = new Capnproto_test.Capnp.Test.TestGenericsWrapper() + {}, DefaultWrapper = new Capnproto_test.Capnp.Test.TestGenericsWrapper() + {}, DefaultWrapper2 = new Capnproto_test.Capnp.Test.TestGenericsWrapper2() + {}, AliasFoo = new Capnproto_test.Capnp.Test.TestAllTypes() + {}, AliasInner = new Capnproto_test.Capnp.Test.TestGenerics.Inner() + {}, AliasInner2 = new Capnproto_test.Capnp.Test.TestGenerics.Inner2() + {}, AliasInner2Bind = new Capnproto_test.Capnp.Test.TestGenerics.Inner2>() + {}, AliasInner2Text = new Capnproto_test.Capnp.Test.TestGenerics.Inner2() + {}, AliasRev = null, UseAliases = new Capnproto_test.Capnp.Test.TestGenerics>.UseAliases() + {}, Cap = new Capnproto_test.Capnp.Test.TestGenerics() + {}}; + DefaultWrapper = DefaultWrapper ?? new Capnproto_test.Capnp.Test.TestGenericsWrapper() + {Value = new Capnproto_test.Capnp.Test.TestGenerics() + {Foo = "text", Rev = new Capnproto_test.Capnp.Test.TestGenerics() + {Foo = new Capnproto_test.Capnp.Test.TestAllTypes() + {BoolField = false, Int8Field = 0, Int16Field = 321, Int32Field = 0, Int64Field = 0L, UInt8Field = 0, UInt16Field = 0, UInt32Field = 0U, UInt64Field = 0UL, Float32Field = 0F, Float64Field = 0, TextField = null, DataField = new byte[]{}, StructField = new Capnproto_test.Capnp.Test.TestAllTypes() + {}, EnumField = Capnproto_test.Capnp.Test.TestEnum.foo, VoidList = 0, BoolList = new bool[]{}, Int8List = new sbyte[]{}, Int16List = new short[]{}, Int32List = new int[]{}, Int64List = new long[]{}, UInt8List = new byte[]{}, UInt16List = new ushort[]{}, UInt32List = new uint[]{}, UInt64List = new ulong[]{}, Float32List = new float[]{}, Float64List = new double[]{}, TextList = new string[]{}, DataList = new IReadOnlyList[]{}, StructList = new Capnproto_test.Capnp.Test.TestAllTypes[]{}, EnumList = new Capnproto_test.Capnp.Test.TestEnum[]{}, InterfaceList = 0}, Rev = new Capnproto_test.Capnp.Test.TestGenerics() + {}, List = new Capnproto_test.Capnp.Test.TestGenerics.Inner[]{}}, List = new Capnproto_test.Capnp.Test.TestGenerics.Inner[]{}}}; + DefaultWrapper2 = DefaultWrapper2 ?? new Capnproto_test.Capnp.Test.TestGenericsWrapper2() + {Value = new Capnproto_test.Capnp.Test.TestGenericsWrapper() + {Value = new Capnproto_test.Capnp.Test.TestGenerics() + {Foo = "text", Rev = new Capnproto_test.Capnp.Test.TestGenerics() + {Foo = new Capnproto_test.Capnp.Test.TestAllTypes() + {BoolField = false, Int8Field = 0, Int16Field = 321, Int32Field = 0, Int64Field = 0L, UInt8Field = 0, UInt16Field = 0, UInt32Field = 0U, UInt64Field = 0UL, Float32Field = 0F, Float64Field = 0, TextField = null, DataField = new byte[]{}, StructField = new Capnproto_test.Capnp.Test.TestAllTypes() + {}, EnumField = Capnproto_test.Capnp.Test.TestEnum.foo, VoidList = 0, BoolList = new bool[]{}, Int8List = new sbyte[]{}, Int16List = new short[]{}, Int32List = new int[]{}, Int64List = new long[]{}, UInt8List = new byte[]{}, UInt16List = new ushort[]{}, UInt32List = new uint[]{}, UInt64List = new ulong[]{}, Float32List = new float[]{}, Float64List = new double[]{}, TextList = new string[]{}, DataList = new IReadOnlyList[]{}, StructList = new Capnproto_test.Capnp.Test.TestAllTypes[]{}, EnumList = new Capnproto_test.Capnp.Test.TestEnum[]{}, InterfaceList = 0}, Rev = new Capnproto_test.Capnp.Test.TestGenerics() + {}, List = new Capnproto_test.Capnp.Test.TestGenerics.Inner[]{}}, List = new Capnproto_test.Capnp.Test.TestGenerics.Inner[]{}}}}; + AliasFoo = AliasFoo ?? new Capnproto_test.Capnp.Test.TestAllTypes() + {BoolField = false, Int8Field = 0, Int16Field = 123, Int32Field = 0, Int64Field = 0L, UInt8Field = 0, UInt16Field = 0, UInt32Field = 0U, UInt64Field = 0UL, Float32Field = 0F, Float64Field = 0, TextField = null, DataField = new byte[]{}, StructField = new Capnproto_test.Capnp.Test.TestAllTypes() + {}, EnumField = Capnproto_test.Capnp.Test.TestEnum.foo, VoidList = 0, BoolList = new bool[]{}, Int8List = new sbyte[]{}, Int16List = new short[]{}, Int32List = new int[]{}, Int64List = new long[]{}, UInt8List = new byte[]{}, UInt16List = new ushort[]{}, UInt32List = new uint[]{}, UInt64List = new ulong[]{}, Float32List = new float[]{}, Float64List = new double[]{}, TextList = new string[]{}, DataList = new IReadOnlyList[]{}, StructList = new Capnproto_test.Capnp.Test.TestAllTypes[]{}, EnumList = new Capnproto_test.Capnp.Test.TestEnum[]{}, InterfaceList = 0}; + AliasInner = AliasInner ?? new Capnproto_test.Capnp.Test.TestGenerics.Inner() + {Foo = new Capnproto_test.Capnp.Test.TestAllTypes() + {BoolField = false, Int8Field = 0, Int16Field = 123, Int32Field = 0, Int64Field = 0L, UInt8Field = 0, UInt16Field = 0, UInt32Field = 0U, UInt64Field = 0UL, Float32Field = 0F, Float64Field = 0, TextField = null, DataField = new byte[]{}, StructField = new Capnproto_test.Capnp.Test.TestAllTypes() + {}, EnumField = Capnproto_test.Capnp.Test.TestEnum.foo, VoidList = 0, BoolList = new bool[]{}, Int8List = new sbyte[]{}, Int16List = new short[]{}, Int32List = new int[]{}, Int64List = new long[]{}, UInt8List = new byte[]{}, UInt16List = new ushort[]{}, UInt32List = new uint[]{}, UInt64List = new ulong[]{}, Float32List = new float[]{}, Float64List = new double[]{}, TextList = new string[]{}, DataList = new IReadOnlyList[]{}, StructList = new Capnproto_test.Capnp.Test.TestAllTypes[]{}, EnumList = new Capnproto_test.Capnp.Test.TestEnum[]{}, InterfaceList = 0}, Bar = new Capnproto_test.Capnp.Test.TestAnyPointer() + {}}; + AliasInner2 = AliasInner2 ?? new Capnproto_test.Capnp.Test.TestGenerics.Inner2() + {Bar = new Capnproto_test.Capnp.Test.TestAnyPointer() + {}, InnerBound = new Capnproto_test.Capnp.Test.TestGenerics.Inner() + {Foo = new Capnproto_test.Capnp.Test.TestAllTypes() + {BoolField = false, Int8Field = 0, Int16Field = 123, Int32Field = 0, Int64Field = 0L, UInt8Field = 0, UInt16Field = 0, UInt32Field = 0U, UInt64Field = 0UL, Float32Field = 0F, Float64Field = 0, TextField = null, DataField = new byte[]{}, StructField = new Capnproto_test.Capnp.Test.TestAllTypes() + {}, EnumField = Capnproto_test.Capnp.Test.TestEnum.foo, VoidList = 0, BoolList = new bool[]{}, Int8List = new sbyte[]{}, Int16List = new short[]{}, Int32List = new int[]{}, Int64List = new long[]{}, UInt8List = new byte[]{}, UInt16List = new ushort[]{}, UInt32List = new uint[]{}, UInt64List = new ulong[]{}, Float32List = new float[]{}, Float64List = new double[]{}, TextList = new string[]{}, DataList = new IReadOnlyList[]{}, StructList = new Capnproto_test.Capnp.Test.TestAllTypes[]{}, EnumList = new Capnproto_test.Capnp.Test.TestEnum[]{}, InterfaceList = 0}, Bar = new Capnproto_test.Capnp.Test.TestAnyPointer() + {}}, InnerUnbound = new Capnproto_test.Capnp.Test.TestGenerics.Inner() + {}}; + AliasInner2Bind = AliasInner2Bind ?? new Capnproto_test.Capnp.Test.TestGenerics.Inner2>() + {Bar = new Capnproto_test.Capnp.Test.TestAnyPointer() + {}, Baz = new uint[]{12U, 34U}, InnerBound = new Capnproto_test.Capnp.Test.TestGenerics.Inner() + {Foo = new Capnproto_test.Capnp.Test.TestAllTypes() + {BoolField = false, Int8Field = 0, Int16Field = 123, Int32Field = 0, Int64Field = 0L, UInt8Field = 0, UInt16Field = 0, UInt32Field = 0U, UInt64Field = 0UL, Float32Field = 0F, Float64Field = 0, TextField = null, DataField = new byte[]{}, StructField = new Capnproto_test.Capnp.Test.TestAllTypes() + {}, EnumField = Capnproto_test.Capnp.Test.TestEnum.foo, VoidList = 0, BoolList = new bool[]{}, Int8List = new sbyte[]{}, Int16List = new short[]{}, Int32List = new int[]{}, Int64List = new long[]{}, UInt8List = new byte[]{}, UInt16List = new ushort[]{}, UInt32List = new uint[]{}, UInt64List = new ulong[]{}, Float32List = new float[]{}, Float64List = new double[]{}, TextList = new string[]{}, DataList = new IReadOnlyList[]{}, StructList = new Capnproto_test.Capnp.Test.TestAllTypes[]{}, EnumList = new Capnproto_test.Capnp.Test.TestEnum[]{}, InterfaceList = 0}, Bar = new Capnproto_test.Capnp.Test.TestAnyPointer() + {}}, InnerUnbound = new Capnproto_test.Capnp.Test.TestGenerics.Inner() + {}}; + AliasInner2Text = AliasInner2Text ?? new Capnproto_test.Capnp.Test.TestGenerics.Inner2() + {Bar = new Capnproto_test.Capnp.Test.TestAnyPointer() + {}, Baz = "text", InnerBound = new Capnproto_test.Capnp.Test.TestGenerics.Inner() + {Foo = new Capnproto_test.Capnp.Test.TestAllTypes() + {BoolField = false, Int8Field = 0, Int16Field = 123, Int32Field = 0, Int64Field = 0L, UInt8Field = 0, UInt16Field = 0, UInt32Field = 0U, UInt64Field = 0UL, Float32Field = 0F, Float64Field = 0, TextField = null, DataField = new byte[]{}, StructField = new Capnproto_test.Capnp.Test.TestAllTypes() + {}, EnumField = Capnproto_test.Capnp.Test.TestEnum.foo, VoidList = 0, BoolList = new bool[]{}, Int8List = new sbyte[]{}, Int16List = new short[]{}, Int32List = new int[]{}, Int64List = new long[]{}, UInt8List = new byte[]{}, UInt16List = new ushort[]{}, UInt32List = new uint[]{}, UInt64List = new ulong[]{}, Float32List = new float[]{}, Float64List = new double[]{}, TextList = new string[]{}, DataList = new IReadOnlyList[]{}, StructList = new Capnproto_test.Capnp.Test.TestAllTypes[]{}, EnumList = new Capnproto_test.Capnp.Test.TestEnum[]{}, InterfaceList = 0}, Bar = new Capnproto_test.Capnp.Test.TestAnyPointer() + {}}, InnerUnbound = new Capnproto_test.Capnp.Test.TestGenerics.Inner() + {}}; + AliasRev = AliasRev ?? "text"; + UseAliases = UseAliases ?? new Capnproto_test.Capnp.Test.TestGenerics>.UseAliases() + {Foo = new Capnproto_test.Capnp.Test.TestAllTypes() + {BoolField = false, Int8Field = 0, Int16Field = 123, Int32Field = 0, Int64Field = 0L, UInt8Field = 0, UInt16Field = 0, UInt32Field = 0U, UInt64Field = 0UL, Float32Field = 0F, Float64Field = 0, TextField = null, DataField = new byte[]{}, StructField = new Capnproto_test.Capnp.Test.TestAllTypes() + {}, EnumField = Capnproto_test.Capnp.Test.TestEnum.foo, VoidList = 0, BoolList = new bool[]{}, Int8List = new sbyte[]{}, Int16List = new short[]{}, Int32List = new int[]{}, Int64List = new long[]{}, UInt8List = new byte[]{}, UInt16List = new ushort[]{}, UInt32List = new uint[]{}, UInt64List = new ulong[]{}, Float32List = new float[]{}, Float64List = new double[]{}, TextList = new string[]{}, DataList = new IReadOnlyList[]{}, StructList = new Capnproto_test.Capnp.Test.TestAllTypes[]{}, EnumList = new Capnproto_test.Capnp.Test.TestEnum[]{}, InterfaceList = 0}, Inner = new Capnproto_test.Capnp.Test.TestGenerics>.Inner() + {Foo = new Capnproto_test.Capnp.Test.TestAllTypes() + {BoolField = false, Int8Field = 0, Int16Field = 123, Int32Field = 0, Int64Field = 0L, UInt8Field = 0, UInt16Field = 0, UInt32Field = 0U, UInt64Field = 0UL, Float32Field = 0F, Float64Field = 0, TextField = null, DataField = new byte[]{}, StructField = new Capnproto_test.Capnp.Test.TestAllTypes() + {}, EnumField = Capnproto_test.Capnp.Test.TestEnum.foo, VoidList = 0, BoolList = new bool[]{}, Int8List = new sbyte[]{}, Int16List = new short[]{}, Int32List = new int[]{}, Int64List = new long[]{}, UInt8List = new byte[]{}, UInt16List = new ushort[]{}, UInt32List = new uint[]{}, UInt64List = new ulong[]{}, Float32List = new float[]{}, Float64List = new double[]{}, TextList = new string[]{}, DataList = new IReadOnlyList[]{}, StructList = new Capnproto_test.Capnp.Test.TestAllTypes[]{}, EnumList = new Capnproto_test.Capnp.Test.TestEnum[]{}, InterfaceList = 0}, Bar = new uint[]{}}, Inner2 = new Capnproto_test.Capnp.Test.TestGenerics>.Inner2() + {Bar = new uint[]{}, InnerBound = new Capnproto_test.Capnp.Test.TestGenerics>.Inner() + {Foo = new Capnproto_test.Capnp.Test.TestAllTypes() + {BoolField = false, Int8Field = 0, Int16Field = 123, Int32Field = 0, Int64Field = 0L, UInt8Field = 0, UInt16Field = 0, UInt32Field = 0U, UInt64Field = 0UL, Float32Field = 0F, Float64Field = 0, TextField = null, DataField = new byte[]{}, StructField = new Capnproto_test.Capnp.Test.TestAllTypes() + {}, EnumField = Capnproto_test.Capnp.Test.TestEnum.foo, VoidList = 0, BoolList = new bool[]{}, Int8List = new sbyte[]{}, Int16List = new short[]{}, Int32List = new int[]{}, Int64List = new long[]{}, UInt8List = new byte[]{}, UInt16List = new ushort[]{}, UInt32List = new uint[]{}, UInt64List = new ulong[]{}, Float32List = new float[]{}, Float64List = new double[]{}, TextList = new string[]{}, DataList = new IReadOnlyList[]{}, StructList = new Capnproto_test.Capnp.Test.TestAllTypes[]{}, EnumList = new Capnproto_test.Capnp.Test.TestEnum[]{}, InterfaceList = 0}, Bar = new uint[]{}}, InnerUnbound = new Capnproto_test.Capnp.Test.TestGenerics>.Inner() + {}}, Inner2Bind = new Capnproto_test.Capnp.Test.TestGenerics>.Inner2() + {Bar = new uint[]{}, Baz = "text", InnerBound = new Capnproto_test.Capnp.Test.TestGenerics>.Inner() + {Foo = new Capnproto_test.Capnp.Test.TestAllTypes() + {BoolField = false, Int8Field = 0, Int16Field = 123, Int32Field = 0, Int64Field = 0L, UInt8Field = 0, UInt16Field = 0, UInt32Field = 0U, UInt64Field = 0UL, Float32Field = 0F, Float64Field = 0, TextField = null, DataField = new byte[]{}, StructField = new Capnproto_test.Capnp.Test.TestAllTypes() + {}, EnumField = Capnproto_test.Capnp.Test.TestEnum.foo, VoidList = 0, BoolList = new bool[]{}, Int8List = new sbyte[]{}, Int16List = new short[]{}, Int32List = new int[]{}, Int64List = new long[]{}, UInt8List = new byte[]{}, UInt16List = new ushort[]{}, UInt32List = new uint[]{}, UInt64List = new ulong[]{}, Float32List = new float[]{}, Float64List = new double[]{}, TextList = new string[]{}, DataList = new IReadOnlyList[]{}, StructList = new Capnproto_test.Capnp.Test.TestAllTypes[]{}, EnumList = new Capnproto_test.Capnp.Test.TestEnum[]{}, InterfaceList = 0}, Bar = new uint[]{}}, InnerUnbound = new Capnproto_test.Capnp.Test.TestGenerics>.Inner() + {}}, Inner2Text = new Capnproto_test.Capnp.Test.TestGenerics>.Inner2() + {Bar = new uint[]{}, Baz = "text", InnerBound = new Capnproto_test.Capnp.Test.TestGenerics>.Inner() + {Foo = new Capnproto_test.Capnp.Test.TestAllTypes() + {BoolField = false, Int8Field = 0, Int16Field = 123, Int32Field = 0, Int64Field = 0L, UInt8Field = 0, UInt16Field = 0, UInt32Field = 0U, UInt64Field = 0UL, Float32Field = 0F, Float64Field = 0, TextField = null, DataField = new byte[]{}, StructField = new Capnproto_test.Capnp.Test.TestAllTypes() + {}, EnumField = Capnproto_test.Capnp.Test.TestEnum.foo, VoidList = 0, BoolList = new bool[]{}, Int8List = new sbyte[]{}, Int16List = new short[]{}, Int32List = new int[]{}, Int64List = new long[]{}, UInt8List = new byte[]{}, UInt16List = new ushort[]{}, UInt32List = new uint[]{}, UInt64List = new ulong[]{}, Float32List = new float[]{}, Float64List = new double[]{}, TextList = new string[]{}, DataList = new IReadOnlyList[]{}, StructList = new Capnproto_test.Capnp.Test.TestAllTypes[]{}, EnumList = new Capnproto_test.Capnp.Test.TestEnum[]{}, InterfaceList = 0}, Bar = new uint[]{}}, InnerUnbound = new Capnproto_test.Capnp.Test.TestGenerics>.Inner() + {}}, RevFoo = new uint[]{12U, 34U, 56U}}; + } + + public Capnproto_test.Capnp.Test.TestGenerics Basic + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestGenerics.Inner Inner + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestGenerics.Inner2 Inner2 + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestGenerics Unspecified + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestGenerics.Inner2 UnspecifiedInner + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestGenerics Default + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestGenerics.Inner DefaultInner + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestUseGenerics DefaultUser + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestGenericsWrapper Wrapper + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestGenericsWrapper DefaultWrapper + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestGenericsWrapper2 DefaultWrapper2 + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestAllTypes AliasFoo + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestGenerics.Inner AliasInner + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestGenerics.Inner2 AliasInner2 + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestGenerics.Inner2> AliasInner2Bind + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestGenerics.Inner2 AliasInner2Text + { + get; + set; + } + + public string AliasRev + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestGenerics>.UseAliases UseAliases + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestGenerics Cap + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestGenerics>.IInterface> GenericCap + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnproto_test.Capnp.Test.TestGenerics.READER Basic => ctx.ReadStruct(0, Capnproto_test.Capnp.Test.TestGenerics.READER.create); + public Capnproto_test.Capnp.Test.TestGenerics.Inner.READER Inner => ctx.ReadStruct(1, Capnproto_test.Capnp.Test.TestGenerics.Inner.READER.create); + public Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER Inner2 => ctx.ReadStruct(2, Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER.create); + public Capnproto_test.Capnp.Test.TestGenerics.READER Unspecified => ctx.ReadStruct(3, Capnproto_test.Capnp.Test.TestGenerics.READER.create); + public Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER UnspecifiedInner => ctx.ReadStruct(4, Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER.create); + public Capnproto_test.Capnp.Test.TestGenerics.READER Default => ctx.ReadStruct(5, Capnproto_test.Capnp.Test.TestGenerics.READER.create); + public Capnproto_test.Capnp.Test.TestGenerics.Inner.READER DefaultInner => ctx.ReadStruct(6, Capnproto_test.Capnp.Test.TestGenerics.Inner.READER.create); + public Capnproto_test.Capnp.Test.TestUseGenerics.READER DefaultUser => ctx.ReadStruct(7, Capnproto_test.Capnp.Test.TestUseGenerics.READER.create); + public Capnproto_test.Capnp.Test.TestGenericsWrapper.READER Wrapper => ctx.ReadStruct(8, Capnproto_test.Capnp.Test.TestGenericsWrapper.READER.create); + public Capnproto_test.Capnp.Test.TestGenericsWrapper.READER DefaultWrapper => ctx.ReadStruct(9, Capnproto_test.Capnp.Test.TestGenericsWrapper.READER.create); + public Capnproto_test.Capnp.Test.TestGenericsWrapper2.READER DefaultWrapper2 => ctx.ReadStruct(10, Capnproto_test.Capnp.Test.TestGenericsWrapper2.READER.create); + public Capnproto_test.Capnp.Test.TestAllTypes.READER AliasFoo => ctx.ReadStruct(11, Capnproto_test.Capnp.Test.TestAllTypes.READER.create); + public Capnproto_test.Capnp.Test.TestGenerics.Inner.READER AliasInner => ctx.ReadStruct(12, Capnproto_test.Capnp.Test.TestGenerics.Inner.READER.create); + public Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER AliasInner2 => ctx.ReadStruct(13, Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER.create); + public Capnproto_test.Capnp.Test.TestGenerics.Inner2>.READER AliasInner2Bind => ctx.ReadStruct(14, Capnproto_test.Capnp.Test.TestGenerics.Inner2>.READER.create); + public Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER AliasInner2Text => ctx.ReadStruct(15, Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER.create); + public string AliasRev => ctx.ReadText(16, "text"); + public Capnproto_test.Capnp.Test.TestGenerics>.UseAliases.READER UseAliases => ctx.ReadStruct(17, Capnproto_test.Capnp.Test.TestGenerics>.UseAliases.READER.create); + public Capnproto_test.Capnp.Test.TestGenerics.READER Cap => ctx.ReadStruct(18, Capnproto_test.Capnp.Test.TestGenerics.READER.create); + public Capnproto_test.Capnp.Test.TestGenerics>.IInterface> GenericCap => ctx.ReadCap>.IInterface>>(19); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 20); + } + + public Capnproto_test.Capnp.Test.TestGenerics.WRITER Basic + { + get => BuildPointer.WRITER>(0); + set => Link(0, value); + } + + public Capnproto_test.Capnp.Test.TestGenerics.Inner.WRITER Inner + { + get => BuildPointer.Inner.WRITER>(1); + set => Link(1, value); + } + + public Capnproto_test.Capnp.Test.TestGenerics.Inner2.WRITER Inner2 + { + get => BuildPointer.Inner2.WRITER>(2); + set => Link(2, value); + } + + public Capnproto_test.Capnp.Test.TestGenerics.WRITER Unspecified + { + get => BuildPointer.WRITER>(3); + set => Link(3, value); + } + + public Capnproto_test.Capnp.Test.TestGenerics.Inner2.WRITER UnspecifiedInner + { + get => BuildPointer.Inner2.WRITER>(4); + set => Link(4, value); + } + + public Capnproto_test.Capnp.Test.TestGenerics.WRITER Default + { + get => BuildPointer.WRITER>(5); + set => Link(5, value); + } + + public Capnproto_test.Capnp.Test.TestGenerics.Inner.WRITER DefaultInner + { + get => BuildPointer.Inner.WRITER>(6); + set => Link(6, value); + } + + public Capnproto_test.Capnp.Test.TestUseGenerics.WRITER DefaultUser + { + get => BuildPointer(7); + set => Link(7, value); + } + + public Capnproto_test.Capnp.Test.TestGenericsWrapper.WRITER Wrapper + { + get => BuildPointer.WRITER>(8); + set => Link(8, value); + } + + public Capnproto_test.Capnp.Test.TestGenericsWrapper.WRITER DefaultWrapper + { + get => BuildPointer.WRITER>(9); + set => Link(9, value); + } + + public Capnproto_test.Capnp.Test.TestGenericsWrapper2.WRITER DefaultWrapper2 + { + get => BuildPointer(10); + set => Link(10, value); + } + + public Capnproto_test.Capnp.Test.TestAllTypes.WRITER AliasFoo + { + get => BuildPointer(11); + set => Link(11, value); + } + + public Capnproto_test.Capnp.Test.TestGenerics.Inner.WRITER AliasInner + { + get => BuildPointer.Inner.WRITER>(12); + set => Link(12, value); + } + + public Capnproto_test.Capnp.Test.TestGenerics.Inner2.WRITER AliasInner2 + { + get => BuildPointer.Inner2.WRITER>(13); + set => Link(13, value); + } + + public Capnproto_test.Capnp.Test.TestGenerics.Inner2>.WRITER AliasInner2Bind + { + get => BuildPointer.Inner2>.WRITER>(14); + set => Link(14, value); + } + + public Capnproto_test.Capnp.Test.TestGenerics.Inner2.WRITER AliasInner2Text + { + get => BuildPointer.Inner2.WRITER>(15); + set => Link(15, value); + } + + public string AliasRev + { + get => this.ReadText(16, "text"); + set => this.WriteText(16, value, "text"); + } + + public Capnproto_test.Capnp.Test.TestGenerics>.UseAliases.WRITER UseAliases + { + get => BuildPointer>.UseAliases.WRITER>(17); + set => Link(17, value); + } + + public Capnproto_test.Capnp.Test.TestGenerics.WRITER Cap + { + get => BuildPointer.WRITER>(18); + set => Link(18, value); + } + + public Capnproto_test.Capnp.Test.TestGenerics>.IInterface> GenericCap + { + get => ReadCap>.IInterface>>(19); + set => LinkObject(19, value); + } + } + } + + public class TestEmptyStruct : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + public class TestConstants : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + public class TestAnyPointerConstants : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + AnyKindAsStruct = CapnpSerializable.Create(reader.AnyKindAsStruct); + AnyStructAsStruct = CapnpSerializable.Create(reader.AnyStructAsStruct); + AnyKindAsList = CapnpSerializable.Create(reader.AnyKindAsList); + AnyListAsList = reader.AnyListAsList.ToReadOnlyList(_ => (object)_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.AnyKindAsStruct.SetObject(AnyKindAsStruct); + writer.AnyStructAsStruct.SetObject(AnyStructAsStruct); + writer.AnyKindAsList.SetObject(AnyKindAsList); + writer.AnyListAsList.SetObject(AnyListAsList); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public AnyPointer AnyKindAsStruct + { + get; + set; + } + + public AnyPointer AnyStructAsStruct + { + get; + set; + } + + public AnyPointer AnyKindAsList + { + get; + set; + } + + public IReadOnlyList AnyListAsList + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public DeserializerState AnyKindAsStruct => ctx.StructReadPointer(0); + public DeserializerState AnyStructAsStruct => ctx.StructReadPointer(1); + public DeserializerState AnyKindAsList => ctx.StructReadPointer(2); + public IReadOnlyList AnyListAsList => (IReadOnlyList)ctx.ReadList(3); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 4); + } + + public DynamicSerializerState AnyKindAsStruct + { + get => BuildPointer(0); + set => Link(0, value); + } + + public DynamicSerializerState AnyStructAsStruct + { + get => BuildPointer(1); + set => Link(1, value); + } + + public DynamicSerializerState AnyKindAsList + { + get => BuildPointer(2); + set => Link(2, value); + } + + public DynamicSerializerState AnyListAsList + { + get => BuildPointer(3); + set => Link(3, value); + } + } + } + + [Proxy(typeof(TestInterfaceProxy)), Skeleton(typeof(TestInterfaceSkeleton))] + public interface ITestInterface : IDisposable + { + Task Foo(uint i, bool j, CancellationToken cancellationToken_ = default); + Task Bar(CancellationToken cancellationToken_ = default); + Task Baz(Capnproto_test.Capnp.Test.TestAllTypes s, CancellationToken cancellationToken_ = default); + } + + public class TestInterfaceProxy : Proxy, ITestInterface + { + public async Task Foo(uint i, bool j, CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_foo() + {I = i, J = j}; + arg_.serialize(in_); + var d_ = await Call(9865999890858873522UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return (r_.X); + } + + public async Task Bar(CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_bar() + {}; + arg_.serialize(in_); + var d_ = await Call(9865999890858873522UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return; + } + + public async Task Baz(Capnproto_test.Capnp.Test.TestAllTypes s, CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_baz() + {S = s}; + arg_.serialize(in_); + var d_ = await Call(9865999890858873522UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return; + } + } + + public class TestInterfaceSkeleton : Skeleton + { + public TestInterfaceSkeleton() + { + SetMethodTable(Foo, Bar, Baz); + } + + public override ulong InterfaceId => 9865999890858873522UL; + Task Foo(DeserializerState d_, CancellationToken cancellationToken_) + { + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.Foo(in_.I, in_.J, cancellationToken_), x => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestInterface.Result_foo{X = x}; + r_.serialize(s_); + return s_; + } + + ); + } + + async Task Bar(DeserializerState d_, CancellationToken cancellationToken_) + { + await Impl.Bar(cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } + + async Task Baz(DeserializerState d_, CancellationToken cancellationToken_) + { + var in_ = CapnpSerializable.Create(d_); + await Impl.Baz(in_.S, cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } + } + + public static class TestInterface + { + public class Params_foo : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + I = reader.I; + J = reader.J; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.I = I; + writer.J = J; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public uint I + { + get; + set; + } + + public bool J + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public uint I => ctx.ReadDataUInt(0UL, 0U); + public bool J => ctx.ReadDataBool(32UL, false); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 0); + } + + public uint I + { + get => this.ReadDataUInt(0UL, 0U); + set => this.WriteData(0UL, value, 0U); + } + + public bool J + { + get => this.ReadDataBool(32UL, false); + set => this.WriteData(32UL, value, false); + } + } + } + + public class Result_foo : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + X = reader.X; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.X = X; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string X + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string X => ctx.ReadText(0, ""); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public string X + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + } + } + + public class Params_bar : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + public class Result_bar : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + public class Params_baz : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + S = CapnpSerializable.Create(reader.S); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + S?.serialize(writer.S); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.TestAllTypes S + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnproto_test.Capnp.Test.TestAllTypes.READER S => ctx.ReadStruct(0, Capnproto_test.Capnp.Test.TestAllTypes.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public Capnproto_test.Capnp.Test.TestAllTypes.WRITER S + { + get => BuildPointer(0); + set => Link(0, value); + } + } + } + + public class Result_baz : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + } + + [Proxy(typeof(TestExtendsProxy)), Skeleton(typeof(TestExtendsSkeleton))] + public interface ITestExtends : Capnproto_test.Capnp.Test.ITestInterface + { + Task Qux(CancellationToken cancellationToken_ = default); + Task Corge(Capnproto_test.Capnp.Test.TestAllTypes arg_, CancellationToken cancellationToken_ = default); + Task Grault(CancellationToken cancellationToken_ = default); + } + + public class TestExtendsProxy : Proxy, ITestExtends + { + public async Task Qux(CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestExtends.Params_qux() + {}; + arg_.serialize(in_); + var d_ = await Call(16494920484927878984UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return; + } + + public async Task Corge(Capnproto_test.Capnp.Test.TestAllTypes arg_, CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + arg_.serialize(in_); + var d_ = await Call(16494920484927878984UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return; + } + + public async Task Grault(CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestExtends.Params_grault() + {}; + arg_.serialize(in_); + var d_ = await Call(16494920484927878984UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return r_; + } + + public async Task Foo(uint i, bool j, CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_foo() + {I = i, J = j}; + arg_.serialize(in_); + var d_ = await Call(9865999890858873522UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return (r_.X); + } + + public async Task Bar(CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_bar() + {}; + arg_.serialize(in_); + var d_ = await Call(9865999890858873522UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return; + } + + public async Task Baz(Capnproto_test.Capnp.Test.TestAllTypes s, CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_baz() + {S = s}; + arg_.serialize(in_); + var d_ = await Call(9865999890858873522UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return; + } + } + + public class TestExtendsSkeleton : Skeleton + { + public TestExtendsSkeleton() + { + SetMethodTable(Qux, Corge, Grault); + } + + public override ulong InterfaceId => 16494920484927878984UL; + async Task Qux(DeserializerState d_, CancellationToken cancellationToken_) + { + await Impl.Qux(cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } + + async Task Corge(DeserializerState d_, CancellationToken cancellationToken_) + { + await Impl.Corge(CapnpSerializable.Create(d_), cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } + + Task Grault(DeserializerState d_, CancellationToken cancellationToken_) + { + return Impatient.MaybeTailCall(Impl.Grault(cancellationToken_), r_ => + { + var s_ = SerializerState.CreateForRpc(); + r_.serialize(s_); + return s_; + } + + ); + } + } + + public static class TestExtends + { + public class Params_qux : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + public class Result_qux : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + public class Result_corge : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + public class Params_grault : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + } + + [Proxy(typeof(TestExtends2Proxy)), Skeleton(typeof(TestExtends2Skeleton))] + public interface ITestExtends2 : Capnproto_test.Capnp.Test.ITestExtends + { + } + + public class TestExtends2Proxy : Proxy, ITestExtends2 + { + public async Task Qux(CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestExtends.Params_qux() + {}; + arg_.serialize(in_); + var d_ = await Call(16494920484927878984UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return; + } + + public async Task Corge(Capnproto_test.Capnp.Test.TestAllTypes arg_, CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + arg_.serialize(in_); + var d_ = await Call(16494920484927878984UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return; + } + + public async Task Grault(CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestExtends.Params_grault() + {}; + arg_.serialize(in_); + var d_ = await Call(16494920484927878984UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return r_; + } + + public async Task Foo(uint i, bool j, CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_foo() + {I = i, J = j}; + arg_.serialize(in_); + var d_ = await Call(9865999890858873522UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return (r_.X); + } + + public async Task Bar(CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_bar() + {}; + arg_.serialize(in_); + var d_ = await Call(9865999890858873522UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return; + } + + public async Task Baz(Capnproto_test.Capnp.Test.TestAllTypes s, CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_baz() + {S = s}; + arg_.serialize(in_); + var d_ = await Call(9865999890858873522UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return; + } + } + + public class TestExtends2Skeleton : Skeleton + { + public TestExtends2Skeleton() + { + SetMethodTable(); + } + + public override ulong InterfaceId => 11013518732491786115UL; + } + + [Proxy(typeof(TestPipelineProxy)), Skeleton(typeof(TestPipelineSkeleton))] + public interface ITestPipeline : IDisposable + { + Task<(string, Capnproto_test.Capnp.Test.TestPipeline.Box)> GetCap(uint n, Capnproto_test.Capnp.Test.ITestInterface inCap, CancellationToken cancellationToken_ = default); + Task TestPointers(Capnproto_test.Capnp.Test.ITestInterface cap, AnyPointer obj, IReadOnlyList list, CancellationToken cancellationToken_ = default); + Task<(string, Capnproto_test.Capnp.Test.TestPipeline.AnyBox)> GetAnyCap(uint n, BareProxy inCap, CancellationToken cancellationToken_ = default); + } + + public class TestPipelineProxy : Proxy, ITestPipeline + { + public Task<(string, Capnproto_test.Capnp.Test.TestPipeline.Box)> GetCap(uint n, Capnproto_test.Capnp.Test.ITestInterface inCap, CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestPipeline.Params_getCap() + {N = n, InCap = inCap}; + arg_.serialize(in_); + return Impatient.MakePipelineAware(Call(11935670180855499984UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => + { + var r_ = CapnpSerializable.Create(d_); + return (r_.S, r_.OutBox); + } + + ); + } + + public async Task TestPointers(Capnproto_test.Capnp.Test.ITestInterface cap, AnyPointer obj, IReadOnlyList list, CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestPipeline.Params_testPointers() + {Cap = cap, Obj = obj, List = list}; + arg_.serialize(in_); + var d_ = await Call(11935670180855499984UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return; + } + + public Task<(string, Capnproto_test.Capnp.Test.TestPipeline.AnyBox)> GetAnyCap(uint n, BareProxy inCap, CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestPipeline.Params_getAnyCap() + {N = n, InCap = inCap}; + arg_.serialize(in_); + return Impatient.MakePipelineAware(Call(11935670180855499984UL, 2, in_.Rewrap(), false, cancellationToken_), d_ => + { + var r_ = CapnpSerializable.Create(d_); + return (r_.S, r_.OutBox); + } + + ); + } + } + + public class TestPipelineSkeleton : Skeleton + { + public TestPipelineSkeleton() + { + SetMethodTable(GetCap, TestPointers, GetAnyCap); + } + + public override ulong InterfaceId => 11935670180855499984UL; + Task GetCap(DeserializerState d_, CancellationToken cancellationToken_) + { + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.GetCap(in_.N, in_.InCap, cancellationToken_), (s, outBox) => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestPipeline.Result_getCap{S = s, OutBox = outBox}; + r_.serialize(s_); + return s_; + } + + ); + } + + async Task TestPointers(DeserializerState d_, CancellationToken cancellationToken_) + { + var in_ = CapnpSerializable.Create(d_); + await Impl.TestPointers(in_.Cap, in_.Obj, in_.List, cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } + + Task GetAnyCap(DeserializerState d_, CancellationToken cancellationToken_) + { + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.GetAnyCap(in_.N, in_.InCap, cancellationToken_), (s, outBox) => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestPipeline.Result_getAnyCap{S = s, OutBox = outBox}; + r_.serialize(s_); + return s_; + } + + ); + } + } + + public static partial class PipeliningSupportExtensions + { + static readonly MemberAccessPath Path_getCap_OutBox_Cap = new MemberAccessPath(1U, 0U); + public static Capnproto_test.Capnp.Test.ITestInterface OutBox_Cap(this Task<(string, Capnproto_test.Capnp.Test.TestPipeline.Box)> task) + { + return (Capnproto_test.Capnp.Test.ITestInterface)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_getCap_OutBox_Cap)); + } + + static readonly MemberAccessPath Path_getAnyCap_OutBox_Cap = new MemberAccessPath(1U, 0U); + public static BareProxy OutBox_Cap(this Task<(string, Capnproto_test.Capnp.Test.TestPipeline.AnyBox)> task) + { + return (BareProxy)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_getAnyCap_OutBox_Cap)); + } + } + + public static class TestPipeline + { + public class Box : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Cap = reader.Cap; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Cap = Cap; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.ITestInterface Cap + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnproto_test.Capnp.Test.ITestInterface Cap => ctx.ReadCap(0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public Capnproto_test.Capnp.Test.ITestInterface Cap + { + get => ReadCap(0); + set => LinkObject(0, value); + } + } + } + + public class AnyBox : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Cap = reader.Cap; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Cap = Cap; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public BareProxy Cap + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public BareProxy Cap => ctx.ReadCap(0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public BareProxy Cap + { + get => ReadCap(0); + set => LinkObject(0, value); + } + } + } + + public class Params_getCap : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + N = reader.N; + InCap = reader.InCap; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.N = N; + writer.InCap = InCap; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public uint N + { + get; + set; + } + + public Capnproto_test.Capnp.Test.ITestInterface InCap + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public uint N => ctx.ReadDataUInt(0UL, 0U); + public Capnproto_test.Capnp.Test.ITestInterface InCap => ctx.ReadCap(0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public uint N + { + get => this.ReadDataUInt(0UL, 0U); + set => this.WriteData(0UL, value, 0U); + } + + public Capnproto_test.Capnp.Test.ITestInterface InCap + { + get => ReadCap(0); + set => LinkObject(0, value); + } + } + } + + public class Result_getCap : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + S = reader.S; + OutBox = CapnpSerializable.Create(reader.OutBox); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.S = S; + OutBox?.serialize(writer.OutBox); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string S + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestPipeline.Box OutBox + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string S => ctx.ReadText(0, ""); + public Capnproto_test.Capnp.Test.TestPipeline.Box.READER OutBox => ctx.ReadStruct(1, Capnproto_test.Capnp.Test.TestPipeline.Box.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 2); + } + + public string S + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + + public Capnproto_test.Capnp.Test.TestPipeline.Box.WRITER OutBox + { + get => BuildPointer(1); + set => Link(1, value); + } + } + } + + public class Params_testPointers : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Cap = reader.Cap; + Obj = CapnpSerializable.Create(reader.Obj); + List = reader.List; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Cap = Cap; + writer.Obj.SetObject(Obj); + writer.List.Init(List); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.ITestInterface Cap + { + get; + set; + } + + public AnyPointer Obj + { + get; + set; + } + + public IReadOnlyList List + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnproto_test.Capnp.Test.ITestInterface Cap => ctx.ReadCap(0); + public DeserializerState Obj => ctx.StructReadPointer(1); + public IReadOnlyList List => ctx.ReadCapList(2); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 3); + } + + public Capnproto_test.Capnp.Test.ITestInterface Cap + { + get => ReadCap(0); + set => LinkObject(0, value); + } + + public DynamicSerializerState Obj + { + get => BuildPointer(1); + set => Link(1, value); + } + + public ListOfCapsSerializer List + { + get => BuildPointer>(2); + set => Link(2, value); + } + } + } + + public class Result_testPointers : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + public class Params_getAnyCap : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + N = reader.N; + InCap = reader.InCap; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.N = N; + writer.InCap = InCap; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public uint N + { + get; + set; + } + + public BareProxy InCap + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public uint N => ctx.ReadDataUInt(0UL, 0U); + public BareProxy InCap => ctx.ReadCap(0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public uint N + { + get => this.ReadDataUInt(0UL, 0U); + set => this.WriteData(0UL, value, 0U); + } + + public BareProxy InCap + { + get => ReadCap(0); + set => LinkObject(0, value); + } + } + } + + public class Result_getAnyCap : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + S = reader.S; + OutBox = CapnpSerializable.Create(reader.OutBox); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.S = S; + OutBox?.serialize(writer.OutBox); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string S + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestPipeline.AnyBox OutBox + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string S => ctx.ReadText(0, ""); + public Capnproto_test.Capnp.Test.TestPipeline.AnyBox.READER OutBox => ctx.ReadStruct(1, Capnproto_test.Capnp.Test.TestPipeline.AnyBox.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 2); + } + + public string S + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + + public Capnproto_test.Capnp.Test.TestPipeline.AnyBox.WRITER OutBox + { + get => BuildPointer(1); + set => Link(1, value); + } + } + } + } + + [Proxy(typeof(TestCallOrderProxy)), Skeleton(typeof(TestCallOrderSkeleton))] + public interface ITestCallOrder : IDisposable + { + Task GetCallSequence(uint expected, CancellationToken cancellationToken_ = default); + } + + public class TestCallOrderProxy : Proxy, ITestCallOrder + { + public async Task GetCallSequence(uint expected, CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestCallOrder.Params_getCallSequence() + {Expected = expected}; + arg_.serialize(in_); + var d_ = await Call(11594359141811814481UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return (r_.N); + } + } + + public class TestCallOrderSkeleton : Skeleton + { + public TestCallOrderSkeleton() + { + SetMethodTable(GetCallSequence); + } + + public override ulong InterfaceId => 11594359141811814481UL; + Task GetCallSequence(DeserializerState d_, CancellationToken cancellationToken_) + { + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.GetCallSequence(in_.Expected, cancellationToken_), n => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestCallOrder.Result_getCallSequence{N = n}; + r_.serialize(s_); + return s_; + } + + ); + } + } + + public static class TestCallOrder + { + public class Params_getCallSequence : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Expected = reader.Expected; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Expected = Expected; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public uint Expected + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public uint Expected => ctx.ReadDataUInt(0UL, 0U); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 0); + } + + public uint Expected + { + get => this.ReadDataUInt(0UL, 0U); + set => this.WriteData(0UL, value, 0U); + } + } + } + + public class Result_getCallSequence : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + N = reader.N; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.N = N; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public uint N + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public uint N => ctx.ReadDataUInt(0UL, 0U); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 0); + } + + public uint N + { + get => this.ReadDataUInt(0UL, 0U); + set => this.WriteData(0UL, value, 0U); + } + } + } + } + + [Proxy(typeof(TestTailCalleeProxy)), Skeleton(typeof(TestTailCalleeSkeleton))] + public interface ITestTailCallee : IDisposable + { + Task Foo(int i, string t, CancellationToken cancellationToken_ = default); + } + + public class TestTailCalleeProxy : Proxy, ITestTailCallee + { + public Task Foo(int i, string t, CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestTailCallee.Params_foo() + {I = i, T = t}; + arg_.serialize(in_); + return Impatient.MakePipelineAware(Call(15985132292242203195UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => + { + var r_ = CapnpSerializable.Create(d_); + return r_; + } + + ); + } + } + + public class TestTailCalleeSkeleton : Skeleton + { + public TestTailCalleeSkeleton() + { + SetMethodTable(Foo); + } + + public override ulong InterfaceId => 15985132292242203195UL; + Task Foo(DeserializerState d_, CancellationToken cancellationToken_) + { + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.Foo(in_.I, in_.T, cancellationToken_), r_ => + { + var s_ = SerializerState.CreateForRpc(); + r_.serialize(s_); + return s_; + } + + ); + } + } + + public static partial class PipeliningSupportExtensions + { + static readonly MemberAccessPath Path_foo_C = new MemberAccessPath(1U); + public static Capnproto_test.Capnp.Test.ITestCallOrder C(this Task task) + { + return (Capnproto_test.Capnp.Test.ITestCallOrder)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_foo_C)); + } + } + + public static class TestTailCallee + { + public class TailResult : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + I = reader.I; + T = reader.T; + C = reader.C; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.I = I; + writer.T = T; + writer.C = C; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public uint I + { + get; + set; + } + + public string T + { + get; + set; + } + + public Capnproto_test.Capnp.Test.ITestCallOrder C + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public uint I => ctx.ReadDataUInt(0UL, 0U); + public string T => ctx.ReadText(0, ""); + public Capnproto_test.Capnp.Test.ITestCallOrder C => ctx.ReadCap(1); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 2); + } + + public uint I + { + get => this.ReadDataUInt(0UL, 0U); + set => this.WriteData(0UL, value, 0U); + } + + public string T + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + + public Capnproto_test.Capnp.Test.ITestCallOrder C + { + get => ReadCap(1); + set => LinkObject(1, value); + } + } + } + + public class Params_foo : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + I = reader.I; + T = reader.T; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.I = I; + writer.T = T; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public int I + { + get; + set; + } + + public string T + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public int I => ctx.ReadDataInt(0UL, 0); + public string T => ctx.ReadText(0, ""); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public int I + { + get => this.ReadDataInt(0UL, 0); + set => this.WriteData(0UL, value, 0); + } + + public string T + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + } + } + } + + [Proxy(typeof(TestTailCallerProxy)), Skeleton(typeof(TestTailCallerSkeleton))] + public interface ITestTailCaller : IDisposable + { + Task Foo(int i, Capnproto_test.Capnp.Test.ITestTailCallee callee, CancellationToken cancellationToken_ = default); + } + + public class TestTailCallerProxy : Proxy, ITestTailCaller + { + public Task Foo(int i, Capnproto_test.Capnp.Test.ITestTailCallee callee, CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestTailCaller.Params_foo() + {I = i, Callee = callee}; + arg_.serialize(in_); + return Impatient.MakePipelineAware(Call(9731139705278181429UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => + { + var r_ = CapnpSerializable.Create(d_); + return r_; + } + + ); + } + } + + public class TestTailCallerSkeleton : Skeleton + { + public TestTailCallerSkeleton() + { + SetMethodTable(Foo); + } + + public override ulong InterfaceId => 9731139705278181429UL; + Task Foo(DeserializerState d_, CancellationToken cancellationToken_) + { + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.Foo(in_.I, in_.Callee, cancellationToken_), r_ => + { + var s_ = SerializerState.CreateForRpc(); + r_.serialize(s_); + return s_; + } + + ); + } + } + + public static partial class PipeliningSupportExtensions + { + } + + public static class TestTailCaller + { + public class Params_foo : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + I = reader.I; + Callee = reader.Callee; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.I = I; + writer.Callee = Callee; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public int I + { + get; + set; + } + + public Capnproto_test.Capnp.Test.ITestTailCallee Callee + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public int I => ctx.ReadDataInt(0UL, 0); + public Capnproto_test.Capnp.Test.ITestTailCallee Callee => ctx.ReadCap(0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public int I + { + get => this.ReadDataInt(0UL, 0); + set => this.WriteData(0UL, value, 0); + } + + public Capnproto_test.Capnp.Test.ITestTailCallee Callee + { + get => ReadCap(0); + set => LinkObject(0, value); + } + } + } + } + + [Proxy(typeof(TestHandleProxy)), Skeleton(typeof(TestHandleSkeleton))] + public interface ITestHandle : IDisposable + { + } + + public class TestHandleProxy : Proxy, ITestHandle + { + } + + public class TestHandleSkeleton : Skeleton + { + public TestHandleSkeleton() + { + SetMethodTable(); + } + + public override ulong InterfaceId => 11785461720995412501UL; + } + + [Proxy(typeof(TestMoreStuffProxy)), Skeleton(typeof(TestMoreStuffSkeleton))] + public interface ITestMoreStuff : Capnproto_test.Capnp.Test.ITestCallOrder + { + Task CallFoo(Capnproto_test.Capnp.Test.ITestInterface cap, CancellationToken cancellationToken_ = default); + Task CallFooWhenResolved(Capnproto_test.Capnp.Test.ITestInterface cap, CancellationToken cancellationToken_ = default); + Task NeverReturn(Capnproto_test.Capnp.Test.ITestInterface cap, CancellationToken cancellationToken_ = default); + Task Hold(Capnproto_test.Capnp.Test.ITestInterface cap, CancellationToken cancellationToken_ = default); + Task CallHeld(CancellationToken cancellationToken_ = default); + Task GetHeld(CancellationToken cancellationToken_ = default); + Task Echo(Capnproto_test.Capnp.Test.ITestCallOrder cap, CancellationToken cancellationToken_ = default); + Task ExpectCancel(Capnproto_test.Capnp.Test.ITestInterface cap, CancellationToken cancellationToken_ = default); + Task<(string, string)> MethodWithDefaults(string a, uint b, string c, CancellationToken cancellationToken_ = default); + Task GetHandle(CancellationToken cancellationToken_ = default); + Task GetNull(CancellationToken cancellationToken_ = default); + Task GetEnormousString(CancellationToken cancellationToken_ = default); + Task MethodWithNullDefault(string a, Capnproto_test.Capnp.Test.ITestInterface b, CancellationToken cancellationToken_ = default); + } + + public class TestMoreStuffProxy : Proxy, ITestMoreStuff + { + public async Task CallFoo(Capnproto_test.Capnp.Test.ITestInterface cap, CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_callFoo() + {Cap = cap}; + arg_.serialize(in_); + var d_ = await Call(15980754968839795663UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return (r_.S); + } + + public async Task CallFooWhenResolved(Capnproto_test.Capnp.Test.ITestInterface cap, CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_callFooWhenResolved() + {Cap = cap}; + arg_.serialize(in_); + var d_ = await Call(15980754968839795663UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return (r_.S); + } + + public Task NeverReturn(Capnproto_test.Capnp.Test.ITestInterface cap, CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_neverReturn() + {Cap = cap}; + arg_.serialize(in_); + return Impatient.MakePipelineAware(Call(15980754968839795663UL, 2, in_.Rewrap(), false, cancellationToken_), d_ => + { + var r_ = CapnpSerializable.Create(d_); + return (r_.CapCopy); + } + + ); + } + + public async Task Hold(Capnproto_test.Capnp.Test.ITestInterface cap, CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_hold() + {Cap = cap}; + arg_.serialize(in_); + var d_ = await Call(15980754968839795663UL, 3, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return; + } + + public async Task CallHeld(CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_callHeld() + {}; + arg_.serialize(in_); + var d_ = await Call(15980754968839795663UL, 4, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return (r_.S); + } + + public Task GetHeld(CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_getHeld() + {}; + arg_.serialize(in_); + return Impatient.MakePipelineAware(Call(15980754968839795663UL, 5, in_.Rewrap(), false, cancellationToken_), d_ => + { + var r_ = CapnpSerializable.Create(d_); + return (r_.Cap); + } + + ); + } + + public Task Echo(Capnproto_test.Capnp.Test.ITestCallOrder cap, CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_echo() + {Cap = cap}; + arg_.serialize(in_); + return Impatient.MakePipelineAware(Call(15980754968839795663UL, 6, in_.Rewrap(), false, cancellationToken_), d_ => + { + var r_ = CapnpSerializable.Create(d_); + return (r_.Cap); + } + + ); + } + + public async Task ExpectCancel(Capnproto_test.Capnp.Test.ITestInterface cap, CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_expectCancel() + {Cap = cap}; + arg_.serialize(in_); + var d_ = await Call(15980754968839795663UL, 7, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return; + } + + public async Task<(string, string)> MethodWithDefaults(string a, uint b, string c, CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_methodWithDefaults() + {A = a, B = b, C = c}; + arg_.serialize(in_); + var d_ = await Call(15980754968839795663UL, 8, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return (r_.D, r_.E); + } + + public Task GetHandle(CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_getHandle() + {}; + arg_.serialize(in_); + return Impatient.MakePipelineAware(Call(15980754968839795663UL, 9, in_.Rewrap(), false, cancellationToken_), d_ => + { + var r_ = CapnpSerializable.Create(d_); + return (r_.Handle); + } + + ); + } + + public Task GetNull(CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_getNull() + {}; + arg_.serialize(in_); + return Impatient.MakePipelineAware(Call(15980754968839795663UL, 10, in_.Rewrap(), false, cancellationToken_), d_ => + { + var r_ = CapnpSerializable.Create(d_); + return (r_.NullCap); + } + + ); + } + + public async Task GetEnormousString(CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_getEnormousString() + {}; + arg_.serialize(in_); + var d_ = await Call(15980754968839795663UL, 11, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return (r_.Str); + } + + public async Task MethodWithNullDefault(string a, Capnproto_test.Capnp.Test.ITestInterface b, CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_methodWithNullDefault() + {A = a, B = b}; + arg_.serialize(in_); + var d_ = await Call(15980754968839795663UL, 12, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return; + } + + public async Task GetCallSequence(uint expected, CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestCallOrder.Params_getCallSequence() + {Expected = expected}; + arg_.serialize(in_); + var d_ = await Call(11594359141811814481UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return (r_.N); + } + } + + public class TestMoreStuffSkeleton : Skeleton + { + public TestMoreStuffSkeleton() + { + SetMethodTable(CallFoo, CallFooWhenResolved, NeverReturn, Hold, CallHeld, GetHeld, Echo, ExpectCancel, MethodWithDefaults, GetHandle, GetNull, GetEnormousString, MethodWithNullDefault); + } + + public override ulong InterfaceId => 15980754968839795663UL; + Task CallFoo(DeserializerState d_, CancellationToken cancellationToken_) + { + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.CallFoo(in_.Cap, cancellationToken_), s => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_callFoo{S = s}; + r_.serialize(s_); + return s_; + } + + ); + } + + Task CallFooWhenResolved(DeserializerState d_, CancellationToken cancellationToken_) + { + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.CallFooWhenResolved(in_.Cap, cancellationToken_), s => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_callFooWhenResolved{S = s}; + r_.serialize(s_); + return s_; + } + + ); + } + + Task NeverReturn(DeserializerState d_, CancellationToken cancellationToken_) + { + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.NeverReturn(in_.Cap, cancellationToken_), capCopy => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_neverReturn{CapCopy = capCopy}; + r_.serialize(s_); + return s_; + } + + ); + } + + async Task Hold(DeserializerState d_, CancellationToken cancellationToken_) + { + var in_ = CapnpSerializable.Create(d_); + await Impl.Hold(in_.Cap, cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } + + Task CallHeld(DeserializerState d_, CancellationToken cancellationToken_) + { + return Impatient.MaybeTailCall(Impl.CallHeld(cancellationToken_), s => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_callHeld{S = s}; + r_.serialize(s_); + return s_; + } + + ); + } + + Task GetHeld(DeserializerState d_, CancellationToken cancellationToken_) + { + return Impatient.MaybeTailCall(Impl.GetHeld(cancellationToken_), cap => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_getHeld{Cap = cap}; + r_.serialize(s_); + return s_; + } + + ); + } + + Task Echo(DeserializerState d_, CancellationToken cancellationToken_) + { + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.Echo(in_.Cap, cancellationToken_), cap => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_echo{Cap = cap}; + r_.serialize(s_); + return s_; + } + + ); + } + + async Task ExpectCancel(DeserializerState d_, CancellationToken cancellationToken_) + { + var in_ = CapnpSerializable.Create(d_); + await Impl.ExpectCancel(in_.Cap, cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } + + Task MethodWithDefaults(DeserializerState d_, CancellationToken cancellationToken_) + { + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.MethodWithDefaults(in_.A, in_.B, in_.C, cancellationToken_), (d, e) => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_methodWithDefaults{D = d, E = e}; + r_.serialize(s_); + return s_; + } + + ); + } + + Task GetHandle(DeserializerState d_, CancellationToken cancellationToken_) + { + return Impatient.MaybeTailCall(Impl.GetHandle(cancellationToken_), handle => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_getHandle{Handle = handle}; + r_.serialize(s_); + return s_; + } + + ); + } + + Task GetNull(DeserializerState d_, CancellationToken cancellationToken_) + { + return Impatient.MaybeTailCall(Impl.GetNull(cancellationToken_), nullCap => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_getNull{NullCap = nullCap}; + r_.serialize(s_); + return s_; + } + + ); + } + + Task GetEnormousString(DeserializerState d_, CancellationToken cancellationToken_) + { + return Impatient.MaybeTailCall(Impl.GetEnormousString(cancellationToken_), str => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_getEnormousString{Str = str}; + r_.serialize(s_); + return s_; + } + + ); + } + + async Task MethodWithNullDefault(DeserializerState d_, CancellationToken cancellationToken_) + { + var in_ = CapnpSerializable.Create(d_); + await Impl.MethodWithNullDefault(in_.A, in_.B, cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } + } + + public static partial class PipeliningSupportExtensions + { + static readonly MemberAccessPath Path_neverReturn_Eager = new MemberAccessPath(0U); + public static Capnproto_test.Capnp.Test.ITestInterface Eager(this Task task) + { + return (Capnproto_test.Capnp.Test.ITestInterface)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_neverReturn_Eager)); + } + + static readonly MemberAccessPath Path_echo_Eager = new MemberAccessPath(0U); + public static Capnproto_test.Capnp.Test.ITestCallOrder Eager(this Task task) + { + return (Capnproto_test.Capnp.Test.ITestCallOrder)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_echo_Eager)); + } + + static readonly MemberAccessPath Path_getHandle_Eager = new MemberAccessPath(0U); + public static Capnproto_test.Capnp.Test.ITestHandle Eager(this Task task) + { + return (Capnproto_test.Capnp.Test.ITestHandle)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_getHandle_Eager)); + } + + static readonly MemberAccessPath Path_getNull_Eager = new MemberAccessPath(0U); + public static Capnproto_test.Capnp.Test.ITestMoreStuff Eager(this Task task) + { + return (Capnproto_test.Capnp.Test.ITestMoreStuff)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_getNull_Eager)); + } + } + + public static class TestMoreStuff + { + public class Params_callFoo : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Cap = reader.Cap; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Cap = Cap; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.ITestInterface Cap + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnproto_test.Capnp.Test.ITestInterface Cap => ctx.ReadCap(0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public Capnproto_test.Capnp.Test.ITestInterface Cap + { + get => ReadCap(0); + set => LinkObject(0, value); + } + } + } + + public class Result_callFoo : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + S = reader.S; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.S = S; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string S + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string S => ctx.ReadText(0, ""); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public string S + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + } + } + + public class Params_callFooWhenResolved : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Cap = reader.Cap; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Cap = Cap; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.ITestInterface Cap + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnproto_test.Capnp.Test.ITestInterface Cap => ctx.ReadCap(0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public Capnproto_test.Capnp.Test.ITestInterface Cap + { + get => ReadCap(0); + set => LinkObject(0, value); + } + } + } + + public class Result_callFooWhenResolved : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + S = reader.S; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.S = S; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string S + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string S => ctx.ReadText(0, ""); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public string S + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + } + } + + public class Params_neverReturn : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Cap = reader.Cap; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Cap = Cap; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.ITestInterface Cap + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnproto_test.Capnp.Test.ITestInterface Cap => ctx.ReadCap(0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public Capnproto_test.Capnp.Test.ITestInterface Cap + { + get => ReadCap(0); + set => LinkObject(0, value); + } + } + } + + public class Result_neverReturn : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + CapCopy = reader.CapCopy; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.CapCopy = CapCopy; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.ITestInterface CapCopy + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnproto_test.Capnp.Test.ITestInterface CapCopy => ctx.ReadCap(0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public Capnproto_test.Capnp.Test.ITestInterface CapCopy + { + get => ReadCap(0); + set => LinkObject(0, value); + } + } + } + + public class Params_hold : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Cap = reader.Cap; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Cap = Cap; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.ITestInterface Cap + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnproto_test.Capnp.Test.ITestInterface Cap => ctx.ReadCap(0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public Capnproto_test.Capnp.Test.ITestInterface Cap + { + get => ReadCap(0); + set => LinkObject(0, value); + } + } + } + + public class Result_hold : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + public class Params_callHeld : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + public class Result_callHeld : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + S = reader.S; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.S = S; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string S + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string S => ctx.ReadText(0, ""); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public string S + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + } + } + + public class Params_getHeld : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + public class Result_getHeld : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Cap = reader.Cap; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Cap = Cap; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.ITestInterface Cap + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnproto_test.Capnp.Test.ITestInterface Cap => ctx.ReadCap(0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public Capnproto_test.Capnp.Test.ITestInterface Cap + { + get => ReadCap(0); + set => LinkObject(0, value); + } + } + } + + public class Params_echo : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Cap = reader.Cap; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Cap = Cap; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.ITestCallOrder Cap + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnproto_test.Capnp.Test.ITestCallOrder Cap => ctx.ReadCap(0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public Capnproto_test.Capnp.Test.ITestCallOrder Cap + { + get => ReadCap(0); + set => LinkObject(0, value); + } + } + } + + public class Result_echo : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Cap = reader.Cap; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Cap = Cap; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.ITestCallOrder Cap + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnproto_test.Capnp.Test.ITestCallOrder Cap => ctx.ReadCap(0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public Capnproto_test.Capnp.Test.ITestCallOrder Cap + { + get => ReadCap(0); + set => LinkObject(0, value); + } + } + } + + public class Params_expectCancel : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Cap = reader.Cap; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Cap = Cap; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.ITestInterface Cap + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnproto_test.Capnp.Test.ITestInterface Cap => ctx.ReadCap(0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public Capnproto_test.Capnp.Test.ITestInterface Cap + { + get => ReadCap(0); + set => LinkObject(0, value); + } + } + } + + public class Result_expectCancel : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + public class Params_methodWithDefaults : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + A = reader.A; + B = reader.B; + C = reader.C; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.A = A; + writer.B = B; + writer.C = C; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + C = C ?? "foo"; + } + + public string A + { + get; + set; + } + + public uint B + { + get; + set; + } + + = 123U; + public string C + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string A => ctx.ReadText(0, ""); + public uint B => ctx.ReadDataUInt(0UL, 123U); + public string C => ctx.ReadText(1, "foo"); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 2); + } + + public string A + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + + public uint B + { + get => this.ReadDataUInt(0UL, 123U); + set => this.WriteData(0UL, value, 123U); + } + + public string C + { + get => this.ReadText(1, "foo"); + set => this.WriteText(1, value, "foo"); + } + } + } + + public class Result_methodWithDefaults : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + D = reader.D; + E = reader.E; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.D = D; + writer.E = E; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + E = E ?? "bar"; + } + + public string D + { + get; + set; + } + + public string E + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string D => ctx.ReadText(0, ""); + public string E => ctx.ReadText(1, "bar"); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 2); + } + + public string D + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + + public string E + { + get => this.ReadText(1, "bar"); + set => this.WriteText(1, value, "bar"); + } + } + } + + public class Params_getHandle : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + public class Result_getHandle : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Handle = reader.Handle; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Handle = Handle; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.ITestHandle Handle + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnproto_test.Capnp.Test.ITestHandle Handle => ctx.ReadCap(0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public Capnproto_test.Capnp.Test.ITestHandle Handle + { + get => ReadCap(0); + set => LinkObject(0, value); + } + } + } + + public class Params_getNull : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + public class Result_getNull : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + NullCap = reader.NullCap; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.NullCap = NullCap; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.ITestMoreStuff NullCap + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnproto_test.Capnp.Test.ITestMoreStuff NullCap => ctx.ReadCap(0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public Capnproto_test.Capnp.Test.ITestMoreStuff NullCap + { + get => ReadCap(0); + set => LinkObject(0, value); + } + } + } + + public class Params_getEnormousString : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + public class Result_getEnormousString : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Str = reader.Str; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Str = Str; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string Str + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string Str => ctx.ReadText(0, ""); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public string Str + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + } + } + + public class Params_methodWithNullDefault : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + A = reader.A; + B = reader.B; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.A = A; + writer.B = B; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string A + { + get; + set; + } + + public Capnproto_test.Capnp.Test.ITestInterface B + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string A => ctx.ReadText(0, ""); + public Capnproto_test.Capnp.Test.ITestInterface B => ctx.ReadCap(1); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 2); + } + + public string A + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + + public Capnproto_test.Capnp.Test.ITestInterface B + { + get => ReadCap(1); + set => LinkObject(1, value); + } + } + } + + public class Result_methodWithNullDefault : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + } + + [Proxy(typeof(TestMembraneProxy)), Skeleton(typeof(TestMembraneSkeleton))] + public interface ITestMembrane : IDisposable + { + Task MakeThing(CancellationToken cancellationToken_ = default); + Task CallPassThrough(Capnproto_test.Capnp.Test.TestMembrane.IThing thing, bool tailCall, CancellationToken cancellationToken_ = default); + Task CallIntercept(Capnproto_test.Capnp.Test.TestMembrane.IThing thing, bool tailCall, CancellationToken cancellationToken_ = default); + Task Loopback(Capnproto_test.Capnp.Test.TestMembrane.IThing thing, CancellationToken cancellationToken_ = default); + Task WaitForever(CancellationToken cancellationToken_ = default); + } + + public class TestMembraneProxy : Proxy, ITestMembrane + { + public Task MakeThing(CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Params_makeThing() + {}; + arg_.serialize(in_); + return Impatient.MakePipelineAware(Call(13870398341137210380UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => + { + var r_ = CapnpSerializable.Create(d_); + return (r_.Thing); + } + + ); + } + + public async Task CallPassThrough(Capnproto_test.Capnp.Test.TestMembrane.IThing thing, bool tailCall, CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Params_callPassThrough() + {Thing = thing, TailCall = tailCall}; + arg_.serialize(in_); + var d_ = await Call(13870398341137210380UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return r_; + } + + public async Task CallIntercept(Capnproto_test.Capnp.Test.TestMembrane.IThing thing, bool tailCall, CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Params_callIntercept() + {Thing = thing, TailCall = tailCall}; + arg_.serialize(in_); + var d_ = await Call(13870398341137210380UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return r_; + } + + public Task Loopback(Capnproto_test.Capnp.Test.TestMembrane.IThing thing, CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Params_loopback() + {Thing = thing}; + arg_.serialize(in_); + return Impatient.MakePipelineAware(Call(13870398341137210380UL, 3, in_.Rewrap(), false, cancellationToken_), d_ => + { + var r_ = CapnpSerializable.Create(d_); + return (r_.Thing); + } + + ); + } + + public async Task WaitForever(CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Params_waitForever() + {}; + arg_.serialize(in_); + var d_ = await Call(13870398341137210380UL, 4, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return; + } + } + + public class TestMembraneSkeleton : Skeleton + { + public TestMembraneSkeleton() + { + SetMethodTable(MakeThing, CallPassThrough, CallIntercept, Loopback, WaitForever); + } + + public override ulong InterfaceId => 13870398341137210380UL; + Task MakeThing(DeserializerState d_, CancellationToken cancellationToken_) + { + return Impatient.MaybeTailCall(Impl.MakeThing(cancellationToken_), thing => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMembrane.Result_makeThing{Thing = thing}; + r_.serialize(s_); + return s_; + } + + ); + } + + Task CallPassThrough(DeserializerState d_, CancellationToken cancellationToken_) + { + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.CallPassThrough(in_.Thing, in_.TailCall, cancellationToken_), r_ => + { + var s_ = SerializerState.CreateForRpc(); + r_.serialize(s_); + return s_; + } + + ); + } + + Task CallIntercept(DeserializerState d_, CancellationToken cancellationToken_) + { + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.CallIntercept(in_.Thing, in_.TailCall, cancellationToken_), r_ => + { + var s_ = SerializerState.CreateForRpc(); + r_.serialize(s_); + return s_; + } + + ); + } + + Task Loopback(DeserializerState d_, CancellationToken cancellationToken_) + { + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.Loopback(in_.Thing, cancellationToken_), thing => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMembrane.Result_loopback{Thing = thing}; + r_.serialize(s_); + return s_; + } + + ); + } + + async Task WaitForever(DeserializerState d_, CancellationToken cancellationToken_) + { + await Impl.WaitForever(cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } + } + + public static partial class PipeliningSupportExtensions + { + static readonly MemberAccessPath Path_makeThing_Eager = new MemberAccessPath(0U); + public static Capnproto_test.Capnp.Test.TestMembrane.IThing Eager(this Task task) + { + return (Capnproto_test.Capnp.Test.TestMembrane.IThing)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_makeThing_Eager)); + } + } + + public static class TestMembrane + { + [Proxy(typeof(ThingProxy)), Skeleton(typeof(ThingSkeleton))] + public interface IThing : IDisposable + { + Task PassThrough(CancellationToken cancellationToken_ = default); + Task Intercept(CancellationToken cancellationToken_ = default); + } + + public class ThingProxy : Proxy, IThing + { + public async Task PassThrough(CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Thing.Params_passThrough() + {}; + arg_.serialize(in_); + var d_ = await Call(10615798940090972439UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return r_; + } + + public async Task Intercept(CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Thing.Params_intercept() + {}; + arg_.serialize(in_); + var d_ = await Call(10615798940090972439UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return r_; + } + } + + public class ThingSkeleton : Skeleton + { + public ThingSkeleton() + { + SetMethodTable(PassThrough, Intercept); + } + + public override ulong InterfaceId => 10615798940090972439UL; + Task PassThrough(DeserializerState d_, CancellationToken cancellationToken_) + { + return Impatient.MaybeTailCall(Impl.PassThrough(cancellationToken_), r_ => + { + var s_ = SerializerState.CreateForRpc(); + r_.serialize(s_); + return s_; + } + + ); + } + + Task Intercept(DeserializerState d_, CancellationToken cancellationToken_) + { + return Impatient.MaybeTailCall(Impl.Intercept(cancellationToken_), r_ => + { + var s_ = SerializerState.CreateForRpc(); + r_.serialize(s_); + return s_; + } + + ); + } + } + + public static class Thing + { + public class Params_passThrough : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + public class Params_intercept : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + } + + public class Result : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Text = reader.Text; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Text = Text; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string Text + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string Text => ctx.ReadText(0, ""); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public string Text + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + } + } + + public class Params_makeThing : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + public class Result_makeThing : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Thing = reader.Thing; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Thing = Thing; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.TestMembrane.IThing Thing + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnproto_test.Capnp.Test.TestMembrane.IThing Thing => ctx.ReadCap(0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public Capnproto_test.Capnp.Test.TestMembrane.IThing Thing + { + get => ReadCap(0); + set => LinkObject(0, value); + } + } + } + + public class Params_callPassThrough : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Thing = reader.Thing; + TailCall = reader.TailCall; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Thing = Thing; + writer.TailCall = TailCall; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.TestMembrane.IThing Thing + { + get; + set; + } + + public bool TailCall + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnproto_test.Capnp.Test.TestMembrane.IThing Thing => ctx.ReadCap(0); + public bool TailCall => ctx.ReadDataBool(0UL, false); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public Capnproto_test.Capnp.Test.TestMembrane.IThing Thing + { + get => ReadCap(0); + set => LinkObject(0, value); + } + + public bool TailCall + { + get => this.ReadDataBool(0UL, false); + set => this.WriteData(0UL, value, false); + } + } + } + + public class Params_callIntercept : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Thing = reader.Thing; + TailCall = reader.TailCall; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Thing = Thing; + writer.TailCall = TailCall; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.TestMembrane.IThing Thing + { + get; + set; + } + + public bool TailCall + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnproto_test.Capnp.Test.TestMembrane.IThing Thing => ctx.ReadCap(0); + public bool TailCall => ctx.ReadDataBool(0UL, false); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public Capnproto_test.Capnp.Test.TestMembrane.IThing Thing + { + get => ReadCap(0); + set => LinkObject(0, value); + } + + public bool TailCall + { + get => this.ReadDataBool(0UL, false); + set => this.WriteData(0UL, value, false); + } + } + } + + public class Params_loopback : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Thing = reader.Thing; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Thing = Thing; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.TestMembrane.IThing Thing + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnproto_test.Capnp.Test.TestMembrane.IThing Thing => ctx.ReadCap(0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public Capnproto_test.Capnp.Test.TestMembrane.IThing Thing + { + get => ReadCap(0); + set => LinkObject(0, value); + } + } + } + + public class Result_loopback : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Thing = reader.Thing; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Thing = Thing; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.TestMembrane.IThing Thing + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnproto_test.Capnp.Test.TestMembrane.IThing Thing => ctx.ReadCap(0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public Capnproto_test.Capnp.Test.TestMembrane.IThing Thing + { + get => ReadCap(0); + set => LinkObject(0, value); + } + } + } + + public class Params_waitForever : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + public class Result_waitForever : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + } + + public class TestContainMembrane : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Cap = reader.Cap; + List = reader.List; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Cap = Cap; + writer.List.Init(List); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.TestMembrane.IThing Cap + { + get; + set; + } + + public IReadOnlyList List + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnproto_test.Capnp.Test.TestMembrane.IThing Cap => ctx.ReadCap(0); + public IReadOnlyList List => ctx.ReadCapList(1); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 2); + } + + public Capnproto_test.Capnp.Test.TestMembrane.IThing Cap + { + get => ReadCap(0); + set => LinkObject(0, value); + } + + public ListOfCapsSerializer List + { + get => BuildPointer>(1); + set => Link(1, value); + } + } + } + + public class TestTransferCap : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + List = reader.List.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.List.Init(List, (_s1, _v1) => _v1?.serialize(_s1)); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public IReadOnlyList List + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public IReadOnlyList List => ctx.ReadList(0).Cast(Capnproto_test.Capnp.Test.TestTransferCap.Element.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public ListOfStructsSerializer List + { + get => BuildPointer>(0); + set => Link(0, value); + } + } + + public class Element : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Text = reader.Text; + Cap = reader.Cap; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Text = Text; + writer.Cap = Cap; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string Text + { + get; + set; + } + + public Capnproto_test.Capnp.Test.ITestInterface Cap + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string Text => ctx.ReadText(0, ""); + public Capnproto_test.Capnp.Test.ITestInterface Cap => ctx.ReadCap(1); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 2); + } + + public string Text + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + + public Capnproto_test.Capnp.Test.ITestInterface Cap + { + get => ReadCap(1); + set => LinkObject(1, value); + } + } + } + } + + [Proxy(typeof(TestKeywordMethodsProxy)), Skeleton(typeof(TestKeywordMethodsSkeleton))] + public interface ITestKeywordMethods : IDisposable + { + Task Delete(CancellationToken cancellationToken_ = default); + Task Class(CancellationToken cancellationToken_ = default); + Task Void(CancellationToken cancellationToken_ = default); + Task Return(CancellationToken cancellationToken_ = default); + } + + public class TestKeywordMethodsProxy : Proxy, ITestKeywordMethods + { + public async Task Delete(CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestKeywordMethods.Params_delete() + {}; + arg_.serialize(in_); + var d_ = await Call(11160837778045172988UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return; + } + + public async Task Class(CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestKeywordMethods.Params_class() + {}; + arg_.serialize(in_); + var d_ = await Call(11160837778045172988UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return; + } + + public async Task Void(CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestKeywordMethods.Params_void() + {}; + arg_.serialize(in_); + var d_ = await Call(11160837778045172988UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return; + } + + public async Task Return(CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestKeywordMethods.Params_return() + {}; + arg_.serialize(in_); + var d_ = await Call(11160837778045172988UL, 3, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return; + } + } + + public class TestKeywordMethodsSkeleton : Skeleton + { + public TestKeywordMethodsSkeleton() + { + SetMethodTable(Delete, Class, Void, Return); + } + + public override ulong InterfaceId => 11160837778045172988UL; + async Task Delete(DeserializerState d_, CancellationToken cancellationToken_) + { + await Impl.Delete(cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } + + async Task Class(DeserializerState d_, CancellationToken cancellationToken_) + { + await Impl.Class(cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } + + async Task Void(DeserializerState d_, CancellationToken cancellationToken_) + { + await Impl.Void(cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } + + async Task Return(DeserializerState d_, CancellationToken cancellationToken_) + { + await Impl.Return(cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } + } + + public static class TestKeywordMethods + { + public class Params_delete : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + public class Result_delete : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + public class Params_class : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + public class Result_class : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + public class Params_void : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + public class Result_void : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + public class Params_return : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + public class Result_return : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + } + + [Proxy(typeof(TestAuthenticatedBootstrapProxy<>)), Skeleton(typeof(TestAuthenticatedBootstrapSkeleton<>))] + public interface ITestAuthenticatedBootstrap : IDisposable + { + Task GetCallerId(CancellationToken cancellationToken_ = default); + } + + public class TestAuthenticatedBootstrapProxy : Proxy, ITestAuthenticatedBootstrap where TVatId : class + { + public Task GetCallerId(CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc.Params_getCallerId.WRITER>(); + var arg_ = new Capnproto_test.Capnp.Test.TestAuthenticatedBootstrap.Params_getCallerId() + {}; + arg_.serialize(in_); + return Impatient.MakePipelineAware(Call(16893789964317726925UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => + { + var r_ = CapnpSerializable.Create.Result_getCallerId>(d_); + return (r_.Caller); + } + + ); + } + } + + public class TestAuthenticatedBootstrapSkeleton : Skeleton> where TVatId : class + { + public TestAuthenticatedBootstrapSkeleton() + { + SetMethodTable(GetCallerId); + } + + public override ulong InterfaceId => 16893789964317726925UL; + Task GetCallerId(DeserializerState d_, CancellationToken cancellationToken_) + { + return Impatient.MaybeTailCall(Impl.GetCallerId(cancellationToken_), caller => + { + var s_ = SerializerState.CreateForRpc.Result_getCallerId.WRITER>(); + var r_ = new Capnproto_test.Capnp.Test.TestAuthenticatedBootstrap.Result_getCallerId{Caller = caller}; + r_.serialize(s_); + return s_; + } + + ); + } + } + + public static class TestAuthenticatedBootstrap + where TVatId : class + { + public class Params_getCallerId : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + public class Result_getCallerId : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Caller = CapnpSerializable.Create(reader.Caller); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Caller.SetObject(Caller); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public TVatId Caller + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public DeserializerState Caller => ctx.StructReadPointer(0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public DynamicSerializerState Caller + { + get => BuildPointer(0); + set => Link(0, value); + } + } + } + } + + public class TestSturdyRef : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + HostId = CapnpSerializable.Create(reader.HostId); + ObjectId = CapnpSerializable.Create(reader.ObjectId); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + HostId?.serialize(writer.HostId); + writer.ObjectId.SetObject(ObjectId); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.TestSturdyRefHostId HostId + { + get; + set; + } + + public AnyPointer ObjectId + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnproto_test.Capnp.Test.TestSturdyRefHostId.READER HostId => ctx.ReadStruct(0, Capnproto_test.Capnp.Test.TestSturdyRefHostId.READER.create); + public DeserializerState ObjectId => ctx.StructReadPointer(1); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 2); + } + + public Capnproto_test.Capnp.Test.TestSturdyRefHostId.WRITER HostId + { + get => BuildPointer(0); + set => Link(0, value); + } + + public DynamicSerializerState ObjectId + { + get => BuildPointer(1); + set => Link(1, value); + } + } + } + + public class TestSturdyRefHostId : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Host = reader.Host; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Host = Host; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public string Host + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public string Host => ctx.ReadText(0, ""); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public string Host + { + get => this.ReadText(0, ""); + set => this.WriteText(0, value, ""); + } + } + } + + public class TestSturdyRefObjectId : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + TheTag = reader.TheTag; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.TheTag = TheTag; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.TestSturdyRefObjectId.Tag TheTag + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public Capnproto_test.Capnp.Test.TestSturdyRefObjectId.Tag TheTag => (Capnproto_test.Capnp.Test.TestSturdyRefObjectId.Tag)ctx.ReadDataUShort(0UL, (ushort)0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 0); + } + + public Capnproto_test.Capnp.Test.TestSturdyRefObjectId.Tag TheTag + { + get => (Capnproto_test.Capnp.Test.TestSturdyRefObjectId.Tag)this.ReadDataUShort(0UL, (ushort)0); + set => this.WriteData(0UL, (ushort)value, (ushort)0); + } + } + + public enum Tag : ushort + { + testInterface, + testExtends, + testPipeline, + testTailCallee, + testTailCaller, + testMoreStuff + } + } + + public class TestProvisionId : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + public class TestRecipientId : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + public class TestThirdPartyCapId : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + public class TestJoinResult : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + public class TestNameAnnotation : ICapnpSerializable + { + public enum WHICH : ushort + { + BadFieldName = 0, + Bar = 1, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.BadFieldName: + BadFieldName = reader.BadFieldName; + break; + case WHICH.Bar: + Bar = reader.Bar; + break; + } + + AnotherBadFieldName = reader.AnotherBadFieldName; + BadlyNamedUnion = CapnpSerializable.Create(reader.BadlyNamedUnion); + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.BadFieldName: + _content = false; + break; + case WHICH.Bar: + _content = 0; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.BadFieldName: + writer.BadFieldName = BadFieldName.Value; + break; + case WHICH.Bar: + writer.Bar = Bar.Value; + break; + } + + writer.AnotherBadFieldName = AnotherBadFieldName; + BadlyNamedUnion?.serialize(writer.BadlyNamedUnion); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public bool? BadFieldName + { + get => _which == WHICH.BadFieldName ? (bool? )_content : null; + set + { + _which = WHICH.BadFieldName; + _content = value; + } + } + + public sbyte? Bar + { + get => _which == WHICH.Bar ? (sbyte? )_content : null; + set + { + _which = WHICH.Bar; + _content = value; + } + } + + public Capnproto_test.Capnp.Test.TestNameAnnotation.BadlyNamedEnum AnotherBadFieldName + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestNameAnnotation.@badlyNamedUnion BadlyNamedUnion + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(16U, (ushort)0); + public bool BadFieldName => which == WHICH.BadFieldName ? ctx.ReadDataBool(0UL, false) : default; + public sbyte Bar => which == WHICH.Bar ? ctx.ReadDataSByte(0UL, (sbyte)0) : default; + public Capnproto_test.Capnp.Test.TestNameAnnotation.BadlyNamedEnum AnotherBadFieldName => (Capnproto_test.Capnp.Test.TestNameAnnotation.BadlyNamedEnum)ctx.ReadDataUShort(32UL, (ushort)0); + public @badlyNamedUnion.READER BadlyNamedUnion => new @badlyNamedUnion.READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(16U, (ushort)0); + set => this.WriteData(16U, (ushort)value, (ushort)0); + } + + public bool BadFieldName + { + get => which == WHICH.BadFieldName ? this.ReadDataBool(0UL, false) : default; + set => this.WriteData(0UL, value, false); + } + + public sbyte Bar + { + get => which == WHICH.Bar ? this.ReadDataSByte(0UL, (sbyte)0) : default; + set => this.WriteData(0UL, value, (sbyte)0); + } + + public Capnproto_test.Capnp.Test.TestNameAnnotation.BadlyNamedEnum AnotherBadFieldName + { + get => (Capnproto_test.Capnp.Test.TestNameAnnotation.BadlyNamedEnum)this.ReadDataUShort(32UL, (ushort)0); + set => this.WriteData(32UL, (ushort)value, (ushort)0); + } + + public @badlyNamedUnion.WRITER BadlyNamedUnion + { + get => Rewrap<@badlyNamedUnion.WRITER>(); + } + } + + public class @badlyNamedUnion : ICapnpSerializable + { + public enum WHICH : ushort + { + BadlyNamedGroup = 0, + Baz = 1, + undefined = 65535 + } + + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + switch (reader.which) + { + case WHICH.BadlyNamedGroup: + BadlyNamedGroup = CapnpSerializable.Create(reader.BadlyNamedGroup); + break; + case WHICH.Baz: + Baz = CapnpSerializable.Create(reader.Baz); + break; + } + + applyDefaults(); + } + + private WHICH _which = WHICH.undefined; + private object _content; + public WHICH which + { + get => _which; + set + { + if (value == _which) + return; + _which = value; + switch (value) + { + case WHICH.BadlyNamedGroup: + _content = null; + break; + case WHICH.Baz: + _content = null; + break; + } + } + } + + public void serialize(WRITER writer) + { + writer.which = which; + switch (which) + { + case WHICH.BadlyNamedGroup: + BadlyNamedGroup?.serialize(writer.BadlyNamedGroup); + break; + case WHICH.Baz: + Baz?.serialize(writer.Baz); + break; + } + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public Capnproto_test.Capnp.Test.TestNameAnnotation.@badlyNamedUnion.@badlyNamedGroup BadlyNamedGroup + { + get => _which == WHICH.BadlyNamedGroup ? (Capnproto_test.Capnp.Test.TestNameAnnotation.@badlyNamedUnion.@badlyNamedGroup)_content : null; + set + { + _which = WHICH.BadlyNamedGroup; + _content = value; + } + } + + public Capnproto_test.Capnp.Test.TestNameAnnotation.NestedStruct Baz + { + get => _which == WHICH.Baz ? (Capnproto_test.Capnp.Test.TestNameAnnotation.NestedStruct)_content : null; + set + { + _which = WHICH.Baz; + _content = value; + } + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public WHICH which => (WHICH)ctx.ReadDataUShort(48U, (ushort)0); + public @badlyNamedGroup.READER BadlyNamedGroup => which == WHICH.BadlyNamedGroup ? new @badlyNamedGroup.READER(ctx) : default; + public Capnproto_test.Capnp.Test.TestNameAnnotation.NestedStruct.READER Baz => which == WHICH.Baz ? ctx.ReadStruct(0, Capnproto_test.Capnp.Test.TestNameAnnotation.NestedStruct.READER.create) : default; + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + + public WHICH which + { + get => (WHICH)this.ReadDataUShort(48U, (ushort)0); + set => this.WriteData(48U, (ushort)value, (ushort)0); + } + + public @badlyNamedGroup.WRITER BadlyNamedGroup + { + get => which == WHICH.BadlyNamedGroup ? Rewrap<@badlyNamedGroup.WRITER>() : default; + } + + public Capnproto_test.Capnp.Test.TestNameAnnotation.NestedStruct.WRITER Baz + { + get => which == WHICH.Baz ? BuildPointer(0) : default; + set => Link(0, value); + } + } + + public class @badlyNamedGroup : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + } + } + } + } + + public enum BadlyNamedEnum : ushort + { + foo, + bar, + baz + } + + public class NestedStruct : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + BadNestedFieldName = reader.BadNestedFieldName; + AnotherBadNestedFieldName = CapnpSerializable.Create(reader.AnotherBadNestedFieldName); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.BadNestedFieldName = BadNestedFieldName; + AnotherBadNestedFieldName?.serialize(writer.AnotherBadNestedFieldName); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public bool BadNestedFieldName + { + get; + set; + } + + public Capnproto_test.Capnp.Test.TestNameAnnotation.NestedStruct AnotherBadNestedFieldName + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public bool BadNestedFieldName => ctx.ReadDataBool(0UL, false); + public Capnproto_test.Capnp.Test.TestNameAnnotation.NestedStruct.READER AnotherBadNestedFieldName => ctx.ReadStruct(0, Capnproto_test.Capnp.Test.TestNameAnnotation.NestedStruct.READER.create); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 1); + } + + public bool BadNestedFieldName + { + get => this.ReadDataBool(0UL, false); + set => this.WriteData(0UL, value, false); + } + + public Capnproto_test.Capnp.Test.TestNameAnnotation.NestedStruct.WRITER AnotherBadNestedFieldName + { + get => BuildPointer(0); + set => Link(0, value); + } + } + + public enum DeeplyNestedEnum : ushort + { + quux, + corge, + grault + } + } + } + + [Proxy(typeof(TestNameAnnotationInterfaceProxy)), Skeleton(typeof(TestNameAnnotationInterfaceSkeleton))] + public interface ITestNameAnnotationInterface : IDisposable + { + Task BadlyNamedMethod(byte badlyNamedParam, CancellationToken cancellationToken_ = default); + } + + public class TestNameAnnotationInterfaceProxy : Proxy, ITestNameAnnotationInterface + { + public async Task BadlyNamedMethod(byte badlyNamedParam, CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestNameAnnotationInterface.Params_badlyNamedMethod() + {BadlyNamedParam = badlyNamedParam}; + arg_.serialize(in_); + var d_ = await Call(15065286897585459595UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return; + } + } + + public class TestNameAnnotationInterfaceSkeleton : Skeleton + { + public TestNameAnnotationInterfaceSkeleton() + { + SetMethodTable(BadlyNamedMethod); + } + + public override ulong InterfaceId => 15065286897585459595UL; + async Task BadlyNamedMethod(DeserializerState d_, CancellationToken cancellationToken_) + { + var in_ = CapnpSerializable.Create(d_); + await Impl.BadlyNamedMethod(in_.BadlyNamedParam, cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } + } + + public static class TestNameAnnotationInterface + { + public class Params_badlyNamedMethod : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + BadlyNamedParam = reader.BadlyNamedParam; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.BadlyNamedParam = BadlyNamedParam; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public byte BadlyNamedParam + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public byte BadlyNamedParam => ctx.ReadDataByte(0UL, (byte)0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 0); + } + + public byte BadlyNamedParam + { + get => this.ReadDataByte(0UL, (byte)0); + set => this.WriteData(0UL, value, (byte)0); + } + } + } + + public class Result_badlyNamedMethod : ICapnpSerializable + { + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + } +} \ No newline at end of file From b01c90111f48d235bca5714b42b6b5fbe16c733c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6llner?= Date: Wed, 2 Oct 2019 15:53:47 +0200 Subject: [PATCH 16/22] Add MsBuildGenerationTest to CI --- .gitignore | 2 +- MsBuildGenerationTest/MsBuildGenerationTest.csproj | 6 ++++-- MsBuildGenerationTest/MsBuildGenerationTest.sln | 5 ++++- appveyor.yml | 2 ++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 4f734c3..64fa334 100644 --- a/.gitignore +++ b/.gitignore @@ -334,5 +334,5 @@ ASALocalRun/ .vscode/launch.json # Capnp code behind -.capnp.cs +*.capnp.cs /globalPackages diff --git a/MsBuildGenerationTest/MsBuildGenerationTest.csproj b/MsBuildGenerationTest/MsBuildGenerationTest.csproj index 58cf166..93163eb 100644 --- a/MsBuildGenerationTest/MsBuildGenerationTest.csproj +++ b/MsBuildGenerationTest/MsBuildGenerationTest.csproj @@ -3,6 +3,8 @@ Exe netcoreapp2.2 + 1.0-local + Debug;Release @@ -10,8 +12,8 @@ - - + + diff --git a/MsBuildGenerationTest/MsBuildGenerationTest.sln b/MsBuildGenerationTest/MsBuildGenerationTest.sln index bd2ebd1..0545a55 100644 --- a/MsBuildGenerationTest/MsBuildGenerationTest.sln +++ b/MsBuildGenerationTest/MsBuildGenerationTest.sln @@ -3,14 +3,17 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.29306.81 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MsBuildGenerationTest", "MsBuildGenerationTest.csproj", "{D2CFBABF-7028-4761-9B24-6054008F41A0}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MsBuildGenerationTest", "MsBuildGenerationTest.csproj", "{D2CFBABF-7028-4761-9B24-6054008F41A0}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution + AppVeyor|Any CPU = AppVeyor|Any CPU Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D2CFBABF-7028-4761-9B24-6054008F41A0}.AppVeyor|Any CPU.ActiveCfg = Release|Any CPU + {D2CFBABF-7028-4761-9B24-6054008F41A0}.AppVeyor|Any CPU.Build.0 = Release|Any CPU {D2CFBABF-7028-4761-9B24-6054008F41A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D2CFBABF-7028-4761-9B24-6054008F41A0}.Debug|Any CPU.Build.0 = Debug|Any CPU {D2CFBABF-7028-4761-9B24-6054008F41A0}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/appveyor.yml b/appveyor.yml index 82c87b2..d32786c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -74,6 +74,8 @@ test_script: - cmd: notinstalled-test - cmd: cd %APPVEYOR_BUILD_FOLDER% - cmd: vstest.console /logger:Appveyor /inIsolation CapnpC.CSharp.MsBuild.Generation.Tests\bin\Release\netcoreapp2.2\CapnpC.CSharp.MsBuild.Generation.Tests.dll + - cmd: dotnet restore ./MsBuildGenerationTest/MsBuildGenerationTest.csproj --verbosity m + - cmd: msbuild ./MsBuildGenerationTest/MsBuildGenerationTest.sln /p:Configuration="Debug" - cmd: vstest.console /logger:Appveyor /inIsolation Capnp.Net.Runtime.Tests\bin\Debug\netcoreapp2.2\Capnp.Net.Runtime.Tests.Std20.dll - cmd: vstest.console /logger:Appveyor /inIsolation Capnp.Net.Runtime.Tests\bin\Release\netcoreapp2.2\Capnp.Net.Runtime.Tests.Std20.dll - cmd: vstest.console /logger:Appveyor /inIsolation Capnp.Net.Runtime.Tests.Core21\bin\Debug\netcoreapp2.2\Capnp.Net.Runtime.Tests.Core21.dll From 98b4b6e355e1689e89f8e954f4cc35cbb6fb9a75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6llner?= Date: Wed, 2 Oct 2019 16:06:12 +0200 Subject: [PATCH 17/22] Added code to MsBuildGenerationTest --- MsBuildGenerationTest/Program.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/MsBuildGenerationTest/Program.cs b/MsBuildGenerationTest/Program.cs index b07986b..bbbb50b 100644 --- a/MsBuildGenerationTest/Program.cs +++ b/MsBuildGenerationTest/Program.cs @@ -6,7 +6,16 @@ namespace MsBuildGenerationTest { static void Main(string[] args) { - Console.WriteLine("Hello World!"); + // Instantiate some generated classes ensures that they are really present. + // Note that this code is not supposed to test runtime behavior, we have plenty of other test cases for that purpose. + + var vatId = new Capnp.Rpc.Twoparty.VatId(); + var msg = new Capnp.Rpc.Message(); + var node = new Capnp.Schema.Node(); + var x = Capnproto_test.Capnp.Test.TestEnum.garply; + var imp = new CapnpGen.TestImport(); + var imp2 = new CapnpGen.TestImport2(); + var book = new CapnpGen.AddressBook(); } } } From a32aee78626281931b3ef2120a129013660b305b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6llner?= Date: Thu, 3 Oct 2019 18:35:24 +0200 Subject: [PATCH 18/22] CI fix --- MsBuildGenerationTest/MsBuildGenerationTest.csproj | 5 +++-- appveyor.yml | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/MsBuildGenerationTest/MsBuildGenerationTest.csproj b/MsBuildGenerationTest/MsBuildGenerationTest.csproj index 93163eb..112ddd9 100644 --- a/MsBuildGenerationTest/MsBuildGenerationTest.csproj +++ b/MsBuildGenerationTest/MsBuildGenerationTest.csproj @@ -5,6 +5,7 @@ netcoreapp2.2 1.0-local Debug;Release + $(Version)* @@ -12,8 +13,8 @@ - - + + diff --git a/appveyor.yml b/appveyor.yml index d32786c..466f512 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -75,7 +75,7 @@ test_script: - cmd: cd %APPVEYOR_BUILD_FOLDER% - cmd: vstest.console /logger:Appveyor /inIsolation CapnpC.CSharp.MsBuild.Generation.Tests\bin\Release\netcoreapp2.2\CapnpC.CSharp.MsBuild.Generation.Tests.dll - cmd: dotnet restore ./MsBuildGenerationTest/MsBuildGenerationTest.csproj --verbosity m - - cmd: msbuild ./MsBuildGenerationTest/MsBuildGenerationTest.sln /p:Configuration="Debug" + - cmd: msbuild ./MsBuildGenerationTest/MsBuildGenerationTest.sln /p:Configuration="Debug" /p:PackageReferenceVersion="{version}" - cmd: vstest.console /logger:Appveyor /inIsolation Capnp.Net.Runtime.Tests\bin\Debug\netcoreapp2.2\Capnp.Net.Runtime.Tests.Std20.dll - cmd: vstest.console /logger:Appveyor /inIsolation Capnp.Net.Runtime.Tests\bin\Release\netcoreapp2.2\Capnp.Net.Runtime.Tests.Std20.dll - cmd: vstest.console /logger:Appveyor /inIsolation Capnp.Net.Runtime.Tests.Core21\bin\Debug\netcoreapp2.2\Capnp.Net.Runtime.Tests.Core21.dll From f54b1532a806f368d8c88ae1d0e48ed5c1da006b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6llner?= Date: Thu, 3 Oct 2019 19:04:30 +0200 Subject: [PATCH 19/22] CI fix II --- MsBuildGenerationTest/MsBuildGenerationTest.csproj | 2 +- appveyor.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/MsBuildGenerationTest/MsBuildGenerationTest.csproj b/MsBuildGenerationTest/MsBuildGenerationTest.csproj index 112ddd9..6b1a4a8 100644 --- a/MsBuildGenerationTest/MsBuildGenerationTest.csproj +++ b/MsBuildGenerationTest/MsBuildGenerationTest.csproj @@ -14,7 +14,7 @@ - + diff --git a/appveyor.yml b/appveyor.yml index 466f512..003fa7b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -74,7 +74,7 @@ test_script: - cmd: notinstalled-test - cmd: cd %APPVEYOR_BUILD_FOLDER% - cmd: vstest.console /logger:Appveyor /inIsolation CapnpC.CSharp.MsBuild.Generation.Tests\bin\Release\netcoreapp2.2\CapnpC.CSharp.MsBuild.Generation.Tests.dll - - cmd: dotnet restore ./MsBuildGenerationTest/MsBuildGenerationTest.csproj --verbosity m + - cmd: msbuild -t:restore ./MsBuildGenerationTest/MsBuildGenerationTest.csproj /p:Configuration="Debug" /p:PackageReferenceVersion="{version}" - cmd: msbuild ./MsBuildGenerationTest/MsBuildGenerationTest.sln /p:Configuration="Debug" /p:PackageReferenceVersion="{version}" - cmd: vstest.console /logger:Appveyor /inIsolation Capnp.Net.Runtime.Tests\bin\Debug\netcoreapp2.2\Capnp.Net.Runtime.Tests.Std20.dll - cmd: vstest.console /logger:Appveyor /inIsolation Capnp.Net.Runtime.Tests\bin\Release\netcoreapp2.2\Capnp.Net.Runtime.Tests.Std20.dll From 7a83aec7ca60d9785f3d47872e7d6680cb6f6686 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6llner?= Date: Thu, 3 Oct 2019 19:17:13 +0200 Subject: [PATCH 20/22] CI fix III --- appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 003fa7b..e5afd8b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -74,8 +74,8 @@ test_script: - cmd: notinstalled-test - cmd: cd %APPVEYOR_BUILD_FOLDER% - cmd: vstest.console /logger:Appveyor /inIsolation CapnpC.CSharp.MsBuild.Generation.Tests\bin\Release\netcoreapp2.2\CapnpC.CSharp.MsBuild.Generation.Tests.dll - - cmd: msbuild -t:restore ./MsBuildGenerationTest/MsBuildGenerationTest.csproj /p:Configuration="Debug" /p:PackageReferenceVersion="{version}" - - cmd: msbuild ./MsBuildGenerationTest/MsBuildGenerationTest.sln /p:Configuration="Debug" /p:PackageReferenceVersion="{version}" + - cmd: msbuild -t:restore ./MsBuildGenerationTest/MsBuildGenerationTest.csproj /p:Configuration="Debug" /p:PackageReferenceVersion='{version}' + - cmd: msbuild ./MsBuildGenerationTest/MsBuildGenerationTest.sln /p:Configuration="Debug" /p:PackageReferenceVersion='{version}' - cmd: vstest.console /logger:Appveyor /inIsolation Capnp.Net.Runtime.Tests\bin\Debug\netcoreapp2.2\Capnp.Net.Runtime.Tests.Std20.dll - cmd: vstest.console /logger:Appveyor /inIsolation Capnp.Net.Runtime.Tests\bin\Release\netcoreapp2.2\Capnp.Net.Runtime.Tests.Std20.dll - cmd: vstest.console /logger:Appveyor /inIsolation Capnp.Net.Runtime.Tests.Core21\bin\Debug\netcoreapp2.2\Capnp.Net.Runtime.Tests.Core21.dll From 468bb9e06797651d960f95724a1dade9b0ad9ced Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6llner?= Date: Thu, 3 Oct 2019 19:45:51 +0200 Subject: [PATCH 21/22] CI fix IV --- appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index e5afd8b..40daed4 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -74,8 +74,8 @@ test_script: - cmd: notinstalled-test - cmd: cd %APPVEYOR_BUILD_FOLDER% - cmd: vstest.console /logger:Appveyor /inIsolation CapnpC.CSharp.MsBuild.Generation.Tests\bin\Release\netcoreapp2.2\CapnpC.CSharp.MsBuild.Generation.Tests.dll - - cmd: msbuild -t:restore ./MsBuildGenerationTest/MsBuildGenerationTest.csproj /p:Configuration="Debug" /p:PackageReferenceVersion='{version}' - - cmd: msbuild ./MsBuildGenerationTest/MsBuildGenerationTest.sln /p:Configuration="Debug" /p:PackageReferenceVersion='{version}' + - cmd: msbuild -t:restore ./MsBuildGenerationTest/MsBuildGenerationTest.csproj /p:Configuration="Debug" /p:PackageReferenceVersion="$(appveyor_build_version)" + - cmd: msbuild ./MsBuildGenerationTest/MsBuildGenerationTest.sln /p:Configuration="Debug" /p:PackageReferenceVersion="$(appveyor_build_version)" - cmd: vstest.console /logger:Appveyor /inIsolation Capnp.Net.Runtime.Tests\bin\Debug\netcoreapp2.2\Capnp.Net.Runtime.Tests.Std20.dll - cmd: vstest.console /logger:Appveyor /inIsolation Capnp.Net.Runtime.Tests\bin\Release\netcoreapp2.2\Capnp.Net.Runtime.Tests.Std20.dll - cmd: vstest.console /logger:Appveyor /inIsolation Capnp.Net.Runtime.Tests.Core21\bin\Debug\netcoreapp2.2\Capnp.Net.Runtime.Tests.Core21.dll From 7d4e1b6bd70dad0adc9ed93dd84b070caff17271 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6llner?= Date: Thu, 3 Oct 2019 20:29:31 +0200 Subject: [PATCH 22/22] CI fix V --- appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 40daed4..73a0e42 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -74,8 +74,8 @@ test_script: - cmd: notinstalled-test - cmd: cd %APPVEYOR_BUILD_FOLDER% - cmd: vstest.console /logger:Appveyor /inIsolation CapnpC.CSharp.MsBuild.Generation.Tests\bin\Release\netcoreapp2.2\CapnpC.CSharp.MsBuild.Generation.Tests.dll - - cmd: msbuild -t:restore ./MsBuildGenerationTest/MsBuildGenerationTest.csproj /p:Configuration="Debug" /p:PackageReferenceVersion="$(appveyor_build_version)" - - cmd: msbuild ./MsBuildGenerationTest/MsBuildGenerationTest.sln /p:Configuration="Debug" /p:PackageReferenceVersion="$(appveyor_build_version)" + - cmd: msbuild -t:restore ./MsBuildGenerationTest/MsBuildGenerationTest.csproj /p:Configuration="Debug" /p:PackageReferenceVersion="%APPVEYOR_BUILD_VERSION%" + - cmd: msbuild ./MsBuildGenerationTest/MsBuildGenerationTest.sln /p:Configuration="Debug" /p:PackageReferenceVersion="%APPVEYOR_BUILD_VERSION%" - cmd: vstest.console /logger:Appveyor /inIsolation Capnp.Net.Runtime.Tests\bin\Debug\netcoreapp2.2\Capnp.Net.Runtime.Tests.Std20.dll - cmd: vstest.console /logger:Appveyor /inIsolation Capnp.Net.Runtime.Tests\bin\Release\netcoreapp2.2\Capnp.Net.Runtime.Tests.Std20.dll - cmd: vstest.console /logger:Appveyor /inIsolation Capnp.Net.Runtime.Tests.Core21\bin\Debug\netcoreapp2.2\Capnp.Net.Runtime.Tests.Core21.dll