File: System\Runtime\Serialization\BinaryFormat\ObjectNullMultipleRecord.cs
Web Access
Project: src\src\libraries\System.Runtime.Serialization.BinaryFormat\src\System.Runtime.Serialization.BinaryFormat.csproj (System.Runtime.Serialization.BinaryFormat)
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
 
using System.IO;
using System.Runtime.Serialization.BinaryFormat.Utils;
 
namespace System.Runtime.Serialization.BinaryFormat;
 
/// <summary>
/// Represents multiple <see langword="null" />.
/// </summary>
/// <remarks>
/// ObjectNullMultiple records are described in <see href="https://learn.microsoft.com/openspecs/windows_protocols/ms-nrbf/f4abb5dd-aab7-4e0a-9d77-1d6c99f5779e">[MS-NRBF] 2.5.5</see>.
/// </remarks>
internal sealed class ObjectNullMultipleRecord : NullsRecord
{
    private ObjectNullMultipleRecord(int count) => NullCount = count;
 
    public override RecordType RecordType => RecordType.ObjectNullMultiple;
 
    internal override int NullCount { get; }
 
    internal static ObjectNullMultipleRecord Decode(BinaryReader reader)
    {
        // 2.5.5 ObjectNullMultiple
 
        // NullCount (4 bytes): An INT32 value ... The value MUST be a positive integer.
        int count = reader.ReadInt32();
        if (count <= 0)
        {
            ThrowHelper.ThrowInvalidValue(count);
        }
 
        return new ObjectNullMultipleRecord(count);
    }
}