< Summary

Information
Class: DeltaSharp.Format.FossilDeltaWriter
Assembly: DeltaSharp
File(s): /home/runner/work/DeltaSharp/DeltaSharp/src/DeltaSharp/Format/Fossil/FossilDeltaWriter.cs
Line coverage
100%
Covered lines: 44
Uncovered lines: 0
Coverable lines: 44
Total lines: 113
Line coverage: 100%
Branch coverage
80%
Covered branches: 8
Total branches: 10
Branch coverage: 80%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
get__buffer()100%11100%
get__position()100%11100%
.ctor()100%11100%
.ctor(...)100%11100%
WriteInt(...)80%1010100%
WriteLength(...)100%11100%
WriteCopy(...)100%11100%
WriteInsert(...)100%11100%
WriteChecksum(...)100%11100%
GetOutput()100%11100%
Dispose()100%11100%

File(s)

/home/runner/work/DeltaSharp/DeltaSharp/src/DeltaSharp/Format/Fossil/FossilDeltaWriter.cs

#LineLine coverage
 1using DeltaSharp.Util;
 2using System.Buffers.Binary;
 3using System.Buffers.Text;
 4using System.Text;
 5
 6namespace DeltaSharp.Format;
 7internal class FossilDeltaWriter : IDeltaWriter
 8{
 9
 1010    private readonly static uint[] _zDigits = {
 1011            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',
 1012            'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
 1013            'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '_', 'a', 'b', 'c', 'd', 'e',
 1014            'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
 1015            't', 'u', 'v', 'w', 'x', 'y', 'z', '~'
 1016        };
 17
 18    private MemoryStream _ms;
 2287019    private byte[] _buffer => _ms.GetBuffer();
 2287020    private int _position => (int)_ms.Position;
 21
 2019022    public FossilDeltaWriter()
 23    {
 2019024        _ms = new MemoryStream();
 2019025    }
 26
 267027    public FossilDeltaWriter(int sizeHint)
 28    {
 267029        _ms = DeltaWriterBuffer.Create(sizeHint);
 267030    }
 31
 32    private unsafe void WriteInt(ulong v)
 33    {
 34        int i, j;
 35
 21703036        if (v == 0)
 37        {
 415038            _ms.WriteByte((byte)'0');
 415039            return;
 40        }
 41
 21288042        fixed (uint* zBuf = stackalloc uint[20])
 21288043        fixed (uint* zDigits = _zDigits)
 44        {
 177984045            for (i = 0; v > 0; i++, v >>= 6)
 46            {
 45136047                zBuf[i] = zDigits[v & 0x3f];
 48            }
 132848049            for (j = i - 1; j >= 0; j--)
 50            {
 45136051                var s = (byte)zBuf[j];
 45136052                _ms.WriteByte(s);
 53            }
 54        }
 21288055    }
 56
 57
 58    public void WriteLength(ulong length)
 59    {
 60        //write length
 2287061        WriteInt(length);
 62
 63        //write line ending
 2287064        _ms.Write("\n"u8);
 2287065    }
 66
 67    public void WriteCopy(ulong position, ulong length)
 68    {
 69        //write length
 6517070        WriteInt(length);
 71
 72        //write command
 6517073        _ms.WriteByte((byte)'@');
 74
 75        //write copy position
 6517076        WriteInt(position);
 77
 78        //write copy end
 6517079        _ms.WriteByte((byte)',');
 6517080    }
 81
 82    public void WriteInsert(ReadOnlySpan<byte> s)
 83    {
 84        //write length
 6105085        WriteInt((ulong)s.Length);
 86
 87        //write command
 6105088        _ms.WriteByte((byte)':');
 89
 90        //write data
 6105091        DeltaWriterBuffer.WriteLiteral(_ms, s, trailerBytes: 7); // up to six base-64 checksum digits and a semicolon
 6105092    }
 93
 94    public void WriteChecksum(uint checksum)
 95    {
 96        //write length
 277097        WriteInt((ulong)checksum);
 98
 99        //write command
 2770100        _ms.WriteByte((byte)';');
 101
 2770102    }
 103
 104    public ReadOnlyMemory<byte> GetOutput()
 105    {
 22870106        return _buffer.AsMemory().Slice(0,_position);
 107    }
 108
 109    public void Dispose()
 110    {
 22850111        _ms.Dispose();
 22850112    }
 113}