< Summary

Class:RPC.Services.CRDTStream
Assembly:RPC.Services.CRDTService.CRDTStream
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/KernelCommunication/RPC/Services/CRDTService/CRDTStream/CRDTStream.cs
Covered lines:25
Uncovered lines:16
Coverable lines:41
Total lines:96
Line coverage:60.9% (25 of 41)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Flush()0%2100%
Read(...)0%2100%
Seek(...)0%2100%
SetLength(...)0%2100%
Write(...)0%110100%
get_offset()0%2100%
CanRead()0%110100%
ReadInt32()0%4.434070%
ReadInt64()0%4.434070%
ReadBytes(...)0%110100%
Skip(...)0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/KernelCommunication/RPC/Services/CRDTService/CRDTStream/CRDTStream.cs

#LineLine coverage
 1using System;
 2using System.IO;
 3using KernelCommunication;
 4
 5namespace RPC.Services
 6{
 7    public class CRDTStream : Stream, IBinaryReader
 8    {
 9        private byte[] streamBuffer;
 10        private int offset;
 11
 212        public override bool CanRead => Position < streamBuffer.Length;
 13
 014        public override bool CanSeek => false;
 15
 016        public override bool CanWrite => true;
 17
 018        public override long Length => streamBuffer.Length;
 19
 220        public override long Position { set => offset = (int)value; get => offset; }
 21
 022        public override void Flush() { }
 23
 24        public override int Read(byte[] buffer, int offset, int count)
 25        {
 026            return 0;
 27        }
 28
 29        public override long Seek(long offset, SeekOrigin origin)
 30        {
 031            return 0;
 32        }
 33
 034        public override void SetLength(long value) { }
 35
 36        public override void Write(byte[] buffer, int offset, int count)
 37        {
 138            streamBuffer = buffer;
 139            this.offset = offset;
 140        }
 41
 042        int IBinaryReader.offset => offset;
 43
 244        bool IBinaryReader.CanRead() => CanRead;
 45
 46        unsafe int IBinaryReader.ReadInt32()
 47        {
 548            int ofs = offset;
 549            offset += 4;
 50
 551            if (streamBuffer == null)
 052                throw new NullReferenceException("bytes array == null");
 553            if ((long)(uint)ofs >= (long)streamBuffer.Length)
 054                throw new IndexOutOfRangeException("offset is bigger than bytes array lenght");
 555            if (ofs > streamBuffer.Length - 4)
 056                throw new IndexOutOfRangeException("bytes.Length is not large enough to contain a valid Int32");
 57
 558            fixed (byte* numPtr = &streamBuffer[ofs])
 59            {
 560                return ByteUtils.PointerToInt32(numPtr);
 61            }
 62        }
 63
 64        unsafe long IBinaryReader.ReadInt64()
 65        {
 166            int ofs = offset;
 167            offset += 8;
 68
 169            if (streamBuffer == null)
 070                throw new NullReferenceException("bytes array == null");
 171            if ((long)(uint)ofs >= (long)streamBuffer.Length)
 072                throw new IndexOutOfRangeException("offset is bigger than bytes array lenght");
 173            if (ofs > streamBuffer.Length - 8)
 074                throw new IndexOutOfRangeException("bytes.Length is not large enough to contain a valid Int64");
 75
 176            fixed (byte* numPtr = &streamBuffer[ofs])
 77            {
 178                return ByteUtils.PointerToInt64(numPtr);
 79            }
 80        }
 81
 82        byte[] IBinaryReader.ReadBytes(int length)
 83        {
 184            int ofs = offset;
 185            offset += length;
 186            byte[] data = new byte[length];
 187            Buffer.BlockCopy(streamBuffer, ofs, data, 0, length);
 188            return data;
 89        }
 90
 91        void IBinaryReader.Skip(int bytesCount)
 92        {
 093            offset += bytesCount;
 094        }
 95    }
 96}