Ejemplo n.º 1
0
        public global::TestData2.Nest2.IdType Deserialize(ref MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options)
        {
            if (reader.TryReadNil())
            {
                return(null);
            }

            options.Security.DepthStep(ref reader);
            IFormatterResolver formatterResolver = options.Resolver;
            var length = reader.ReadMapHeader();

            for (int i = 0; i < length; i++)
            {
                ReadOnlySpan <byte> stringKey = global::MessagePack.Internal.CodeGenHelpers.ReadStringSpan(ref reader);
                int key;
                if (!this.____keyMapping.TryGetValue(stringKey, out key))
                {
                    reader.Skip();
                    continue;
                }

                switch (key)
                {
                default:
                    reader.Skip();
                    break;
                }
            }

            var ____result = new global::TestData2.Nest2.IdType();

            reader.Depth--;
            return(____result);
        }
        protected override IProjectContextInfo?DeserializeCore(ref MessagePackReader reader, MessagePackSerializerOptions options)
        {
            NuGetProjectKind projectKind  = NuGetProjectKind.Unknown;
            ProjectStyle     projectStyle = ProjectStyle.Unknown;
            string?          projectId    = null;

            int propertyCount = reader.ReadMapHeader();

            for (int propertyIndex = 0; propertyIndex < propertyCount; propertyIndex++)
            {
                switch (reader.ReadString())
                {
                case ProjectIdPropertyName:
                    projectId = reader.ReadString();
                    break;

                case ProjectKindPropertyName:
                    projectKind = options.Resolver.GetFormatter <NuGetProjectKind>().Deserialize(ref reader, options);
                    break;

                case ProjectStylePropertyName:
                    projectStyle = options.Resolver.GetFormatter <ProjectStyle>().Deserialize(ref reader, options);
                    break;

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

            Assumes.NotNull(projectId);

            return(new ProjectContextInfo(projectId, projectStyle, projectKind));
        }
        protected override PackageDependencyGroup?DeserializeCore(ref MessagePackReader reader, MessagePackSerializerOptions options)
        {
            NuGetFramework?framework = null;
            IEnumerable <PackageDependency>?packageDependencies = null;

            int propertyCount = reader.ReadMapHeader();

            for (var propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex)
            {
                switch (reader.ReadString())
                {
                case TargetFrameworkPropertyName:
                    framework = NuGetFrameworkFormatter.Instance.Deserialize(ref reader, options);
                    break;

                case PackagesPropertyName:
                    packageDependencies = options.Resolver.GetFormatter <IEnumerable <PackageDependency> >().Deserialize(ref reader, options);
                    break;

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

            Assumes.NotNull(framework);
            Assumes.NotNull(packageDependencies);

            return(new PackageDependencyGroup(framework, packageDependencies));
        }
Ejemplo n.º 4
0
        protected override PackageVulnerabilityMetadataContextInfo?DeserializeCore(ref MessagePackReader reader, MessagePackSerializerOptions options)
        {
            Uri?advisoryUrl = null;
            int severity    = 0;

            int propertyCount = reader.ReadMapHeader();

            for (int propertyIndex = 0; propertyIndex < propertyCount; propertyIndex++)
            {
                switch (reader.ReadString())
                {
                case AdvisoryUrlPropertyName:
                    advisoryUrl = options.Resolver.GetFormatter <Uri>().Deserialize(ref reader, options);
                    break;

                case SeverityPropertyName:
                    severity = reader.ReadInt32();
                    break;

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

            Assumes.NotNull(advisoryUrl);

            return(new PackageVulnerabilityMetadataContextInfo(advisoryUrl, severity));
        }
Ejemplo n.º 5
0
#pragma warning disable CS0618 // Type or member is obsolete
        protected override PackageSourceUpdateOptions?DeserializeCore(ref MessagePackReader reader, MessagePackSerializerOptions options)
#pragma warning restore CS0618 // Type or member is obsolete
        {
            bool updateCredentials = true;
            bool updateEnabled     = true;

            int propertyCount = reader.ReadMapHeader();

            for (int propertyIndex = 0; propertyIndex < propertyCount; propertyIndex++)
            {
                switch (reader.ReadString())
                {
                case UpdateCredentialsPropertyName:
                    updateCredentials = reader.ReadBoolean();
                    break;

                case UpdateEnabledPropertyName:
                    updateEnabled = reader.ReadBoolean();
                    break;

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

#pragma warning disable CS0618 // Type or member is obsolete
            return(new PackageSourceUpdateOptions(updateCredentials, updateEnabled));

#pragma warning restore CS0618 // Type or member is obsolete
        }
Ejemplo n.º 6
0
        public TDictionary Deserialize(ref MessagePackReader reader, IFormatterResolver resolver)
        {
            if (reader.TryReadNil())
            {
                return(default(TDictionary));
            }
            else
            {
                var keyFormatter   = resolver.GetFormatterWithVerify <TKey>();
                var valueFormatter = resolver.GetFormatterWithVerify <TValue>();

                var len = reader.ReadMapHeader();

                var dict = Create(len);
                for (int i = 0; i < len; i++)
                {
                    var key = keyFormatter.Deserialize(ref reader, resolver);

                    var value = valueFormatter.Deserialize(ref reader, resolver);

                    Add(dict, i, key, value);
                }

                return(Complete(dict));
            }
        }
        protected override PackageDeprecationMetadataContextInfo?DeserializeCore(ref MessagePackReader reader, MessagePackSerializerOptions options)
        {
            string?message = null;
            IReadOnlyCollection <string>?       reasons = null;
            AlternatePackageMetadataContextInfo?alternatePackageMetadataContextInfo = null;

            int propertyCount = reader.ReadMapHeader();

            for (int propertyIndex = 0; propertyIndex < propertyCount; propertyIndex++)
            {
                switch (reader.ReadString())
                {
                case MessagePropertyName:
                    message = reader.ReadString();
                    break;

                case ReasonsPropertyName:
                    reasons = reader.TryReadNil() ? null : options.Resolver.GetFormatter <IReadOnlyCollection <string> >().Deserialize(ref reader, options);
                    break;

                case AlternatePackageMetadataPropertyName:
                    alternatePackageMetadataContextInfo = reader.TryReadNil() ? null : AlternatePackageMetadataContextInfoFormatter.Instance.Deserialize(ref reader, options);
                    break;

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

            Assumes.NotNullOrEmpty(message);

            return(new PackageDeprecationMetadataContextInfo(message, reasons, alternatePackageMetadataContextInfo));
        }
Ejemplo n.º 8
0
        protected override FloatRange?DeserializeCore(ref MessagePackReader reader, MessagePackSerializerOptions options)
        {
            NuGetVersionFloatBehavior?floatBehavior = null;
            NuGetVersion?minVersion    = null;
            string?      releasePrefix = null;

            int propertyCount = reader.ReadMapHeader();

            for (var propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex)
            {
                switch (reader.ReadString())
                {
                case FloatBehaviorPropertyName:
                    floatBehavior = options.Resolver.GetFormatter <NuGetVersionFloatBehavior>().Deserialize(ref reader, options);
                    break;

                case MinVersionPropertyName:
                    minVersion = NuGetVersionFormatter.Instance.Deserialize(ref reader, options);
                    break;

                case ReleasePrefixPropertyName:
                    releasePrefix = reader.ReadString();
                    break;

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

            Assumes.True(floatBehavior.HasValue);

            return(new FloatRange(floatBehavior.Value, minVersion, releasePrefix));
        }
Ejemplo n.º 9
0
        internal void ReadExtensionMembers(ref MessagePackReader reader)
        {
            int count = reader.ReadMapHeader();

            for (int i = 0; i < count; i++)
            {
                switch (reader.ReadInt32())
                {
                case TracingId:
                    if (this is IMessageWithTracingId withTracingId)
                    {
                        withTracingId.TracingId = reader.ReadUInt64();
                    }
                    break;

                case Ttl:
                    if (this is IHasTtl hasTtl)
                    {
                        hasTtl.Ttl = reader.ReadInt32();
                    }
                    break;

                case Protocol:
                    if (this is IHasProtocol hasProtocol)
                    {
                        hasProtocol.Protocol = reader.ReadString();
                    }
                    break;

                // todo : more optional fields
                default:
                    break;
                }
            }
        }
Ejemplo n.º 10
0
        public TDictionary Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
        {
            if (reader.TryReadNil())
            {
                return(default(TDictionary));
            }
            else
            {
                IFormatterResolver             resolver       = options.Resolver;
                IMessagePackFormatter <TKey>   keyFormatter   = resolver.GetFormatterWithVerify <TKey>();
                IMessagePackFormatter <TValue> valueFormatter = resolver.GetFormatterWithVerify <TValue>();

                var len = reader.ReadMapHeader();

                TIntermediate dict = this.Create(len, options);
                for (int i = 0; i < len; i++)
                {
                    reader.CancellationToken.ThrowIfCancellationRequested();
                    TKey key = keyFormatter.Deserialize(ref reader, options);

                    TValue value = valueFormatter.Deserialize(ref reader, options);

                    this.Add(dict, i, key, value, options);
                }

                return(this.Complete(dict));
            }
        }
    private static void DeserializeFormat0(ref MessagePackReader reader, MessagePackSerializerOptions options, ref string message, ref int number)
    {
        int length = reader.ReadMapHeader();
        int i      = 0;
        IFormatterResolver resolver = options.Resolver;

        while (i < length)
        {
            ReadOnlySpan <byte> stringKey = CodeGenHelpers.ReadStringSpan(ref reader);
            int   length2 = stringKey.Length;
            ulong key     = 0uL;
            if (length2 <= 8)
            {
                key = AutomataKeyGen.GetKey(ref stringKey);
            }

            if (length2 == 7 && key == 28542640894207341L)
            {
                message = reader.ReadString();
            }
            else if (length2 == 6 && key == 125779768604014L)
            {
                number = reader.ReadInt32();
            }
            else
            {
                reader.Skip();
            }

            i++;
        }
    }
        public ArgumentDictionary Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
        {
            if (reader.TryReadNil())
            {
                return(null);
            }

            ArgumentDictionary arguments = new ArgumentDictionary();

            var len = reader.ReadMapHeader();

            options.Security.DepthStep(ref reader);
            try
            {
                for (int i = 0; i < len; i++)
                {
                    string argumentName = reader.ReadString();
                    Type   argumentType = argumentMapping[argumentName];

                    object value = Deserialize(argumentType, ref reader, options);

                    arguments.Add(argumentName, value);
                }
            }
            finally
            {
                reader.Depth--;
            }

            return(arguments);
        }
Ejemplo n.º 13
0
        public void MapHeaderTest(uint target, int length)
        {
            (MemoryStream stream, MsgPack.Packer packer) = this.CreateReferencePacker();

            var sequence = new Sequence <byte>();
            var writer   = new MessagePackWriter(sequence);

            writer.WriteMapHeader(target);
            writer.Flush();
            sequence.Length.Is(length);

            packer.PackMapHeader((int)target).Position.Is(sequence.Length);
            stream.ToArray().SequenceEqual(sequence.AsReadOnlySequence.ToArray()).IsTrue();

            // Expand sequence enough that ReadArrayHeader doesn't throw due to its security check.
            writer.Write(new byte[target * 2]);
            writer.Flush();

            var sequenceReader = new MessagePackReader(sequence.AsReadOnlySequence);

            sequenceReader.ReadMapHeader().Is((int)target);
            sequenceReader.ReadBytes(); // read the padding we added
            sequenceReader.End.IsTrue();

            var  ms       = new MemoryStream(sequence.AsReadOnlySequence.ToArray());
            var  unpacker = MsgPack.Unpacker.Create(ms);
            long len;

            unpacker.ReadMapLength(out len).IsTrue();
            len.Is(target);
        }
        protected override PackageIdentity?DeserializeCore(ref MessagePackReader reader, MessagePackSerializerOptions options)
        {
            string?      id      = null;
            NuGetVersion?version = null;

            int propertyCount = reader.ReadMapHeader();

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

                case NuGetVersionPropertyName:
                    version = NuGetVersionFormatter.Instance.Deserialize(ref reader, options);
                    break;

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

            return(new PackageIdentity(id, version));
        }
        protected override AlternatePackageMetadataContextInfo?DeserializeCore(ref MessagePackReader reader, MessagePackSerializerOptions options)
        {
            string?      packageId = null;
            VersionRange?range     = null;

            int propertyCount = reader.ReadMapHeader();

            for (int propertyIndex = 0; propertyIndex < propertyCount; propertyIndex++)
            {
                switch (reader.ReadString())
                {
                case PackageIdPropertyName:
                    packageId = reader.ReadString();
                    break;

                case VersionRangePropertyName:
                    range = VersionRangeFormatter.Instance.Deserialize(ref reader, options);
                    break;

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

            Assumes.NotNullOrEmpty(packageId);
            Assumes.NotNull(range);

            return(new AlternatePackageMetadataContextInfo(packageId, range));
        }
        public ExpandoObject Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
        {
            if (reader.TryReadNil())
            {
                return(null);
            }

            var result = new ExpandoObject();
            int count  = reader.ReadMapHeader();

            if (count > 0)
            {
                IFormatterResolver             resolver       = options.Resolver;
                IMessagePackFormatter <string> keyFormatter   = resolver.GetFormatterWithVerify <string>();
                IMessagePackFormatter <object> valueFormatter = resolver.GetFormatterWithVerify <object>();
                IDictionary <string, object>   dictionary     = result;

                options.Security.DepthStep(ref reader);
                try
                {
                    for (int i = 0; i < count; i++)
                    {
                        string key   = keyFormatter.Deserialize(ref reader, options);
                        object value = valueFormatter.Deserialize(ref reader, options);
                        dictionary.Add(key, value);
                    }
                }
                finally
                {
                    reader.Depth--;
                }
            }

            return(result);
        }
Ejemplo n.º 17
0
        protected override NuGetFramework?DeserializeCore(ref MessagePackReader reader, MessagePackSerializerOptions options)
        {
            string?frameworkName = null;
            string?platformName  = null;

            int propertyCount = reader.ReadMapHeader();

            for (int propertyIndex = 0; propertyIndex < propertyCount; propertyIndex++)
            {
                switch (reader.ReadString())
                {
                case DotNetFrameworkNamePropertyName:
                    frameworkName = reader.ReadString();
                    break;

                case DotNetPlatformNamePropertyName:
                    platformName = reader.ReadString();
                    break;

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

            return(NuGetFramework.ParseComponents(frameworkName, platformName));
        }
Ejemplo n.º 18
0
        public global::DM.MessagePackTest Deserialize(ref MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options)
        {
            if (reader.TryReadNil())
            {
                return(null);
            }

            options.Security.DepthStep(ref reader);
            IFormatterResolver formatterResolver = options.Resolver;
            var length             = reader.ReadMapHeader();
            var __IsNetworkError__ = default(bool);
            var __IsHttpError__    = default(bool);
            var __ResponseCode__   = default(int);
            var __Sec__            = default(int);

            for (int i = 0; i < length; i++)
            {
                ReadOnlySpan <byte> stringKey = global::MessagePack.Internal.CodeGenHelpers.ReadStringSpan(ref reader);
                int key;
                if (!this.____keyMapping.TryGetValue(stringKey, out key))
                {
                    reader.Skip();
                    continue;
                }

                switch (key)
                {
                case 0:
                    __IsNetworkError__ = reader.ReadBoolean();
                    break;

                case 1:
                    __IsHttpError__ = reader.ReadBoolean();
                    break;

                case 2:
                    __ResponseCode__ = reader.ReadInt32();
                    break;

                case 3:
                    __Sec__ = reader.ReadInt32();
                    break;

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

            var ____result = new global::DM.MessagePackTest();

            ____result.IsNetworkError = __IsNetworkError__;
            ____result.IsHttpError    = __IsHttpError__;
            ____result.ResponseCode   = __ResponseCode__;
            ____result.Sec            = __Sec__;
            reader.Depth--;
            return(____result);
        }
Ejemplo n.º 19
0
        public global::DM.Person Deserialize(ref MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options)
        {
            if (reader.TryReadNil())
            {
                return(null);
            }

            options.Security.DepthStep(ref reader);
            IFormatterResolver formatterResolver = options.Resolver;
            var length       = reader.ReadMapHeader();
            var __PersonId__ = default(int);
            var __Age__      = default(int);
            var __Gender__   = default(global::DM.Gender);
            var __Name__     = default(string);

            for (int i = 0; i < length; i++)
            {
                ReadOnlySpan <byte> stringKey = global::MessagePack.Internal.CodeGenHelpers.ReadStringSpan(ref reader);
                int key;
                if (!this.____keyMapping.TryGetValue(stringKey, out key))
                {
                    reader.Skip();
                    continue;
                }

                switch (key)
                {
                case 0:
                    __PersonId__ = reader.ReadInt32();
                    break;

                case 1:
                    __Age__ = reader.ReadInt32();
                    break;

                case 2:
                    __Gender__ = formatterResolver.GetFormatterWithVerify <global::DM.Gender>().Deserialize(ref reader, options);
                    break;

                case 3:
                    __Name__ = formatterResolver.GetFormatterWithVerify <string>().Deserialize(ref reader, options);
                    break;

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

            var ____result = new global::DM.Person();

            ____result.PersonId = __PersonId__;
            ____result.Age      = __Age__;
            ____result.Gender   = __Gender__;
            ____result.Name     = __Name__;
            reader.Depth--;
            return(____result);
        }
Ejemplo n.º 20
0
        public EventDocumentAckResult Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
        {
            reader.ReadArrayHeader();
            StatusCode status       = (StatusCode)reader.ReadInt32();
            string     notification = reader.ReadString();

            reader.ReadMapHeader();
            return(new EventDocumentAckResult(status, notification));
        }
Ejemplo n.º 21
0
        private static int ReadMapHeader(ref MessagePackReader reader, string field)
        {
            if (reader.End || reader.NextMessagePackType != MessagePackType.Map)
            {
                ThrowInvalidCollectionLengthException(field, "map");
            }

            return(reader.ReadMapHeader());
        }
        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);
        }
Ejemplo n.º 23
0
        public global::MasterMemory.Tests.Sample Deserialize(ref MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options)
        {
            if (reader.TryReadNil())
            {
                return(null);
            }

            IFormatterResolver formatterResolver = options.Resolver;
            var length        = reader.ReadMapHeader();
            var __Id__        = default(int);
            var __Age__       = default(int);
            var __FirstName__ = default(string);
            var __LastName__  = default(string);

            for (int i = 0; i < length; i++)
            {
                ReadOnlySpan <byte> stringKey = Internal.CodeGenHelpers.ReadStringSpan(ref reader);
                int key;
                if (!this.____keyMapping.TryGetValue(stringKey, out key))
                {
                    reader.Skip();
                    continue;
                }

                switch (key)
                {
                case 0:
                    __Id__ = reader.ReadInt32();
                    break;

                case 1:
                    __Age__ = reader.ReadInt32();
                    break;

                case 2:
                    __FirstName__ = formatterResolver.GetFormatterWithVerify <string>().Deserialize(ref reader, options);
                    break;

                case 3:
                    __LastName__ = formatterResolver.GetFormatterWithVerify <string>().Deserialize(ref reader, options);
                    break;

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

            var ____result = new global::MasterMemory.Tests.Sample(__Id__, __Age__, __FirstName__, __LastName__);

            ____result.Id        = __Id__;
            ____result.Age       = __Age__;
            ____result.FirstName = __FirstName__;
            ____result.LastName  = __LastName__;
            return(____result);
        }
        public override TestTarget Deserialize(ref MessagePackReader reader)
        {
            if (!reader.TryReadNil())
            {
                var value = new TestTarget();
                int count = reader.ReadMapHeader();

                for (int i = 0; i < count; i++)
                {
                    ArraySegment<byte> segment = reader.ReadStringSegment();

                    if (m_nameToKey.TryGetValue(segment.Array, segment.Offset, segment.Count, out int key))
                    {
                        switch (key)
                        {
                            case 0:
                            {
                                value.BoolValue = reader.ReadBoolean();
                                break;
                            }
                            case 1:
                            {
                                value.IntValue = reader.ReadInt32();
                                break;
                            }
                            case 2:
                            {
                                value.FloatValue = reader.ReadSingle();
                                break;
                            }
                            case 3:
                            {
                                value.StringValue = reader.ReadString();
                                break;
                            }
                            case 4:
                            {
                                value.EnumValue = m_formatterTypeCode.Deserialize(ref reader);
                                break;
                            }
                            default:
                            {
                                reader.ReadNextBlock();
                                break;
                            }
                        }
                    }
                    else
                    {
                        reader.ReadNextBlock();
                    }
                }
            }

            return default;
        }
        protected override VersionRange?DeserializeCore(ref MessagePackReader reader, MessagePackSerializerOptions options)
        {
            FloatRange?  floatRange     = null;
            bool?        isMaxInclusive = null;
            bool?        isMinInclusive = null;
            NuGetVersion?maxVersion     = null;
            NuGetVersion?minVersion     = null;
            string?      originalString = null;

            int propertyCount = reader.ReadMapHeader();

            for (var propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex)
            {
                switch (reader.ReadString())
                {
                case FloatRangePropertyName:
                    floatRange = FloatRangeFormatter.Instance.Deserialize(ref reader, options);
                    break;

                case IsMaxInclusivePropertyName:
                    isMaxInclusive = reader.ReadBoolean();
                    break;

                case IsMinInclusivePropertyName:
                    isMinInclusive = reader.ReadBoolean();
                    break;

                case MaxVersionPropertyName:
                    maxVersion = NuGetVersionFormatter.Instance.Deserialize(ref reader, options);
                    break;

                case MinVersionPropertyName:
                    minVersion = NuGetVersionFormatter.Instance.Deserialize(ref reader, options);
                    break;

                case OriginalStringPropertyName:
                    originalString = reader.ReadString();
                    break;

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

            Assumes.True(isMinInclusive.HasValue);
            Assumes.True(isMaxInclusive.HasValue);

            return(new VersionRange(
                       minVersion,
                       isMinInclusive.Value,
                       maxVersion,
                       isMaxInclusive.Value,
                       floatRange,
                       originalString));
        }
        protected override PackageReference?DeserializeCore(ref MessagePackReader reader, MessagePackSerializerOptions options)
        {
            VersionRange?   allowedVersions         = null;
            bool            isDevelopmentDependency = false;
            bool            isUserInstalled         = true;
            bool            requireReinstallation   = false;
            PackageIdentity?identity  = null;
            NuGetFramework? framework = null;

            int propertyCount = reader.ReadMapHeader();

            for (int propertyIndex = 0; propertyIndex < propertyCount; propertyIndex++)
            {
                switch (reader.ReadString())
                {
                case AllowedVersionsPropertyName:
                    allowedVersions = VersionRangeFormatter.Instance.Deserialize(ref reader, options);
                    break;

                case IsDevelopmentDependencyPropertyName:
                    isDevelopmentDependency = reader.ReadBoolean();
                    break;

                case IsUserInstalledPropertyName:
                    isUserInstalled = reader.ReadBoolean();
                    break;

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

                case RequireReinstallationPropertyName:
                    requireReinstallation = reader.ReadBoolean();
                    break;

                case TargetFrameworkPropertyName:
                    framework = NuGetFrameworkFormatter.Instance.Deserialize(ref reader, options);
                    break;

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

            Assumes.NotNull(identity);
            Assumes.NotNull(framework);

            return(new PackageReference(
                       identity,
                       framework,
                       isUserInstalled,
                       isDevelopmentDependency,
                       requireReinstallation,
                       allowedVersions));
        }
        public PackageDependencyInfo?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
            {
                PackageIdentity?         packageIdentity     = null;
                List <PackageDependency>?packageDependencies = null;

                int propertyCount = reader.ReadMapHeader();

                for (var propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex)
                {
                    switch (reader.ReadString())
                    {
                    case PackageIdentityPropertyName:
                        packageIdentity = PackageIdentityFormatter.Instance.Deserialize(ref reader, options);
                        break;

                    case PackageDependenciesPropertyName:
                        packageDependencies = new List <PackageDependency>();

                        int dependenciesCount = reader.ReadArrayHeader();

                        for (var i = 0; i < dependenciesCount; ++i)
                        {
                            PackageDependency?packageDependency = PackageDependencyFormatter.Instance.Deserialize(ref reader, options);

                            Assumes.NotNull(packageDependency);

                            packageDependencies.Add(packageDependency);
                        }
                        break;

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

                Assumes.NotNull(packageIdentity);

                return(new PackageDependencyInfo(packageIdentity, packageDependencies));
            }
            finally
            {
                // stack overflow mitigation - see https://github.com/neuecc/MessagePack-CSharp/security/advisories/GHSA-7q36-4xx7-xcxf
                reader.Depth--;
            }
        }
Ejemplo n.º 28
0
        protected override LicenseMetadata?DeserializeCore(ref MessagePackReader reader, MessagePackSerializerOptions options)
        {
            LicenseType            type              = LicenseType.File;
            string?                license           = null;
            NuGetLicenseExpression?licenseExpression = null;
            IReadOnlyList <string>?warningsAndErrors = null;
            Version?               version           = null;

            int propertyCount = reader.ReadMapHeader();

            for (int propertyIndex = 0; propertyIndex < propertyCount; propertyIndex++)
            {
                switch (reader.ReadString())
                {
                case TypePropertyName:
                    if (!reader.TryReadNil())
                    {
                        type = options.Resolver.GetFormatter <LicenseType>().Deserialize(ref reader, options);
                    }
                    break;

                case LicensePropertyName:
                    license = reader.ReadString();
                    break;

                case LicenseExpressionPropertyName:
                    var expressionString = reader.ReadString();
                    if (expressionString != null)
                    {
                        licenseExpression = NuGetLicenseExpression.Parse(expressionString);
                    }
                    break;

                case WarningsAndErrorsPropertyName:
                    if (!reader.TryReadNil())
                    {
                        warningsAndErrors = options.Resolver.GetFormatter <IReadOnlyList <string> >().Deserialize(ref reader, options);
                    }
                    break;

                case VersionPropertyName:
                    version = options.Resolver.GetFormatter <Version>().Deserialize(ref reader, options);
                    break;

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

            return(new LicenseMetadata(type,
                                       license,
                                       licenseExpression,
                                       warningsAndErrors,
                                       version));
        }
Ejemplo n.º 29
0
        public void Read(ref MessagePackReader reader, ref byte position)
        {
            var length = reader.ReadMapHeader();

            for (int i = 0; i < length; i++)
            {
                reader.ReadNext(); // key
                reader.ReadNext(); // value
            }
        }
        public PackageSource?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?name          = null;
                string?source        = null;
                bool   isEnabled     = false;
                bool   isMachineWide = false;

                int propertyCount = reader.ReadMapHeader();
                for (int propertyIndex = 0; propertyIndex < propertyCount; propertyIndex++)
                {
                    switch (reader.ReadString())
                    {
                    case NamePropertyName:
                        name = reader.ReadString();
                        break;

                    case SourcePropertyName:
                        source = reader.ReadString();
                        break;

                    case IsEnabledPropertyName:
                        isEnabled = reader.ReadBoolean();
                        break;

                    case IsMachineWidePropertyName:
                        isMachineWide = reader.ReadBoolean();
                        break;

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

                return(new PackageSource(source, name, isEnabled)
                {
                    IsMachineWide = isMachineWide
                });
            }
            finally
            {
                // stack overflow mitigation - see https://github.com/neuecc/MessagePack-CSharp/security/advisories/GHSA-7q36-4xx7-xcxf
                reader.Depth--;
            }
        }