< Summary

Class:DCL.CRDT.CRDTDeserializer
Assembly:DCL.CRDTProtocol.Deserializer
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/CRDTProtocol/Deserializer/CRDTDeserializer.cs
Covered lines:28
Uncovered lines:0
Coverable lines:28
Total lines:75
Line coverage:100% (28 of 28)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
CRDTDeserializer()0%110100%
DeserializeBatch()0%660100%
DeserializeSingle(...)0%440100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/CRDTProtocol/Deserializer/CRDTDeserializer.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using KernelCommunication;
 4
 5namespace DCL.CRDT
 6{
 7    // Deserialize CRDT binary messages (BigEndian)
 8    public static class CRDTDeserializer
 9    {
 110        internal static readonly CRDTComponentMessageHeader componentHeader = new CRDTComponentMessageHeader();
 11
 12        public static IEnumerator<object> DeserializeBatch(ReadOnlyMemory<byte> memory)
 13        {
 1414            int position = 0;
 15
 2916            while (position < memory.Length)
 17            {
 1718                int messageLength = ByteUtils.ReadInt32(memory.Span, position);
 1719                position += 4;
 20
 1721                CrdtMessageType messageType = (CrdtMessageType)ByteUtils.ReadInt32(memory.Span, position);
 1722                position += 4;
 23
 1724                if (messageLength <= CrdtConstants.MESSAGE_HEADER_LENGTH)
 25                {
 26                    continue;
 27                }
 28
 29                switch (messageType)
 30                {
 31                    case CrdtMessageType.PUT_COMPONENT:
 32                    case CrdtMessageType.DELETE_COMPONENT:
 1633                        yield return DeserializeSingle(memory, messageType, ref position);
 1434                        break;
 35                    default:
 136                        position += messageLength - CrdtConstants.MESSAGE_HEADER_LENGTH;
 37                        break;
 38                }
 39            }
 1240        }
 41
 42        public static CRDTMessage DeserializeSingle(ReadOnlyMemory<byte> memory, CrdtMessageType messageType, ref int me
 43        {
 1844            ReadOnlySpan<byte> memorySpan = memory.Span;
 45
 1846            componentHeader.entityId = ByteUtils.ReadInt32(memorySpan, memoryPosition);
 1847            memoryPosition += 4;
 1848            componentHeader.componentClassId = ByteUtils.ReadInt32(memorySpan, memoryPosition);
 1849            memoryPosition += 4;
 1850            componentHeader.timestamp = ByteUtils.ReadInt64(memorySpan, memoryPosition);
 1851            memoryPosition += 8;
 1852            componentHeader.dataLength = ByteUtils.ReadInt32(memorySpan, memoryPosition);
 1853            memoryPosition += 4;
 54
 1855            byte[] data = null;
 1856            if (componentHeader.dataLength > 0 && messageType != CrdtMessageType.DELETE_COMPONENT)
 57            {
 1558                data = memorySpan.Slice(memoryPosition, componentHeader.dataLength).ToArray();
 59            }
 360            else if (messageType == CrdtMessageType.PUT_COMPONENT)
 61            {
 262                data = new byte[0];
 63            }
 1864            memoryPosition += componentHeader.dataLength;
 65
 1866            return new CRDTMessage()
 67            {
 68                key1 = componentHeader.entityId,
 69                key2 = componentHeader.componentClassId,
 70                timestamp = componentHeader.timestamp,
 71                data = data
 72            };
 73        }
 74    }
 75}