/// <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. // string cppProxyTypeFullName = CppTypeMapper.GetCppProxyFullTypeName(fieldType); // Write the property, for arrays, use PropertyArrayProxy. // if (cppField.FieldInfo.IsFixedSizedArray()) { // Get the fixed array length and write the property. // FixedSizeArrayAttribute arrayAttribute = cppField.FieldInfo.GetCustomAttribute <FixedSizeArrayAttribute>(); WriteLine($"::Mlos::Core::PropertyArrayProxy<{cppProxyTypeFullName}, {arrayAttribute.Length}> {fieldName}() {{ return ::Mlos::Core::PropertyArrayProxy<{cppProxyTypeFullName}, {arrayAttribute.Length}>(buffer, {fieldOffset}); }}"); } else { WriteLine($"{cppProxyTypeFullName} {fieldName}() {{ return {cppProxyTypeFullName}(buffer, {fieldOffset}); }}"); } WriteLine(); }
/// <summary> /// For each serializable structure, create an entry with deserialization handler in the dispatch callback table. /// </summary> /// <param name="sourceType"></param> public override void BeginVisitType(Type sourceType) { string cppTypeFullName = CppTypeMapper.GetCppFullTypeName(sourceType); string cppProxyTypeFullName = CppTypeMapper.GetCppProxyFullTypeName(sourceType); WriteBlock(@$ " ::Mlos::Core::DispatchEntry {{ {Constants.TypeMetadataInfoNamespace}::CodegenTypeHash<{cppTypeFullName}>(),
/// <summary> /// Write a specialization of the template function to calculate the length of the variable fields for the provided type. /// </summary> /// <param name="sourceType"></param> public override void BeginVisitType(Type sourceType) { string cppElementTypeFullName = CppTypeMapper.GetCppProxyFullTypeName(sourceType); WriteBlock($@" template<> inline bool VerifyVariableData<{cppElementTypeFullName}>({cppElementTypeFullName} object, uint64_t objectOffset, uint64_t totalDataSize, uint64_t& expectedDataOffset) {{ bool isValid = true;"); IndentationLevel++; }
/// <summary> /// For a new structure, create a entry in metadata table. /// </summary> /// <param name="sourceType"></param> public override void BeginVisitType(Type sourceType) { // Receiver is using proxy struct. // string cppProxyTypeFullName = CppTypeMapper.GetCppProxyFullTypeName(sourceType); // Use type name, as we are already in type namespace. // string cppTypeNameAsField = $"{sourceType.Name}_Callback"; WriteLine($"__declspec(selectany) std::function<void ({cppProxyTypeFullName}&&)> {cppTypeNameAsField} = nullptr;"); WriteLine(); }
/// <inheritdoc /> public override void BeginVisitType(Type sourceType) { string cppClassName = sourceType.Name; string cppProxyTypeFullName = CppTypeMapper.GetCppProxyFullTypeName(sourceType); AlignAttribute alignmentAttribute = sourceType.GetCustomAttribute <AlignAttribute>(); string structAlignAsCodeString = alignmentAttribute == null ? string.Empty : $"alignas({alignmentAttribute.Size})"; WriteBlock($@" struct {structAlignAsCodeString} {cppClassName} {{ typedef {cppProxyTypeFullName} ProxyObjectType;"); IndentationLevel++; }