< Summary

Class:KernelCommunication.ByteArrayReader
Assembly:KernelCommunication.BinaryReader
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/KernelCommunication/BinaryMessage/BinaryReader/ByteArrayReader.cs
Covered lines:26
Uncovered lines:7
Coverable lines:33
Total lines:70
Line coverage:78.7% (26 of 33)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ByteArrayReader(...)0%110100%
get_offset()0%2100%
CanRead()0%110100%
ReadInt32()0%4.434070%
ReadInt64()0%4.434070%
ReadBytes(...)0%110100%
Skip(...)0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/KernelCommunication/BinaryMessage/BinaryReader/ByteArrayReader.cs

#LineLine coverage
 1using System;
 2
 3namespace KernelCommunication
 4{
 5    public class ByteArrayReader : IBinaryReader
 6    {
 7        private readonly byte[] bytes;
 8        private int currentOffset;
 9
 1510        public ByteArrayReader(byte[] bytes)
 11        {
 1512            this.bytes = bytes;
 1513            currentOffset = 0;
 1514        }
 15
 016        int IBinaryReader.offset => currentOffset;
 17
 2418        bool IBinaryReader.CanRead() => currentOffset < bytes.Length;
 19
 20        unsafe int IBinaryReader.ReadInt32()
 21        {
 7922            int ofs = currentOffset;
 7923            currentOffset += 4;
 24
 7925            if (bytes == null)
 026                throw new NullReferenceException("bytes array == null");
 7927            if ((long)(uint)ofs >= (long)bytes.Length)
 028                throw new IndexOutOfRangeException("offset is bigger than bytes array lenght");
 7929            if (ofs > bytes.Length - 4)
 030                throw new IndexOutOfRangeException("bytes.Length is not large enough to contain a valid Int32");
 31
 7932            fixed (byte* numPtr = &bytes[ofs])
 33            {
 7934                return ByteUtils.PointerToInt32(numPtr);
 35            }
 36        }
 37
 38        unsafe long IBinaryReader.ReadInt64()
 39        {
 1540            int ofs = currentOffset;
 1541            currentOffset += 8;
 42
 1543            if (bytes == null)
 044                throw new NullReferenceException("bytes array == null");
 1545            if ((long)(uint)ofs >= (long)bytes.Length)
 046                throw new IndexOutOfRangeException("offset is bigger than bytes array lenght");
 1547            if (ofs > bytes.Length - 8)
 048                throw new IndexOutOfRangeException("bytes.Length is not large enough to contain a valid Int64");
 49
 1550            fixed (byte* numPtr = &bytes[ofs])
 51            {
 1552                return ByteUtils.PointerToInt64(numPtr);
 53            }
 54        }
 55
 56        byte[] IBinaryReader.ReadBytes(int length)
 57        {
 1158            int ofs = currentOffset;
 1159            currentOffset += length;
 1160            byte[] data = new byte[length];
 1161            Buffer.BlockCopy(bytes, ofs, data, 0, length);
 1162            return data;
 63        }
 64
 65        void IBinaryReader.Skip(int bytesCount)
 66        {
 467            currentOffset += bytesCount;
 468        }
 69    }
 70}