Example #1
0
        private static string GetMapTypeSerialization(FieldDefinition.MapTypeRef mapType, string schemaObjectName, string fieldName, string fieldId, TypeDescription parentType, Bundle bundle)
        {
            return($@"for (const TPair<{Types.GetTypeDisplayName(mapType.KeyType, bundle, parentType)}, {Types.GetTypeDisplayName(mapType.ValueType, bundle, parentType)}>& Pair : {fieldName})
{{
{Text.Indent(1, $@"Schema_Object* PairObj = Schema_AddObject({schemaObjectName}, {fieldId});
{GetValueTypeSerialization(mapType.KeyType, "PairObj", "Pair.Key", "SCHEMA_MAP_KEY_FIELD_ID")}
{GetValueTypeSerialization(mapType.ValueType, "PairObj", "Pair.Value", "SCHEMA_MAP_VALUE_FIELD_ID")}")}
}}");
        }
Example #2
0
        private static string GetMapTypeDeserialization(FieldDefinition.MapTypeRef mapType, string schemaObjectName, string targetObjectName, string fieldName, string fieldId,
                                                        TypeDescription parentType, Bundle bundle, bool wrapInBlock = false, bool targetIsOption = false)
        {
            var keyTypeName   = Types.GetTypeDisplayName(mapType.KeyType, bundle, parentType);
            var valueTypeName = Types.GetTypeDisplayName(mapType.ValueType, bundle, parentType);
            var mapName       = $"{fieldName}Map";
            var kvPairName    = "KvPair";

            var deserializationText = $@"{{
{Text.Indent(1, $@"{targetObjectName} = {Types.CollectionTypesToQualifiedTypes[Types.Collection.Map]}<{keyTypeName}, {valueTypeName}>();
auto MapEntryCount = Schema_GetObjectCount({schemaObjectName}, {fieldId});
for (uint32 i = 0; i < MapEntryCount; ++i)
{{
{Text.Indent(1, $@"Schema_Object* {kvPairName} = Schema_IndexObject({schemaObjectName}, {fieldId}, i);
auto Key = {GetValueTypeDeserialization(mapType.KeyType, kvPairName, "SCHEMA_MAP_KEY_FIELD_ID", parentType)};
auto Value = {GetValueTypeDeserialization(mapType.ValueType, kvPairName, "SCHEMA_MAP_VALUE_FIELD_ID", parentType)};
{(targetIsOption ? $"(*{targetObjectName})" : targetObjectName)}[std::move(Key)] = std::move(Value);")}
}}")}
}}";

            return(wrapInBlock ? $"{{{Environment.NewLine}{Text.Indent(1, deserializationText)}{Environment.NewLine}}}" : deserializationText);
        }