protected override ProjectAction? DeserializeCore(ref MessagePackReader reader, MessagePackSerializerOptions options)
        {
            string? id = null;
            ImplicitProjectAction[]? implicitActions = null;
            PackageIdentity? packageIdentity = null;
            NuGetProjectActionType? projectActionType = null;
            string? projectId = null;

            int propertyCount = reader.ReadMapHeader();

            for (var propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex)
            {
                switch (reader.ReadString())
                {
                    case IdPropertyName:
                        id = reader.ReadString();
                        break;

                    case ImplicitActionsPropertyName:
                        int elementCount = reader.ReadArrayHeader();
                        implicitActions = new ImplicitProjectAction[elementCount];

                        for (var i = 0; i < elementCount; ++i)
                        {
                            ImplicitProjectAction? implicitAction = ImplicitProjectActionFormatter.Instance.Deserialize(ref reader, options);

                            Assumes.NotNull(implicitAction);

                            implicitActions[i] = implicitAction;
                        }
                        break;

                    case PackageIdentityPropertyName:
                        packageIdentity = PackageIdentityFormatter.Instance.Deserialize(ref reader, options);
                        break;

                    case ProjectActionTypePropertyName:
                        projectActionType = options.Resolver.GetFormatter<NuGetProjectActionType>().Deserialize(ref reader, options);
                        break;

                    case ProjectIdPropertyName:
                        projectId = reader.ReadString();
                        break;

                    default:
                        reader.Skip();
                        break;
                }
            }

            Assumes.NotNullOrEmpty(id);
            Assumes.NotNull(packageIdentity);
            Assumes.True(projectActionType.HasValue);
            Assumes.NotNullOrEmpty(projectId);

            return new ProjectAction(id, projectId, packageIdentity, projectActionType.Value, implicitActions);
        }
예제 #2
0
        public ProjectAction?Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
        {
            if (reader.TryReadNil())
            {
                return(null);
            }

            // stack overflow mitigation - see https://github.com/neuecc/MessagePack-CSharp/security/advisories/GHSA-7q36-4xx7-xcxf
            options.Security.DepthStep(ref reader);

            try
            {
                string?id = null;
                ImplicitProjectAction[]? implicitActions = null;
                PackageIdentity?       packageIdentity   = null;
                NuGetProjectActionType?projectActionType = null;
                string?projectId = null;

                int propertyCount = reader.ReadMapHeader();

                for (var propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex)
                {
                    switch (reader.ReadString())
                    {
                    case IdPropertyName:
                        id = reader.ReadString();
                        break;

                    case ImplicitActionsPropertyName:
                        int elementCount = reader.ReadArrayHeader();
                        implicitActions = new ImplicitProjectAction[elementCount];

                        for (var i = 0; i < elementCount; ++i)
                        {
                            ImplicitProjectAction?implicitAction = ImplicitProjectActionFormatter.Instance.Deserialize(ref reader, options);

                            Assumes.NotNull(implicitAction);

                            implicitActions[i] = implicitAction;
                        }
                        break;

                    case PackageIdentityPropertyName:
                        packageIdentity = PackageIdentityFormatter.Instance.Deserialize(ref reader, options);
                        break;

                    case ProjectActionTypePropertyName:
                        projectActionType = options.Resolver.GetFormatter <NuGetProjectActionType>().Deserialize(ref reader, options);
                        break;

                    case ProjectIdPropertyName:
                        projectId = reader.ReadString();
                        break;

                    default:
                        reader.Skip();
                        break;
                    }
                }

                Assumes.NotNullOrEmpty(id);
                Assumes.NotNull(packageIdentity);
                Assumes.True(projectActionType.HasValue);
                Assumes.NotNullOrEmpty(projectId);

                return(new ProjectAction(id, projectId, packageIdentity, projectActionType.Value, implicitActions));
            }
            finally
            {
                // stack overflow mitigation - see https://github.com/neuecc/MessagePack-CSharp/security/advisories/GHSA-7q36-4xx7-xcxf
                reader.Depth--;
            }
        }