< Summary

Information
Class: DeltaSharp.Format.DeltaReaderException
Assembly: DeltaSharp
File(s): /home/runner/work/DeltaSharp/DeltaSharp/src/DeltaSharp/Format/Binary/BinaryDeltaReader.cs
Line coverage
50%
Covered lines: 1
Uncovered lines: 1
Coverable lines: 2
Total lines: 90
Line coverage: 50%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%210%
.ctor(...)100%11100%

File(s)

/home/runner/work/DeltaSharp/DeltaSharp/src/DeltaSharp/Format/Binary/BinaryDeltaReader.cs

#LineLine coverage
 1using DeltaSharp.Util;
 2
 3namespace DeltaSharp.Format;
 4
 5/// <summary>Reads DeltaSharp binary command headers with variable-length integer operands.</summary>
 6public class BinaryDeltaReader : IDeltaReader
 7{
 8
 9    /// <inheritdoc cref="IDeltaReader.TryRead"/>
 10    public bool TryRead(ReadOnlySpan<byte> input, out DeltaCommand command, out uint consumed)
 11    {
 12        command = default;
 13        consumed = 0;
 14
 15        if (input.IsEmpty)
 16            return false;
 17
 18        var commandChar = (char)input[0];
 19
 20        switch (commandChar)
 21        {
 22            case 'l':
 23                {
 24                    input = input.Slice(1);
 25                    if (!VarIntFormatter.TryDecode(input, out var length, out var lengthChars))
 26                        return false;
 27
 28                    consumed = (uint)lengthChars + 1;
 29
 30                    command = new DeltaCommand(DeltaCommandEnum.Length, 0, length);
 31
 32                    return true;
 33                }
 34            case 'c':
 35                {
 36                    input = input.Slice(1);
 37                    if (!VarIntFormatter.TryDecode(input, out var position, out var positionBytes))
 38                        return false;
 39
 40                    input = input.Slice(positionBytes);
 41                    if (!VarIntFormatter.TryDecode(input, out var length, out var lengthBytes))
 42                        return false;
 43
 44                    consumed = (uint)positionBytes + (uint)lengthBytes + 1;
 45
 46                    command = new DeltaCommand(DeltaCommandEnum.Copy, position, length);
 47
 48                    return true;
 49                }
 50            case 'i':
 51                {
 52                    input = input.Slice(1);
 53                    if (!VarIntFormatter.TryDecode(input, out var length, out var lengthBytes))
 54                        return false;
 55
 56                    consumed = (uint)lengthBytes + 1;
 57
 58                    command = new DeltaCommand(DeltaCommandEnum.Insert, 0, length);
 59
 60                    return true;
 61                }
 62            case 'v':
 63                {
 64                    input = input.Slice(1);
 65                    if (!VarIntFormatter.TryDecode(input, out var length, out var lengthBytes))
 66                        return false;
 67
 68                    consumed = (uint)lengthBytes + 1;
 69
 70                    command = new DeltaCommand(DeltaCommandEnum.Checksum, 0, length);
 71
 72                    return true;
 73                }
 74            default:
 75                throw new DeltaReaderException("Invalid command");
 76        }
 77    }
 78
 79}
 80
 81/// <summary>Reports invalid syntax or an unsupported numeric value in an encoded delta command.</summary>
 82public class DeltaReaderException : Exception
 83{
 84    /// <summary>Initializes a reader exception with the default exception message.</summary>
 085    public DeltaReaderException() { }
 86
 87    /// <summary>Initializes a reader exception with a description of the parsing failure.</summary>
 88    /// <param name="message">The description of the invalid command.</param>
 7886089    public DeltaReaderException(string message) : base(message) { }
 90}

Methods/Properties

.ctor()
.ctor(System.String)