diff --git a/Compiler/CommandLineFlags.cs b/Compiler/CommandLineFlags.cs index 40b23d3f..2b29aa73 100644 --- a/Compiler/CommandLineFlags.cs +++ b/Compiler/CommandLineFlags.cs @@ -100,7 +100,7 @@ public static CommandLineFlag GetFlag(this List flags, string f } /// - /// Represents a parsed command-line flag and it's values. + /// Represents a parsed command-line flag and its values. /// public class CommandLineFlag { @@ -153,20 +153,20 @@ public class CommandLineFlags "--config bebop.json")] public string? ConfigFile { get; private set; } - [CommandLineFlag("cs", "Generate C# source code to the specified file", "--cs ./cowboy/bebop/HelloWorld.cs", + [CommandLineFlag("cs", "Generate C# source code to the specified file", "--cs ./my/output/HelloWorld.cs", true)] public string? CSharpOutput { get; private set; } [CommandLineFlag("ts", "Generate TypeScript source code to the specified file", - "--ts ./cowboy/bebop/HelloWorld.ts", true)] + "--ts ./my/output/HelloWorld.ts", true)] public string? TypeScriptOutput { get; private set; } [CommandLineFlag("dart", "Generate Dart source code to the specified file", - "--dart ./cowboy/bebop/HelloWorld.dart", true)] + "--dart ./my/output/HelloWorld.dart", true)] public string? DartOutput { get; private set; } [CommandLineFlag("cpp", "Generate C++ source code to the specified file", - "--cpp ./cowboy/bebop/HelloWorld.cpp", true)] + "--cpp ./my/output/HelloWorld.hpp", true)] public string? CPlusPlusOutput { get; private set; } [CommandLineFlag("namespace", "When this option is specified generated code will use namespaces", @@ -294,7 +294,7 @@ private static List GetFlags(string[] args) } /// - /// Attempts to find the flag and parse it's value. + /// Attempts to find the flag and parse its value. /// /// The command-line arguments to sort through /// @@ -383,15 +383,29 @@ public static bool TryParse(string[] args, out CommandLineFlags flagStore, out s ? parsedFlags.GetFlag("config").GetValue() : FindBebopConfig(); // if bebop.json exist load it. the values in the JSON file are written to the store. - if (!string.IsNullOrWhiteSpace(bebopConfig) && new FileInfo(bebopConfig).Exists) + if (!string.IsNullOrWhiteSpace(bebopConfig)) { - if (!TryParseConfig(flagStore, bebopConfig)) + if (new FileInfo(bebopConfig).Exists) { - errorMessage = $"Failed to parse bebop configuration file at '{bebopConfig}'"; + if (!TryParseConfig(flagStore, bebopConfig)) + { + errorMessage = $"Failed to parse bebop configuration file at '{bebopConfig}'"; + return false; + } + } + else + { + errorMessage = $"Bebop configuration file not found at '{bebopConfig}'"; return false; } } + var validFlagNames = props.Select(p => p.Attribute.Name).ToHashSet(); + if (parsedFlags.Find(x => !validFlagNames.Contains(x.Name)) is CommandLineFlag unrecognizedFlag) + { + errorMessage = $"Unrecognized flag: --{unrecognizedFlag.Name}"; + return false; + } // parse all present command-line flags // any flag on the command-line that was also present in bebop.json will be overwritten. diff --git a/Compiler/Compiler.csproj b/Compiler/Compiler.csproj index 02c4b06b..6c6425d9 100644 --- a/Compiler/Compiler.csproj +++ b/Compiler/Compiler.csproj @@ -89,5 +89,8 @@ + + + \ No newline at end of file diff --git a/Core/Exceptions/Exceptions.cs b/Core/Exceptions/Exceptions.cs index 0e9f8c56..c74457d7 100644 --- a/Core/Exceptions/Exceptions.cs +++ b/Core/Exceptions/Exceptions.cs @@ -117,14 +117,22 @@ public InvalidMapKeyTypeException(TypeBase type) class DuplicateFieldException : SpanException { public DuplicateFieldException(IField field, Definition definition) - : base($"The type '{definition.Name}' already contains a definition for '{field.Name}'", field.Span, 112) { } + : base($"The type '{definition.Name}' already contains a definition for '{field.Name}'.", field.Span, 112) { } } [Serializable] class InvalidUnionBranchException : SpanException { public InvalidUnionBranchException(Definition definition) - : base($"The definition '{definition.Name}' cannot be used as a union branch. Valid union branches are messages, structs, or unions.", definition.Span, 108) + : base($"The definition '{definition.Name}' cannot be used as a union branch. Valid union branches are messages, structs, or unions.", definition.Span, 113) + { } + } + + [Serializable] + class DuplicateUnionDiscriminatorException : SpanException + { + public DuplicateUnionDiscriminatorException(Token discriminator, string unionName) + : base($"The discriminator index {discriminator.Lexeme} was used more than once in union '{unionName}'.", discriminator.Span, 114) { } } diff --git a/Core/Generators/CPlusPlus/CPlusPlusGenerator.cs b/Core/Generators/CPlusPlus/CPlusPlusGenerator.cs index 4ff79d74..0bf56ed9 100644 --- a/Core/Generators/CPlusPlus/CPlusPlusGenerator.cs +++ b/Core/Generators/CPlusPlus/CPlusPlusGenerator.cs @@ -19,7 +19,7 @@ private string FormatDocumentation(string documentation, int spaces) { var builder = new IndentedStringBuilder(); builder.Indent(spaces); - foreach (var line in documentation.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None)) + foreach (var line in documentation.GetLines()) { builder.AppendLine($"/// {line}"); } @@ -211,7 +211,7 @@ private string CompileDecodeUnion(UnionDefinition definition) var i = branch.Discriminator - 1; builder.AppendLine($" case {branch.Discriminator}:"); builder.AppendLine($" target.variant.emplace<{i}>();"); - builder.AppendLine($" {branch.Definition.Name}::decodeInto(std::get<{i}>(target.variant), reader);"); + builder.AppendLine($" {branch.Definition.Name}::decodeInto(reader, std::get<{i}>(target.variant));"); builder.AppendLine(" break;"); } builder.AppendLine(" default:"); @@ -271,7 +271,7 @@ private string CompileDecodeField(TypeBase type, string target, int depth = 0, i }, DefinedType dt when Schema.Definitions[dt.Name] is EnumDefinition => $"{target} = static_cast<{dt.Name}>(reader.readUint32());", - DefinedType dt => $"{dt.Name}::decodeInto({target}, reader);", + DefinedType dt => $"{dt.Name}::decodeInto(reader, {target});", _ => throw new InvalidOperationException($"CompileDecodeField: {type}") }; } @@ -299,8 +299,8 @@ private string TypeName(in TypeBase type) BaseType.Float32 => "float", BaseType.Float64 => "double", BaseType.String => "std::string", - BaseType.Guid => "bebop::Guid", - BaseType.Date => "bebop::TickDuration", + BaseType.Guid => "::bebop::Guid", + BaseType.Date => "::bebop::TickDuration", _ => throw new ArgumentOutOfRangeException(st.BaseType.ToString()) }; // case ArrayType at when at.IsBytes(): @@ -407,24 +407,27 @@ public override string Compile() throw new InvalidOperationException($"unsupported definition {td}"); } - builder.AppendLine($" static std::unique_ptr> encode(const {td.Name}& message) {{"); - builder.AppendLine(" bebop::BebopWriter writer{};"); + builder.AppendLine($" static void encodeInto(const {td.Name}& message, std::vector& targetBuffer) {{"); + builder.AppendLine(" ::bebop::Writer writer{targetBuffer};"); builder.AppendLine($" {td.Name}::encodeInto(message, writer);"); - builder.AppendLine(" return writer.buffer();"); builder.AppendLine(" }"); builder.AppendLine(""); - builder.AppendLine($" static void encodeInto(const {td.Name}& message, bebop::BebopWriter& writer) {{"); + builder.AppendLine($" static void encodeInto(const {td.Name}& message, ::bebop::Writer& writer) {{"); builder.Append(CompileEncode(td)); builder.AppendLine(" }"); builder.AppendLine(""); - builder.AppendLine($" static {td.Name} decode(const uint8_t *buffer) {{"); + builder.AppendLine($" static {td.Name} decode(const uint8_t* sourceBuffer) {{"); builder.AppendLine($" {td.Name} result;"); - builder.AppendLine(" bebop::BebopReader reader{buffer};"); - builder.AppendLine($" {td.Name}::decodeInto(result, reader);"); + builder.AppendLine($" {td.Name}::decodeInto(sourceBuffer, result);"); builder.AppendLine($" return result;"); builder.AppendLine(" }"); builder.AppendLine(""); - builder.AppendLine($" static void decodeInto({td.Name}& target, bebop::BebopReader& reader) {{"); + builder.AppendLine($" static void decodeInto(const uint8_t* sourceBuffer, {td.Name}& target) {{"); + builder.AppendLine(" ::bebop::Reader reader{sourceBuffer};"); + builder.AppendLine($" {td.Name}::decodeInto(reader, target);"); + builder.AppendLine(" }"); + builder.AppendLine(""); + builder.AppendLine($" static void decodeInto(::bebop::Reader& reader, {td.Name}& target) {{"); builder.Append(CompileDecode(td)); builder.AppendLine(" }"); builder.AppendLine("};"); @@ -444,7 +447,13 @@ public override string Compile() public override void WriteAuxiliaryFiles(string outputPath) { - // There is nothing to do here. + var assembly = Assembly.GetEntryAssembly()!; + var runtime = assembly.GetManifestResourceNames()!.FirstOrDefault(n => n.Contains("bebop.hpp"))!; + + using Stream stream = assembly.GetManifestResourceStream(runtime)!; + using StreamReader reader = new StreamReader(stream); + string result = reader.ReadToEnd(); + File.WriteAllText(Path.Join(outputPath, "bebop.hpp"), result); } } } diff --git a/Core/Generators/CSharp/CSharpGenerator.cs b/Core/Generators/CSharp/CSharpGenerator.cs index fb358482..ebbefef4 100644 --- a/Core/Generators/CSharp/CSharpGenerator.cs +++ b/Core/Generators/CSharp/CSharpGenerator.cs @@ -10,10 +10,18 @@ namespace Core.Generators.CSharp public class CSharpGenerator : Generator { private const int indentStep = 2; - private const string HotPath = "[System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)]"; - private static readonly string GeneratedAttribute = $"[System.CodeDom.Compiler.GeneratedCode(\"{ReservedWords.CompilerName}\", \"{ReservedWords.CompilerVersion}\")]"; - - + private const string DisallowNullAttribute = "[global::System.Diagnostics.CodeAnalysis.NotNull, global::System.Diagnostics.CodeAnalysis.DisallowNull]"; + private const string AllowNullAttribute = "[global::System.Diagnostics.CodeAnalysis.MaybeNull, global::System.Diagnostics.CodeAnalysis.AllowNull]"; + private const string HotPath = "[global::System.Runtime.CompilerServices.MethodImpl(global::Bebop.Runtime.BebopConstants.HotPath)]"; + private static readonly string GeneratedAttribute = $"[global::System.CodeDom.Compiler.GeneratedCode(\"{ReservedWords.CompilerName}\", \"{ReservedWords.CompilerVersion}\")]"; + private const string Warning = "/// DO NOT CALL THIS METHOD DIRECTLY!"; + private const string NonUserCodeAttribute = "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"; + private const string BrowsableAttribute = "[global::System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]"; + private const string BebopWriter = "global::Bebop.Runtime.BebopWriter"; + private const string BebopReader = "global::Bebop.Runtime.BebopReader"; + private const string BebopException = "global::Bebop.Exceptions.BebopRuntimeException"; + private const string ImmutableArrayType = "global::System.Collections.Immutable.ImmutableArray"; + private const string ImmutableByteArrayType = "global::System.Collections.Immutable.ImmutableArray"; private static readonly string WarningBlock = $@"//------------------------------------------------------------------------------ // // This code was generated by a tool. @@ -25,18 +33,33 @@ public class CSharpGenerator : Generator //------------------------------------------------------------------------------"; - private static readonly string[] DecodeBufferTypes = {"byte[]", "System.ReadOnlySpan", "System.ReadOnlyMemory", "System.ArraySegment", "ImmutableArray"}; + private static readonly string[] DecodeBufferTypes = {"byte[]", "global::System.ReadOnlySpan", "global::System.ReadOnlyMemory", "global::System.ArraySegment", ImmutableByteArrayType}; public CSharpGenerator(ISchema schema) : base(schema) { } + private string FormatConstructorDocumentation(FieldsDefinition fieldsDefinition) + { + var builder = new IndentedStringBuilder(); + builder.AppendLine("/// "); + foreach (var line in fieldsDefinition.Documentation.GetLines()) + { + builder.AppendLine($"/// {line}"); + } + builder.AppendLine("/// "); + foreach (var field in fieldsDefinition.Fields) + { + builder.AppendLine($"/// {field.Documentation}"); + } + return builder.ToString(); + } private string FormatDocumentation(string documentation, int spaces) { var builder = new IndentedStringBuilder(spaces); builder.AppendLine("/// "); - foreach (var line in documentation.Split(new[] {"\r\n", "\r", "\n"}, StringSplitOptions.None)) + foreach (var line in documentation.GetLines()) { builder.AppendLine($"/// {line}"); } @@ -48,12 +71,6 @@ public override string Compile() { var builder = new IndentedStringBuilder(); builder.AppendLine(WarningBlock); - builder.AppendLine("using global::System.Collections.Immutable;"); - builder.AppendLine("using global::System.Linq;"); - builder.AppendLine("using global::System;"); - builder.AppendLine("using global::Bebop.Attributes;"); - builder.AppendLine("using global::Bebop.Runtime;"); - builder.AppendLine("using global::Bebop.Exceptions;"); builder.AppendLine("//"); builder.AppendLine($"// This source code was auto-generated by {ReservedWords.CompilerName}, Version={ReservedWords.CompilerVersion}."); builder.AppendLine("//"); @@ -63,6 +80,7 @@ public override string Compile() builder.AppendLine($"namespace {Schema.Namespace.ToPascalCase()} {{"); builder.Indent(indentStep); } + foreach (var definition in Schema.Definitions.Values) { var definitionName = definition.Name.ToPascalCase(); @@ -74,7 +92,7 @@ public override string Compile() if (definition is EnumDefinition ed) { - builder.AppendLine("[BebopRecord(BebopKind.Enum)]"); + builder.AppendLine("[global::Bebop.Attributes.BebopRecord(global::Bebop.Runtime.BebopKind.Enum)]"); builder.AppendLine($"public enum {definition.Name} : uint {{"); builder.Indent(indentStep); for (var i = 0; i < ed.Members.Count; i++) @@ -101,14 +119,20 @@ public override string Compile() { var recordAttribute = fd switch { - MessageDefinition => "[BebopRecord(BebopKind.Message)]", - StructDefinition {IsReadOnly: true} => "[BebopRecord(BebopKind.Struct, true)]", - StructDefinition => "[BebopRecord(BebopKind.Struct)]", + MessageDefinition => "[global::Bebop.Attributes.BebopRecord(global::Bebop.Runtime.BebopKind.Message)]", + StructDefinition {IsReadOnly: true} => "[global::Bebop.Attributes.BebopRecord(global::Bebop.Runtime.BebopKind.Struct, true)]", + StructDefinition => "[global::Bebop.Attributes.BebopRecord(global::Bebop.Runtime.BebopKind.Struct)]", _ => string.Empty }; var baseName = "Base" + definitionName; builder.AppendLine(recordAttribute); - builder.AppendLine($"public abstract class {baseName} : System.IEquatable<{baseName}> {{"); + if (fd is StructDefinition {IsReadOnly: true}) + { + builder.AppendLine($"public abstract record {baseName} {{"); + } else + { + builder.AppendLine($"public abstract class {baseName} : System.IEquatable<{baseName}> {{"); + } builder.Indent(indentStep); if (fd.OpcodeAttribute is not null) { @@ -124,7 +148,7 @@ public override string Compile() if (!string.IsNullOrWhiteSpace(field.Documentation)) { - builder.AppendLine(FormatDocumentation(field.Documentation, 4)); + builder.AppendLine(FormatDocumentation(field.Documentation, 0)); } if (field.DeprecatedAttribute is not null && !string.IsNullOrWhiteSpace(field.DeprecatedAttribute.Value)) @@ -133,24 +157,59 @@ public override string Compile() } if (fd is StructDefinition) { - builder.AppendLine("[System.Diagnostics.CodeAnalysis.NotNull, System.Diagnostics.CodeAnalysis.DisallowNull]"); + builder.AppendLine(DisallowNullAttribute); } else if (fd is MessageDefinition) { - builder.AppendLine("[System.Diagnostics.CodeAnalysis.MaybeNull, System.Diagnostics.CodeAnalysis.AllowNull]"); + builder.AppendLine(AllowNullAttribute); } var type = TypeName(field.Type, string.Empty); var opt = fd is MessageDefinition && IsNullableType(field.Type) ? "?" : ""; var setOrInit = fd is StructDefinition {IsReadOnly: true} ? "init" : "set"; builder.AppendLine($"public {type}{opt} {field.Name.ToPascalCase()} {{ get; {setOrInit}; }}"); } + + + + + builder.AppendLine(); + // generate constructors + builder.AppendLine(FormatDocumentation(fd.Documentation, 0)); + builder.AppendLine($"protected {baseName}() {{ }}"); + builder.AppendLine(FormatConstructorDocumentation(fd)); + var nulllabilityAttribute = fd is StructDefinition ? DisallowNullAttribute : AllowNullAttribute; + var constructorArguments = string.Join(", ", fd.Fields.Select(f => $"{nulllabilityAttribute} {TypeName(f.Type)}{(fd is MessageDefinition && IsNullableType(f.Type) ? "?" : "")} {f.Name.ToCamelCase()}")).Trim(); + var constructorArgumentNames = string.Join(", ", fd.Fields.Select(f => f.Name.ToCamelCase())).Trim(); + if (fd is StructDefinition {IsReadOnly: true}) + { + var propertyTuple = $"({string.Join(", ", fd.Fields.Select(f => f.Name.ToPascalCase())).Trim()})"; + var argumentsTuple = $"({constructorArgumentNames})"; + builder.AppendLine($"protected {baseName}({constructorArguments}) => {propertyTuple} = {argumentsTuple};"); + var destructorArguments = string.Join(", ", fd.Fields.Select(f => $"{nulllabilityAttribute} out {TypeName(f.Type)} {f.Name.ToCamelCase()}")).Trim(); + builder.AppendLine($"public void Deconstruct({destructorArguments}) => {argumentsTuple} = {propertyTuple};"); + } + else + { + builder.AppendLine($"protected {baseName}({constructorArguments}) {{"); + builder.Indent(indentStep); + foreach (var field in fd.Fields) + { + builder.AppendLine($"{field.Name.ToPascalCase()} = {field.Name.ToCamelCase()};"); + } + builder.Dedent(indentStep); + builder.AppendLine("}"); + } + if (fd is MessageDefinition) { builder.AppendLine("#nullable disable"); } - builder.AppendLine(); - builder.AppendLine(GenerateEqualityMembers(fd)); - builder.AppendLine(); + + if (fd is not StructDefinition {IsReadOnly: true}) + { + builder.AppendLine(GenerateEqualityMembers(fd)); + builder.AppendLine(); + } builder.Dedent(indentStep); builder.AppendLine("}"); @@ -158,14 +217,33 @@ public override string Compile() builder.AppendLine("/// "); builder.AppendLine(GeneratedAttribute); builder.AppendLine($"{recordAttribute}"); - builder.AppendLine($"public sealed class {definitionName} : {baseName} {{").AppendLine(); + var keyword = fd is StructDefinition {IsReadOnly: true} ? "record" : "class"; + builder.AppendLine($"public sealed partial {keyword} {definitionName} : {baseName} {{").AppendLine(); builder.Indent(indentStep); + + // generate more constructors + builder.AppendLine("/// "); + if (fd is MessageDefinition) + { + builder.AppendLine("#nullable enable"); + } + builder.AppendLine($"public {definitionName}() : base() {{ }}"); + builder.AppendLine("/// "); + builder.AppendLine($"public {definitionName}({constructorArguments}) : base({constructorArgumentNames}) {{ }}"); + + if (fd is MessageDefinition) + { + builder.AppendLine("#nullable disable"); + } builder.AppendLine(CompileEncodeHelper(definition, "byte[]", "Encode")); builder.AppendLine(); - builder.AppendLine(CompileEncodeHelper(definition, "ImmutableArray", "EncodeAsImmutable")); + builder.AppendLine(CompileEncodeHelper(definition, ImmutableByteArrayType, "EncodeAsImmutable")); builder.AppendLine(); + builder.AppendLine(Warning); builder.AppendLine(HotPath); - builder.AppendLine($"internal static void EncodeInto({baseName} record, ref BebopWriter writer) {{"); + builder.AppendLine(NonUserCodeAttribute); + builder.AppendLine(BrowsableAttribute); + builder.AppendLine($"internal static void __EncodeInto({baseName} record, ref {BebopWriter} writer) {{"); builder.Indent(indentStep); builder.AppendLine(CompileEncode(fd)); builder.Dedent(indentStep); @@ -177,8 +255,11 @@ public override string Compile() builder.AppendLine(); } builder.AppendLine(); + builder.AppendLine(Warning); builder.AppendLine(HotPath); - builder.AppendLine($"internal static {definitionName} DecodeFrom(ref BebopReader reader) {{"); + builder.AppendLine(NonUserCodeAttribute); + builder.AppendLine(BrowsableAttribute); + builder.AppendLine($"internal static {definitionName} __DecodeFrom(ref {BebopReader} reader) {{"); builder.Indent(indentStep).AppendLine(); // when you do new T() the compile uses System.Activator::CreateInstance // this non-generic variant avoids that penalty hit. @@ -186,8 +267,11 @@ public override string Compile() builder.AppendLine(CompileDecode(fd, false)); builder.Dedent(indentStep); builder.AppendLine("}").AppendLine(); + builder.AppendLine(Warning); builder.AppendLine(HotPath); - builder.AppendLine($"internal static T DecodeFrom(ref BebopReader reader) where T: {baseName}, new() {{"); + builder.AppendLine(NonUserCodeAttribute); + builder.AppendLine(BrowsableAttribute); + builder.AppendLine($"internal static T __DecodeFrom(ref {BebopReader} reader) where T: {baseName}, new() {{"); builder.Indent(indentStep); // a generic decode method that allows for run-time polymorphism // this will initiate objects via a slower .ctor reflection @@ -219,7 +303,7 @@ public override string Compile() /// private void CompileUnionFamily(IndentedStringBuilder builder, UnionDefinition ud) { - var recordAttribute = "[BebopRecord(BebopKind.Union)]"; + var recordAttribute = "[global::Bebop.Attributes.BebopRecord(global::Bebop.Runtime.BebopKind.Union)]"; var genericPositionalArguments = string.Join(", ", ud.Branches.Select(b => $"T{b.GenericIndex()}")).Trim(); var genericTypeArguments = string.Join(", ", ud.Branches.Select(b => $"{b.BaseClassName()}")).Trim(); var genericConstraints = string.Join(' ', ud.Branches.Select(b => $"where T{b.GenericIndex()}: Base{b.Definition.Name.ToPascalCase()}")).Trim(); @@ -234,7 +318,7 @@ void CompileValueProperty() { builder.AppendLine($"{branch.Discriminator} => _value{branch.GenericIndex()},"); } - builder.AppendLine("_ => throw new BebopRuntimeException()").Dedent(4).AppendLine("};").AppendLine(); + builder.AppendLine($"_ => throw new {BebopException}()").Dedent(4).AppendLine("};").AppendLine(); builder.AppendLine("public byte Discriminator => _discriminator;").AppendLine(); } @@ -244,13 +328,13 @@ void CompileIsAs() { builder.AppendLine($"public bool Is{branch.BaseClassName()} => _discriminator is {branch.Discriminator};"); builder.AppendLine( - $"public T{branch.GenericIndex()} As{branch.BaseClassName()} => _discriminator is {branch.Discriminator} ? _value{branch.GenericIndex()} : throw new NotImplementedException($\"Cannot return as {branch.BaseClassName()} as result is T{branch.GenericIndex()}\");").AppendLine(); + $"public T{branch.GenericIndex()} As{branch.BaseClassName()} => _discriminator is {branch.Discriminator} ? _value{branch.GenericIndex()} : throw new global::System.NotImplementedException($\"Cannot return as {branch.BaseClassName()} as result is T{branch.GenericIndex()}\");").AppendLine(); } } void CompileSwitch() { - var switchParams = string.Join(", ", ud.Branches.Select(b => $"Action f{b.GenericIndex()}")).Trim(); + var switchParams = string.Join(", ", ud.Branches.Select(b => $"global::System.Action f{b.GenericIndex()}")).Trim(); builder.AppendLine($"public void Switch({switchParams}) {{"); foreach (var branch in ud.Branches) { @@ -258,18 +342,18 @@ void CompileSwitch() builder.Indent(2).AppendLine($"f{branch.GenericIndex()}(_value{branch.GenericIndex()});").AppendLine("return;"); builder.Dedent(2).AppendLine("}").Dedent(4); } - builder.Indent(4).AppendLine("throw new BebopRuntimeException();").Dedent(4).AppendLine("}").AppendLine(); + builder.Indent(4).AppendLine($"throw new {BebopException}();").Dedent(4).AppendLine("}").AppendLine(); } void CompileMatch() { - var matchParams = string.Join(", ", ud.Branches.Select(b => $"Func f{b.GenericIndex()}")).Trim(); + var matchParams = string.Join(", ", ud.Branches.Select(b => $"global::System.Func f{b.GenericIndex()}")).Trim(); builder.AppendLine($"public TResult Match({matchParams}) => _discriminator switch {{").Indent(4); foreach (var branch in ud.Branches) { builder.AppendLine($"{branch.Discriminator} when f{branch.GenericIndex()} is not null => f{branch.GenericIndex()}(_value{branch.GenericIndex()}),"); } - builder.AppendLine("_ => throw new BebopRuntimeException()").Dedent(4).AppendLine("};").AppendLine(); + builder.AppendLine($"_ => throw new {BebopException}()").Dedent(4).AppendLine("};").AppendLine(); } void CompileHashCode() @@ -363,7 +447,7 @@ void CompileUnionBaseClasses() { builder.AppendLine($"case {branch.Discriminator}: _value{branch.GenericIndex()} = input.As{branch.BaseClassName()}; break;"); } - builder.AppendLine("default: throw new BebopRuntimeException();").Dedent(indentStep).AppendLine("}"); + builder.AppendLine($"default: throw new {BebopException}();").Dedent(indentStep).AppendLine("}"); builder.Dedent(4).AppendLine("}").AppendLine(); CompileValueProperty(); CompileIsAs(); @@ -384,7 +468,7 @@ void CompileUnionConcreteClass() builder.AppendLine("/// "); builder.AppendLine(GeneratedAttribute); builder.AppendLine(recordAttribute); - builder.AppendLine($"public sealed class {definitionName} : {baseClassName} {{").Indent(indentStep).AppendLine(); + builder.AppendLine($"public sealed partial class {definitionName} : {baseClassName} {{").Indent(indentStep).AppendLine(); builder.AppendLine($"private {definitionName}({structName}<{genericTypeArguments}> _) : base(_) {{ }}").AppendLine(); foreach (var branch in ud.Branches) { @@ -393,14 +477,14 @@ void CompileUnionConcreteClass() } builder.AppendLine(HotPath); - builder.AppendLine($"internal static void EncodeInto({baseClassName} record, ref BebopWriter writer) {{"); + builder.AppendLine($"internal static void __EncodeInto({baseClassName} record, ref {BebopWriter} writer) {{"); builder.Indent(indentStep); builder.AppendLine(CompileEncode(ud)); builder.Dedent(indentStep); builder.AppendLine("}").AppendLine(); builder.AppendLine(HotPath); - builder.AppendLine($"internal static {definitionName} DecodeFrom(ref BebopReader reader) {{").Indent(indentStep).AppendLine(); + builder.AppendLine($"internal static {definitionName} __DecodeFrom(ref {BebopReader} reader) {{").Indent(indentStep).AppendLine(); builder.AppendLine(CompileDecode(ud, false)); builder.Dedent(indentStep); builder.AppendLine("}").AppendLine(); @@ -408,7 +492,7 @@ void CompileUnionConcreteClass() builder.AppendLine(CompileEncodeHelper(ud, "byte[]", "Encode")); builder.AppendLine(); - builder.AppendLine(CompileEncodeHelper(ud, "ImmutableArray", "EncodeAsImmutable")).AppendLine(); + builder.AppendLine(CompileEncodeHelper(ud, ImmutableByteArrayType, "EncodeAsImmutable")).AppendLine(); foreach (var bufferType in DecodeBufferTypes) @@ -461,7 +545,7 @@ private string GenerateEqualityMembers(FieldsDefinition definition) var notNullCheck = isNullableType ? "is not null" : "!= null"; // for collections we try to be extra safe to avoid throwing exceptions. returnStatement.Append(field.IsCollection() - ? $" ({fieldName} {nullCheck} ? other.{fieldName} {nullCheck} : other.{fieldName} {notNullCheck} && {fieldName}.SequenceEqual(other.{fieldName})){and}" + ? $" ({fieldName} {nullCheck} ? other.{fieldName} {nullCheck} : other.{fieldName} {notNullCheck} && global::System.Linq.Enumerable.SequenceEqual({fieldName}, other.{fieldName})){and}" : $" {fieldName} == other.{fieldName}{and}"); } returnStatement.Append(";"); @@ -562,7 +646,7 @@ private string TypeName(in TypeBase type, string arraySizeVar = "") _ => throw new ArgumentOutOfRangeException(st.BaseType.ToString()) }, ArrayType {MemberType: ScalarType {BaseType: BaseType.Byte}} at => - $"ImmutableArray<{TypeName(at.MemberType)}>", + $"{ImmutableArrayType}<{TypeName(at.MemberType)}>", ArrayType at => $"{(at.MemberType is ArrayType ? $"{TypeName(at.MemberType, arraySizeVar)}[]" : $"{TypeName(at.MemberType)}[{arraySizeVar}]")}", MapType mt => @@ -599,7 +683,7 @@ private string CompileDecodeUnion(UnionDefinition definition) { builder.AppendLine($"case {branch.Discriminator}:").Indent(4); var nameSpace = string.IsNullOrWhiteSpace(Schema.Namespace) ? string.Empty : $"{Schema.Namespace.ToPascalCase()}."; - builder.AppendLine($"return {nameSpace}{branch.Definition.Name.ToPascalCase()}.DecodeFrom(ref reader);").Dedent(4); + builder.AppendLine($"return {nameSpace}{branch.Definition.Name.ToPascalCase()}.__DecodeFrom(ref reader);").Dedent(4); } builder.AppendLine("default:").Indent(4); builder.AppendLine("reader.Position = end;"); @@ -734,7 +818,7 @@ private string CompileDecodeField(TypeBase type, string target, int depth = 0) DefinedType dt when Schema.Definitions[dt.Name] is EnumDefinition => $"{target} = reader.ReadEnum<{dt.Name}>();", DefinedType dt => - $"{target} = {(string.IsNullOrWhiteSpace(Schema.Namespace) ? string.Empty : $"{Schema.Namespace.ToPascalCase()}.")}{dt.Name.ToPascalCase()}.DecodeFrom(ref reader);", + $"{target} = {(string.IsNullOrWhiteSpace(Schema.Namespace) ? string.Empty : $"{Schema.Namespace.ToPascalCase()}.")}{dt.Name.ToPascalCase()}.__DecodeFrom(ref reader);", _ => throw new InvalidOperationException($"CompileDecodeField: {type}") }; } @@ -748,13 +832,14 @@ private string CompileDecodeField(TypeBase type, string target, int depth = 0) /// public string CompileEncodeHelper(Definition definition, string bufferType, string methodName) { - var returnMethod = bufferType.Equals("ImmutableArray") ? "ToImmutableArray" : "ToArray"; + var returnMethod = bufferType.Equals(ImmutableByteArrayType) ? "ToImmutableArray" : "ToArray"; var builder = new IndentedStringBuilder(); + builder.AppendLine(HotPath); builder.AppendLine($"public static {bufferType} {methodName}(Base{definition.Name.ToPascalCase()} record) {{"); builder.Indent(indentStep); - builder.AppendLine("var writer = BebopWriter.Create();"); - builder.AppendLine("EncodeInto(record, ref writer);"); + builder.AppendLine($"var writer = {BebopWriter}.Create();"); + builder.AppendLine("__EncodeInto(record, ref writer);"); builder.AppendLine($"return writer.{returnMethod}();"); builder.Dedent(indentStep); builder.AppendLine("}"); @@ -762,8 +847,8 @@ public string CompileEncodeHelper(Definition definition, string bufferType, stri builder.AppendLine(HotPath); builder.AppendLine($"public {bufferType} {methodName}() {{"); builder.Indent(indentStep); - builder.AppendLine("var writer = BebopWriter.Create();"); - builder.AppendLine("EncodeInto(this, ref writer);"); + builder.AppendLine($"var writer = {BebopWriter}.Create();"); + builder.AppendLine("__EncodeInto(this, ref writer);"); builder.AppendLine($"return writer.{returnMethod}();"); builder.Dedent(indentStep); builder.AppendLine("}"); @@ -784,8 +869,8 @@ public string CompileDecodeHelper(Definition definition, string bufferType, bool builder.AppendLine(HotPath); builder.AppendLine($"public static T DecodeAs({bufferType} record) where T : Base{definition.Name.ToPascalCase()}, new() {{"); builder.Indent(indentStep); - builder.AppendLine("var reader = BebopReader.From(record);"); - builder.AppendLine("return DecodeFrom(ref reader);"); + builder.AppendLine($"var reader = {BebopReader}.From(record);"); + builder.AppendLine("return __DecodeFrom(ref reader);"); builder.Dedent(indentStep); builder.AppendLine("}"); builder.AppendLine(); @@ -793,8 +878,8 @@ public string CompileDecodeHelper(Definition definition, string bufferType, bool builder.AppendLine(HotPath); builder.AppendLine($"public static {definition.Name.ToPascalCase()} Decode({bufferType} record) {{"); builder.Indent(indentStep); - builder.AppendLine("var reader = BebopReader.From(record);"); - builder.AppendLine("return DecodeFrom(ref reader);"); + builder.AppendLine($"var reader = {BebopReader}.From(record);"); + builder.AppendLine("return __DecodeFrom(ref reader);"); builder.Dedent(indentStep); builder.AppendLine("}"); builder.AppendLine(); @@ -828,7 +913,7 @@ private string CompileEncodeUnion(UnionDefinition definition) foreach (var branch in definition.Branches) { var nameSpace = string.IsNullOrWhiteSpace(Schema.Namespace) ? string.Empty : $"{Schema.Namespace.ToPascalCase()}."; - builder.AppendLine($"case {branch.Discriminator}: {nameSpace}{branch.Definition.Name.ToPascalCase()}.EncodeInto(record.As{branch.BaseClassName()}, ref writer); break;"); + builder.AppendLine($"case {branch.Discriminator}: {nameSpace}{branch.Definition.Name.ToPascalCase()}.__EncodeInto(record.As{branch.BaseClassName()}, ref writer); break;"); } builder.Dedent(indentStep).AppendLine("}"); builder.AppendLine("var end = writer.Length;"); @@ -947,7 +1032,7 @@ private string CompileEncodeField(TypeBase type, string target, int depth = 0, i DefinedType dt when IsEnum(dt) => $"writer.WriteEnum<{dt.Name}>({target});", DefinedType dt => - $"{(string.IsNullOrWhiteSpace(Schema.Namespace) ? string.Empty : $"{Schema.Namespace.ToPascalCase()}.")}{dt.Name.ToPascalCase()}.EncodeInto({target}, ref writer);", + $"{(string.IsNullOrWhiteSpace(Schema.Namespace) ? string.Empty : $"{Schema.Namespace.ToPascalCase()}.")}{dt.Name.ToPascalCase()}.__EncodeInto({target}, ref writer);", _ => throw new InvalidOperationException($"CompileEncodeField: {type}") }; } diff --git a/Core/Generators/Dart/DartGenerator.cs b/Core/Generators/Dart/DartGenerator.cs index 01a5d51d..fe532f79 100644 --- a/Core/Generators/Dart/DartGenerator.cs +++ b/Core/Generators/Dart/DartGenerator.cs @@ -19,7 +19,7 @@ private string FormatDocumentation(string documentation, int spaces) { var builder = new IndentedStringBuilder(); builder.Indent(spaces); - foreach (var line in documentation.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None)) + foreach (var line in documentation.GetLines()) { builder.AppendLine($"/// {line}"); } diff --git a/Core/Generators/IndentedStringBuilder.cs b/Core/Generators/IndentedStringBuilder.cs index 47112b07..cc37dba6 100644 --- a/Core/Generators/IndentedStringBuilder.cs +++ b/Core/Generators/IndentedStringBuilder.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Text; +using Core.Meta.Extensions; namespace Core.Generators { @@ -8,7 +9,7 @@ public class IndentedStringBuilder { private int Spaces { get; set; } private StringBuilder Builder { get; } - static readonly string[] _newlines = new[] { "\r\n", "\r", "\n" }; + public IndentedStringBuilder(int spaces = 0) { @@ -24,7 +25,7 @@ public IndentedStringBuilder AppendLine() public IndentedStringBuilder AppendLine(string text) { var indent = new string(' ', Spaces); - var lines = text.Split(_newlines, StringSplitOptions.None); + var lines = text.GetLines(); var indentedLines = lines.Select(x => (indent + x).TrimEnd()).ToArray(); var indentedText = string.Join(Environment.NewLine, indentedLines).TrimEnd(); Builder.AppendLine(indentedText); diff --git a/Core/Generators/TypeScript/TypeScriptGenerator.cs b/Core/Generators/TypeScript/TypeScriptGenerator.cs index 5c25444e..a2af300b 100644 --- a/Core/Generators/TypeScript/TypeScriptGenerator.cs +++ b/Core/Generators/TypeScript/TypeScriptGenerator.cs @@ -22,7 +22,7 @@ private static string FormatDocumentation(string documentation, string deprecati builder.Indent(spaces); builder.AppendLine("/**"); builder.Indent(1); - foreach (var line in documentation.Split(new[] {"\r\n", "\r", "\n"}, StringSplitOptions.None)) + foreach (var line in documentation.GetLines()) { builder.AppendLine($"* {line}"); } diff --git a/Core/Lexer/Tokenization/Tokenizer.cs b/Core/Lexer/Tokenization/Tokenizer.cs index 8a598974..1570c34f 100644 --- a/Core/Lexer/Tokenization/Tokenizer.cs +++ b/Core/Lexer/Tokenization/Tokenizer.cs @@ -7,6 +7,7 @@ using Core.Lexer.Extensions; using Core.Lexer.Tokenization.Interfaces; using Core.Lexer.Tokenization.Models; +using Core.Meta.Extensions; namespace Core.Lexer.Tokenization { @@ -166,7 +167,7 @@ private bool IsBlockComment(char surrogate, out Token token) var cleanedDocumentation = new StringBuilder(); - foreach (var line in builder.ToString().Split(new[] {"\r\n", "\r", "\n"}, StringSplitOptions.None)) + foreach (var line in builder.ToString().GetLines()) { var trimmedLine = line.Trim(' ', '*'); cleanedDocumentation.AppendLine(trimmedLine); diff --git a/Core/Meta/BebopSchema.cs b/Core/Meta/BebopSchema.cs index dae98aba..8ec1327e 100644 --- a/Core/Meta/BebopSchema.cs +++ b/Core/Meta/BebopSchema.cs @@ -83,14 +83,20 @@ public void Validate() } if (definition is EnumDefinition ed) { - HashSet seen = new HashSet(); + HashSet values = new HashSet(); + HashSet names = new HashSet(StringComparer.OrdinalIgnoreCase); foreach (var field in ed.Members) { - if (seen.Contains(field.ConstantValue)) + if (values.Contains(field.ConstantValue)) { throw new InvalidFieldException(field, "Enum value must be unique"); } - seen.Add(field.ConstantValue); + if (names.Contains(field.Name)) + { + throw new DuplicateFieldException(field, ed); + } + values.Add(field.ConstantValue); + names.Add(field.Name); } } } diff --git a/Core/Meta/Definition.cs b/Core/Meta/Definition.cs index 87ceaec4..c6272e62 100644 --- a/Core/Meta/Definition.cs +++ b/Core/Meta/Definition.cs @@ -29,7 +29,7 @@ protected Definition(string name, Span span, string documentation) /// /// The inner text of a block comment that preceded the definition. /// - public string Documentation { get; } + public string Documentation { get; set; } } /// @@ -105,13 +105,11 @@ public readonly struct UnionBranch { public readonly byte Discriminator; public readonly TopLevelDefinition Definition; - public readonly string Documentation; - public UnionBranch(byte discriminator, TopLevelDefinition definition, string documentation) + public UnionBranch(byte discriminator, TopLevelDefinition definition) { Discriminator = discriminator; Definition = definition; - Documentation = documentation; } } diff --git a/Core/Meta/Extensions/StringExtensions.cs b/Core/Meta/Extensions/StringExtensions.cs index d3d97516..9996f874 100644 --- a/Core/Meta/Extensions/StringExtensions.cs +++ b/Core/Meta/Extensions/StringExtensions.cs @@ -5,38 +5,57 @@ namespace Core.Meta.Extensions { public static class StringExtensions { + + private static readonly string[] _newLines = new[] {"\r\n", "\r", "\n"}; + /// + /// Splits the specified based on line ending. + /// + /// The input string to split. + /// An array of each line in the string. + public static string[] GetLines(this string value) + { + return string.IsNullOrWhiteSpace(value) ? Array.Empty() : value.Split(_newLines, StringSplitOptions.None); + } + /// - /// Converts a string into Pascal case + /// Converts the specified string into PascalCase. /// - /// the input string we need to convert - /// a pascal converted string + /// The input string that will be converted. + /// The mutated string. public static string ToPascalCase(this string input) { // If there are 0 or 1 characters, just return the string. - if (input.Length < 2) return input.ToUpper(); + if (input.Length < 2) + { + return input.ToUpper(); + } - // Split the string into words. - var words = input.Split( - new char[] { }, - StringSplitOptions.RemoveEmptyEntries); + // splits the input string by underscore so snake casing is converted. + var words = input.Split('_', StringSplitOptions.RemoveEmptyEntries); - // Combine the words. - return words.Aggregate("", (current, word) => current + (word.Substring(0, 1).ToUpper() + word.Substring(1))); + // combine the words into PascalCase + return words.Aggregate(string.Empty, (current, word) => current + word[..1].ToUpper() + word[1..]); } /// - /// Converts a string to a camelcase representation + /// Converts a string to a camelcase representation /// /// /// public static string ToCamelCase(this string str) { - if (str.Length == 1) return str; + if (str.Length == 1) + { + return str; + } - var f = str.Substring(0, 1); - var r = str.Substring(1); + var f = str[..1]; + var r = str[1..]; - if (char.IsUpper(f[0]) && char.IsUpper(r[0])) return str; + if (char.IsUpper(f[0]) && char.IsUpper(r[0])) + { + return str; + } return f.ToLowerInvariant() + r; } @@ -62,4 +81,4 @@ public static bool TryParseUInt(this string str, out uint result) return false; } } -} +} \ No newline at end of file diff --git a/Core/Parser/SchemaParser.cs b/Core/Parser/SchemaParser.cs index 93a3381c..40cb5da1 100644 --- a/Core/Parser/SchemaParser.cs +++ b/Core/Parser/SchemaParser.cs @@ -357,6 +357,7 @@ private UnionDefinition ParseUnionDefinition(Token definitionToken, { var name = definitionToken.Lexeme; var branches = new List(); + var usedDiscriminators = new HashSet(); Expect(TokenKind.Identifier, hint: $"Did you forget to specify a name for this union?"); Expect(TokenKind.OpenBrace); @@ -371,16 +372,22 @@ private UnionDefinition ParseUnionDefinition(Token definitionToken, } const string? indexHint = "Branches in a union must be explicitly indexed: union U { 1 -> struct A{} 2 -> message B{} }"; - var indexLexeme = CurrentToken.Lexeme; + var indexToken = CurrentToken; + var indexLexeme = indexToken.Lexeme; Expect(TokenKind.Number, hint: indexHint); if (!indexLexeme.TryParseUInt(out uint discriminator)) { - throw new UnexpectedTokenException(TokenKind.Number, CurrentToken, "A union branch discriminator must be an unsigned integer."); + throw new UnexpectedTokenException(TokenKind.Number, indexToken, "A union branch discriminator must be an unsigned integer."); } - if (discriminator > 255) + if (discriminator < 1 || discriminator > 255) { - throw new UnexpectedTokenException(TokenKind.Number, CurrentToken, "A union branch discriminator must be between 0 and 255."); + throw new UnexpectedTokenException(TokenKind.Number, indexToken, "A union branch discriminator must be between 1 and 255."); } + if (usedDiscriminators.Contains(discriminator)) + { + throw new DuplicateUnionDiscriminatorException(indexToken, name); + } + usedDiscriminators.Add(discriminator); // Parse an arrow ("->"). Expect(TokenKind.Hyphen, hint: indexHint); Expect(TokenKind.CloseCaret, hint: indexHint); @@ -391,7 +398,11 @@ private UnionDefinition ParseUnionDefinition(Token definitionToken, } Eat(TokenKind.Semicolon); definitionEnd = CurrentToken.Span; - branches.Add(new UnionBranch((byte)discriminator, (TopLevelDefinition)definition, documentation)); + if (string.IsNullOrWhiteSpace(definition.Documentation)) + { + definition.Documentation = documentation; + } + branches.Add(new UnionBranch((byte)discriminator, (TopLevelDefinition)definition)); } var definitionSpan = definitionToken.Span.Combine(definitionEnd); var unionDefinition = new UnionDefinition(name, definitionSpan, definitionDocumentation, opcodeAttribute, branches); diff --git a/Laboratory/C#/Benchmarks/Benchmarks.csproj b/Laboratory/C#/Benchmarks/Benchmarks.csproj index 9c261737..20ece905 100644 --- a/Laboratory/C#/Benchmarks/Benchmarks.csproj +++ b/Laboratory/C#/Benchmarks/Benchmarks.csproj @@ -11,5 +11,6 @@ + diff --git a/Laboratory/C#/Benchmarks/Decoding.cs b/Laboratory/C#/Benchmarks/Decoding.cs deleted file mode 100644 index 03178414..00000000 --- a/Laboratory/C#/Benchmarks/Decoding.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Bebop; -using Bebop.Runtime; -using BenchmarkDotNet.Attributes; -using Gateway.Contracts; - -namespace Benchmarks -{ - [MinColumn] - [MaxColumn] - [MemoryDiagnoser] - public class Decoding - { - private readonly byte[] _testBuffer; - private const string TestString = @"Hello 明 World!😊 Lorem ipsum dolor sit amet."; - - public Decoding() - { - - _testBuffer = new ChatMessage - { - Content = TestString, - LobbyId = Guid.Parse("02281d74-a708-4f64-8a5c-699100654587"), - SendTime = DateTime.Now, - }.Encode(); - } - - [Benchmark] - public void DynamicDecode() - { - _ = BebopMirror.GetRecordFromOpCode(0x54414843).Decode(_testBuffer); - } - - [Benchmark] - public void StrongDecode() - { - _ = ChatMessage.Decode(_testBuffer); - } - - [Benchmark] - public void GenericDecode() - { - _ = ChatMessage.DecodeAs(_testBuffer); - } - } -} diff --git a/Laboratory/C#/Benchmarks/Gen.cs b/Laboratory/C#/Benchmarks/Gen.cs deleted file mode 100644 index a9d95ca2..00000000 --- a/Laboratory/C#/Benchmarks/Gen.cs +++ /dev/null @@ -1,555 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:0.1.0.0 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ -using global::Bebop.Attributes; -using global::Bebop.Runtime; -// -// This source code was auto-generated by bebopc, Version=0.1.0.0. -// -namespace Gateway.Contracts { - /// - /// The current state of a user connection to a lobby - /// - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [BebopRecord] - public enum LobbyConnectionState : uint { - Invalid = 0 - } - /// - /// Represents a message received by the gateway - /// - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [BebopRecord] - public abstract class BaseGatewayMessage { - public const uint OpCode = 0x45544147; - /// - /// The opcode of the child message - /// - public uint ChildOpcode { get; init; } - /// - /// A bebop encoded message - /// - public byte[] Buffer { get; init; } - } - - /// - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [BebopRecord] - public sealed class GatewayMessage : BaseGatewayMessage { - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static byte[] Encode(BaseGatewayMessage record) { - var writer = BebopWriter.Create(); - EncodeInto(record, ref writer); - return writer.ToArray(); - } - - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public byte[] Encode() { - var writer = BebopWriter.Create(); - EncodeInto(this, ref writer); - return writer.ToArray(); - } - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - internal static void EncodeInto(BaseGatewayMessage record, ref BebopWriter writer) { - writer.WriteUInt32(record.ChildOpcode); - writer.WriteBytes(record.Buffer); - } - - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(byte[] record) where T : BaseGatewayMessage, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static GatewayMessage Decode(byte[] record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - internal static GatewayMessage DecodeFrom(ref BebopReader reader) { - uint field0; - field0 = reader.ReadUInt32(); - byte[] field1; - field1 = reader.ReadBytes(); - return new GatewayMessage { - ChildOpcode = field0, - Buffer = field1, - }; - } - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - internal static T DecodeFrom(ref BebopReader reader) where T: BaseGatewayMessage, new() { - uint field0; - field0 = reader.ReadUInt32(); - byte[] field1; - field1 = reader.ReadBytes(); - return new T { - ChildOpcode = field0, - Buffer = field1, - }; - } - } - /// - /// A structure which represents an incoming chat message sent by a user - /// - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [BebopRecord] - public abstract class BaseChatMessage { - public const uint OpCode = 0x54414843; - /// - /// the time at which the message was sent to the gateway - /// - public System.DateTime SendTime { get; init; } - /// - /// the GUID of the lobby the message should be forwarded to - /// - public System.Guid LobbyId { get; init; } - /// - /// the contents of the chat message - /// - public string Content { get; init; } - } - - /// - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [BebopRecord] - public sealed class ChatMessage : BaseChatMessage { - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static byte[] Encode(BaseChatMessage record) { - var writer = BebopWriter.Create(); - EncodeInto(record, ref writer); - return writer.ToArray(); - } - - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public byte[] Encode() { - var writer = BebopWriter.Create(); - EncodeInto(this, ref writer); - return writer.ToArray(); - } - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - internal static void EncodeInto(BaseChatMessage record, ref BebopWriter writer) { - writer.WriteDate(record.SendTime); - writer.WriteGuid(record.LobbyId); - writer.WriteString(record.Content); - } - - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(byte[] record) where T : BaseChatMessage, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static ChatMessage Decode(byte[] record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - internal static ChatMessage DecodeFrom(ref BebopReader reader) { - System.DateTime field0; - field0 = reader.ReadDate(); - System.Guid field1; - field1 = reader.ReadGuid(); - string field2; - field2 = reader.ReadString(); - return new ChatMessage { - SendTime = field0, - LobbyId = field1, - Content = field2, - }; - } - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - internal static T DecodeFrom(ref BebopReader reader) where T: BaseChatMessage, new() { - System.DateTime field0; - field0 = reader.ReadDate(); - System.Guid field1; - field1 = reader.ReadGuid(); - string field2; - field2 = reader.ReadString(); - return new T { - SendTime = field0, - LobbyId = field1, - Content = field2, - }; - } - } - /// - /// A structure that represents a user connected to a lobby - /// - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [BebopRecord] - public abstract class BaseLobbyUser { - /// - /// the unique ID of the user - /// - public System.Guid Id { get; set; } - /// - /// the display name of the user visible to other members of the lobby - /// - public string DisplayName { get; set; } - /// - /// the time at which the user joined the lobby - /// - public System.DateTime JoinTime { get; set; } - /// - /// the current state of the user in the lobby - /// - public LobbyConnectionState State { get; set; } - } - - /// - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [BebopRecord] - public sealed class LobbyUser : BaseLobbyUser { - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static byte[] Encode(BaseLobbyUser record) { - var writer = BebopWriter.Create(); - EncodeInto(record, ref writer); - return writer.ToArray(); - } - - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public byte[] Encode() { - var writer = BebopWriter.Create(); - EncodeInto(this, ref writer); - return writer.ToArray(); - } - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - internal static void EncodeInto(BaseLobbyUser record, ref BebopWriter writer) { - writer.WriteGuid(record.Id); - writer.WriteString(record.DisplayName); - writer.WriteDate(record.JoinTime); - writer.WriteEnum(record.State); - } - - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(byte[] record) where T : BaseLobbyUser, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static LobbyUser Decode(byte[] record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - internal static LobbyUser DecodeFrom(ref BebopReader reader) { - System.Guid field0; - field0 = reader.ReadGuid(); - string field1; - field1 = reader.ReadString(); - System.DateTime field2; - field2 = reader.ReadDate(); - LobbyConnectionState field3; - field3 = reader.ReadEnum(); - return new LobbyUser { - Id = field0, - DisplayName = field1, - JoinTime = field2, - State = field3, - }; - } - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - internal static T DecodeFrom(ref BebopReader reader) where T: BaseLobbyUser, new() { - System.Guid field0; - field0 = reader.ReadGuid(); - string field1; - field1 = reader.ReadString(); - System.DateTime field2; - field2 = reader.ReadDate(); - LobbyConnectionState field3; - field3 = reader.ReadEnum(); - return new T { - Id = field0, - DisplayName = field1, - JoinTime = field2, - State = field3, - }; - } - } - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [BebopRecord] - public abstract class BaseLobby { - public BaseLobbyUser[] Users { get; set; } - public System.DateTime CreationTime { get; set; } - public string DisplayName { get; set; } - } - - /// - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [BebopRecord] - public sealed class Lobby : BaseLobby { - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static byte[] Encode(BaseLobby record) { - var writer = BebopWriter.Create(); - EncodeInto(record, ref writer); - return writer.ToArray(); - } - - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public byte[] Encode() { - var writer = BebopWriter.Create(); - EncodeInto(this, ref writer); - return writer.ToArray(); - } - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - internal static void EncodeInto(BaseLobby record, ref BebopWriter writer) { - { - var length0 = unchecked((uint)record.Users.Length); - writer.WriteUInt32(length0); - for (var i0 = 0; i0 < length0; i0++) { - Gateway.Contracts.LobbyUser.EncodeInto(record.Users[i0], ref writer); - } - } - writer.WriteDate(record.CreationTime); - writer.WriteString(record.DisplayName); - } - - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(byte[] record) where T : BaseLobby, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static Lobby Decode(byte[] record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - internal static Lobby DecodeFrom(ref BebopReader reader) { - BaseLobbyUser[] field0; - { - var length0 = unchecked((int)reader.ReadUInt32()); - field0 = new BaseLobbyUser[length0]; - for (var i0 = 0; i0 < length0; i0++) { - BaseLobbyUser x0; - x0 = Gateway.Contracts.LobbyUser.DecodeFrom(ref reader); - field0[i0] = x0; - } - } - System.DateTime field1; - field1 = reader.ReadDate(); - string field2; - field2 = reader.ReadString(); - return new Lobby { - Users = field0, - CreationTime = field1, - DisplayName = field2, - }; - } - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - internal static T DecodeFrom(ref BebopReader reader) where T: BaseLobby, new() { - BaseLobbyUser[] field0; - { - var length0 = unchecked((int)reader.ReadUInt32()); - field0 = new BaseLobbyUser[length0]; - for (var i0 = 0; i0 < length0; i0++) { - BaseLobbyUser x0; - x0 = Gateway.Contracts.LobbyUser.DecodeFrom(ref reader); - field0[i0] = x0; - } - } - System.DateTime field1; - field1 = reader.ReadDate(); - string field2; - field2 = reader.ReadString(); - return new T { - Users = field0, - CreationTime = field1, - DisplayName = field2, - }; - } - } - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [BebopRecord] - public abstract class BaseTestMessage { - #nullable enable - public BaseGatewayMessage? GateWayMessage { get; set; } - public BaseChatMessage? ChatMessage { get; set; } - public Example? ExampleEnum { get; set; } - public BaseLobbyUser? User { get; set; } - #nullable disable - } - - /// - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [BebopRecord] - public sealed class TestMessage : BaseTestMessage { - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static byte[] Encode(BaseTestMessage record) { - var writer = BebopWriter.Create(); - EncodeInto(record, ref writer); - return writer.ToArray(); - } - - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public byte[] Encode() { - var writer = BebopWriter.Create(); - EncodeInto(this, ref writer); - return writer.ToArray(); - } - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - internal static void EncodeInto(BaseTestMessage record, ref BebopWriter writer) { - var pos = writer.ReserveRecordLength(); - var start = writer.Length; - - if (record.GateWayMessage is not null) { - writer.WriteByte(1); - Gateway.Contracts.GatewayMessage.EncodeInto(record.GateWayMessage, ref writer); - } - - if (record.ChatMessage is not null) { - writer.WriteByte(2); - Gateway.Contracts.ChatMessage.EncodeInto(record.ChatMessage, ref writer); - } - - if (record.ExampleEnum is not null) { - writer.WriteByte(3); - writer.WriteEnum(record.ExampleEnum.Value); - } - - if (record.User is not null) { - writer.WriteByte(4); - Gateway.Contracts.LobbyUser.EncodeInto(record.User, ref writer); - } - writer.WriteByte(0); - var end = writer.Length; - writer.FillRecordLength(pos, unchecked((uint) unchecked(end - start))); - } - - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(byte[] record) where T : BaseTestMessage, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static TestMessage Decode(byte[] record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - internal static TestMessage DecodeFrom(ref BebopReader reader) { - var record = new TestMessage(); - var length = reader.ReadRecordLength(); - var end = unchecked((int) (reader.Position + length)); - while (true) { - switch (reader.ReadByte()) { - case 0: - return record; - case 1: - record.GateWayMessage = Gateway.Contracts.GatewayMessage.DecodeFrom(ref reader); - break; - case 2: - record.ChatMessage = Gateway.Contracts.ChatMessage.DecodeFrom(ref reader); - break; - case 3: - record.ExampleEnum = reader.ReadEnum(); - break; - case 4: - record.User = Gateway.Contracts.LobbyUser.DecodeFrom(ref reader); - break; - default: - reader.Position = end; - return record; - } - } - } - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - internal static T DecodeFrom(ref BebopReader reader) where T: BaseTestMessage, new() { - var record = new T(); - var length = reader.ReadRecordLength(); - var end = unchecked((int) (reader.Position + length)); - while (true) { - switch (reader.ReadByte()) { - case 0: - return record; - case 1: - record.GateWayMessage = Gateway.Contracts.GatewayMessage.DecodeFrom(ref reader); - break; - case 2: - record.ChatMessage = Gateway.Contracts.ChatMessage.DecodeFrom(ref reader); - break; - case 3: - record.ExampleEnum = reader.ReadEnum(); - break; - case 4: - record.User = Gateway.Contracts.LobbyUser.DecodeFrom(ref reader); - break; - default: - reader.Position = end; - return record; - } - } - } - } - /// - /// Hello World - /// - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.1.0.0")] - [BebopRecord] - public enum Example : uint { - A = 0, - B = 1, - C = 2 - } -} diff --git a/Laboratory/C#/Benchmarks/IsExternalInit.cs b/Laboratory/C#/Benchmarks/IsExternalInit.cs deleted file mode 100644 index cd5df714..00000000 --- a/Laboratory/C#/Benchmarks/IsExternalInit.cs +++ /dev/null @@ -1,18 +0,0 @@ -#if NETSTANDARD2_0 || NETSTANDARD2_1 || NETCOREAPP2_0 || NETCOREAPP2_1 || NETCOREAPP2_2 || NETCOREAPP3_0 || NETCOREAPP3_1 || NET45 || NET451 || NET452 || NET6 || NET461 || NET462 || NET47 || NET471 || NET472 || NET48 - -using System.ComponentModel; - -// ReSharper disable once CheckNamespace -namespace System.Runtime.CompilerServices -{ - /// - /// Reserved to be used by the compiler for tracking metadata. - /// This class should not be used by developers in source code. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - internal static class IsExternalInit - { - } -} - -#endif \ No newline at end of file diff --git a/Laboratory/C#/Benchmarks/Program.cs b/Laboratory/C#/Benchmarks/Program.cs index 45022764..4c73b22f 100644 --- a/Laboratory/C#/Benchmarks/Program.cs +++ b/Laboratory/C#/Benchmarks/Program.cs @@ -1,13 +1,7 @@ using System; -using BenchmarkDotNet.Running; +using Bebop.Codegen; -namespace Benchmarks -{ - class Program - { - static void Main(string[] args) - { - BenchmarkRunner.Run(); - } - } -} + +var a = new Musician("Travis Scott", Instrument.Clarinet); +var b = new Musician { Name = "Travis Scott", Plays = Instrument.Clarinet}; +Console.WriteLine(a == b); \ No newline at end of file diff --git a/Laboratory/C#/GeneratedTestCode/Output.g.cs b/Laboratory/C#/GeneratedTestCode/Output.g.cs index 5b89b8a3..28c297dd 100644 --- a/Laboratory/C#/GeneratedTestCode/Output.g.cs +++ b/Laboratory/C#/GeneratedTestCode/Output.g.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:0.0.1-20210208-0337 +// Runtime Version:0.0.1-20210301-0356 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -14,10 +14,10 @@ using global::Bebop.Runtime; using global::Bebop.Exceptions; // -// This source code was auto-generated by bebopc, Version=0.0.1-20210208-0337. +// This source code was auto-generated by bebopc, Version=0.0.1-20210301-0356. // namespace Bebop.Codegen { - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210208-0337")] + [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210301-0356")] [BebopRecord(BebopKind.Enum)] public enum Instrument : uint { Sax = 0, @@ -25,84 +25,77 @@ public enum Instrument : uint { Clarinet = 2 } - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210208-0337")] + /// + /// test + /// + [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210301-0356")] [BebopRecord(BebopKind.Struct, true)] - public abstract class BaseMusician : System.IEquatable { + public abstract record BaseMusician { + public const uint OpCode = 0x5A5A414A; + /// + /// a name + /// [System.Diagnostics.CodeAnalysis.NotNull, System.Diagnostics.CodeAnalysis.DisallowNull] public string Name { get; init; } + /// + /// an instrument + /// [System.Diagnostics.CodeAnalysis.NotNull, System.Diagnostics.CodeAnalysis.DisallowNull] public Instrument Plays { get; init; } - public bool Equals(BaseMusician other) { - if (ReferenceEquals(null, other)) { - return false; - } - if (ReferenceEquals(this, other)) { - return true; - } - return Name == other.Name && Plays == other.Plays; - } - - public override bool Equals(object obj) { - if (ReferenceEquals(null, obj)) { - return false; - } - if (ReferenceEquals(this, obj)) { - return true; - } - if (obj is not BaseMusician baseType) { - return false; - } - return Equals(baseType); - } - - public override int GetHashCode() { - int hash = 1; - hash ^= Name.GetHashCode(); - hash ^= Plays.GetHashCode(); - return hash; - } - - public static bool operator ==(BaseMusician left, BaseMusician right) => Equals(left, right); - public static bool operator !=(BaseMusician left, BaseMusician right) => !Equals(left, right); - + /// + /// test + /// + protected BaseMusician() { } + /// + /// test + /// + /// a name + /// an instrument + protected BaseMusician([System.Diagnostics.CodeAnalysis.NotNull, System.Diagnostics.CodeAnalysis.DisallowNull] string name, [System.Diagnostics.CodeAnalysis.NotNull, System.Diagnostics.CodeAnalysis.DisallowNull] Instrument plays) => (Name, Plays) = (name, plays); + public void Deconstruct([System.Diagnostics.CodeAnalysis.NotNull, System.Diagnostics.CodeAnalysis.DisallowNull] out string name, [System.Diagnostics.CodeAnalysis.NotNull, System.Diagnostics.CodeAnalysis.DisallowNull] out Instrument plays) => (name, plays) = (Name, Plays); } /// - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210208-0337")] + [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210301-0356")] [BebopRecord(BebopKind.Struct, true)] - public sealed class Musician : BaseMusician { + public sealed record Musician : BaseMusician { + /// + public Musician() : base() { } + /// + public Musician([System.Diagnostics.CodeAnalysis.NotNull, System.Diagnostics.CodeAnalysis.DisallowNull] string name, [System.Diagnostics.CodeAnalysis.NotNull, System.Diagnostics.CodeAnalysis.DisallowNull] Instrument plays) : base(name, plays) { } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static byte[] Encode(BaseMusician record) { var writer = BebopWriter.Create(); - EncodeInto(record, ref writer); + __EncodeInto(record, ref writer); return writer.ToArray(); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public byte[] Encode() { var writer = BebopWriter.Create(); - EncodeInto(this, ref writer); + __EncodeInto(this, ref writer); return writer.ToArray(); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static ImmutableArray EncodeAsImmutable(BaseMusician record) { var writer = BebopWriter.Create(); - EncodeInto(record, ref writer); + __EncodeInto(record, ref writer); return writer.ToImmutableArray(); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public ImmutableArray EncodeAsImmutable() { var writer = BebopWriter.Create(); - EncodeInto(this, ref writer); + __EncodeInto(this, ref writer); return writer.ToImmutableArray(); } + /// DO NOT CALL THIS METHOD DIRECTLY! [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static void EncodeInto(BaseMusician record, ref BebopWriter writer) { + internal static void __EncodeInto(BaseMusician record, ref BebopWriter writer) { writer.WriteString(record.Name); writer.WriteEnum(record.Plays); } @@ -110,66 +103,67 @@ internal static void EncodeInto(BaseMusician record, ref BebopWriter writer) { [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static T DecodeAs(byte[] record) where T : BaseMusician, new() { var reader = BebopReader.From(record); - return DecodeFrom(ref reader); + return __DecodeFrom(ref reader); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static Musician Decode(byte[] record) { var reader = BebopReader.From(record); - return DecodeFrom(ref reader); + return __DecodeFrom(ref reader); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static T DecodeAs(System.ReadOnlySpan record) where T : BaseMusician, new() { var reader = BebopReader.From(record); - return DecodeFrom(ref reader); + return __DecodeFrom(ref reader); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static Musician Decode(System.ReadOnlySpan record) { var reader = BebopReader.From(record); - return DecodeFrom(ref reader); + return __DecodeFrom(ref reader); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static T DecodeAs(System.ReadOnlyMemory record) where T : BaseMusician, new() { var reader = BebopReader.From(record); - return DecodeFrom(ref reader); + return __DecodeFrom(ref reader); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static Musician Decode(System.ReadOnlyMemory record) { var reader = BebopReader.From(record); - return DecodeFrom(ref reader); + return __DecodeFrom(ref reader); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static T DecodeAs(System.ArraySegment record) where T : BaseMusician, new() { var reader = BebopReader.From(record); - return DecodeFrom(ref reader); + return __DecodeFrom(ref reader); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static Musician Decode(System.ArraySegment record) { var reader = BebopReader.From(record); - return DecodeFrom(ref reader); + return __DecodeFrom(ref reader); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static T DecodeAs(ImmutableArray record) where T : BaseMusician, new() { var reader = BebopReader.From(record); - return DecodeFrom(ref reader); + return __DecodeFrom(ref reader); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static Musician Decode(ImmutableArray record) { var reader = BebopReader.From(record); - return DecodeFrom(ref reader); + return __DecodeFrom(ref reader); } + /// DO NOT CALL THIS METHOD DIRECTLY! [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static Musician DecodeFrom(ref BebopReader reader) { + internal static Musician __DecodeFrom(ref BebopReader reader) { string field0; field0 = reader.ReadString(); @@ -182,7 +176,7 @@ internal static Musician DecodeFrom(ref BebopReader reader) { } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static T DecodeFrom(ref BebopReader reader) where T: BaseMusician, new() { + internal static T __DecodeFrom(ref BebopReader reader) where T: BaseMusician, new() { string field0; field0 = reader.ReadString(); Instrument field1; @@ -195,7 +189,7 @@ internal static Musician DecodeFrom(ref BebopReader reader) { } - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210208-0337")] + [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210301-0356")] [BebopRecord(BebopKind.Message)] public abstract class BaseSong : System.IEquatable { #nullable enable @@ -205,8 +199,21 @@ public abstract class BaseSong : System.IEquatable { public ushort? Year { get; set; } [System.Diagnostics.CodeAnalysis.MaybeNull, System.Diagnostics.CodeAnalysis.AllowNull] public BaseMusician[]? Performers { get; set; } - #nullable disable + /// + /// + protected BaseSong() { } + /// + /// + /// + /// + /// + protected BaseSong([System.Diagnostics.CodeAnalysis.MaybeNull, System.Diagnostics.CodeAnalysis.AllowNull] string? title, [System.Diagnostics.CodeAnalysis.MaybeNull, System.Diagnostics.CodeAnalysis.AllowNull] ushort? year, [System.Diagnostics.CodeAnalysis.MaybeNull, System.Diagnostics.CodeAnalysis.AllowNull] BaseMusician[]? performers) { + Title = title; + Year = year; + Performers = performers; + } + #nullable disable public bool Equals(BaseSong other) { if (ReferenceEquals(null, other)) { return false; @@ -244,40 +251,47 @@ public override int GetHashCode() { } /// - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210208-0337")] + [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210301-0356")] [BebopRecord(BebopKind.Message)] public sealed class Song : BaseSong { + /// + #nullable enable + public Song() : base() { } + /// + public Song([System.Diagnostics.CodeAnalysis.MaybeNull, System.Diagnostics.CodeAnalysis.AllowNull] string? title, [System.Diagnostics.CodeAnalysis.MaybeNull, System.Diagnostics.CodeAnalysis.AllowNull] ushort? year, [System.Diagnostics.CodeAnalysis.MaybeNull, System.Diagnostics.CodeAnalysis.AllowNull] BaseMusician[]? performers) : base(title, year, performers) { } + #nullable disable [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static byte[] Encode(BaseSong record) { var writer = BebopWriter.Create(); - EncodeInto(record, ref writer); + __EncodeInto(record, ref writer); return writer.ToArray(); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public byte[] Encode() { var writer = BebopWriter.Create(); - EncodeInto(this, ref writer); + __EncodeInto(this, ref writer); return writer.ToArray(); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static ImmutableArray EncodeAsImmutable(BaseSong record) { var writer = BebopWriter.Create(); - EncodeInto(record, ref writer); + __EncodeInto(record, ref writer); return writer.ToImmutableArray(); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public ImmutableArray EncodeAsImmutable() { var writer = BebopWriter.Create(); - EncodeInto(this, ref writer); + __EncodeInto(this, ref writer); return writer.ToImmutableArray(); } + /// DO NOT CALL THIS METHOD DIRECTLY! [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static void EncodeInto(BaseSong record, ref BebopWriter writer) { + internal static void __EncodeInto(BaseSong record, ref BebopWriter writer) { var pos = writer.ReserveRecordLength(); var start = writer.Length; @@ -297,7 +311,7 @@ internal static void EncodeInto(BaseSong record, ref BebopWriter writer) { var length0 = unchecked((uint)record.Performers.Length); writer.WriteUInt32(length0); for (var i0 = 0; i0 < length0; i0++) { - Bebop.Codegen.Musician.EncodeInto(record.Performers[i0], ref writer); + Bebop.Codegen.Musician.__EncodeInto(record.Performers[i0], ref writer); } } } @@ -309,66 +323,67 @@ internal static void EncodeInto(BaseSong record, ref BebopWriter writer) { [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static T DecodeAs(byte[] record) where T : BaseSong, new() { var reader = BebopReader.From(record); - return DecodeFrom(ref reader); + return __DecodeFrom(ref reader); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static Song Decode(byte[] record) { var reader = BebopReader.From(record); - return DecodeFrom(ref reader); + return __DecodeFrom(ref reader); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static T DecodeAs(System.ReadOnlySpan record) where T : BaseSong, new() { var reader = BebopReader.From(record); - return DecodeFrom(ref reader); + return __DecodeFrom(ref reader); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static Song Decode(System.ReadOnlySpan record) { var reader = BebopReader.From(record); - return DecodeFrom(ref reader); + return __DecodeFrom(ref reader); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static T DecodeAs(System.ReadOnlyMemory record) where T : BaseSong, new() { var reader = BebopReader.From(record); - return DecodeFrom(ref reader); + return __DecodeFrom(ref reader); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static Song Decode(System.ReadOnlyMemory record) { var reader = BebopReader.From(record); - return DecodeFrom(ref reader); + return __DecodeFrom(ref reader); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static T DecodeAs(System.ArraySegment record) where T : BaseSong, new() { var reader = BebopReader.From(record); - return DecodeFrom(ref reader); + return __DecodeFrom(ref reader); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static Song Decode(System.ArraySegment record) { var reader = BebopReader.From(record); - return DecodeFrom(ref reader); + return __DecodeFrom(ref reader); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static T DecodeAs(ImmutableArray record) where T : BaseSong, new() { var reader = BebopReader.From(record); - return DecodeFrom(ref reader); + return __DecodeFrom(ref reader); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static Song Decode(ImmutableArray record) { var reader = BebopReader.From(record); - return DecodeFrom(ref reader); + return __DecodeFrom(ref reader); } + /// DO NOT CALL THIS METHOD DIRECTLY! [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static Song DecodeFrom(ref BebopReader reader) { + internal static Song __DecodeFrom(ref BebopReader reader) { var record = new Song(); var length = reader.ReadRecordLength(); @@ -389,7 +404,7 @@ internal static Song DecodeFrom(ref BebopReader reader) { record.Performers = new BaseMusician[length0]; for (var i0 = 0; i0 < length0; i0++) { BaseMusician x0; - x0 = Bebop.Codegen.Musician.DecodeFrom(ref reader); + x0 = Bebop.Codegen.Musician.__DecodeFrom(ref reader); record.Performers[i0] = x0; } } @@ -402,7 +417,7 @@ internal static Song DecodeFrom(ref BebopReader reader) { } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static T DecodeFrom(ref BebopReader reader) where T: BaseSong, new() { + internal static T __DecodeFrom(ref BebopReader reader) where T: BaseSong, new() { var record = new T(); var length = reader.ReadRecordLength(); var end = unchecked((int) (reader.Position + length)); @@ -422,7 +437,7 @@ internal static Song DecodeFrom(ref BebopReader reader) { record.Performers = new BaseMusician[length0]; for (var i0 = 0; i0 < length0; i0++) { BaseMusician x0; - x0 = Bebop.Codegen.Musician.DecodeFrom(ref reader); + x0 = Bebop.Codegen.Musician.__DecodeFrom(ref reader); record.Performers[i0] = x0; } } @@ -436,12 +451,21 @@ internal static Song DecodeFrom(ref BebopReader reader) { } - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210208-0337")] + [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210301-0356")] [BebopRecord(BebopKind.Struct)] public abstract class BaseLibrary : System.IEquatable { [System.Diagnostics.CodeAnalysis.NotNull, System.Diagnostics.CodeAnalysis.DisallowNull] public System.Collections.Generic.Dictionary Songs { get; set; } + /// + /// + protected BaseLibrary() { } + /// + /// + /// + protected BaseLibrary([System.Diagnostics.CodeAnalysis.NotNull, System.Diagnostics.CodeAnalysis.DisallowNull] System.Collections.Generic.Dictionary songs) { + Songs = songs; + } public bool Equals(BaseLibrary other) { if (ReferenceEquals(null, other)) { return false; @@ -477,110 +501,116 @@ public override int GetHashCode() { } /// - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210208-0337")] + [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210301-0356")] [BebopRecord(BebopKind.Struct)] public sealed class Library : BaseLibrary { + /// + public Library() : base() { } + /// + public Library([System.Diagnostics.CodeAnalysis.NotNull, System.Diagnostics.CodeAnalysis.DisallowNull] System.Collections.Generic.Dictionary songs) : base(songs) { } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static byte[] Encode(BaseLibrary record) { var writer = BebopWriter.Create(); - EncodeInto(record, ref writer); + __EncodeInto(record, ref writer); return writer.ToArray(); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public byte[] Encode() { var writer = BebopWriter.Create(); - EncodeInto(this, ref writer); + __EncodeInto(this, ref writer); return writer.ToArray(); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static ImmutableArray EncodeAsImmutable(BaseLibrary record) { var writer = BebopWriter.Create(); - EncodeInto(record, ref writer); + __EncodeInto(record, ref writer); return writer.ToImmutableArray(); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public ImmutableArray EncodeAsImmutable() { var writer = BebopWriter.Create(); - EncodeInto(this, ref writer); + __EncodeInto(this, ref writer); return writer.ToImmutableArray(); } + /// DO NOT CALL THIS METHOD DIRECTLY! [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static void EncodeInto(BaseLibrary record, ref BebopWriter writer) { + internal static void __EncodeInto(BaseLibrary record, ref BebopWriter writer) { writer.WriteUInt32(unchecked((uint)record.Songs.Count)); foreach (var kv0 in record.Songs) { writer.WriteGuid(kv0.Key); - Bebop.Codegen.Song.EncodeInto(kv0.Value, ref writer); + Bebop.Codegen.Song.__EncodeInto(kv0.Value, ref writer); } } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static T DecodeAs(byte[] record) where T : BaseLibrary, new() { var reader = BebopReader.From(record); - return DecodeFrom(ref reader); + return __DecodeFrom(ref reader); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static Library Decode(byte[] record) { var reader = BebopReader.From(record); - return DecodeFrom(ref reader); + return __DecodeFrom(ref reader); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static T DecodeAs(System.ReadOnlySpan record) where T : BaseLibrary, new() { var reader = BebopReader.From(record); - return DecodeFrom(ref reader); + return __DecodeFrom(ref reader); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static Library Decode(System.ReadOnlySpan record) { var reader = BebopReader.From(record); - return DecodeFrom(ref reader); + return __DecodeFrom(ref reader); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static T DecodeAs(System.ReadOnlyMemory record) where T : BaseLibrary, new() { var reader = BebopReader.From(record); - return DecodeFrom(ref reader); + return __DecodeFrom(ref reader); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static Library Decode(System.ReadOnlyMemory record) { var reader = BebopReader.From(record); - return DecodeFrom(ref reader); + return __DecodeFrom(ref reader); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static T DecodeAs(System.ArraySegment record) where T : BaseLibrary, new() { var reader = BebopReader.From(record); - return DecodeFrom(ref reader); + return __DecodeFrom(ref reader); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static Library Decode(System.ArraySegment record) { var reader = BebopReader.From(record); - return DecodeFrom(ref reader); + return __DecodeFrom(ref reader); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static T DecodeAs(ImmutableArray record) where T : BaseLibrary, new() { var reader = BebopReader.From(record); - return DecodeFrom(ref reader); + return __DecodeFrom(ref reader); } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] public static Library Decode(ImmutableArray record) { var reader = BebopReader.From(record); - return DecodeFrom(ref reader); + return __DecodeFrom(ref reader); } + /// DO NOT CALL THIS METHOD DIRECTLY! [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static Library DecodeFrom(ref BebopReader reader) { + internal static Library __DecodeFrom(ref BebopReader reader) { System.Collections.Generic.Dictionary field0; { @@ -590,7 +620,7 @@ internal static Library DecodeFrom(ref BebopReader reader) { System.Guid k0; BaseSong v0; k0 = reader.ReadGuid(); - v0 = Bebop.Codegen.Song.DecodeFrom(ref reader); + v0 = Bebop.Codegen.Song.__DecodeFrom(ref reader); field0.Add(k0, v0); } } @@ -600,7 +630,7 @@ internal static Library DecodeFrom(ref BebopReader reader) { } [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static T DecodeFrom(ref BebopReader reader) where T: BaseLibrary, new() { + internal static T __DecodeFrom(ref BebopReader reader) where T: BaseLibrary, new() { System.Collections.Generic.Dictionary field0; { var length0 = unchecked((int)reader.ReadUInt32()); @@ -609,7 +639,7 @@ internal static Library DecodeFrom(ref BebopReader reader) { System.Guid k0; BaseSong v0; k0 = reader.ReadGuid(); - v0 = Bebop.Codegen.Song.DecodeFrom(ref reader); + v0 = Bebop.Codegen.Song.__DecodeFrom(ref reader); field0.Add(k0, v0); } } @@ -620,1989 +650,4 @@ internal static Library DecodeFrom(ref BebopReader reader) { } - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210208-0337")] - [BebopRecord(BebopKind.Message)] - public abstract class BaseA : System.IEquatable { - #nullable enable - [System.Diagnostics.CodeAnalysis.MaybeNull, System.Diagnostics.CodeAnalysis.AllowNull] - public uint? A { get; set; } - #nullable disable - - public bool Equals(BaseA other) { - if (ReferenceEquals(null, other)) { - return false; - } - if (ReferenceEquals(this, other)) { - return true; - } - return A == other.A; - } - - public override bool Equals(object obj) { - if (ReferenceEquals(null, obj)) { - return false; - } - if (ReferenceEquals(this, obj)) { - return true; - } - if (obj is not BaseA baseType) { - return false; - } - return Equals(baseType); - } - - public override int GetHashCode() { - int hash = 1; - if (A is not null) hash ^= A.Value.GetHashCode(); - return hash; - } - - public static bool operator ==(BaseA left, BaseA right) => Equals(left, right); - public static bool operator !=(BaseA left, BaseA right) => !Equals(left, right); - - } - - /// - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210208-0337")] - [BebopRecord(BebopKind.Message)] - public sealed class A : BaseA { - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static byte[] Encode(BaseA record) { - var writer = BebopWriter.Create(); - EncodeInto(record, ref writer); - return writer.ToArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public byte[] Encode() { - var writer = BebopWriter.Create(); - EncodeInto(this, ref writer); - return writer.ToArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static ImmutableArray EncodeAsImmutable(BaseA record) { - var writer = BebopWriter.Create(); - EncodeInto(record, ref writer); - return writer.ToImmutableArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public ImmutableArray EncodeAsImmutable() { - var writer = BebopWriter.Create(); - EncodeInto(this, ref writer); - return writer.ToImmutableArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static void EncodeInto(BaseA record, ref BebopWriter writer) { - var pos = writer.ReserveRecordLength(); - var start = writer.Length; - - if (record.A is not null) { - writer.WriteByte(1); - writer.WriteUInt32(record.A.Value); - } - writer.WriteByte(0); - var end = writer.Length; - writer.FillRecordLength(pos, unchecked((uint) unchecked(end - start))); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(byte[] record) where T : BaseA, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static A Decode(byte[] record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(System.ReadOnlySpan record) where T : BaseA, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static A Decode(System.ReadOnlySpan record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(System.ReadOnlyMemory record) where T : BaseA, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static A Decode(System.ReadOnlyMemory record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(System.ArraySegment record) where T : BaseA, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static A Decode(System.ArraySegment record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(ImmutableArray record) where T : BaseA, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static A Decode(ImmutableArray record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static A DecodeFrom(ref BebopReader reader) { - - var record = new A(); - var length = reader.ReadRecordLength(); - var end = unchecked((int) (reader.Position + length)); - while (true) { - switch (reader.ReadByte()) { - case 0: - return record; - case 1: - record.A = reader.ReadUInt32(); - break; - default: - reader.Position = end; - return record; - } - } - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static T DecodeFrom(ref BebopReader reader) where T: BaseA, new() { - var record = new T(); - var length = reader.ReadRecordLength(); - var end = unchecked((int) (reader.Position + length)); - while (true) { - switch (reader.ReadByte()) { - case 0: - return record; - case 1: - record.A = reader.ReadUInt32(); - break; - default: - reader.Position = end; - return record; - } - } - } - - } - - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210208-0337")] - [BebopRecord(BebopKind.Struct)] - public abstract class BaseB : System.IEquatable { - [System.Diagnostics.CodeAnalysis.NotNull, System.Diagnostics.CodeAnalysis.DisallowNull] - public bool B { get; set; } - - public bool Equals(BaseB other) { - if (ReferenceEquals(null, other)) { - return false; - } - if (ReferenceEquals(this, other)) { - return true; - } - return B == other.B; - } - - public override bool Equals(object obj) { - if (ReferenceEquals(null, obj)) { - return false; - } - if (ReferenceEquals(this, obj)) { - return true; - } - if (obj is not BaseB baseType) { - return false; - } - return Equals(baseType); - } - - public override int GetHashCode() { - int hash = 1; - hash ^= B.GetHashCode(); - return hash; - } - - public static bool operator ==(BaseB left, BaseB right) => Equals(left, right); - public static bool operator !=(BaseB left, BaseB right) => !Equals(left, right); - - } - - /// - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210208-0337")] - [BebopRecord(BebopKind.Struct)] - public sealed class B : BaseB { - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static byte[] Encode(BaseB record) { - var writer = BebopWriter.Create(); - EncodeInto(record, ref writer); - return writer.ToArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public byte[] Encode() { - var writer = BebopWriter.Create(); - EncodeInto(this, ref writer); - return writer.ToArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static ImmutableArray EncodeAsImmutable(BaseB record) { - var writer = BebopWriter.Create(); - EncodeInto(record, ref writer); - return writer.ToImmutableArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public ImmutableArray EncodeAsImmutable() { - var writer = BebopWriter.Create(); - EncodeInto(this, ref writer); - return writer.ToImmutableArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static void EncodeInto(BaseB record, ref BebopWriter writer) { - writer.WriteByte(record.B); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(byte[] record) where T : BaseB, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static B Decode(byte[] record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(System.ReadOnlySpan record) where T : BaseB, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static B Decode(System.ReadOnlySpan record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(System.ReadOnlyMemory record) where T : BaseB, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static B Decode(System.ReadOnlyMemory record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(System.ArraySegment record) where T : BaseB, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static B Decode(System.ArraySegment record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(ImmutableArray record) where T : BaseB, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static B Decode(ImmutableArray record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static B DecodeFrom(ref BebopReader reader) { - - bool field0; - field0 = reader.ReadByte() != 0; - return new B { - B = field0, - }; - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static T DecodeFrom(ref BebopReader reader) where T: BaseB, new() { - bool field0; - field0 = reader.ReadByte() != 0; - return new T { - B = field0, - }; - } - - } - - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210208-0337")] - [BebopRecord(BebopKind.Struct)] - public abstract class BaseC : System.IEquatable { - - public bool Equals(BaseC other) { - if (ReferenceEquals(null, other)) { - return false; - } - if (ReferenceEquals(this, other)) { - return true; - } - return true; - } - - public override bool Equals(object obj) { - if (ReferenceEquals(null, obj)) { - return false; - } - if (ReferenceEquals(this, obj)) { - return true; - } - if (obj is not BaseC baseType) { - return false; - } - return Equals(baseType); - } - - public override int GetHashCode() { - int hash = 1; - return hash; - } - - public static bool operator ==(BaseC left, BaseC right) => Equals(left, right); - public static bool operator !=(BaseC left, BaseC right) => !Equals(left, right); - - } - - /// - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210208-0337")] - [BebopRecord(BebopKind.Struct)] - public sealed class C : BaseC { - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static byte[] Encode(BaseC record) { - var writer = BebopWriter.Create(); - EncodeInto(record, ref writer); - return writer.ToArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public byte[] Encode() { - var writer = BebopWriter.Create(); - EncodeInto(this, ref writer); - return writer.ToArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static ImmutableArray EncodeAsImmutable(BaseC record) { - var writer = BebopWriter.Create(); - EncodeInto(record, ref writer); - return writer.ToImmutableArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public ImmutableArray EncodeAsImmutable() { - var writer = BebopWriter.Create(); - EncodeInto(this, ref writer); - return writer.ToImmutableArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static void EncodeInto(BaseC record, ref BebopWriter writer) { - - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(byte[] record) where T : BaseC, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static C Decode(byte[] record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(System.ReadOnlySpan record) where T : BaseC, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static C Decode(System.ReadOnlySpan record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(System.ReadOnlyMemory record) where T : BaseC, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static C Decode(System.ReadOnlyMemory record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(System.ArraySegment record) where T : BaseC, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static C Decode(System.ArraySegment record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(ImmutableArray record) where T : BaseC, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static C Decode(ImmutableArray record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static C DecodeFrom(ref BebopReader reader) { - - return new C { - }; - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static T DecodeFrom(ref BebopReader reader) where T: BaseC, new() { - return new T { - }; - } - - } - - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210208-0337")] - [BebopRecord(BebopKind.Struct)] - public abstract class BaseD : System.IEquatable { - [System.Diagnostics.CodeAnalysis.NotNull, System.Diagnostics.CodeAnalysis.DisallowNull] - public string S { get; set; } - - public bool Equals(BaseD other) { - if (ReferenceEquals(null, other)) { - return false; - } - if (ReferenceEquals(this, other)) { - return true; - } - return S == other.S; - } - - public override bool Equals(object obj) { - if (ReferenceEquals(null, obj)) { - return false; - } - if (ReferenceEquals(this, obj)) { - return true; - } - if (obj is not BaseD baseType) { - return false; - } - return Equals(baseType); - } - - public override int GetHashCode() { - int hash = 1; - hash ^= S.GetHashCode(); - return hash; - } - - public static bool operator ==(BaseD left, BaseD right) => Equals(left, right); - public static bool operator !=(BaseD left, BaseD right) => !Equals(left, right); - - } - - /// - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210208-0337")] - [BebopRecord(BebopKind.Struct)] - public sealed class D : BaseD { - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static byte[] Encode(BaseD record) { - var writer = BebopWriter.Create(); - EncodeInto(record, ref writer); - return writer.ToArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public byte[] Encode() { - var writer = BebopWriter.Create(); - EncodeInto(this, ref writer); - return writer.ToArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static ImmutableArray EncodeAsImmutable(BaseD record) { - var writer = BebopWriter.Create(); - EncodeInto(record, ref writer); - return writer.ToImmutableArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public ImmutableArray EncodeAsImmutable() { - var writer = BebopWriter.Create(); - EncodeInto(this, ref writer); - return writer.ToImmutableArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static void EncodeInto(BaseD record, ref BebopWriter writer) { - writer.WriteString(record.S); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(byte[] record) where T : BaseD, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static D Decode(byte[] record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(System.ReadOnlySpan record) where T : BaseD, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static D Decode(System.ReadOnlySpan record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(System.ReadOnlyMemory record) where T : BaseD, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static D Decode(System.ReadOnlyMemory record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(System.ArraySegment record) where T : BaseD, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static D Decode(System.ArraySegment record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(ImmutableArray record) where T : BaseD, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static D Decode(ImmutableArray record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static D DecodeFrom(ref BebopReader reader) { - - string field0; - field0 = reader.ReadString(); - return new D { - S = field0, - }; - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static T DecodeFrom(ref BebopReader reader) where T: BaseD, new() { - string field0; - field0 = reader.ReadString(); - return new T { - S = field0, - }; - } - - } - - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210208-0337")] - [BebopRecord(BebopKind.Struct)] - public abstract class BaseX : System.IEquatable { - [System.Diagnostics.CodeAnalysis.NotNull, System.Diagnostics.CodeAnalysis.DisallowNull] - public bool X { get; set; } - - public bool Equals(BaseX other) { - if (ReferenceEquals(null, other)) { - return false; - } - if (ReferenceEquals(this, other)) { - return true; - } - return X == other.X; - } - - public override bool Equals(object obj) { - if (ReferenceEquals(null, obj)) { - return false; - } - if (ReferenceEquals(this, obj)) { - return true; - } - if (obj is not BaseX baseType) { - return false; - } - return Equals(baseType); - } - - public override int GetHashCode() { - int hash = 1; - hash ^= X.GetHashCode(); - return hash; - } - - public static bool operator ==(BaseX left, BaseX right) => Equals(left, right); - public static bool operator !=(BaseX left, BaseX right) => !Equals(left, right); - - } - - /// - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210208-0337")] - [BebopRecord(BebopKind.Struct)] - public sealed class X : BaseX { - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static byte[] Encode(BaseX record) { - var writer = BebopWriter.Create(); - EncodeInto(record, ref writer); - return writer.ToArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public byte[] Encode() { - var writer = BebopWriter.Create(); - EncodeInto(this, ref writer); - return writer.ToArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static ImmutableArray EncodeAsImmutable(BaseX record) { - var writer = BebopWriter.Create(); - EncodeInto(record, ref writer); - return writer.ToImmutableArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public ImmutableArray EncodeAsImmutable() { - var writer = BebopWriter.Create(); - EncodeInto(this, ref writer); - return writer.ToImmutableArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static void EncodeInto(BaseX record, ref BebopWriter writer) { - writer.WriteByte(record.X); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(byte[] record) where T : BaseX, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static X Decode(byte[] record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(System.ReadOnlySpan record) where T : BaseX, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static X Decode(System.ReadOnlySpan record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(System.ReadOnlyMemory record) where T : BaseX, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static X Decode(System.ReadOnlyMemory record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(System.ArraySegment record) where T : BaseX, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static X Decode(System.ArraySegment record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(ImmutableArray record) where T : BaseX, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static X Decode(ImmutableArray record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static X DecodeFrom(ref BebopReader reader) { - - bool field0; - field0 = reader.ReadByte() != 0; - return new X { - X = field0, - }; - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static T DecodeFrom(ref BebopReader reader) where T: BaseX, new() { - bool field0; - field0 = reader.ReadByte() != 0; - return new T { - X = field0, - }; - } - - } - - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210208-0337")] - public abstract class BaseW where T0: BaseD where T1: BaseX { - internal readonly T0 _value0; - internal readonly T1 _value1; - private readonly byte _discriminator; - - protected BaseW(WUnion input) { - _discriminator = input.Discriminator; - switch (_discriminator) { - case 1: _value0 = input.AsBaseD; break; - case 2: _value1 = input.AsBaseX; break; - default: throw new BebopRuntimeException(); - } - } - - public object Value => _discriminator switch { - 1 => _value0, - 2 => _value1, - _ => throw new BebopRuntimeException() - }; - - public byte Discriminator => _discriminator; - - public bool IsBaseD => _discriminator is 1; - public T0 AsBaseD => _discriminator is 1 ? _value0 : throw new NotImplementedException($"Cannot return as BaseD as result is T0"); - - public bool IsBaseX => _discriminator is 2; - public T1 AsBaseX => _discriminator is 2 ? _value1 : throw new NotImplementedException($"Cannot return as BaseX as result is T1"); - - public void Switch(Action f0, Action f1) { - if (_discriminator is 1 && f0 is not null) { - f0(_value0); - return; - } - if (_discriminator is 2 && f1 is not null) { - f1(_value1); - return; - } - throw new BebopRuntimeException(); - } - - public TResult Match(Func f0, Func f1) => _discriminator switch { - 1 when f0 is not null => f0(_value0), - 2 when f1 is not null => f1(_value1), - _ => throw new BebopRuntimeException() - }; - - private bool Equals(BaseW other) => _discriminator == other.Discriminator && _discriminator switch { - 1 => Equals(_value0, other._value0), - 2 => Equals(_value1, other._value1), - _ => false - }; - - public override bool Equals(object other) { - if (ReferenceEquals(null, other)) { - return false; - } - if (ReferenceEquals(this, other)) { - return true; - } - return other is BaseW o && Equals(o); - } - - public static bool operator ==(BaseW left, BaseW right) => Equals(left, right); - public static bool operator !=(BaseW left, BaseW right) => !Equals(left, right); - public override int GetHashCode() => (_discriminator switch { - 1 => _value0?.GetHashCode() ?? 0, - 2 => _value1?.GetHashCode() ?? 0, - _ => 0 - } * 397) ^ _discriminator; - - } - - /// - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210208-0337")] - [BebopRecord(BebopKind.Union)] - public abstract class BaseW : BaseW { - protected BaseW(WUnion _) : base(_) { } - } - - /// - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210208-0337")] - [BebopRecord(BebopKind.Union)] - public sealed class W : BaseW { - - private W(WUnion _) : base(_) { } - - public static implicit operator W(BaseD _) => new (_); - public static W FromBaseD(BaseD input) => new (input); - - public static implicit operator W(BaseX _) => new (_); - public static W FromBaseX(BaseX input) => new (input); - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static void EncodeInto(BaseW record, ref BebopWriter writer) { - var pos = writer.ReserveRecordLength(); - writer.WriteByte(record.Discriminator); - var start = writer.Length; - switch (record.Discriminator) { - case 1: Bebop.Codegen.D.EncodeInto(record.AsBaseD, ref writer); break; - case 2: Bebop.Codegen.X.EncodeInto(record.AsBaseX, ref writer); break; - } - var end = writer.Length; - writer.FillRecordLength(pos, unchecked((uint) unchecked(end - start))); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static W DecodeFrom(ref BebopReader reader) { - - var length = reader.ReadRecordLength(); - var end = unchecked((int) (reader.Position + length)); - switch (reader.ReadByte()) { - case 1: - return Bebop.Codegen.D.DecodeFrom(ref reader); - case 2: - return Bebop.Codegen.X.DecodeFrom(ref reader); - default: - reader.Position = end; - return null; - } - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static byte[] Encode(BaseW record) { - var writer = BebopWriter.Create(); - EncodeInto(record, ref writer); - return writer.ToArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public byte[] Encode() { - var writer = BebopWriter.Create(); - EncodeInto(this, ref writer); - return writer.ToArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static ImmutableArray EncodeAsImmutable(BaseW record) { - var writer = BebopWriter.Create(); - EncodeInto(record, ref writer); - return writer.ToImmutableArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public ImmutableArray EncodeAsImmutable() { - var writer = BebopWriter.Create(); - EncodeInto(this, ref writer); - return writer.ToImmutableArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static W Decode(byte[] record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static W Decode(System.ReadOnlySpan record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static W Decode(System.ReadOnlyMemory record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static W Decode(System.ArraySegment record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static W Decode(ImmutableArray record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - } - - /// - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210208-0337")] - public readonly struct WUnion where T0: BaseD where T1: BaseX { - - internal readonly T0 _value0; - internal readonly T1 _value1; - private readonly byte _discriminator; - - private WUnion(byte discriminator, T0 value0 = default, T1 value1 = default) { - _discriminator = discriminator; - _value0 = value0; - _value1 = value1; - } - - public object Value => _discriminator switch { - 1 => _value0, - 2 => _value1, - _ => throw new BebopRuntimeException() - }; - - public byte Discriminator => _discriminator; - - public bool IsBaseD => _discriminator is 1; - public T0 AsBaseD => _discriminator is 1 ? _value0 : throw new NotImplementedException($"Cannot return as BaseD as result is T0"); - - public bool IsBaseX => _discriminator is 2; - public T1 AsBaseX => _discriminator is 2 ? _value1 : throw new NotImplementedException($"Cannot return as BaseX as result is T1"); - - public static implicit operator WUnion(T0 t) => new WUnion(1, value0: t); - public static WUnion FromBaseD(T0 input) => input; - - public static implicit operator WUnion(T1 t) => new WUnion(2, value1: t); - public static WUnion FromBaseX(T1 input) => input; - - - public void Switch(Action f0, Action f1) { - if (_discriminator is 1 && f0 is not null) { - f0(_value0); - return; - } - if (_discriminator is 2 && f1 is not null) { - f1(_value1); - return; - } - throw new BebopRuntimeException(); - } - - public TResult Match(Func f0, Func f1) => _discriminator switch { - 1 when f0 is not null => f0(_value0), - 2 when f1 is not null => f1(_value1), - _ => throw new BebopRuntimeException() - }; - - private bool Equals(BaseW other) => _discriminator == other.Discriminator && _discriminator switch { - 1 => Equals(_value0, other._value0), - 2 => Equals(_value1, other._value1), - _ => false - }; - - public override bool Equals(object other) { - if (ReferenceEquals(null, other)) { - return false; - } - return other is BaseW o && Equals(o); - } - - public override int GetHashCode() => (_discriminator switch { - 1 => _value0?.GetHashCode() ?? 0, - 2 => _value1?.GetHashCode() ?? 0, - _ => 0 - } * 397) ^ _discriminator; - - } - - /// - /// This union is so documented! - /// - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210208-0337")] - public abstract class BaseU where T0: BaseA where T1: BaseB where T2: BaseC where T3: BaseW { - public const uint OpCode = 0x68616579; - internal readonly T0 _value0; - internal readonly T1 _value1; - internal readonly T2 _value2; - internal readonly T3 _value3; - private readonly byte _discriminator; - - protected BaseU(UUnion input) { - _discriminator = input.Discriminator; - switch (_discriminator) { - case 1: _value0 = input.AsBaseA; break; - case 2: _value1 = input.AsBaseB; break; - case 3: _value2 = input.AsBaseC; break; - case 4: _value3 = input.AsBaseW; break; - default: throw new BebopRuntimeException(); - } - } - - public object Value => _discriminator switch { - 1 => _value0, - 2 => _value1, - 3 => _value2, - 4 => _value3, - _ => throw new BebopRuntimeException() - }; - - public byte Discriminator => _discriminator; - - public bool IsBaseA => _discriminator is 1; - public T0 AsBaseA => _discriminator is 1 ? _value0 : throw new NotImplementedException($"Cannot return as BaseA as result is T0"); - - public bool IsBaseB => _discriminator is 2; - public T1 AsBaseB => _discriminator is 2 ? _value1 : throw new NotImplementedException($"Cannot return as BaseB as result is T1"); - - public bool IsBaseC => _discriminator is 3; - public T2 AsBaseC => _discriminator is 3 ? _value2 : throw new NotImplementedException($"Cannot return as BaseC as result is T2"); - - public bool IsBaseW => _discriminator is 4; - public T3 AsBaseW => _discriminator is 4 ? _value3 : throw new NotImplementedException($"Cannot return as BaseW as result is T3"); - - public void Switch(Action f0, Action f1, Action f2, Action f3) { - if (_discriminator is 1 && f0 is not null) { - f0(_value0); - return; - } - if (_discriminator is 2 && f1 is not null) { - f1(_value1); - return; - } - if (_discriminator is 3 && f2 is not null) { - f2(_value2); - return; - } - if (_discriminator is 4 && f3 is not null) { - f3(_value3); - return; - } - throw new BebopRuntimeException(); - } - - public TResult Match(Func f0, Func f1, Func f2, Func f3) => _discriminator switch { - 1 when f0 is not null => f0(_value0), - 2 when f1 is not null => f1(_value1), - 3 when f2 is not null => f2(_value2), - 4 when f3 is not null => f3(_value3), - _ => throw new BebopRuntimeException() - }; - - private bool Equals(BaseU other) => _discriminator == other.Discriminator && _discriminator switch { - 1 => Equals(_value0, other._value0), - 2 => Equals(_value1, other._value1), - 3 => Equals(_value2, other._value2), - 4 => Equals(_value3, other._value3), - _ => false - }; - - public override bool Equals(object other) { - if (ReferenceEquals(null, other)) { - return false; - } - if (ReferenceEquals(this, other)) { - return true; - } - return other is BaseU o && Equals(o); - } - - public static bool operator ==(BaseU left, BaseU right) => Equals(left, right); - public static bool operator !=(BaseU left, BaseU right) => !Equals(left, right); - public override int GetHashCode() => (_discriminator switch { - 1 => _value0?.GetHashCode() ?? 0, - 2 => _value1?.GetHashCode() ?? 0, - 3 => _value2?.GetHashCode() ?? 0, - 4 => _value3?.GetHashCode() ?? 0, - _ => 0 - } * 397) ^ _discriminator; - - } - - /// - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210208-0337")] - [BebopRecord(BebopKind.Union)] - public abstract class BaseU : BaseU { - protected BaseU(UUnion _) : base(_) { } - } - - /// - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210208-0337")] - [BebopRecord(BebopKind.Union)] - public sealed class U : BaseU { - - private U(UUnion _) : base(_) { } - - public static implicit operator U(BaseA _) => new (_); - public static U FromBaseA(BaseA input) => new (input); - - public static implicit operator U(BaseB _) => new (_); - public static U FromBaseB(BaseB input) => new (input); - - public static implicit operator U(BaseC _) => new (_); - public static U FromBaseC(BaseC input) => new (input); - - public static implicit operator U(BaseW _) => new (_); - public static U FromBaseW(BaseW input) => new (input); - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static void EncodeInto(BaseU record, ref BebopWriter writer) { - var pos = writer.ReserveRecordLength(); - writer.WriteByte(record.Discriminator); - var start = writer.Length; - switch (record.Discriminator) { - case 1: Bebop.Codegen.A.EncodeInto(record.AsBaseA, ref writer); break; - case 2: Bebop.Codegen.B.EncodeInto(record.AsBaseB, ref writer); break; - case 3: Bebop.Codegen.C.EncodeInto(record.AsBaseC, ref writer); break; - case 4: Bebop.Codegen.W.EncodeInto(record.AsBaseW, ref writer); break; - } - var end = writer.Length; - writer.FillRecordLength(pos, unchecked((uint) unchecked(end - start))); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static U DecodeFrom(ref BebopReader reader) { - - var length = reader.ReadRecordLength(); - var end = unchecked((int) (reader.Position + length)); - switch (reader.ReadByte()) { - case 1: - return Bebop.Codegen.A.DecodeFrom(ref reader); - case 2: - return Bebop.Codegen.B.DecodeFrom(ref reader); - case 3: - return Bebop.Codegen.C.DecodeFrom(ref reader); - case 4: - return Bebop.Codegen.W.DecodeFrom(ref reader); - default: - reader.Position = end; - return null; - } - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static byte[] Encode(BaseU record) { - var writer = BebopWriter.Create(); - EncodeInto(record, ref writer); - return writer.ToArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public byte[] Encode() { - var writer = BebopWriter.Create(); - EncodeInto(this, ref writer); - return writer.ToArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static ImmutableArray EncodeAsImmutable(BaseU record) { - var writer = BebopWriter.Create(); - EncodeInto(record, ref writer); - return writer.ToImmutableArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public ImmutableArray EncodeAsImmutable() { - var writer = BebopWriter.Create(); - EncodeInto(this, ref writer); - return writer.ToImmutableArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static U Decode(byte[] record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static U Decode(System.ReadOnlySpan record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static U Decode(System.ReadOnlyMemory record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static U Decode(System.ArraySegment record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static U Decode(ImmutableArray record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - } - - /// - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210208-0337")] - public readonly struct UUnion where T0: BaseA where T1: BaseB where T2: BaseC where T3: BaseW { - - internal readonly T0 _value0; - internal readonly T1 _value1; - internal readonly T2 _value2; - internal readonly T3 _value3; - private readonly byte _discriminator; - - private UUnion(byte discriminator, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default) { - _discriminator = discriminator; - _value0 = value0; - _value1 = value1; - _value2 = value2; - _value3 = value3; - } - - public object Value => _discriminator switch { - 1 => _value0, - 2 => _value1, - 3 => _value2, - 4 => _value3, - _ => throw new BebopRuntimeException() - }; - - public byte Discriminator => _discriminator; - - public bool IsBaseA => _discriminator is 1; - public T0 AsBaseA => _discriminator is 1 ? _value0 : throw new NotImplementedException($"Cannot return as BaseA as result is T0"); - - public bool IsBaseB => _discriminator is 2; - public T1 AsBaseB => _discriminator is 2 ? _value1 : throw new NotImplementedException($"Cannot return as BaseB as result is T1"); - - public bool IsBaseC => _discriminator is 3; - public T2 AsBaseC => _discriminator is 3 ? _value2 : throw new NotImplementedException($"Cannot return as BaseC as result is T2"); - - public bool IsBaseW => _discriminator is 4; - public T3 AsBaseW => _discriminator is 4 ? _value3 : throw new NotImplementedException($"Cannot return as BaseW as result is T3"); - - public static implicit operator UUnion(T0 t) => new UUnion(1, value0: t); - public static UUnion FromBaseA(T0 input) => input; - - public static implicit operator UUnion(T1 t) => new UUnion(2, value1: t); - public static UUnion FromBaseB(T1 input) => input; - - public static implicit operator UUnion(T2 t) => new UUnion(3, value2: t); - public static UUnion FromBaseC(T2 input) => input; - - public static implicit operator UUnion(T3 t) => new UUnion(4, value3: t); - public static UUnion FromBaseW(T3 input) => input; - - - public void Switch(Action f0, Action f1, Action f2, Action f3) { - if (_discriminator is 1 && f0 is not null) { - f0(_value0); - return; - } - if (_discriminator is 2 && f1 is not null) { - f1(_value1); - return; - } - if (_discriminator is 3 && f2 is not null) { - f2(_value2); - return; - } - if (_discriminator is 4 && f3 is not null) { - f3(_value3); - return; - } - throw new BebopRuntimeException(); - } - - public TResult Match(Func f0, Func f1, Func f2, Func f3) => _discriminator switch { - 1 when f0 is not null => f0(_value0), - 2 when f1 is not null => f1(_value1), - 3 when f2 is not null => f2(_value2), - 4 when f3 is not null => f3(_value3), - _ => throw new BebopRuntimeException() - }; - - private bool Equals(BaseU other) => _discriminator == other.Discriminator && _discriminator switch { - 1 => Equals(_value0, other._value0), - 2 => Equals(_value1, other._value1), - 3 => Equals(_value2, other._value2), - 4 => Equals(_value3, other._value3), - _ => false - }; - - public override bool Equals(object other) { - if (ReferenceEquals(null, other)) { - return false; - } - return other is BaseU o && Equals(o); - } - - public override int GetHashCode() => (_discriminator switch { - 1 => _value0?.GetHashCode() ?? 0, - 2 => _value1?.GetHashCode() ?? 0, - 3 => _value2?.GetHashCode() ?? 0, - 4 => _value3?.GetHashCode() ?? 0, - _ => 0 - } * 397) ^ _discriminator; - - } - - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210208-0337")] - [BebopRecord(BebopKind.Struct)] - public abstract class BaseCons : System.IEquatable { - [System.Diagnostics.CodeAnalysis.NotNull, System.Diagnostics.CodeAnalysis.DisallowNull] - public uint Head { get; set; } - [System.Diagnostics.CodeAnalysis.NotNull, System.Diagnostics.CodeAnalysis.DisallowNull] - public BaseList Tail { get; set; } - - public bool Equals(BaseCons other) { - if (ReferenceEquals(null, other)) { - return false; - } - if (ReferenceEquals(this, other)) { - return true; - } - return Head == other.Head && Tail == other.Tail; - } - - public override bool Equals(object obj) { - if (ReferenceEquals(null, obj)) { - return false; - } - if (ReferenceEquals(this, obj)) { - return true; - } - if (obj is not BaseCons baseType) { - return false; - } - return Equals(baseType); - } - - public override int GetHashCode() { - int hash = 1; - hash ^= Head.GetHashCode(); - hash ^= Tail.GetHashCode(); - return hash; - } - - public static bool operator ==(BaseCons left, BaseCons right) => Equals(left, right); - public static bool operator !=(BaseCons left, BaseCons right) => !Equals(left, right); - - } - - /// - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210208-0337")] - [BebopRecord(BebopKind.Struct)] - public sealed class Cons : BaseCons { - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static byte[] Encode(BaseCons record) { - var writer = BebopWriter.Create(); - EncodeInto(record, ref writer); - return writer.ToArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public byte[] Encode() { - var writer = BebopWriter.Create(); - EncodeInto(this, ref writer); - return writer.ToArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static ImmutableArray EncodeAsImmutable(BaseCons record) { - var writer = BebopWriter.Create(); - EncodeInto(record, ref writer); - return writer.ToImmutableArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public ImmutableArray EncodeAsImmutable() { - var writer = BebopWriter.Create(); - EncodeInto(this, ref writer); - return writer.ToImmutableArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static void EncodeInto(BaseCons record, ref BebopWriter writer) { - writer.WriteUInt32(record.Head); - Bebop.Codegen.List.EncodeInto(record.Tail, ref writer); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(byte[] record) where T : BaseCons, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static Cons Decode(byte[] record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(System.ReadOnlySpan record) where T : BaseCons, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static Cons Decode(System.ReadOnlySpan record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(System.ReadOnlyMemory record) where T : BaseCons, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static Cons Decode(System.ReadOnlyMemory record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(System.ArraySegment record) where T : BaseCons, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static Cons Decode(System.ArraySegment record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(ImmutableArray record) where T : BaseCons, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static Cons Decode(ImmutableArray record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static Cons DecodeFrom(ref BebopReader reader) { - - uint field0; - field0 = reader.ReadUInt32(); - BaseList field1; - field1 = Bebop.Codegen.List.DecodeFrom(ref reader); - return new Cons { - Head = field0, - Tail = field1, - }; - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static T DecodeFrom(ref BebopReader reader) where T: BaseCons, new() { - uint field0; - field0 = reader.ReadUInt32(); - BaseList field1; - field1 = Bebop.Codegen.List.DecodeFrom(ref reader); - return new T { - Head = field0, - Tail = field1, - }; - } - - } - - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210208-0337")] - [BebopRecord(BebopKind.Struct)] - public abstract class BaseNil : System.IEquatable { - - public bool Equals(BaseNil other) { - if (ReferenceEquals(null, other)) { - return false; - } - if (ReferenceEquals(this, other)) { - return true; - } - return true; - } - - public override bool Equals(object obj) { - if (ReferenceEquals(null, obj)) { - return false; - } - if (ReferenceEquals(this, obj)) { - return true; - } - if (obj is not BaseNil baseType) { - return false; - } - return Equals(baseType); - } - - public override int GetHashCode() { - int hash = 1; - return hash; - } - - public static bool operator ==(BaseNil left, BaseNil right) => Equals(left, right); - public static bool operator !=(BaseNil left, BaseNil right) => !Equals(left, right); - - } - - /// - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210208-0337")] - [BebopRecord(BebopKind.Struct)] - public sealed class Nil : BaseNil { - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static byte[] Encode(BaseNil record) { - var writer = BebopWriter.Create(); - EncodeInto(record, ref writer); - return writer.ToArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public byte[] Encode() { - var writer = BebopWriter.Create(); - EncodeInto(this, ref writer); - return writer.ToArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static ImmutableArray EncodeAsImmutable(BaseNil record) { - var writer = BebopWriter.Create(); - EncodeInto(record, ref writer); - return writer.ToImmutableArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public ImmutableArray EncodeAsImmutable() { - var writer = BebopWriter.Create(); - EncodeInto(this, ref writer); - return writer.ToImmutableArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static void EncodeInto(BaseNil record, ref BebopWriter writer) { - - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(byte[] record) where T : BaseNil, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static Nil Decode(byte[] record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(System.ReadOnlySpan record) where T : BaseNil, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static Nil Decode(System.ReadOnlySpan record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(System.ReadOnlyMemory record) where T : BaseNil, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static Nil Decode(System.ReadOnlyMemory record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(System.ArraySegment record) where T : BaseNil, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static Nil Decode(System.ArraySegment record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static T DecodeAs(ImmutableArray record) where T : BaseNil, new() { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static Nil Decode(ImmutableArray record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static Nil DecodeFrom(ref BebopReader reader) { - - return new Nil { - }; - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static T DecodeFrom(ref BebopReader reader) where T: BaseNil, new() { - return new T { - }; - } - - } - - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210208-0337")] - public abstract class BaseList where T0: BaseCons where T1: BaseNil { - internal readonly T0 _value0; - internal readonly T1 _value1; - private readonly byte _discriminator; - - protected BaseList(ListUnion input) { - _discriminator = input.Discriminator; - switch (_discriminator) { - case 1: _value0 = input.AsBaseCons; break; - case 2: _value1 = input.AsBaseNil; break; - default: throw new BebopRuntimeException(); - } - } - - public object Value => _discriminator switch { - 1 => _value0, - 2 => _value1, - _ => throw new BebopRuntimeException() - }; - - public byte Discriminator => _discriminator; - - public bool IsBaseCons => _discriminator is 1; - public T0 AsBaseCons => _discriminator is 1 ? _value0 : throw new NotImplementedException($"Cannot return as BaseCons as result is T0"); - - public bool IsBaseNil => _discriminator is 2; - public T1 AsBaseNil => _discriminator is 2 ? _value1 : throw new NotImplementedException($"Cannot return as BaseNil as result is T1"); - - public void Switch(Action f0, Action f1) { - if (_discriminator is 1 && f0 is not null) { - f0(_value0); - return; - } - if (_discriminator is 2 && f1 is not null) { - f1(_value1); - return; - } - throw new BebopRuntimeException(); - } - - public TResult Match(Func f0, Func f1) => _discriminator switch { - 1 when f0 is not null => f0(_value0), - 2 when f1 is not null => f1(_value1), - _ => throw new BebopRuntimeException() - }; - - private bool Equals(BaseList other) => _discriminator == other.Discriminator && _discriminator switch { - 1 => Equals(_value0, other._value0), - 2 => Equals(_value1, other._value1), - _ => false - }; - - public override bool Equals(object other) { - if (ReferenceEquals(null, other)) { - return false; - } - if (ReferenceEquals(this, other)) { - return true; - } - return other is BaseList o && Equals(o); - } - - public static bool operator ==(BaseList left, BaseList right) => Equals(left, right); - public static bool operator !=(BaseList left, BaseList right) => !Equals(left, right); - public override int GetHashCode() => (_discriminator switch { - 1 => _value0?.GetHashCode() ?? 0, - 2 => _value1?.GetHashCode() ?? 0, - _ => 0 - } * 397) ^ _discriminator; - - } - - /// - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210208-0337")] - [BebopRecord(BebopKind.Union)] - public abstract class BaseList : BaseList { - protected BaseList(ListUnion _) : base(_) { } - } - - /// - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210208-0337")] - [BebopRecord(BebopKind.Union)] - public sealed class List : BaseList { - - private List(ListUnion _) : base(_) { } - - public static implicit operator List(BaseCons _) => new (_); - public static List FromBaseCons(BaseCons input) => new (input); - - public static implicit operator List(BaseNil _) => new (_); - public static List FromBaseNil(BaseNil input) => new (input); - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static void EncodeInto(BaseList record, ref BebopWriter writer) { - var pos = writer.ReserveRecordLength(); - writer.WriteByte(record.Discriminator); - var start = writer.Length; - switch (record.Discriminator) { - case 1: Bebop.Codegen.Cons.EncodeInto(record.AsBaseCons, ref writer); break; - case 2: Bebop.Codegen.Nil.EncodeInto(record.AsBaseNil, ref writer); break; - } - var end = writer.Length; - writer.FillRecordLength(pos, unchecked((uint) unchecked(end - start))); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - internal static List DecodeFrom(ref BebopReader reader) { - - var length = reader.ReadRecordLength(); - var end = unchecked((int) (reader.Position + length)); - switch (reader.ReadByte()) { - case 1: - return Bebop.Codegen.Cons.DecodeFrom(ref reader); - case 2: - return Bebop.Codegen.Nil.DecodeFrom(ref reader); - default: - reader.Position = end; - return null; - } - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static byte[] Encode(BaseList record) { - var writer = BebopWriter.Create(); - EncodeInto(record, ref writer); - return writer.ToArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public byte[] Encode() { - var writer = BebopWriter.Create(); - EncodeInto(this, ref writer); - return writer.ToArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static ImmutableArray EncodeAsImmutable(BaseList record) { - var writer = BebopWriter.Create(); - EncodeInto(record, ref writer); - return writer.ToImmutableArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public ImmutableArray EncodeAsImmutable() { - var writer = BebopWriter.Create(); - EncodeInto(this, ref writer); - return writer.ToImmutableArray(); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static List Decode(byte[] record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static List Decode(System.ReadOnlySpan record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static List Decode(System.ReadOnlyMemory record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static List Decode(System.ArraySegment record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - [System.Runtime.CompilerServices.MethodImpl(BebopConstants.HotPath)] - public static List Decode(ImmutableArray record) { - var reader = BebopReader.From(record); - return DecodeFrom(ref reader); - } - - } - - /// - [System.CodeDom.Compiler.GeneratedCode("bebopc", "0.0.1-20210208-0337")] - public readonly struct ListUnion where T0: BaseCons where T1: BaseNil { - - internal readonly T0 _value0; - internal readonly T1 _value1; - private readonly byte _discriminator; - - private ListUnion(byte discriminator, T0 value0 = default, T1 value1 = default) { - _discriminator = discriminator; - _value0 = value0; - _value1 = value1; - } - - public object Value => _discriminator switch { - 1 => _value0, - 2 => _value1, - _ => throw new BebopRuntimeException() - }; - - public byte Discriminator => _discriminator; - - public bool IsBaseCons => _discriminator is 1; - public T0 AsBaseCons => _discriminator is 1 ? _value0 : throw new NotImplementedException($"Cannot return as BaseCons as result is T0"); - - public bool IsBaseNil => _discriminator is 2; - public T1 AsBaseNil => _discriminator is 2 ? _value1 : throw new NotImplementedException($"Cannot return as BaseNil as result is T1"); - - public static implicit operator ListUnion(T0 t) => new ListUnion(1, value0: t); - public static ListUnion FromBaseCons(T0 input) => input; - - public static implicit operator ListUnion(T1 t) => new ListUnion(2, value1: t); - public static ListUnion FromBaseNil(T1 input) => input; - - - public void Switch(Action f0, Action f1) { - if (_discriminator is 1 && f0 is not null) { - f0(_value0); - return; - } - if (_discriminator is 2 && f1 is not null) { - f1(_value1); - return; - } - throw new BebopRuntimeException(); - } - - public TResult Match(Func f0, Func f1) => _discriminator switch { - 1 when f0 is not null => f0(_value0), - 2 when f1 is not null => f1(_value1), - _ => throw new BebopRuntimeException() - }; - - private bool Equals(BaseList other) => _discriminator == other.Discriminator && _discriminator switch { - 1 => Equals(_value0, other._value0), - 2 => Equals(_value1, other._value1), - _ => false - }; - - public override bool Equals(object other) { - if (ReferenceEquals(null, other)) { - return false; - } - return other is BaseList o && Equals(o); - } - - public override int GetHashCode() => (_discriminator switch { - 1 => _value0?.GetHashCode() ?? 0, - 2 => _value1?.GetHashCode() ?? 0, - _ => 0 - } * 397) ^ _discriminator; - - } - } diff --git a/Laboratory/C#/bebop-net.sln b/Laboratory/C#/bebop-net.sln index da57b001..7e40f0b0 100644 --- a/Laboratory/C#/bebop-net.sln +++ b/Laboratory/C#/bebop-net.sln @@ -13,6 +13,7 @@ Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "GeneratedTestCode", "Genera EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution + GeneratedTestCode\GeneratedTestCode.projitems*{32498399-92f5-47c8-b792-235a7e311f95}*SharedItemsImports = 5 GeneratedTestCode\GeneratedTestCode.projitems*{a54205bb-1ecc-4901-9cda-2f2186ad0584}*SharedItemsImports = 5 GeneratedTestCode\GeneratedTestCode.projitems*{cadef40f-bdcc-40ee-8995-c5d33194431b}*SharedItemsImports = 13 EndGlobalSection diff --git a/Laboratory/C++/test/.gitignore b/Laboratory/C++/.gitignore similarity index 100% rename from Laboratory/C++/test/.gitignore rename to Laboratory/C++/.gitignore diff --git a/Laboratory/C++/README.md b/Laboratory/C++/README.md index ab24faa2..1c004826 100644 --- a/Laboratory/C++/README.md +++ b/Laboratory/C++/README.md @@ -1,5 +1,5 @@ Try this: - cd test - dotnet run --project ../../../Compiler --cpp "../gen/jazz.hpp" --files "../../Schemas/jazz.bop" - g++ -std=c++17 test.cpp && ./a.out + ./run_test.sh jazz + ./run_test.sh union_perf_a + ./run_test.sh union_perf_b diff --git a/Laboratory/C++/gen/bebop.hpp b/Laboratory/C++/gen/bebop.hpp deleted file mode 120000 index f8373e37..00000000 --- a/Laboratory/C++/gen/bebop.hpp +++ /dev/null @@ -1 +0,0 @@ -../../../Runtime/C++/src/bebop.hpp \ No newline at end of file diff --git a/Laboratory/C++/gen/bebop.hpp b/Laboratory/C++/gen/bebop.hpp new file mode 100644 index 00000000..8eaa42f3 --- /dev/null +++ b/Laboratory/C++/gen/bebop.hpp @@ -0,0 +1,403 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +#ifndef BEBOP_ASSUME_LITTLE_ENDIAN +#define BEBOP_ASSUME_LITTLE_ENDIAN 1 +#endif + +namespace bebop { + +/// A "tick" is a ten-millionth of a second, or 100ns. +using Tick = std::ratio<1, 10000000>; +using TickDuration = std::chrono::duration; + +namespace { + /// The number of ticks between 1/1/0001 and 1/1/1970. + const int64_t ticksBetweenEpochs = 621355968000000000; +} + +enum class GuidStyle { + Dashes, + NoDashes, +}; + +#pragma pack(push, 1) +struct Guid { + /// The GUID data is stored the way it is to match the memory layout + /// of a _GUID in Windows: the idea is to "trick" P/Invoke into recognizing + /// our type as corresponding to a .NET "Guid". + uint32_t m_a; + uint16_t m_b; + uint16_t m_c; + uint8_t m_d; + uint8_t m_e; + uint8_t m_f; + uint8_t m_g; + uint8_t m_h; + uint8_t m_i; + uint8_t m_j; + uint8_t m_k; + + Guid() = default; + Guid(const uint8_t* bytes) { +#if BEBOP_ASSUME_LITTLE_ENDIAN + memcpy(&m_a, bytes + 0, sizeof(uint32_t)); + memcpy(&m_b, bytes + 4, sizeof(uint16_t)); + memcpy(&m_c, bytes + 6, sizeof(uint16_t)); +#else + m_a = bytes[0] + | (static_cast(bytes[1]) << 8) + | (static_cast(bytes[2]) << 16) + | (static_cast(bytes[3]) << 24); + m_b = bytes[4] + | (static_cast(bytes[5]) << 8); + m_c = bytes[6] + | (static_cast(bytes[7]) << 8); +#endif + m_d = bytes[8]; + m_e = bytes[9]; + m_f = bytes[10]; + m_g = bytes[11]; + m_h = bytes[12]; + m_i = bytes[13]; + m_j = bytes[14]; + m_k = bytes[15]; + } + Guid(Guid const& other) { + m_a = other.m_a; + m_b = other.m_b; + m_c = other.m_c; + m_d = other.m_d; + m_e = other.m_e; + m_f = other.m_f; + m_g = other.m_g; + m_h = other.m_h; + m_i = other.m_i; + m_j = other.m_j; + m_k = other.m_k; + } + + static Guid fromString(const std::string& string) { + uint8_t bytes[16]; + const char* s = string.c_str(); + + for (const auto i : layout) { + if (i == dash) { + // Skip over a possible dash in the string. + if (*s == '-') s++; + } else { + // Read two hex digits from the string. + uint8_t high = *s++; + uint8_t low = *s++; + bytes[i] = (asciiToHex[high] << 4) | asciiToHex[low]; + } + } + + return Guid(bytes); + } + + std::string toString(GuidStyle style = GuidStyle::Dashes) { + int size = style == GuidStyle::Dashes ? 36 : 32; + const char* dash = style == GuidStyle::Dashes ? "-" : ""; + std::unique_ptr buffer(new char[size+1]); + snprintf(buffer.get(), size+1, "%08x%s%04x%s%04x%s%02x%02x%s%02x%02x%02x%02x%02x%02x", + m_a, dash, m_b, dash, m_c, dash, m_d, m_e, dash, m_f, m_g, m_h, m_i, m_j, m_k); + return std::string(buffer.get(), buffer.get() + size); + } + + bool operator<(const Guid& other) const { + if (m_a < other.m_a) return true; + if (m_a > other.m_a) return false; + if (m_b < other.m_b) return true; + if (m_b > other.m_b) return false; + if (m_c < other.m_c) return true; + if (m_c > other.m_c) return false; + if (m_d < other.m_d) return true; + if (m_d > other.m_d) return false; + if (m_e < other.m_e) return true; + if (m_e > other.m_e) return false; + if (m_f < other.m_f) return true; + if (m_f > other.m_f) return false; + if (m_g < other.m_g) return true; + if (m_g > other.m_g) return false; + if (m_h < other.m_h) return true; + if (m_h > other.m_h) return false; + if (m_i < other.m_i) return true; + if (m_i > other.m_i) return false; + if (m_j < other.m_j) return true; + if (m_j > other.m_j) return false; + if (m_k < other.m_k) return true; + if (m_k > other.m_k) return false; + return false; + } + + bool operator==(const Guid& other) const { + if (m_a != other.m_a) return false; + if (m_b != other.m_b) return false; + if (m_c != other.m_c) return false; + if (m_d != other.m_d) return false; + if (m_e != other.m_e) return false; + if (m_f != other.m_f) return false; + if (m_g != other.m_g) return false; + if (m_h != other.m_h) return false; + if (m_i != other.m_i) return false; + if (m_j != other.m_j) return false; + if (m_k != other.m_k) return false; + return true; + } + +private: + static constexpr int dash = -1; + static constexpr int layout[] = {3, 2, 1, 0, dash, 5, 4, dash, 7, 6, dash, 8, 9, dash, 10, 11, 12, 13, 14, 15}; + static constexpr char nibbleToHex[16] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}; + static constexpr uint8_t asciiToHex[256] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, + 0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 10, 11, 12, 13, 14, 15, // and the rest is zeroes + }; +}; +#pragma pack(pop) + +class Reader { + const uint8_t* m_pointer; +public: + Reader(const uint8_t* buffer) : m_pointer(buffer) {} + Reader(Reader const&) = delete; + void operator=(Reader const&) = delete; + + const uint8_t* pointer() const { return m_pointer; } + void seek(const uint8_t* pointer) { m_pointer = pointer; } + + void skip(size_t amount) { m_pointer += amount; } + + uint8_t readByte() { return *m_pointer++; } + + uint16_t readUint16() { +#if BEBOP_ASSUME_LITTLE_ENDIAN + uint16_t v; + memcpy(&v, m_pointer, sizeof(uint16_t)); + m_pointer += 2; + return v; +#else + const uint16_t b0 = *m_pointer++; + const uint16_t b1 = *m_pointer++; + return (b1 << 8) | b0; +#endif + } + + uint32_t readUint32() { +#if BEBOP_ASSUME_LITTLE_ENDIAN + uint32_t v; + memcpy(&v, m_pointer, sizeof(uint32_t)); + m_pointer += 4; + return v; +#else + const uint32_t b0 = *m_pointer++; + const uint32_t b1 = *m_pointer++; + const uint32_t b2 = *m_pointer++; + const uint32_t b3 = *m_pointer++; + return (b3 << 24) | (b2 << 16) | (b1 << 8) | b0; +#endif + } + + uint64_t readUint64() { +#if BEBOP_ASSUME_LITTLE_ENDIAN + uint64_t v; + memcpy(&v, m_pointer, sizeof(uint64_t)); + m_pointer += 8; + return v; +#else + const uint64_t b0 = *m_pointer++; + const uint64_t b1 = *m_pointer++; + const uint64_t b2 = *m_pointer++; + const uint64_t b3 = *m_pointer++; + const uint64_t b4 = *m_pointer++; + const uint64_t b5 = *m_pointer++; + const uint64_t b6 = *m_pointer++; + const uint64_t b7 = *m_pointer++; + return (b7 << 0x38) | (b6 << 0x30) | (b5 << 0x28) | (b4 << 0x20) | (b3 << 0x18) | (b2 << 0x10) | (b1 << 0x08) | b0; +#endif + } + + int16_t readInt16() { return static_cast(readUint16()); } + int32_t readInt32() { return static_cast(readUint32()); } + int64_t readInt64() { return static_cast(readUint64()); } + + float readFloat32() { + float f; + const uint32_t v = readUint32(); + memcpy(&f, &v, sizeof(float)); + return f; + } + + double readFloat64() { + double f; + const uint64_t v = readUint64(); + memcpy(&f, &v, sizeof(double)); + return f; + } + + bool readBool() { + return readByte() != 0; + } + + std::vector readBytes() { + const auto length = readUint32(); + std::vector v(m_pointer, m_pointer + length); + m_pointer += length; + return v; + } + + std::string readString() { + const auto length = readUint32(); + std::string v(m_pointer, m_pointer + length); + m_pointer += length; + return v; + } + + Guid readGuid() { + Guid guid { m_pointer }; + m_pointer += 16; + return guid; + } + + // Read a date (as ticks since the Unix Epoch). + TickDuration readDate() { + const uint64_t ticks = readUint64() & 0x3fffffffffffffff; + return TickDuration(ticks - ticksBetweenEpochs); + } + + uint32_t readMessageLength() { return readUint32(); } +}; + +class Writer { + std::vector& m_buffer; +public: + Writer(std::vector& buffer) : m_buffer(buffer) {} + Writer(Writer const&) = delete; + void operator=(Writer const&) = delete; + + std::vector& buffer() { + return m_buffer; + } + + size_t length() { return m_buffer.size(); } + + void writeByte(uint8_t value) { m_buffer.push_back(value); } + void writeUint16(uint16_t value) { +#if BEBOP_ASSUME_LITTLE_ENDIAN + const auto position = m_buffer.size(); + m_buffer.resize(position + sizeof(value)); + memcpy(m_buffer.data() + position, &value, sizeof(value)); +#else + m_buffer.push_back(value); + m_buffer.push_back(value >> 8); +#endif + } + void writeUint32(uint32_t value) { +#if BEBOP_ASSUME_LITTLE_ENDIAN + const auto position = m_buffer.size(); + m_buffer.resize(position + sizeof(value)); + memcpy(m_buffer.data() + position, &value, sizeof(value)); +#else + m_buffer.push_back(value); + m_buffer.push_back(value >> 8); + m_buffer.push_back(value >> 16); + m_buffer.push_back(value >> 24); +#endif + } + void writeUint64(uint64_t value) { +#if BEBOP_ASSUME_LITTLE_ENDIAN + const auto position = m_buffer.size(); + m_buffer.resize(position + sizeof(value)); + memcpy(m_buffer.data() + position, &value, sizeof(value)); +#else + m_buffer.push_back(value); + m_buffer.push_back(value >> 0x08); + m_buffer.push_back(value >> 0x10); + m_buffer.push_back(value >> 0x18); + m_buffer.push_back(value >> 0x20); + m_buffer.push_back(value >> 0x28); + m_buffer.push_back(value >> 0x30); + m_buffer.push_back(value >> 0x38); +#endif + } + + void writeInt16(int16_t value) { writeUint16(static_cast(value)); } + void writeInt32(int32_t value) { writeUint32(static_cast(value)); } + void writeInt64(int64_t value) { writeUint64(static_cast(value)); } + void writeFloat32(float value) { + uint32_t temp; + memcpy(&temp, &value, sizeof(float)); + writeUint32(temp); + } + void writeFloat64(double value) { + uint64_t temp; + memcpy(&temp, &value, sizeof(double)); + writeUint64(temp); + } + void writeBool(bool value) { writeByte(value); } + + void writeBytes(std::vector value) { + const auto byteCount = value.size(); + writeUint32(byteCount); + m_buffer.insert(m_buffer.end(), value.begin(), value.end()); + } + + void writeString(std::string value) { + const auto byteCount = value.size(); + writeUint32(byteCount); + m_buffer.insert(m_buffer.end(), value.begin(), value.end()); + } + + void writeGuid(Guid value) { + writeUint32(value.m_a); + writeUint16(value.m_b); + writeUint16(value.m_c); + writeByte(value.m_d); + writeByte(value.m_e); + writeByte(value.m_f); + writeByte(value.m_g); + writeByte(value.m_h); + writeByte(value.m_i); + writeByte(value.m_j); + writeByte(value.m_k); + } + + void writeDate(TickDuration duration) { + writeUint64(duration.count() + ticksBetweenEpochs); + } + + /// Reserve some space to write a message's length prefix, and return its index. + /// The length is stored as a little-endian fixed-width unsigned 32-bit integer, so 4 bytes are reserved. + size_t reserveMessageLength() { + const auto n = m_buffer.size(); + m_buffer.resize(n + 4); + return n; + } + + /// Fill in a message's length prefix. + void fillMessageLength(size_t position, uint32_t messageLength) { +#if BEBOP_ASSUME_LITTLE_ENDIAN + memcpy(m_buffer.data() + position, &messageLength, sizeof(uint32_t)); +#else + m_buffer[position++] = messageLength; + m_buffer[position++] = messageLength >> 8; + m_buffer[position++] = messageLength >> 16; + m_buffer[position++] = messageLength >> 24; +#endif + } +}; + +} // namespace bebop diff --git a/Laboratory/C++/gen/jazz.hpp b/Laboratory/C++/gen/jazz.hpp index 47e3a27e..ab214ff6 100644 --- a/Laboratory/C++/gen/jazz.hpp +++ b/Laboratory/C++/gen/jazz.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include "bebop.hpp" @@ -17,25 +18,28 @@ struct Musician { std::string name; Instrument plays; - static std::unique_ptr> encode(const Musician& message) { - bebop::BebopWriter writer{}; + static void encodeInto(const Musician& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; Musician::encodeInto(message, writer); - return writer.buffer(); } - static void encodeInto(const Musician& message, bebop::BebopWriter& writer) { + static void encodeInto(const Musician& message, ::bebop::Writer& writer) { writer.writeString(message.name); writer.writeUint32(static_cast(message.plays)); } - static Musician decode(const uint8_t *buffer) { + static Musician decode(const uint8_t *sourceBuffer) { Musician result; - bebop::BebopReader reader{buffer}; - Musician::decodeInto(result, reader); + Musician::decodeInto(sourceBuffer, result); return result; } - static void decodeInto(Musician& target, bebop::BebopReader& reader) { + static void decodeInto(const uint8_t *sourceBuffer, Musician& target) { + ::bebop::Reader reader{sourceBuffer}; + Musician::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, Musician& target) { target.name = reader.readString(); target.plays = static_cast(reader.readUint32()); } @@ -46,13 +50,12 @@ struct Song { std::optional year; std::optional> performers; - static std::unique_ptr> encode(const Song& message) { - bebop::BebopWriter writer{}; + static void encodeInto(const Song& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; Song::encodeInto(message, writer); - return writer.buffer(); } - static void encodeInto(const Song& message, bebop::BebopWriter& writer) { + static void encodeInto(const Song& message, ::bebop::Writer& writer) { const auto pos = writer.reserveMessageLength(); const auto start = writer.length(); if (message.title.has_value()) { @@ -78,14 +81,18 @@ struct Song { writer.fillMessageLength(pos, end - start); } - static Song decode(const uint8_t *buffer) { + static Song decode(const uint8_t *sourceBuffer) { Song result; - bebop::BebopReader reader{buffer}; - Song::decodeInto(result, reader); + Song::decodeInto(sourceBuffer, result); return result; } - static void decodeInto(Song& target, bebop::BebopReader& reader) { + static void decodeInto(const uint8_t *sourceBuffer, Song& target) { + ::bebop::Reader reader{sourceBuffer}; + Song::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, Song& target) { const auto length = reader.readMessageLength(); const auto end = reader.pointer() + length; while (true) { @@ -105,7 +112,7 @@ struct Song { target.performers->reserve(length0); for (size_t i0 = 0; i0 < length0; i0++) { Musician x0; - Musician::decodeInto(x0, reader); + Musician::decodeInto(reader, x0); target.performers->push_back(x0); } } @@ -119,15 +126,14 @@ struct Song { }; struct Library { - std::map songs; + std::map<::bebop::Guid, Song> songs; - static std::unique_ptr> encode(const Library& message) { - bebop::BebopWriter writer{}; + static void encodeInto(const Library& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; Library::encodeInto(message, writer); - return writer.buffer(); } - static void encodeInto(const Library& message, bebop::BebopWriter& writer) { + static void encodeInto(const Library& message, ::bebop::Writer& writer) { writer.writeUint32(message.songs.size()); for (const auto& e0 : message.songs) { writer.writeGuid(e0.first); @@ -135,22 +141,26 @@ struct Library { } } - static Library decode(const uint8_t *buffer) { + static Library decode(const uint8_t *sourceBuffer) { Library result; - bebop::BebopReader reader{buffer}; - Library::decodeInto(result, reader); + Library::decodeInto(sourceBuffer, result); return result; } - static void decodeInto(Library& target, bebop::BebopReader& reader) { + static void decodeInto(const uint8_t *sourceBuffer, Library& target) { + ::bebop::Reader reader{sourceBuffer}; + Library::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, Library& target) { { const auto length0 = reader.readUint32(); - target.songs = std::map(); + target.songs = std::map<::bebop::Guid, Song>(); for (size_t i0 = 0; i0 < length0; i0++) { - bebop::Guid k0; + ::bebop::Guid k0; k0 = reader.readGuid(); Song& v0 = target.songs.operator[](k0); - Song::decodeInto(v0, reader); + Song::decodeInto(reader, v0); } } } diff --git a/Laboratory/C++/gen/union_perf_a.hpp b/Laboratory/C++/gen/union_perf_a.hpp new file mode 100644 index 00000000..dbe4c975 --- /dev/null +++ b/Laboratory/C++/gen/union_perf_a.hpp @@ -0,0 +1,2585 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include "bebop.hpp" + +struct A1 { + int32_t i1; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A1& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A1::encodeInto(message, writer); + } + + static void encodeInto(const A1& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i1); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A1 decode(const uint8_t *sourceBuffer) { + A1 result; + A1::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A1& target) { + ::bebop::Reader reader{sourceBuffer}; + A1::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A1& target) { + target.i1 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A2 { + int32_t i2; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A2& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A2::encodeInto(message, writer); + } + + static void encodeInto(const A2& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i2); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A2 decode(const uint8_t *sourceBuffer) { + A2 result; + A2::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A2& target) { + ::bebop::Reader reader{sourceBuffer}; + A2::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A2& target) { + target.i2 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A3 { + int32_t i3; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A3& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A3::encodeInto(message, writer); + } + + static void encodeInto(const A3& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i3); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A3 decode(const uint8_t *sourceBuffer) { + A3 result; + A3::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A3& target) { + ::bebop::Reader reader{sourceBuffer}; + A3::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A3& target) { + target.i3 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A4 { + int32_t i4; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A4& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A4::encodeInto(message, writer); + } + + static void encodeInto(const A4& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i4); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A4 decode(const uint8_t *sourceBuffer) { + A4 result; + A4::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A4& target) { + ::bebop::Reader reader{sourceBuffer}; + A4::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A4& target) { + target.i4 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A5 { + int32_t i5; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A5& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A5::encodeInto(message, writer); + } + + static void encodeInto(const A5& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i5); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A5 decode(const uint8_t *sourceBuffer) { + A5 result; + A5::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A5& target) { + ::bebop::Reader reader{sourceBuffer}; + A5::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A5& target) { + target.i5 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A6 { + int32_t i6; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A6& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A6::encodeInto(message, writer); + } + + static void encodeInto(const A6& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i6); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A6 decode(const uint8_t *sourceBuffer) { + A6 result; + A6::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A6& target) { + ::bebop::Reader reader{sourceBuffer}; + A6::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A6& target) { + target.i6 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A7 { + int32_t i7; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A7& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A7::encodeInto(message, writer); + } + + static void encodeInto(const A7& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i7); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A7 decode(const uint8_t *sourceBuffer) { + A7 result; + A7::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A7& target) { + ::bebop::Reader reader{sourceBuffer}; + A7::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A7& target) { + target.i7 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A8 { + int32_t i8; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A8& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A8::encodeInto(message, writer); + } + + static void encodeInto(const A8& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i8); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A8 decode(const uint8_t *sourceBuffer) { + A8 result; + A8::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A8& target) { + ::bebop::Reader reader{sourceBuffer}; + A8::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A8& target) { + target.i8 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A9 { + int32_t i9; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A9& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A9::encodeInto(message, writer); + } + + static void encodeInto(const A9& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i9); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A9 decode(const uint8_t *sourceBuffer) { + A9 result; + A9::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A9& target) { + ::bebop::Reader reader{sourceBuffer}; + A9::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A9& target) { + target.i9 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A10 { + int32_t i10; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A10& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A10::encodeInto(message, writer); + } + + static void encodeInto(const A10& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i10); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A10 decode(const uint8_t *sourceBuffer) { + A10 result; + A10::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A10& target) { + ::bebop::Reader reader{sourceBuffer}; + A10::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A10& target) { + target.i10 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A11 { + int32_t i11; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A11& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A11::encodeInto(message, writer); + } + + static void encodeInto(const A11& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i11); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A11 decode(const uint8_t *sourceBuffer) { + A11 result; + A11::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A11& target) { + ::bebop::Reader reader{sourceBuffer}; + A11::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A11& target) { + target.i11 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A12 { + int32_t i12; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A12& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A12::encodeInto(message, writer); + } + + static void encodeInto(const A12& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i12); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A12 decode(const uint8_t *sourceBuffer) { + A12 result; + A12::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A12& target) { + ::bebop::Reader reader{sourceBuffer}; + A12::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A12& target) { + target.i12 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A13 { + int32_t i13; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A13& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A13::encodeInto(message, writer); + } + + static void encodeInto(const A13& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i13); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A13 decode(const uint8_t *sourceBuffer) { + A13 result; + A13::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A13& target) { + ::bebop::Reader reader{sourceBuffer}; + A13::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A13& target) { + target.i13 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A14 { + int32_t i14; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A14& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A14::encodeInto(message, writer); + } + + static void encodeInto(const A14& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i14); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A14 decode(const uint8_t *sourceBuffer) { + A14 result; + A14::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A14& target) { + ::bebop::Reader reader{sourceBuffer}; + A14::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A14& target) { + target.i14 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A15 { + int32_t i15; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A15& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A15::encodeInto(message, writer); + } + + static void encodeInto(const A15& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i15); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A15 decode(const uint8_t *sourceBuffer) { + A15 result; + A15::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A15& target) { + ::bebop::Reader reader{sourceBuffer}; + A15::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A15& target) { + target.i15 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A16 { + int32_t i16; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A16& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A16::encodeInto(message, writer); + } + + static void encodeInto(const A16& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i16); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A16 decode(const uint8_t *sourceBuffer) { + A16 result; + A16::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A16& target) { + ::bebop::Reader reader{sourceBuffer}; + A16::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A16& target) { + target.i16 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A17 { + int32_t i17; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A17& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A17::encodeInto(message, writer); + } + + static void encodeInto(const A17& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i17); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A17 decode(const uint8_t *sourceBuffer) { + A17 result; + A17::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A17& target) { + ::bebop::Reader reader{sourceBuffer}; + A17::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A17& target) { + target.i17 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A18 { + int32_t i18; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A18& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A18::encodeInto(message, writer); + } + + static void encodeInto(const A18& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i18); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A18 decode(const uint8_t *sourceBuffer) { + A18 result; + A18::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A18& target) { + ::bebop::Reader reader{sourceBuffer}; + A18::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A18& target) { + target.i18 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A19 { + int32_t i19; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A19& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A19::encodeInto(message, writer); + } + + static void encodeInto(const A19& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i19); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A19 decode(const uint8_t *sourceBuffer) { + A19 result; + A19::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A19& target) { + ::bebop::Reader reader{sourceBuffer}; + A19::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A19& target) { + target.i19 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A20 { + int32_t i20; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A20& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A20::encodeInto(message, writer); + } + + static void encodeInto(const A20& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i20); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A20 decode(const uint8_t *sourceBuffer) { + A20 result; + A20::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A20& target) { + ::bebop::Reader reader{sourceBuffer}; + A20::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A20& target) { + target.i20 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A21 { + int32_t i21; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A21& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A21::encodeInto(message, writer); + } + + static void encodeInto(const A21& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i21); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A21 decode(const uint8_t *sourceBuffer) { + A21 result; + A21::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A21& target) { + ::bebop::Reader reader{sourceBuffer}; + A21::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A21& target) { + target.i21 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A22 { + int32_t i22; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A22& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A22::encodeInto(message, writer); + } + + static void encodeInto(const A22& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i22); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A22 decode(const uint8_t *sourceBuffer) { + A22 result; + A22::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A22& target) { + ::bebop::Reader reader{sourceBuffer}; + A22::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A22& target) { + target.i22 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A23 { + int32_t i23; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A23& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A23::encodeInto(message, writer); + } + + static void encodeInto(const A23& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i23); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A23 decode(const uint8_t *sourceBuffer) { + A23 result; + A23::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A23& target) { + ::bebop::Reader reader{sourceBuffer}; + A23::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A23& target) { + target.i23 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A24 { + int32_t i24; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A24& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A24::encodeInto(message, writer); + } + + static void encodeInto(const A24& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i24); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A24 decode(const uint8_t *sourceBuffer) { + A24 result; + A24::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A24& target) { + ::bebop::Reader reader{sourceBuffer}; + A24::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A24& target) { + target.i24 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A25 { + int32_t i25; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A25& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A25::encodeInto(message, writer); + } + + static void encodeInto(const A25& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i25); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A25 decode(const uint8_t *sourceBuffer) { + A25 result; + A25::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A25& target) { + ::bebop::Reader reader{sourceBuffer}; + A25::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A25& target) { + target.i25 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A26 { + int32_t i26; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A26& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A26::encodeInto(message, writer); + } + + static void encodeInto(const A26& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i26); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A26 decode(const uint8_t *sourceBuffer) { + A26 result; + A26::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A26& target) { + ::bebop::Reader reader{sourceBuffer}; + A26::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A26& target) { + target.i26 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A27 { + int32_t i27; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A27& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A27::encodeInto(message, writer); + } + + static void encodeInto(const A27& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i27); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A27 decode(const uint8_t *sourceBuffer) { + A27 result; + A27::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A27& target) { + ::bebop::Reader reader{sourceBuffer}; + A27::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A27& target) { + target.i27 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A28 { + int32_t i28; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A28& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A28::encodeInto(message, writer); + } + + static void encodeInto(const A28& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i28); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A28 decode(const uint8_t *sourceBuffer) { + A28 result; + A28::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A28& target) { + ::bebop::Reader reader{sourceBuffer}; + A28::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A28& target) { + target.i28 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A29 { + int32_t i29; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A29& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A29::encodeInto(message, writer); + } + + static void encodeInto(const A29& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i29); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A29 decode(const uint8_t *sourceBuffer) { + A29 result; + A29::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A29& target) { + ::bebop::Reader reader{sourceBuffer}; + A29::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A29& target) { + target.i29 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A30 { + int32_t i30; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A30& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A30::encodeInto(message, writer); + } + + static void encodeInto(const A30& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i30); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A30 decode(const uint8_t *sourceBuffer) { + A30 result; + A30::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A30& target) { + ::bebop::Reader reader{sourceBuffer}; + A30::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A30& target) { + target.i30 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A31 { + int32_t i31; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A31& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A31::encodeInto(message, writer); + } + + static void encodeInto(const A31& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i31); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A31 decode(const uint8_t *sourceBuffer) { + A31 result; + A31::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A31& target) { + ::bebop::Reader reader{sourceBuffer}; + A31::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A31& target) { + target.i31 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A32 { + int32_t i32; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A32& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A32::encodeInto(message, writer); + } + + static void encodeInto(const A32& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i32); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A32 decode(const uint8_t *sourceBuffer) { + A32 result; + A32::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A32& target) { + ::bebop::Reader reader{sourceBuffer}; + A32::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A32& target) { + target.i32 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A33 { + int32_t i33; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A33& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A33::encodeInto(message, writer); + } + + static void encodeInto(const A33& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i33); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A33 decode(const uint8_t *sourceBuffer) { + A33 result; + A33::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A33& target) { + ::bebop::Reader reader{sourceBuffer}; + A33::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A33& target) { + target.i33 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A34 { + int32_t i34; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A34& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A34::encodeInto(message, writer); + } + + static void encodeInto(const A34& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i34); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A34 decode(const uint8_t *sourceBuffer) { + A34 result; + A34::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A34& target) { + ::bebop::Reader reader{sourceBuffer}; + A34::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A34& target) { + target.i34 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A35 { + int32_t i35; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A35& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A35::encodeInto(message, writer); + } + + static void encodeInto(const A35& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i35); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A35 decode(const uint8_t *sourceBuffer) { + A35 result; + A35::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A35& target) { + ::bebop::Reader reader{sourceBuffer}; + A35::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A35& target) { + target.i35 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A36 { + int32_t i36; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A36& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A36::encodeInto(message, writer); + } + + static void encodeInto(const A36& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i36); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A36 decode(const uint8_t *sourceBuffer) { + A36 result; + A36::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A36& target) { + ::bebop::Reader reader{sourceBuffer}; + A36::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A36& target) { + target.i36 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A37 { + int32_t i37; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A37& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A37::encodeInto(message, writer); + } + + static void encodeInto(const A37& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i37); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A37 decode(const uint8_t *sourceBuffer) { + A37 result; + A37::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A37& target) { + ::bebop::Reader reader{sourceBuffer}; + A37::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A37& target) { + target.i37 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A38 { + int32_t i38; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A38& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A38::encodeInto(message, writer); + } + + static void encodeInto(const A38& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i38); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A38 decode(const uint8_t *sourceBuffer) { + A38 result; + A38::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A38& target) { + ::bebop::Reader reader{sourceBuffer}; + A38::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A38& target) { + target.i38 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A39 { + int32_t i39; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A39& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A39::encodeInto(message, writer); + } + + static void encodeInto(const A39& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i39); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A39 decode(const uint8_t *sourceBuffer) { + A39 result; + A39::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A39& target) { + ::bebop::Reader reader{sourceBuffer}; + A39::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A39& target) { + target.i39 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A40 { + int32_t i40; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A40& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A40::encodeInto(message, writer); + } + + static void encodeInto(const A40& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i40); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A40 decode(const uint8_t *sourceBuffer) { + A40 result; + A40::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A40& target) { + ::bebop::Reader reader{sourceBuffer}; + A40::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A40& target) { + target.i40 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A41 { + int32_t i41; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A41& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A41::encodeInto(message, writer); + } + + static void encodeInto(const A41& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i41); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A41 decode(const uint8_t *sourceBuffer) { + A41 result; + A41::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A41& target) { + ::bebop::Reader reader{sourceBuffer}; + A41::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A41& target) { + target.i41 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A42 { + int32_t i42; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A42& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A42::encodeInto(message, writer); + } + + static void encodeInto(const A42& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i42); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A42 decode(const uint8_t *sourceBuffer) { + A42 result; + A42::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A42& target) { + ::bebop::Reader reader{sourceBuffer}; + A42::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A42& target) { + target.i42 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A43 { + int32_t i43; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A43& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A43::encodeInto(message, writer); + } + + static void encodeInto(const A43& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i43); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A43 decode(const uint8_t *sourceBuffer) { + A43 result; + A43::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A43& target) { + ::bebop::Reader reader{sourceBuffer}; + A43::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A43& target) { + target.i43 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A44 { + int32_t i44; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A44& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A44::encodeInto(message, writer); + } + + static void encodeInto(const A44& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i44); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A44 decode(const uint8_t *sourceBuffer) { + A44 result; + A44::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A44& target) { + ::bebop::Reader reader{sourceBuffer}; + A44::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A44& target) { + target.i44 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A45 { + int32_t i45; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A45& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A45::encodeInto(message, writer); + } + + static void encodeInto(const A45& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i45); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A45 decode(const uint8_t *sourceBuffer) { + A45 result; + A45::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A45& target) { + ::bebop::Reader reader{sourceBuffer}; + A45::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A45& target) { + target.i45 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A46 { + int32_t i46; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A46& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A46::encodeInto(message, writer); + } + + static void encodeInto(const A46& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i46); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A46 decode(const uint8_t *sourceBuffer) { + A46 result; + A46::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A46& target) { + ::bebop::Reader reader{sourceBuffer}; + A46::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A46& target) { + target.i46 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A47 { + int32_t i47; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A47& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A47::encodeInto(message, writer); + } + + static void encodeInto(const A47& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i47); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A47 decode(const uint8_t *sourceBuffer) { + A47 result; + A47::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A47& target) { + ::bebop::Reader reader{sourceBuffer}; + A47::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A47& target) { + target.i47 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A48 { + int32_t i48; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A48& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A48::encodeInto(message, writer); + } + + static void encodeInto(const A48& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i48); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A48 decode(const uint8_t *sourceBuffer) { + A48 result; + A48::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A48& target) { + ::bebop::Reader reader{sourceBuffer}; + A48::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A48& target) { + target.i48 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A49 { + int32_t i49; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A49& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A49::encodeInto(message, writer); + } + + static void encodeInto(const A49& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i49); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A49 decode(const uint8_t *sourceBuffer) { + A49 result; + A49::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A49& target) { + ::bebop::Reader reader{sourceBuffer}; + A49::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A49& target) { + target.i49 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct A50 { + int32_t i50; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const A50& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A50::encodeInto(message, writer); + } + + static void encodeInto(const A50& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i50); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static A50 decode(const uint8_t *sourceBuffer) { + A50 result; + A50::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A50& target) { + ::bebop::Reader reader{sourceBuffer}; + A50::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A50& target) { + target.i50 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +/// Option A: put the whole thing in a union. +struct U { + std::variant variant; + static void encodeInto(const U& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + U::encodeInto(message, writer); + } + + static void encodeInto(const U& message, ::bebop::Writer& writer) { + const auto pos = writer.reserveMessageLength(); + const auto start = writer.length(); + const uint8_t discriminator = message.variant.index() + 1; + writer.writeByte(discriminator); + switch (discriminator) { + case 1: + A1::encodeInto(std::get<0>(message.variant), writer); + break; + case 2: + A2::encodeInto(std::get<1>(message.variant), writer); + break; + case 3: + A3::encodeInto(std::get<2>(message.variant), writer); + break; + case 4: + A4::encodeInto(std::get<3>(message.variant), writer); + break; + case 5: + A5::encodeInto(std::get<4>(message.variant), writer); + break; + case 6: + A6::encodeInto(std::get<5>(message.variant), writer); + break; + case 7: + A7::encodeInto(std::get<6>(message.variant), writer); + break; + case 8: + A8::encodeInto(std::get<7>(message.variant), writer); + break; + case 9: + A9::encodeInto(std::get<8>(message.variant), writer); + break; + case 10: + A10::encodeInto(std::get<9>(message.variant), writer); + break; + case 11: + A11::encodeInto(std::get<10>(message.variant), writer); + break; + case 12: + A12::encodeInto(std::get<11>(message.variant), writer); + break; + case 13: + A13::encodeInto(std::get<12>(message.variant), writer); + break; + case 14: + A14::encodeInto(std::get<13>(message.variant), writer); + break; + case 15: + A15::encodeInto(std::get<14>(message.variant), writer); + break; + case 16: + A16::encodeInto(std::get<15>(message.variant), writer); + break; + case 17: + A17::encodeInto(std::get<16>(message.variant), writer); + break; + case 18: + A18::encodeInto(std::get<17>(message.variant), writer); + break; + case 19: + A19::encodeInto(std::get<18>(message.variant), writer); + break; + case 20: + A20::encodeInto(std::get<19>(message.variant), writer); + break; + case 21: + A21::encodeInto(std::get<20>(message.variant), writer); + break; + case 22: + A22::encodeInto(std::get<21>(message.variant), writer); + break; + case 23: + A23::encodeInto(std::get<22>(message.variant), writer); + break; + case 24: + A24::encodeInto(std::get<23>(message.variant), writer); + break; + case 25: + A25::encodeInto(std::get<24>(message.variant), writer); + break; + case 26: + A26::encodeInto(std::get<25>(message.variant), writer); + break; + case 27: + A27::encodeInto(std::get<26>(message.variant), writer); + break; + case 28: + A28::encodeInto(std::get<27>(message.variant), writer); + break; + case 29: + A29::encodeInto(std::get<28>(message.variant), writer); + break; + case 30: + A30::encodeInto(std::get<29>(message.variant), writer); + break; + case 31: + A31::encodeInto(std::get<30>(message.variant), writer); + break; + case 32: + A32::encodeInto(std::get<31>(message.variant), writer); + break; + case 33: + A33::encodeInto(std::get<32>(message.variant), writer); + break; + case 34: + A34::encodeInto(std::get<33>(message.variant), writer); + break; + case 35: + A35::encodeInto(std::get<34>(message.variant), writer); + break; + case 36: + A36::encodeInto(std::get<35>(message.variant), writer); + break; + case 37: + A37::encodeInto(std::get<36>(message.variant), writer); + break; + case 38: + A38::encodeInto(std::get<37>(message.variant), writer); + break; + case 39: + A39::encodeInto(std::get<38>(message.variant), writer); + break; + case 40: + A40::encodeInto(std::get<39>(message.variant), writer); + break; + case 41: + A41::encodeInto(std::get<40>(message.variant), writer); + break; + case 42: + A42::encodeInto(std::get<41>(message.variant), writer); + break; + case 43: + A43::encodeInto(std::get<42>(message.variant), writer); + break; + case 44: + A44::encodeInto(std::get<43>(message.variant), writer); + break; + case 45: + A45::encodeInto(std::get<44>(message.variant), writer); + break; + case 46: + A46::encodeInto(std::get<45>(message.variant), writer); + break; + case 47: + A47::encodeInto(std::get<46>(message.variant), writer); + break; + case 48: + A48::encodeInto(std::get<47>(message.variant), writer); + break; + case 49: + A49::encodeInto(std::get<48>(message.variant), writer); + break; + case 50: + A50::encodeInto(std::get<49>(message.variant), writer); + break; + } + const auto end = writer.length(); + writer.fillMessageLength(pos, end - start); + } + + static U decode(const uint8_t *sourceBuffer) { + U result; + U::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, U& target) { + ::bebop::Reader reader{sourceBuffer}; + U::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, U& target) { + const auto length = reader.readMessageLength(); + const auto end = reader.pointer() + length; + switch (reader.readByte()) { + case 1: + target.variant.emplace<0>(); + A1::decodeInto(reader, std::get<0>(target.variant)); + break; + case 2: + target.variant.emplace<1>(); + A2::decodeInto(reader, std::get<1>(target.variant)); + break; + case 3: + target.variant.emplace<2>(); + A3::decodeInto(reader, std::get<2>(target.variant)); + break; + case 4: + target.variant.emplace<3>(); + A4::decodeInto(reader, std::get<3>(target.variant)); + break; + case 5: + target.variant.emplace<4>(); + A5::decodeInto(reader, std::get<4>(target.variant)); + break; + case 6: + target.variant.emplace<5>(); + A6::decodeInto(reader, std::get<5>(target.variant)); + break; + case 7: + target.variant.emplace<6>(); + A7::decodeInto(reader, std::get<6>(target.variant)); + break; + case 8: + target.variant.emplace<7>(); + A8::decodeInto(reader, std::get<7>(target.variant)); + break; + case 9: + target.variant.emplace<8>(); + A9::decodeInto(reader, std::get<8>(target.variant)); + break; + case 10: + target.variant.emplace<9>(); + A10::decodeInto(reader, std::get<9>(target.variant)); + break; + case 11: + target.variant.emplace<10>(); + A11::decodeInto(reader, std::get<10>(target.variant)); + break; + case 12: + target.variant.emplace<11>(); + A12::decodeInto(reader, std::get<11>(target.variant)); + break; + case 13: + target.variant.emplace<12>(); + A13::decodeInto(reader, std::get<12>(target.variant)); + break; + case 14: + target.variant.emplace<13>(); + A14::decodeInto(reader, std::get<13>(target.variant)); + break; + case 15: + target.variant.emplace<14>(); + A15::decodeInto(reader, std::get<14>(target.variant)); + break; + case 16: + target.variant.emplace<15>(); + A16::decodeInto(reader, std::get<15>(target.variant)); + break; + case 17: + target.variant.emplace<16>(); + A17::decodeInto(reader, std::get<16>(target.variant)); + break; + case 18: + target.variant.emplace<17>(); + A18::decodeInto(reader, std::get<17>(target.variant)); + break; + case 19: + target.variant.emplace<18>(); + A19::decodeInto(reader, std::get<18>(target.variant)); + break; + case 20: + target.variant.emplace<19>(); + A20::decodeInto(reader, std::get<19>(target.variant)); + break; + case 21: + target.variant.emplace<20>(); + A21::decodeInto(reader, std::get<20>(target.variant)); + break; + case 22: + target.variant.emplace<21>(); + A22::decodeInto(reader, std::get<21>(target.variant)); + break; + case 23: + target.variant.emplace<22>(); + A23::decodeInto(reader, std::get<22>(target.variant)); + break; + case 24: + target.variant.emplace<23>(); + A24::decodeInto(reader, std::get<23>(target.variant)); + break; + case 25: + target.variant.emplace<24>(); + A25::decodeInto(reader, std::get<24>(target.variant)); + break; + case 26: + target.variant.emplace<25>(); + A26::decodeInto(reader, std::get<25>(target.variant)); + break; + case 27: + target.variant.emplace<26>(); + A27::decodeInto(reader, std::get<26>(target.variant)); + break; + case 28: + target.variant.emplace<27>(); + A28::decodeInto(reader, std::get<27>(target.variant)); + break; + case 29: + target.variant.emplace<28>(); + A29::decodeInto(reader, std::get<28>(target.variant)); + break; + case 30: + target.variant.emplace<29>(); + A30::decodeInto(reader, std::get<29>(target.variant)); + break; + case 31: + target.variant.emplace<30>(); + A31::decodeInto(reader, std::get<30>(target.variant)); + break; + case 32: + target.variant.emplace<31>(); + A32::decodeInto(reader, std::get<31>(target.variant)); + break; + case 33: + target.variant.emplace<32>(); + A33::decodeInto(reader, std::get<32>(target.variant)); + break; + case 34: + target.variant.emplace<33>(); + A34::decodeInto(reader, std::get<33>(target.variant)); + break; + case 35: + target.variant.emplace<34>(); + A35::decodeInto(reader, std::get<34>(target.variant)); + break; + case 36: + target.variant.emplace<35>(); + A36::decodeInto(reader, std::get<35>(target.variant)); + break; + case 37: + target.variant.emplace<36>(); + A37::decodeInto(reader, std::get<36>(target.variant)); + break; + case 38: + target.variant.emplace<37>(); + A38::decodeInto(reader, std::get<37>(target.variant)); + break; + case 39: + target.variant.emplace<38>(); + A39::decodeInto(reader, std::get<38>(target.variant)); + break; + case 40: + target.variant.emplace<39>(); + A40::decodeInto(reader, std::get<39>(target.variant)); + break; + case 41: + target.variant.emplace<40>(); + A41::decodeInto(reader, std::get<40>(target.variant)); + break; + case 42: + target.variant.emplace<41>(); + A42::decodeInto(reader, std::get<41>(target.variant)); + break; + case 43: + target.variant.emplace<42>(); + A43::decodeInto(reader, std::get<42>(target.variant)); + break; + case 44: + target.variant.emplace<43>(); + A44::decodeInto(reader, std::get<43>(target.variant)); + break; + case 45: + target.variant.emplace<44>(); + A45::decodeInto(reader, std::get<44>(target.variant)); + break; + case 46: + target.variant.emplace<45>(); + A46::decodeInto(reader, std::get<45>(target.variant)); + break; + case 47: + target.variant.emplace<46>(); + A47::decodeInto(reader, std::get<46>(target.variant)); + break; + case 48: + target.variant.emplace<47>(); + A48::decodeInto(reader, std::get<47>(target.variant)); + break; + case 49: + target.variant.emplace<48>(); + A49::decodeInto(reader, std::get<48>(target.variant)); + break; + case 50: + target.variant.emplace<49>(); + A50::decodeInto(reader, std::get<49>(target.variant)); + break; + default: + reader.seek(end); // do nothing? + return; + } + } +}; + +struct A { + uint32_t containerOpcode; + uint32_t protocolVersion; + U u; + + static void encodeInto(const A& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + A::encodeInto(message, writer); + } + + static void encodeInto(const A& message, ::bebop::Writer& writer) { + writer.writeUint32(message.containerOpcode); + writer.writeUint32(message.protocolVersion); + U::encodeInto(message.u, writer); + } + + static A decode(const uint8_t *sourceBuffer) { + A result; + A::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, A& target) { + ::bebop::Reader reader{sourceBuffer}; + A::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, A& target) { + target.containerOpcode = reader.readUint32(); + target.protocolVersion = reader.readUint32(); + U::decodeInto(reader, target.u); + } +}; + diff --git a/Laboratory/C++/gen/union_perf_b.hpp b/Laboratory/C++/gen/union_perf_b.hpp new file mode 100644 index 00000000..7a979e6c --- /dev/null +++ b/Laboratory/C++/gen/union_perf_b.hpp @@ -0,0 +1,2295 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include "bebop.hpp" + +/// Option B: an "encodedData" field, that "decode" is called a second time on. +struct B { + uint32_t protocolVersion; + uint32_t incomingOpcode; + std::vector encodedData; + + static void encodeInto(const B& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B::encodeInto(message, writer); + } + + static void encodeInto(const B& message, ::bebop::Writer& writer) { + writer.writeUint32(message.protocolVersion); + writer.writeUint32(message.incomingOpcode); + writer.writeBytes(message.encodedData); + } + + static B decode(const uint8_t *sourceBuffer) { + B result; + B::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B& target) { + ::bebop::Reader reader{sourceBuffer}; + B::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B& target) { + target.protocolVersion = reader.readUint32(); + target.incomingOpcode = reader.readUint32(); + target.encodedData = reader.readBytes(); + } +}; + +struct B1 { + static const uint32_t opcode = 0x1; + + int32_t i1; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B1& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B1::encodeInto(message, writer); + } + + static void encodeInto(const B1& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i1); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B1 decode(const uint8_t *sourceBuffer) { + B1 result; + B1::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B1& target) { + ::bebop::Reader reader{sourceBuffer}; + B1::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B1& target) { + target.i1 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B2 { + static const uint32_t opcode = 0x2; + + int32_t i2; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B2& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B2::encodeInto(message, writer); + } + + static void encodeInto(const B2& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i2); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B2 decode(const uint8_t *sourceBuffer) { + B2 result; + B2::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B2& target) { + ::bebop::Reader reader{sourceBuffer}; + B2::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B2& target) { + target.i2 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B3 { + static const uint32_t opcode = 0x3; + + int32_t i3; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B3& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B3::encodeInto(message, writer); + } + + static void encodeInto(const B3& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i3); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B3 decode(const uint8_t *sourceBuffer) { + B3 result; + B3::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B3& target) { + ::bebop::Reader reader{sourceBuffer}; + B3::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B3& target) { + target.i3 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B4 { + static const uint32_t opcode = 0x4; + + int32_t i4; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B4& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B4::encodeInto(message, writer); + } + + static void encodeInto(const B4& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i4); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B4 decode(const uint8_t *sourceBuffer) { + B4 result; + B4::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B4& target) { + ::bebop::Reader reader{sourceBuffer}; + B4::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B4& target) { + target.i4 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B5 { + static const uint32_t opcode = 0x5; + + int32_t i5; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B5& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B5::encodeInto(message, writer); + } + + static void encodeInto(const B5& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i5); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B5 decode(const uint8_t *sourceBuffer) { + B5 result; + B5::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B5& target) { + ::bebop::Reader reader{sourceBuffer}; + B5::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B5& target) { + target.i5 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B6 { + static const uint32_t opcode = 0x6; + + int32_t i6; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B6& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B6::encodeInto(message, writer); + } + + static void encodeInto(const B6& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i6); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B6 decode(const uint8_t *sourceBuffer) { + B6 result; + B6::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B6& target) { + ::bebop::Reader reader{sourceBuffer}; + B6::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B6& target) { + target.i6 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B7 { + static const uint32_t opcode = 0x7; + + int32_t i7; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B7& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B7::encodeInto(message, writer); + } + + static void encodeInto(const B7& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i7); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B7 decode(const uint8_t *sourceBuffer) { + B7 result; + B7::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B7& target) { + ::bebop::Reader reader{sourceBuffer}; + B7::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B7& target) { + target.i7 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B8 { + static const uint32_t opcode = 0x8; + + int32_t i8; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B8& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B8::encodeInto(message, writer); + } + + static void encodeInto(const B8& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i8); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B8 decode(const uint8_t *sourceBuffer) { + B8 result; + B8::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B8& target) { + ::bebop::Reader reader{sourceBuffer}; + B8::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B8& target) { + target.i8 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B9 { + static const uint32_t opcode = 0x9; + + int32_t i9; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B9& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B9::encodeInto(message, writer); + } + + static void encodeInto(const B9& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i9); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B9 decode(const uint8_t *sourceBuffer) { + B9 result; + B9::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B9& target) { + ::bebop::Reader reader{sourceBuffer}; + B9::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B9& target) { + target.i9 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B10 { + static const uint32_t opcode = 0xA; + + int32_t i10; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B10& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B10::encodeInto(message, writer); + } + + static void encodeInto(const B10& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i10); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B10 decode(const uint8_t *sourceBuffer) { + B10 result; + B10::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B10& target) { + ::bebop::Reader reader{sourceBuffer}; + B10::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B10& target) { + target.i10 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B11 { + static const uint32_t opcode = 0xB; + + int32_t i11; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B11& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B11::encodeInto(message, writer); + } + + static void encodeInto(const B11& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i11); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B11 decode(const uint8_t *sourceBuffer) { + B11 result; + B11::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B11& target) { + ::bebop::Reader reader{sourceBuffer}; + B11::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B11& target) { + target.i11 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B12 { + static const uint32_t opcode = 0xC; + + int32_t i12; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B12& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B12::encodeInto(message, writer); + } + + static void encodeInto(const B12& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i12); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B12 decode(const uint8_t *sourceBuffer) { + B12 result; + B12::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B12& target) { + ::bebop::Reader reader{sourceBuffer}; + B12::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B12& target) { + target.i12 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B13 { + static const uint32_t opcode = 0xD; + + int32_t i13; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B13& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B13::encodeInto(message, writer); + } + + static void encodeInto(const B13& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i13); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B13 decode(const uint8_t *sourceBuffer) { + B13 result; + B13::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B13& target) { + ::bebop::Reader reader{sourceBuffer}; + B13::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B13& target) { + target.i13 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B14 { + static const uint32_t opcode = 0xE; + + int32_t i14; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B14& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B14::encodeInto(message, writer); + } + + static void encodeInto(const B14& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i14); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B14 decode(const uint8_t *sourceBuffer) { + B14 result; + B14::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B14& target) { + ::bebop::Reader reader{sourceBuffer}; + B14::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B14& target) { + target.i14 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B15 { + static const uint32_t opcode = 0xF; + + int32_t i15; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B15& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B15::encodeInto(message, writer); + } + + static void encodeInto(const B15& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i15); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B15 decode(const uint8_t *sourceBuffer) { + B15 result; + B15::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B15& target) { + ::bebop::Reader reader{sourceBuffer}; + B15::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B15& target) { + target.i15 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B16 { + static const uint32_t opcode = 0x10; + + int32_t i16; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B16& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B16::encodeInto(message, writer); + } + + static void encodeInto(const B16& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i16); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B16 decode(const uint8_t *sourceBuffer) { + B16 result; + B16::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B16& target) { + ::bebop::Reader reader{sourceBuffer}; + B16::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B16& target) { + target.i16 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B17 { + static const uint32_t opcode = 0x11; + + int32_t i17; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B17& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B17::encodeInto(message, writer); + } + + static void encodeInto(const B17& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i17); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B17 decode(const uint8_t *sourceBuffer) { + B17 result; + B17::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B17& target) { + ::bebop::Reader reader{sourceBuffer}; + B17::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B17& target) { + target.i17 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B18 { + static const uint32_t opcode = 0x12; + + int32_t i18; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B18& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B18::encodeInto(message, writer); + } + + static void encodeInto(const B18& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i18); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B18 decode(const uint8_t *sourceBuffer) { + B18 result; + B18::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B18& target) { + ::bebop::Reader reader{sourceBuffer}; + B18::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B18& target) { + target.i18 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B19 { + static const uint32_t opcode = 0x13; + + int32_t i19; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B19& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B19::encodeInto(message, writer); + } + + static void encodeInto(const B19& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i19); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B19 decode(const uint8_t *sourceBuffer) { + B19 result; + B19::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B19& target) { + ::bebop::Reader reader{sourceBuffer}; + B19::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B19& target) { + target.i19 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B20 { + static const uint32_t opcode = 0x14; + + int32_t i20; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B20& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B20::encodeInto(message, writer); + } + + static void encodeInto(const B20& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i20); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B20 decode(const uint8_t *sourceBuffer) { + B20 result; + B20::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B20& target) { + ::bebop::Reader reader{sourceBuffer}; + B20::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B20& target) { + target.i20 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B21 { + static const uint32_t opcode = 0x15; + + int32_t i21; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B21& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B21::encodeInto(message, writer); + } + + static void encodeInto(const B21& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i21); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B21 decode(const uint8_t *sourceBuffer) { + B21 result; + B21::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B21& target) { + ::bebop::Reader reader{sourceBuffer}; + B21::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B21& target) { + target.i21 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B22 { + static const uint32_t opcode = 0x16; + + int32_t i22; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B22& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B22::encodeInto(message, writer); + } + + static void encodeInto(const B22& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i22); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B22 decode(const uint8_t *sourceBuffer) { + B22 result; + B22::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B22& target) { + ::bebop::Reader reader{sourceBuffer}; + B22::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B22& target) { + target.i22 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B23 { + static const uint32_t opcode = 0x17; + + int32_t i23; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B23& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B23::encodeInto(message, writer); + } + + static void encodeInto(const B23& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i23); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B23 decode(const uint8_t *sourceBuffer) { + B23 result; + B23::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B23& target) { + ::bebop::Reader reader{sourceBuffer}; + B23::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B23& target) { + target.i23 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B24 { + static const uint32_t opcode = 0x18; + + int32_t i24; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B24& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B24::encodeInto(message, writer); + } + + static void encodeInto(const B24& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i24); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B24 decode(const uint8_t *sourceBuffer) { + B24 result; + B24::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B24& target) { + ::bebop::Reader reader{sourceBuffer}; + B24::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B24& target) { + target.i24 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B25 { + static const uint32_t opcode = 0x19; + + int32_t i25; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B25& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B25::encodeInto(message, writer); + } + + static void encodeInto(const B25& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i25); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B25 decode(const uint8_t *sourceBuffer) { + B25 result; + B25::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B25& target) { + ::bebop::Reader reader{sourceBuffer}; + B25::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B25& target) { + target.i25 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B26 { + static const uint32_t opcode = 0x1A; + + int32_t i26; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B26& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B26::encodeInto(message, writer); + } + + static void encodeInto(const B26& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i26); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B26 decode(const uint8_t *sourceBuffer) { + B26 result; + B26::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B26& target) { + ::bebop::Reader reader{sourceBuffer}; + B26::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B26& target) { + target.i26 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B27 { + static const uint32_t opcode = 0x1B; + + int32_t i27; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B27& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B27::encodeInto(message, writer); + } + + static void encodeInto(const B27& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i27); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B27 decode(const uint8_t *sourceBuffer) { + B27 result; + B27::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B27& target) { + ::bebop::Reader reader{sourceBuffer}; + B27::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B27& target) { + target.i27 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B28 { + static const uint32_t opcode = 0x1C; + + int32_t i28; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B28& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B28::encodeInto(message, writer); + } + + static void encodeInto(const B28& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i28); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B28 decode(const uint8_t *sourceBuffer) { + B28 result; + B28::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B28& target) { + ::bebop::Reader reader{sourceBuffer}; + B28::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B28& target) { + target.i28 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B29 { + static const uint32_t opcode = 0x1D; + + int32_t i29; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B29& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B29::encodeInto(message, writer); + } + + static void encodeInto(const B29& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i29); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B29 decode(const uint8_t *sourceBuffer) { + B29 result; + B29::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B29& target) { + ::bebop::Reader reader{sourceBuffer}; + B29::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B29& target) { + target.i29 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B30 { + static const uint32_t opcode = 0x1E; + + int32_t i30; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B30& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B30::encodeInto(message, writer); + } + + static void encodeInto(const B30& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i30); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B30 decode(const uint8_t *sourceBuffer) { + B30 result; + B30::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B30& target) { + ::bebop::Reader reader{sourceBuffer}; + B30::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B30& target) { + target.i30 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B31 { + static const uint32_t opcode = 0x1F; + + int32_t i31; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B31& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B31::encodeInto(message, writer); + } + + static void encodeInto(const B31& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i31); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B31 decode(const uint8_t *sourceBuffer) { + B31 result; + B31::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B31& target) { + ::bebop::Reader reader{sourceBuffer}; + B31::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B31& target) { + target.i31 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B32 { + static const uint32_t opcode = 0x20; + + int32_t i32; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B32& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B32::encodeInto(message, writer); + } + + static void encodeInto(const B32& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i32); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B32 decode(const uint8_t *sourceBuffer) { + B32 result; + B32::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B32& target) { + ::bebop::Reader reader{sourceBuffer}; + B32::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B32& target) { + target.i32 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B33 { + static const uint32_t opcode = 0x21; + + int32_t i33; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B33& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B33::encodeInto(message, writer); + } + + static void encodeInto(const B33& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i33); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B33 decode(const uint8_t *sourceBuffer) { + B33 result; + B33::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B33& target) { + ::bebop::Reader reader{sourceBuffer}; + B33::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B33& target) { + target.i33 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B34 { + static const uint32_t opcode = 0x22; + + int32_t i34; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B34& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B34::encodeInto(message, writer); + } + + static void encodeInto(const B34& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i34); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B34 decode(const uint8_t *sourceBuffer) { + B34 result; + B34::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B34& target) { + ::bebop::Reader reader{sourceBuffer}; + B34::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B34& target) { + target.i34 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B35 { + static const uint32_t opcode = 0x23; + + int32_t i35; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B35& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B35::encodeInto(message, writer); + } + + static void encodeInto(const B35& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i35); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B35 decode(const uint8_t *sourceBuffer) { + B35 result; + B35::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B35& target) { + ::bebop::Reader reader{sourceBuffer}; + B35::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B35& target) { + target.i35 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B36 { + static const uint32_t opcode = 0x24; + + int32_t i36; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B36& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B36::encodeInto(message, writer); + } + + static void encodeInto(const B36& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i36); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B36 decode(const uint8_t *sourceBuffer) { + B36 result; + B36::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B36& target) { + ::bebop::Reader reader{sourceBuffer}; + B36::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B36& target) { + target.i36 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B37 { + static const uint32_t opcode = 0x25; + + int32_t i37; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B37& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B37::encodeInto(message, writer); + } + + static void encodeInto(const B37& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i37); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B37 decode(const uint8_t *sourceBuffer) { + B37 result; + B37::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B37& target) { + ::bebop::Reader reader{sourceBuffer}; + B37::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B37& target) { + target.i37 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B38 { + static const uint32_t opcode = 0x26; + + int32_t i38; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B38& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B38::encodeInto(message, writer); + } + + static void encodeInto(const B38& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i38); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B38 decode(const uint8_t *sourceBuffer) { + B38 result; + B38::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B38& target) { + ::bebop::Reader reader{sourceBuffer}; + B38::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B38& target) { + target.i38 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B39 { + static const uint32_t opcode = 0x27; + + int32_t i39; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B39& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B39::encodeInto(message, writer); + } + + static void encodeInto(const B39& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i39); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B39 decode(const uint8_t *sourceBuffer) { + B39 result; + B39::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B39& target) { + ::bebop::Reader reader{sourceBuffer}; + B39::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B39& target) { + target.i39 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B40 { + static const uint32_t opcode = 0x28; + + int32_t i40; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B40& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B40::encodeInto(message, writer); + } + + static void encodeInto(const B40& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i40); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B40 decode(const uint8_t *sourceBuffer) { + B40 result; + B40::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B40& target) { + ::bebop::Reader reader{sourceBuffer}; + B40::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B40& target) { + target.i40 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B41 { + static const uint32_t opcode = 0x29; + + int32_t i41; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B41& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B41::encodeInto(message, writer); + } + + static void encodeInto(const B41& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i41); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B41 decode(const uint8_t *sourceBuffer) { + B41 result; + B41::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B41& target) { + ::bebop::Reader reader{sourceBuffer}; + B41::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B41& target) { + target.i41 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B42 { + static const uint32_t opcode = 0x2A; + + int32_t i42; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B42& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B42::encodeInto(message, writer); + } + + static void encodeInto(const B42& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i42); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B42 decode(const uint8_t *sourceBuffer) { + B42 result; + B42::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B42& target) { + ::bebop::Reader reader{sourceBuffer}; + B42::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B42& target) { + target.i42 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B43 { + static const uint32_t opcode = 0x2B; + + int32_t i43; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B43& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B43::encodeInto(message, writer); + } + + static void encodeInto(const B43& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i43); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B43 decode(const uint8_t *sourceBuffer) { + B43 result; + B43::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B43& target) { + ::bebop::Reader reader{sourceBuffer}; + B43::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B43& target) { + target.i43 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B44 { + static const uint32_t opcode = 0x2C; + + int32_t i44; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B44& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B44::encodeInto(message, writer); + } + + static void encodeInto(const B44& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i44); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B44 decode(const uint8_t *sourceBuffer) { + B44 result; + B44::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B44& target) { + ::bebop::Reader reader{sourceBuffer}; + B44::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B44& target) { + target.i44 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B45 { + static const uint32_t opcode = 0x2D; + + int32_t i45; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B45& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B45::encodeInto(message, writer); + } + + static void encodeInto(const B45& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i45); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B45 decode(const uint8_t *sourceBuffer) { + B45 result; + B45::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B45& target) { + ::bebop::Reader reader{sourceBuffer}; + B45::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B45& target) { + target.i45 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B46 { + static const uint32_t opcode = 0x2E; + + int32_t i46; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B46& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B46::encodeInto(message, writer); + } + + static void encodeInto(const B46& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i46); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B46 decode(const uint8_t *sourceBuffer) { + B46 result; + B46::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B46& target) { + ::bebop::Reader reader{sourceBuffer}; + B46::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B46& target) { + target.i46 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B47 { + static const uint32_t opcode = 0x2F; + + int32_t i47; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B47& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B47::encodeInto(message, writer); + } + + static void encodeInto(const B47& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i47); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B47 decode(const uint8_t *sourceBuffer) { + B47 result; + B47::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B47& target) { + ::bebop::Reader reader{sourceBuffer}; + B47::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B47& target) { + target.i47 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B48 { + static const uint32_t opcode = 0x30; + + int32_t i48; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B48& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B48::encodeInto(message, writer); + } + + static void encodeInto(const B48& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i48); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B48 decode(const uint8_t *sourceBuffer) { + B48 result; + B48::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B48& target) { + ::bebop::Reader reader{sourceBuffer}; + B48::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B48& target) { + target.i48 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B49 { + static const uint32_t opcode = 0x31; + + int32_t i49; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B49& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B49::encodeInto(message, writer); + } + + static void encodeInto(const B49& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i49); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B49 decode(const uint8_t *sourceBuffer) { + B49 result; + B49::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B49& target) { + ::bebop::Reader reader{sourceBuffer}; + B49::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B49& target) { + target.i49 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + +struct B50 { + static const uint32_t opcode = 0x32; + + int32_t i50; + uint64_t u; + double f; + std::string s; + ::bebop::Guid g; + bool b; + + static void encodeInto(const B50& message, std::vector &targetBuffer) { + ::bebop::Writer writer{targetBuffer}; + B50::encodeInto(message, writer); + } + + static void encodeInto(const B50& message, ::bebop::Writer& writer) { + writer.writeInt32(message.i50); + writer.writeUint64(message.u); + writer.writeFloat64(message.f); + writer.writeString(message.s); + writer.writeGuid(message.g); + writer.writeBool(message.b); + } + + static B50 decode(const uint8_t *sourceBuffer) { + B50 result; + B50::decodeInto(sourceBuffer, result); + return result; + } + + static void decodeInto(const uint8_t *sourceBuffer, B50& target) { + ::bebop::Reader reader{sourceBuffer}; + B50::decodeInto(reader, target); + } + + static void decodeInto(::bebop::Reader& reader, B50& target) { + target.i50 = reader.readInt32(); + target.u = reader.readUint64(); + target.f = reader.readFloat64(); + target.s = reader.readString(); + target.g = reader.readGuid(); + target.b = reader.readBool(); + } +}; + diff --git a/Laboratory/C++/run_test.sh b/Laboratory/C++/run_test.sh new file mode 100755 index 00000000..8ac8f635 --- /dev/null +++ b/Laboratory/C++/run_test.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -e +>&2 echo "Timing bebopc:" +time dotnet run --project ../../Compiler --cpp "gen/$1.hpp" --files "../Schemas/$1.bop" +>&2 echo "Timing C++ compiler:" +time g++ -std=c++17 test/$1.cpp +./a.out diff --git a/Laboratory/C++/test/test.cpp b/Laboratory/C++/test/jazz.cpp similarity index 79% rename from Laboratory/C++/test/test.cpp rename to Laboratory/C++/test/jazz.cpp index 7d71eebb..48217e90 100644 --- a/Laboratory/C++/test/test.cpp +++ b/Laboratory/C++/test/jazz.cpp @@ -14,11 +14,13 @@ int main() { std::map songs {{g, s}}; Library l {songs}; - std::vector lb = *Library::encode(l); - for (auto x : lb) printf(" %02x", x); + std::vector buf; + Library::encodeInto(l, buf); + for (auto x : buf) printf(" %02x", x); printf("\n"); - const auto l2 = Library::decode(lb.data()); + Library l2; + Library::decodeInto(buf.data(), l2); printf("%s\n", l2.songs.at(g).title.value().c_str()); printf("%d\n", l2.songs.at(g).year.value()); printf("%s\n", l2.songs.at(g).performers.value()[0].name.c_str()); diff --git a/Laboratory/C++/test/union_perf_a.cpp b/Laboratory/C++/test/union_perf_a.cpp new file mode 100644 index 00000000..fed220d7 --- /dev/null +++ b/Laboratory/C++/test/union_perf_a.cpp @@ -0,0 +1,45 @@ +#include "../gen/union_perf_a.hpp" +#include +#include +#include +#include +#include +#include + +int main() +{ + using std::chrono::duration; + using std::chrono::duration_cast; + using std::chrono::high_resolution_clock; + using std::chrono::milliseconds; + + bebop::Guid myGuid = bebop::Guid::fromString("81c6987b-48b7-495f-ad01-ec20cc5f5be1"); + const int count = 1000000; + { + std::srand(std::time(nullptr)); + auto t1 = high_resolution_clock::now(); + int32_t sum = 0; + for (int i = 0; i < count; i++) + { + A14 inner; + inner.i14 = std::rand() % 2; + inner.u = 11111; + inner.b = true; + inner.f = 3.14; + inner.g = myGuid; + inner.s = "yeah"; + A a; + a.containerOpcode = 123; + a.protocolVersion = 456; + a.u.variant.emplace(inner); + std::vector buf; + A::encodeInto(a, buf); + A a2; + A::decodeInto(buf.data(), a2); + sum += std::get(a2.u.variant).i14; + } + auto t2 = high_resolution_clock::now(); + auto ms_int = duration_cast(t2 - t1); + std::cout << "Computed sum=" << sum << " in " << ms_int.count() << "ms\n"; + } +} diff --git a/Laboratory/C++/test/union_perf_b.cpp b/Laboratory/C++/test/union_perf_b.cpp new file mode 100644 index 00000000..64697462 --- /dev/null +++ b/Laboratory/C++/test/union_perf_b.cpp @@ -0,0 +1,46 @@ +#include "../gen/union_perf_b.hpp" +#include +#include +#include +#include +#include +#include + +int main() +{ + using std::chrono::duration; + using std::chrono::duration_cast; + using std::chrono::high_resolution_clock; + using std::chrono::milliseconds; + + bebop::Guid myGuid = bebop::Guid::fromString("81c6987b-48b7-495f-ad01-ec20cc5f5be1"); + const int count = 1000000; + { + auto t1 = high_resolution_clock::now(); + int32_t sum = 0; + for (int i = 0; i < count; i++) + { + B14 inner; + inner.i14 = std::rand() % 2; + inner.u = 11111; + inner.b = true; + inner.f = 3.14; + inner.g = myGuid; + inner.s = "yeah"; + B b; + b.protocolVersion = 456; + b.incomingOpcode = 789; + B14::encodeInto(inner, b.encodedData); + std::vector buf; + B::encodeInto(b, buf); + B b2; + B::decodeInto(buf.data(), b2); + B14 inner2; + B14::decodeInto(b2.encodedData.data(), inner2); + sum += inner2.i14; + } + auto t2 = high_resolution_clock::now(); + auto ms_int = duration_cast(t2 - t1); + std::cout << "Computed sum=" << sum << " in " << ms_int.count() << "ms\n"; + } +} diff --git a/Laboratory/Schemas/jazz.bop b/Laboratory/Schemas/jazz.bop index fc0a3a24..cadda963 100644 --- a/Laboratory/Schemas/jazz.bop +++ b/Laboratory/Schemas/jazz.bop @@ -4,8 +4,12 @@ enum Instrument { Clarinet = 2; } +/* test */ +[opcode("JAZZ")] readonly struct Musician { + /* a name */ string name; + /* an instrument */ Instrument plays; } diff --git a/Laboratory/Schemas/union_perf_a.bop b/Laboratory/Schemas/union_perf_a.bop new file mode 100644 index 00000000..0b699cba --- /dev/null +++ b/Laboratory/Schemas/union_perf_a.bop @@ -0,0 +1,61 @@ +/** + * Option A: put the whole thing in a union. + */ +union U { + 1 -> struct A1 { int32 i1; uint64 u; float64 f; string s; guid g; bool b; } + 2 -> struct A2 { int32 i2; uint64 u; float64 f; string s; guid g; bool b; } + 3 -> struct A3 { int32 i3; uint64 u; float64 f; string s; guid g; bool b; } + 4 -> struct A4 { int32 i4; uint64 u; float64 f; string s; guid g; bool b; } + 5 -> struct A5 { int32 i5; uint64 u; float64 f; string s; guid g; bool b; } + 6 -> struct A6 { int32 i6; uint64 u; float64 f; string s; guid g; bool b; } + 7 -> struct A7 { int32 i7; uint64 u; float64 f; string s; guid g; bool b; } + 8 -> struct A8 { int32 i8; uint64 u; float64 f; string s; guid g; bool b; } + 9 -> struct A9 { int32 i9; uint64 u; float64 f; string s; guid g; bool b; } + 10 -> struct A10 { int32 i10; uint64 u; float64 f; string s; guid g; bool b; } + 11 -> struct A11 { int32 i11; uint64 u; float64 f; string s; guid g; bool b; } + 12 -> struct A12 { int32 i12; uint64 u; float64 f; string s; guid g; bool b; } + 13 -> struct A13 { int32 i13; uint64 u; float64 f; string s; guid g; bool b; } + 14 -> struct A14 { int32 i14; uint64 u; float64 f; string s; guid g; bool b; } + 15 -> struct A15 { int32 i15; uint64 u; float64 f; string s; guid g; bool b; } + 16 -> struct A16 { int32 i16; uint64 u; float64 f; string s; guid g; bool b; } + 17 -> struct A17 { int32 i17; uint64 u; float64 f; string s; guid g; bool b; } + 18 -> struct A18 { int32 i18; uint64 u; float64 f; string s; guid g; bool b; } + 19 -> struct A19 { int32 i19; uint64 u; float64 f; string s; guid g; bool b; } + 20 -> struct A20 { int32 i20; uint64 u; float64 f; string s; guid g; bool b; } + 21 -> struct A21 { int32 i21; uint64 u; float64 f; string s; guid g; bool b; } + 22 -> struct A22 { int32 i22; uint64 u; float64 f; string s; guid g; bool b; } + 23 -> struct A23 { int32 i23; uint64 u; float64 f; string s; guid g; bool b; } + 24 -> struct A24 { int32 i24; uint64 u; float64 f; string s; guid g; bool b; } + 25 -> struct A25 { int32 i25; uint64 u; float64 f; string s; guid g; bool b; } + 26 -> struct A26 { int32 i26; uint64 u; float64 f; string s; guid g; bool b; } + 27 -> struct A27 { int32 i27; uint64 u; float64 f; string s; guid g; bool b; } + 28 -> struct A28 { int32 i28; uint64 u; float64 f; string s; guid g; bool b; } + 29 -> struct A29 { int32 i29; uint64 u; float64 f; string s; guid g; bool b; } + 30 -> struct A30 { int32 i30; uint64 u; float64 f; string s; guid g; bool b; } + 31 -> struct A31 { int32 i31; uint64 u; float64 f; string s; guid g; bool b; } + 32 -> struct A32 { int32 i32; uint64 u; float64 f; string s; guid g; bool b; } + 33 -> struct A33 { int32 i33; uint64 u; float64 f; string s; guid g; bool b; } + 34 -> struct A34 { int32 i34; uint64 u; float64 f; string s; guid g; bool b; } + 35 -> struct A35 { int32 i35; uint64 u; float64 f; string s; guid g; bool b; } + 36 -> struct A36 { int32 i36; uint64 u; float64 f; string s; guid g; bool b; } + 37 -> struct A37 { int32 i37; uint64 u; float64 f; string s; guid g; bool b; } + 38 -> struct A38 { int32 i38; uint64 u; float64 f; string s; guid g; bool b; } + 39 -> struct A39 { int32 i39; uint64 u; float64 f; string s; guid g; bool b; } + 40 -> struct A40 { int32 i40; uint64 u; float64 f; string s; guid g; bool b; } + 41 -> struct A41 { int32 i41; uint64 u; float64 f; string s; guid g; bool b; } + 42 -> struct A42 { int32 i42; uint64 u; float64 f; string s; guid g; bool b; } + 43 -> struct A43 { int32 i43; uint64 u; float64 f; string s; guid g; bool b; } + 44 -> struct A44 { int32 i44; uint64 u; float64 f; string s; guid g; bool b; } + 45 -> struct A45 { int32 i45; uint64 u; float64 f; string s; guid g; bool b; } + 46 -> struct A46 { int32 i46; uint64 u; float64 f; string s; guid g; bool b; } + 47 -> struct A47 { int32 i47; uint64 u; float64 f; string s; guid g; bool b; } + 48 -> struct A48 { int32 i48; uint64 u; float64 f; string s; guid g; bool b; } + 49 -> struct A49 { int32 i49; uint64 u; float64 f; string s; guid g; bool b; } + 50 -> struct A50 { int32 i50; uint64 u; float64 f; string s; guid g; bool b; } +} + +struct A { + uint32 containerOpcode; + uint32 protocolVersion; + U u; +} diff --git a/Laboratory/Schemas/union_perf_b.bop b/Laboratory/Schemas/union_perf_b.bop new file mode 100644 index 00000000..684f77bf --- /dev/null +++ b/Laboratory/Schemas/union_perf_b.bop @@ -0,0 +1,59 @@ +/** + * Option B: an "encodedData" field, that "decode" is called a second time on. + */ +struct B { + uint32 protocolVersion; + uint32 incomingOpcode; + byte[] encodedData; +} + +[opcode(1)] struct B1 { int32 i1; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(2)] struct B2 { int32 i2; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(3)] struct B3 { int32 i3; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(4)] struct B4 { int32 i4; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(5)] struct B5 { int32 i5; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(6)] struct B6 { int32 i6; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(7)] struct B7 { int32 i7; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(8)] struct B8 { int32 i8; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(9)] struct B9 { int32 i9; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(10)] struct B10 { int32 i10; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(11)] struct B11 { int32 i11; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(12)] struct B12 { int32 i12; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(13)] struct B13 { int32 i13; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(14)] struct B14 { int32 i14; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(15)] struct B15 { int32 i15; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(16)] struct B16 { int32 i16; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(17)] struct B17 { int32 i17; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(18)] struct B18 { int32 i18; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(19)] struct B19 { int32 i19; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(20)] struct B20 { int32 i20; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(21)] struct B21 { int32 i21; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(22)] struct B22 { int32 i22; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(23)] struct B23 { int32 i23; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(24)] struct B24 { int32 i24; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(25)] struct B25 { int32 i25; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(26)] struct B26 { int32 i26; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(27)] struct B27 { int32 i27; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(28)] struct B28 { int32 i28; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(29)] struct B29 { int32 i29; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(30)] struct B30 { int32 i30; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(31)] struct B31 { int32 i31; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(32)] struct B32 { int32 i32; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(33)] struct B33 { int32 i33; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(34)] struct B34 { int32 i34; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(35)] struct B35 { int32 i35; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(36)] struct B36 { int32 i36; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(37)] struct B37 { int32 i37; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(38)] struct B38 { int32 i38; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(39)] struct B39 { int32 i39; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(40)] struct B40 { int32 i40; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(41)] struct B41 { int32 i41; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(42)] struct B42 { int32 i42; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(43)] struct B43 { int32 i43; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(44)] struct B44 { int32 i44; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(45)] struct B45 { int32 i45; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(46)] struct B46 { int32 i46; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(47)] struct B47 { int32 i47; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(48)] struct B48 { int32 i48; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(49)] struct B49 { int32 i49; uint64 u; float64 f; string s; guid g; bool b; } +[opcode(50)] struct B50 { int32 i50; uint64 u; float64 f; string s; guid g; bool b; } diff --git a/Runtime/C++/src/bebop.hpp b/Runtime/C++/src/bebop.hpp index 7b776daf..8eaa42f3 100644 --- a/Runtime/C++/src/bebop.hpp +++ b/Runtime/C++/src/bebop.hpp @@ -169,12 +169,12 @@ struct Guid { }; #pragma pack(pop) -class BebopReader { +class Reader { const uint8_t* m_pointer; public: - BebopReader(const uint8_t* buffer) : m_pointer(buffer) {} - BebopReader(BebopReader const&) = delete; - void operator=(BebopReader const&) = delete; + Reader(const uint8_t* buffer) : m_pointer(buffer) {} + Reader(Reader const&) = delete; + void operator=(Reader const&) = delete; const uint8_t* pointer() const { return m_pointer; } void seek(const uint8_t* pointer) { m_pointer = pointer; } @@ -281,39 +281,57 @@ class BebopReader { uint32_t readMessageLength() { return readUint32(); } }; -class BebopWriter { - std::unique_ptr> m_buffer; +class Writer { + std::vector& m_buffer; public: - BebopWriter() : m_buffer(std::make_unique>()) {} - BebopWriter(BebopWriter const&) = delete; - void operator=(BebopWriter const&) = delete; + Writer(std::vector& buffer) : m_buffer(buffer) {} + Writer(Writer const&) = delete; + void operator=(Writer const&) = delete; - std::unique_ptr> buffer() { - return std::move(m_buffer); + std::vector& buffer() { + return m_buffer; } - size_t length() { return m_buffer->size(); } + size_t length() { return m_buffer.size(); } - void writeByte(uint8_t value) { m_buffer->push_back(value); } + void writeByte(uint8_t value) { m_buffer.push_back(value); } void writeUint16(uint16_t value) { - m_buffer->push_back(value); - m_buffer->push_back(value >> 8); +#if BEBOP_ASSUME_LITTLE_ENDIAN + const auto position = m_buffer.size(); + m_buffer.resize(position + sizeof(value)); + memcpy(m_buffer.data() + position, &value, sizeof(value)); +#else + m_buffer.push_back(value); + m_buffer.push_back(value >> 8); +#endif } void writeUint32(uint32_t value) { - m_buffer->push_back(value); - m_buffer->push_back(value >> 8); - m_buffer->push_back(value >> 16); - m_buffer->push_back(value >> 24); +#if BEBOP_ASSUME_LITTLE_ENDIAN + const auto position = m_buffer.size(); + m_buffer.resize(position + sizeof(value)); + memcpy(m_buffer.data() + position, &value, sizeof(value)); +#else + m_buffer.push_back(value); + m_buffer.push_back(value >> 8); + m_buffer.push_back(value >> 16); + m_buffer.push_back(value >> 24); +#endif } void writeUint64(uint64_t value) { - m_buffer->push_back(value); - m_buffer->push_back(value >> 0x08); - m_buffer->push_back(value >> 0x10); - m_buffer->push_back(value >> 0x18); - m_buffer->push_back(value >> 0x20); - m_buffer->push_back(value >> 0x28); - m_buffer->push_back(value >> 0x30); - m_buffer->push_back(value >> 0x38); +#if BEBOP_ASSUME_LITTLE_ENDIAN + const auto position = m_buffer.size(); + m_buffer.resize(position + sizeof(value)); + memcpy(m_buffer.data() + position, &value, sizeof(value)); +#else + m_buffer.push_back(value); + m_buffer.push_back(value >> 0x08); + m_buffer.push_back(value >> 0x10); + m_buffer.push_back(value >> 0x18); + m_buffer.push_back(value >> 0x20); + m_buffer.push_back(value >> 0x28); + m_buffer.push_back(value >> 0x30); + m_buffer.push_back(value >> 0x38); +#endif } void writeInt16(int16_t value) { writeUint16(static_cast(value)); } @@ -327,20 +345,20 @@ class BebopWriter { void writeFloat64(double value) { uint64_t temp; memcpy(&temp, &value, sizeof(double)); - writeUint32(temp); + writeUint64(temp); } void writeBool(bool value) { writeByte(value); } void writeBytes(std::vector value) { const auto byteCount = value.size(); writeUint32(byteCount); - m_buffer->insert(m_buffer->end(), value.begin(), value.end()); + m_buffer.insert(m_buffer.end(), value.begin(), value.end()); } void writeString(std::string value) { const auto byteCount = value.size(); writeUint32(byteCount); - m_buffer->insert(m_buffer->end(), value.begin(), value.end()); + m_buffer.insert(m_buffer.end(), value.begin(), value.end()); } void writeGuid(Guid value) { @@ -364,20 +382,20 @@ class BebopWriter { /// Reserve some space to write a message's length prefix, and return its index. /// The length is stored as a little-endian fixed-width unsigned 32-bit integer, so 4 bytes are reserved. size_t reserveMessageLength() { - const auto n = m_buffer->size(); - m_buffer->resize(n + 4); + const auto n = m_buffer.size(); + m_buffer.resize(n + 4); return n; } /// Fill in a message's length prefix. void fillMessageLength(size_t position, uint32_t messageLength) { #if BEBOP_ASSUME_LITTLE_ENDIAN - memcpy(m_buffer->data() + position, &messageLength, sizeof(uint32_t)); + memcpy(m_buffer.data() + position, &messageLength, sizeof(uint32_t)); #else - (*m_buffer)[position++] = messageLength; - (*m_buffer)[position++] = messageLength >> 8; - (*m_buffer)[position++] = messageLength >> 16; - (*m_buffer)[position++] = messageLength >> 24; + m_buffer[position++] = messageLength; + m_buffer[position++] = messageLength >> 8; + m_buffer[position++] = messageLength >> 16; + m_buffer[position++] = messageLength >> 24; #endif } };