コード例 #1
0
    public void SerializeISerializable(byte[] expected, float first, int second, byte third)
    {
        var buffer     = new byte[9];
        var serializer = new Serializer(new ByteArray(buffer));
        var structure  = new SerializedStruct()
        {
            First = first, Second = second, Third = third
        };

        serializer.Serialize(structure);

        Assert.That(
            CompareArray(serializer.Internal, expected),
            "The serialization result is different than expected.\n" +
            "Got: " + PrintArray(serializer.Internal) + "\nExpected: " +
            PrintArray(expected)
            );
        Assert.That(!serializer.HasData, "Serializer still has data.");
    }
コード例 #2
0
        internal static List <FPropertyTag> DeserializePropertiesUnversioned(FAssetArchive Ar, UStruct struc)
        {
            var properties = new List <FPropertyTag>();
            var header     = new FUnversionedHeader(Ar);

            if (!header.HasValues)
            {
                return(properties);
            }
            var type = struc.Name;

            Struct?propMappings = null;

            if (struc is UScriptClass)
            {
                Ar.Owner.Mappings?.Types.TryGetValue(type, out propMappings);
            }
            else
            {
                propMappings = new SerializedStruct(Ar.Owner.Mappings, struc);
            }

            if (propMappings == null)
            {
                throw new ParserException(Ar, "Missing prop mappings for type " + type);
            }

            using var it = new FIterator(header);
            do
            {
                var(val, isNonZero) = it.Current;
                // The value has content and needs to be serialized normally
                if (isNonZero)
                {
                    if (propMappings.TryGetValue(val, out var propertyInfo))
                    {
                        var tag = new FPropertyTag(Ar, propertyInfo, ReadType.NORMAL);
                        if (tag.Tag != null)
                        {
                            properties.Add(tag);
                        }
                        else
                        {
                            throw new ParserException(Ar, $"{type}: Failed to serialize property {propertyInfo.MappingType.Type} {propertyInfo.Name}. Can't proceed with serialization (Serialized {properties.Count} properties until now)");
                        }
                    }
                    else
                    {
                        throw new ParserException(Ar, $"{type}: Unknown property with value {val}. Can't proceed with serialization (Serialized {properties.Count} properties until now)");
                    }
                }
                // The value is serialized as zero meaning we don't have to read any bytes here
                else
                {
                    if (propMappings.TryGetValue(val, out var propertyInfo))
                    {
                        properties.Add(new FPropertyTag(Ar, propertyInfo, ReadType.ZERO));
                    }
                    else
                    {
                        Log.Warning(
                            "{0}: Unknown property with value {1} but it's zero so we are good",
                            type, val);
                    }
                }
            } while (it.MoveNext());
            return(properties);
        }