< 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:11
Uncovered lines:22
Coverable lines:33
Total lines:70
Line coverage:33.3% (11 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%2100%
ReadInt32()0%4.434070%
ReadInt64()0%20400%
ReadBytes(...)0%2100%
Skip(...)0%2100%

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
 310        public ByteArrayReader(byte[] bytes)
 11        {
 312            this.bytes = bytes;
 313            currentOffset = 0;
 314        }
 15
 016        int IBinaryReader.offset => currentOffset;
 17
 018        bool IBinaryReader.CanRead() => currentOffset < bytes.Length;
 19
 20        unsafe int IBinaryReader.ReadInt32()
 21        {
 622            int ofs = currentOffset;
 623            currentOffset += 4;
 24
 625            if (bytes == null)
 026                throw new NullReferenceException("bytes array == null");
 627            if ((long)(uint)ofs >= (long)bytes.Length)
 028                throw new IndexOutOfRangeException("offset is bigger than bytes array lenght");
 629            if (ofs > bytes.Length - 4)
 030                throw new IndexOutOfRangeException("bytes.Length is not large enough to contain a valid Int32");
 31
 632            fixed (byte* numPtr = &bytes[ofs])
 33            {
 634                return ByteUtils.PointerToInt32(numPtr);
 35            }
 36        }
 37
 38        unsafe long IBinaryReader.ReadInt64()
 39        {
 040            int ofs = currentOffset;
 041            currentOffset += 8;
 42
 043            if (bytes == null)
 044                throw new NullReferenceException("bytes array == null");
 045            if ((long)(uint)ofs >= (long)bytes.Length)
 046                throw new IndexOutOfRangeException("offset is bigger than bytes array lenght");
 047            if (ofs > bytes.Length - 8)
 048                throw new IndexOutOfRangeException("bytes.Length is not large enough to contain a valid Int64");
 49
 050            fixed (byte* numPtr = &bytes[ofs])
 51            {
 052                return ByteUtils.PointerToInt64(numPtr);
 53            }
 54        }
 55
 56        byte[] IBinaryReader.ReadBytes(int length)
 57        {
 058            int ofs = currentOffset;
 059            currentOffset += length;
 060            byte[] data = new byte[length];
 061            Buffer.BlockCopy(bytes, ofs, data, 0, length);
 062            return data;
 63        }
 64
 65        void IBinaryReader.Skip(int bytesCount)
 66        {
 067            currentOffset += bytesCount;
 068        }
 69    }
 70}