< Summary

Class:Itinero.IO.BitCoderBuffer
Assembly:Itinero
File(s):/home/runner/work/routing2/routing2/src/Itinero/IO/BitCoderBuffer.cs
Covered lines:0
Uncovered lines:96
Coverable lines:96
Total lines:145
Line coverage:0% (0 of 96)
Covered branches:0
Total branches:14
Branch coverage:0% (0 of 14)
Tag:251_23667616543

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
GetVarUInt32(...)100%10%
GetVarUInt32Nullable(...)100%10%
GetVarInt32(...)100%10%
GetVarInt32Nullable(...)100%10%
GetGuid(...)100%10%
GetInt64(...)0%20%
GetWithSizeString(...)100%10%
SetVarUInt32(...)100%10%
SetVarUInt32Nullable(...)100%10%
SetVarInt32(...)100%10%
SetVarInt32Nullable(...)100%10%
SetGuid(...)100%10%
SetInt64(...)0%20%
SetWithSizeString(...)100%10%
ToUnsigned(...)0%40%
ToUnsigned(...)0%20%
FromUnsigned(...)0%20%
FromUnsigned(...)0%20%

File(s)

/home/runner/work/routing2/routing2/src/Itinero/IO/BitCoderBuffer.cs

#LineLine coverage
 1using System;
 2using System.Text;
 3using Itinero.Network.Storage;
 4
 5namespace Itinero.IO;
 6
 7internal static class BitCoderBuffer
 8{
 9    public static uint GetVarUInt32(byte[] data, ref int offset)
 010    {
 011        var size = data.GetDynamicUInt32(offset, out var value);
 012        offset += size;
 013        return value;
 014    }
 15
 16    public static uint? GetVarUInt32Nullable(byte[] data, ref int offset)
 017    {
 018        var size = data.GetDynamicUInt32Nullable(offset, out var value);
 019        offset += size;
 020        return value;
 021    }
 22
 23    public static int GetVarInt32(byte[] data, ref int offset)
 024    {
 025        return FromUnsigned(GetVarUInt32(data, ref offset));
 026    }
 27
 28    public static int? GetVarInt32Nullable(byte[] data, ref int offset)
 029    {
 030        return FromUnsigned(GetVarUInt32Nullable(data, ref offset));
 031    }
 32
 33    public static Guid GetGuid(byte[] data, ref int offset)
 034    {
 035        data.GetGuid(offset, out var value);
 036        offset += 16;
 037        return value;
 038    }
 39
 40    public static long GetInt64(byte[] data, ref int offset)
 041    {
 042        long value = 0;
 043        for (var b = 0; b < 8; b++)
 044        {
 045            value += (long)data[offset + b] << (b * 8);
 046        }
 47
 048        offset += 8;
 049        return value;
 050    }
 51
 52    public static string GetWithSizeString(byte[] data, ref int offset)
 053    {
 054        var size = GetInt64(data, ref offset);
 055        var str = Encoding.Unicode.GetString(data, offset, (int)size);
 056        offset += (int)size;
 057        return str;
 058    }
 59
 60    public static void SetVarUInt32(byte[] data, ref int offset, uint value)
 061    {
 062        offset += data.SetDynamicUInt32(offset, value);
 063    }
 64
 65    public static void SetVarUInt32Nullable(byte[] data, ref int offset, uint? value)
 066    {
 067        offset += data.SetDynamicUInt32Nullable(offset, value);
 068    }
 69
 70    public static void SetVarInt32(byte[] data, ref int offset, int value)
 071    {
 072        SetVarUInt32(data, ref offset, ToUnsigned(value));
 073    }
 74
 75    public static void SetVarInt32Nullable(byte[] data, ref int offset, int? value)
 076    {
 077        SetVarUInt32Nullable(data, ref offset, ToUnsigned(value));
 078    }
 79
 80    public static void SetGuid(byte[] data, ref int offset, Guid value)
 081    {
 082        data.SetGuid(offset, value);
 083        offset += 16;
 084    }
 85
 86    public static void SetInt64(byte[] data, ref int offset, long value)
 087    {
 088        for (var b = 0; b < 8; b++)
 089        {
 090            data[offset + b] = (byte)(value & byte.MaxValue);
 091            value >>= 8;
 092        }
 93
 094        offset += 8;
 095    }
 96
 97    public static void SetWithSizeString(byte[] data, ref int offset, string value)
 098    {
 099        var bytes = Encoding.Unicode.GetBytes(value);
 0100        SetInt64(data, ref offset, bytes.Length);
 0101        Buffer.BlockCopy(bytes, 0, data, offset, bytes.Length);
 0102        offset += bytes.Length;
 0103    }
 104
 105    private static uint ToUnsigned(int value)
 0106    {
 0107        var unsigned = (uint)value;
 0108        if (value < 0)
 0109        {
 0110            unsigned = (uint)-value;
 0111        }
 112
 0113        unsigned <<= 1;
 0114        if (value < 0)
 0115        {
 0116            unsigned += 1;
 0117        }
 118
 0119        return unsigned;
 0120    }
 121
 122    private static uint? ToUnsigned(int? value)
 0123    {
 0124        if (value == null) return null;
 0125        return ToUnsigned(value.Value);
 0126    }
 127
 128    private static int FromUnsigned(uint unsigned)
 0129    {
 0130        var sign = unsigned & 1;
 0131        var value = (int)(unsigned >> 1);
 0132        if (sign == 1)
 0133        {
 0134            value = -value;
 0135        }
 136
 0137        return value;
 0138    }
 139
 140    private static int? FromUnsigned(uint? unsigned)
 0141    {
 0142        if (unsigned == null) return null;
 0143        return FromUnsigned(unsigned.Value);
 0144    }
 145}