Example #1
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);
        }
        /// <inheritdoc />
        public override bool Accept(Type sourceType)
        {
            // Fixed length structure with no variable length fields.
            // No custom serialization is required.
            //
            CppType cppType = CppTypeMapper.GetCppType(sourceType);

            return(cppType.HasVariableData);
        }
Example #3
0
        /// <inheritdoc />
        public override bool Accept(Type sourceType)
        {
            // Fixed size structures do not have variable data fields.
            // No custom serialization code is required.
            //
            CppType cppType = CppTypeMapper.GetCppType(sourceType);

            return(cppType.HasVariableData);
        }
Example #4
0
        public override void EndVisitType(Type sourceType)
        {
            CppType cppType = CppTypeMapper.GetCppType(sourceType);

            if (cppType.PaddingSize != 0)
            {
                // Include padding to match defined structure size.
                //
                WriteLine($"byte __finalPadding[{cppType.PaddingSize}];");
            }

            base.EndVisitType(sourceType);
        }
Example #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);
        }
Example #6
0
        /// <inheritdoc />
        public override void BeginVisitType(Type sourceType)
        {
            WriteOpenTypeDeclaration(sourceType);

            CppType cppType = CppTypeMapper.GetCppType(sourceType);

            WriteBlock($@"
                    ulong global::Mlos.Core.ICodegenType.SerializeVariableData(IntPtr buffer, ulong objectOffset, ulong dataOffset)
                    {{
                        ulong totalDataSize = 0;");

            IndentationLevel++;

            if (cppType.HasVariableData)
            {
                WriteLine("ulong dataSize = 0;");
            }

            WriteLine();
        }
Example #7
0
        /// <inheritdoc />
        public override void VisitField(CppField cppField)
        {
            string fieldName   = cppField.FieldInfo.Name;
            string fieldOffset = $"{cppField.CppStructOffset}";

            Type fieldType = cppField.FieldInfo.FieldType;

            if (cppField.FieldInfo.IsFixedSizedArray())
            {
                // When field is array, get element type to use correct proxy type.
                //
                fieldType = fieldType.GetElementType();
            }

            // Get the proxy type name.
            //
            CppType cppType = CppTypeMapper.GetCppType(fieldType);

            // Get the proxy type name.
            //
            string fieldTypeName = $"global::{fieldType.FullName}";

            // Write the property, for arrays, use PropertyArrayProxy.
            //
            if (cppField.FieldInfo.IsFixedSizedArray() ||
                cppField.CppType.IsCodegenType)
            {
                string csharpProxyTypeFullName = cppType.IsCodegenType ? $"global::Proxy.{fieldType.FullName}" : $"global::{fieldType.FullName}";

                if (cppField.FieldInfo.IsFixedSizedArray())
                {
                    string csharpArrayProxyTypeName = cppType.IsCodegenType ? "global::Mlos.Core.PropertyProxyArray" : "global::Mlos.Core.ProxyArray";

                    // Declare the property.
                    //
                    WriteLine($@"public {csharpArrayProxyTypeName}<{csharpProxyTypeFullName}> {fieldName} => new {csharpArrayProxyTypeName}<{csharpProxyTypeFullName}>(buffer + {fieldOffset}, {cppType.TypeSize});");
                }
                else
                {
                    WriteLine($@"public {csharpProxyTypeFullName} {fieldName} => new {csharpProxyTypeFullName}() {{ Buffer = buffer + {fieldOffset} }};");
                }
            }
            else
            {
                WriteBlock($@"
                    public {fieldTypeName} {fieldName}
                    {{
                        get
                        {{
                            unsafe
                            {{
                                return *({fieldTypeName}*)(buffer + {fieldOffset}).ToPointer();
                            }}
                        }}

                        set
                        {{
                            unsafe
                            {{
                                *({fieldTypeName}*)(buffer + {fieldOffset}).ToPointer() = value;
                            }}
                        }}
                    }}");
            }

            WriteLine();
        }