/// <summary>
        /// For each serializable structure, create an entry with deserialization handler in the dispatch callback table.
        /// </summary>
        /// <param name="sourceType"></param>
        public override void EndVisitType(Type sourceType)
        {
            string proxyTypeFullName = $"{Constants.ProxyNamespace}.{sourceType.GetTypeFullName()}";

            ulong typeHashValue = TypeMetadataMapper.GetTypeHashValue(sourceType);

            WriteBlock($@"
                new DispatchEntry
                {{
                    CodegenTypeHash = 0x{typeHashValue:x},
                    Callback = (bufferPtr, frameLength) =>
                    {{
                        var recvObjectProxy = new {proxyTypeFullName}() {{ Buffer = bufferPtr }};

                        bool isValid = recvObjectProxy.VerifyVariableData(frameLength);
                        if (isValid && {proxyTypeFullName}.Callback != null)
                        {{
                            {proxyTypeFullName}.Callback(recvObjectProxy);
                        }}

                        return isValid;
                    }},
                }},");

            ++ClassCount;
        }
        /// <inheritdoc/>
        public override void EndVisitType(Type sourceType)
        {
            WriteLine();
            WriteLine("return hashValue;");
            IndentationLevel--;

            WriteLine("}");
            WriteLine();

            uint typeIndex = TypeMetadataMapper.GetTypeIndex(sourceType);

            ulong typeHashValue = TypeMetadataMapper.GetTypeHashValue(sourceType);

            WriteBlock($@"
                /// <inheritdoc/>
                [MethodImpl(MethodImplOptions.AggressiveInlining)]
                uint global::Mlos.Core.ICodegenKey.CodegenTypeIndex() => {typeIndex} + {DispatchTableBaseIndexVariableName};");

            WriteBlock($@"
                /// <inheritdoc/>
                [MethodImpl(MethodImplOptions.AggressiveInlining)]
                ulong global::Mlos.Core.ICodegenKey.CodegenTypeHash() => 0x{typeHashValue:x};");

            IndentationLevel--;

            WriteLine("}");
            WriteLine();

            WriteCloseTypeDeclaration(sourceType);
        }
예제 #3
0
        /// <inheritdoc/>
        public override void EndVisitType(Type sourceType)
        {
            CppType cppType = CppTypeMapper.GetCppType(sourceType);

            uint  typeIndex     = TypeMetadataMapper.GetTypeIndex(sourceType);
            ulong typeHashValue = TypeMetadataMapper.GetTypeHashValue(sourceType);

            WriteLine();

            WriteLine("return hashValue;");
            IndentationLevel--;
            WriteLine("}");
            WriteLine();

            string dispatchTableBaseIndexVariable =
                "global::" +
                (string.IsNullOrEmpty(DispatchTableCSharpNamespace) ? string.Empty : $"{DispatchTableCSharpNamespace}.")
                + "ObjectDeserializeHandler.DispatchTableBaseIndex";

            WriteBlock($@"
                [MethodImpl(MethodImplOptions.AggressiveInlining)]
                uint global::Mlos.Core.ICodegenKey.CodegenTypeIndex() => {typeIndex} + {dispatchTableBaseIndexVariable};");

            WriteBlock($@"
                [MethodImpl(MethodImplOptions.AggressiveInlining)]
                ulong global::Mlos.Core.ICodegenKey.CodegenTypeHash() => 0x{typeHashValue:x};");

            WriteBlock($@"
                [MethodImpl(MethodImplOptions.AggressiveInlining)]
                ulong global::Mlos.Core.ICodegenType.CodegenTypeSize() => {cppType.TypeSize};");

            WriteCloseTypeDeclaration(sourceType);
        }
예제 #4
0
        /// <summary>
        /// For a new structure, create a entry in matadata table.
        /// </summary>
        /// <param name="sourceType"></param>
        public override void EndVisitType(Type sourceType)
        {
            // Type CppType is beeing generated and it is not yet available.
            // Create a full name from CSharp type.
            //
            string cppTypeFullName = CppTypeMapper.GenerateCppFullTypeName(sourceType);

            uint typeIndex = TypeMetadataMapper.GetTypeIndex(sourceType);

            // Write a link to next metadata object.
            //
            WriteBlock(@$ "
                template<>
                constexpr uint32_t CodegenTypeIndex<{cppTypeFullName}>() {{ return {DispatchTableCppNamespace}::DispatchTableBaseIndex() + {typeIndex}; }}");
예제 #5
0
        /// <inheritdoc/>
        public override void EndVisitType(Type sourceType)
        {
            // Get the cppType.
            //
            CppType cppType = CppTypeMapper.GetCppType(sourceType);

            uint  typeIndex     = TypeMetadataMapper.GetTypeIndex(sourceType);
            ulong typeHashValue = TypeMetadataMapper.GetTypeHashValue(sourceType);

            WriteBlock($@"
                /// <inheritdoc/>
                [MethodImpl(MethodImplOptions.AggressiveInlining)]
                uint global::Mlos.Core.ICodegenKey.CodegenTypeIndex()
                {{
                    return {typeIndex} + {DispatchTableBaseIndexVariableName};
                }}");

            WriteBlock($@"
                /// <inheritdoc/>
                [MethodImpl(MethodImplOptions.AggressiveInlining)]
                ulong global::Mlos.Core.ICodegenKey.CodegenTypeHash() => 0x{typeHashValue:x};");

            WriteBlock($@"
                /// <inheritdoc/>
                [MethodImpl(MethodImplOptions.AggressiveInlining)]
                public ulong CodegenTypeSize() => {cppType.TypeSize};");

            WriteBlock($@"
                /// <inheritdoc/>
                [System.Text.Json.Serialization.JsonIgnore]
                public IntPtr Buffer
                {{
                    get
                    {{
                        return buffer;
                    }}
                    set
                    {{
                        buffer = value;
                    }}
                }}");

            WriteBlock($@"
                private IntPtr buffer;");

            WriteCloseTypeDeclaration(sourceType);
        }
        /// <summary>
        /// For each serializable structure, create an entry with deserialization handler in the dispatch callback table.
        /// </summary>
        /// <param name="sourceType"></param>
        public override void EndVisitType(Type sourceType)
        {
            string proxyTypeFullName = $"{Constants.ProxyNamespace}.{sourceType.GetTypeFullName()}";

            ulong typeHashValue = TypeMetadataMapper.GetTypeHashValue(sourceType);

            WriteBlock($@"
                new DeserializeEntry
                {{
                    TypeHash = 0x{typeHashValue:x},
                    Deserialize = bufferPtr =>
                    {{
                        var recvObjectProxy = new {proxyTypeFullName}() {{ Buffer = bufferPtr }};
                        return recvObjectProxy;
                    }},
                }},");

            ++ClassCount;
        }