< Summary

Class:DCL.CRDT.CrdtMessage
Assembly:DCL.CRDTProtocol
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/CRDTProtocol/CrdtMessage.cs
Covered lines:8
Uncovered lines:3
Coverable lines:11
Total lines:59
Line coverage:72.7% (8 of 11)
Covered branches:0
Total branches:0
Covered methods:2
Total methods:2
Method coverage:100% (2 of 2)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
CrdtMessage(...)0%110100%
GetMessageDataLength(...)0%22.899044.44%

File(s)

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

#LineLine coverage
 1namespace DCL.CRDT
 2{
 3    public enum CrdtMessageType
 4    {
 5        NONE = 0,
 6        PUT_COMPONENT = 1,
 7        DELETE_COMPONENT = 2,
 8        DELETE_ENTITY = 3,
 9        APPEND_COMPONENT = 4
 10    }
 11
 12    public static class CrdtConstants
 13    {
 14        public const int MESSAGE_HEADER_LENGTH = 8;
 15
 16        public const int CRDT_PUT_COMPONENT_HEADER_LENGTH = 16;
 17        public const int CRDT_DELETE_COMPONENT_HEADER_LENGTH = 12;
 18        public const int CRDT_DELETE_ENTITY_HEADER_LENGTH = 4;
 19        public const int CRDT_APPEND_COMPONENT_HEADER_LENGTH = 16;
 20
 21        public const int CRDT_PUT_COMPONENT_BASE_LENGTH = MESSAGE_HEADER_LENGTH + CRDT_PUT_COMPONENT_HEADER_LENGTH;
 22        public const int CRDT_DELETE_COMPONENT_BASE_LENGTH = MESSAGE_HEADER_LENGTH + CRDT_DELETE_COMPONENT_HEADER_LENGTH
 23        public const int CRDT_DELETE_ENTITY_BASE_LENGTH = MESSAGE_HEADER_LENGTH + CRDT_DELETE_ENTITY_HEADER_LENGTH;
 24        public const int CRDT_APPEND_COMPONENT_BASE_LENGTH = MESSAGE_HEADER_LENGTH + CRDT_APPEND_COMPONENT_HEADER_LENGTH
 25    }
 26
 27    public readonly struct CrdtMessage
 28    {
 29        public readonly CrdtMessageType Type;
 30
 31        // the entityId is stored as 64bit integer, but in the protocol is serialized as 32bit (ADR-117)
 32        public readonly long EntityId;
 33        public readonly int ComponentId;
 34        public readonly int Timestamp;
 35        public readonly object Data;
 36
 37        public CrdtMessage(CrdtMessageType type, long entityId, int componentId, int timestamp, object data)
 38        {
 15239            EntityId = entityId;
 15240            ComponentId = componentId;
 15241            Timestamp = timestamp;
 15242            Data = data;
 15243            Type = type;
 15244        }
 45
 46        public static int GetMessageDataLength(CrdtMessage message)
 47        {
 3248            if (message.Type == CrdtMessageType.PUT_COMPONENT) { return CrdtConstants.CRDT_PUT_COMPONENT_BASE_LENGTH + (
 49
 450            if (message.Type == CrdtMessageType.DELETE_COMPONENT) { return CrdtConstants.CRDT_DELETE_COMPONENT_BASE_LENG
 51
 052            if (message.Type == CrdtMessageType.DELETE_ENTITY) { return CrdtConstants.CRDT_DELETE_ENTITY_BASE_LENGTH; }
 53
 054            if (message.Type == CrdtMessageType.APPEND_COMPONENT) { return CrdtConstants.CRDT_APPEND_COMPONENT_BASE_LENG
 55
 056            return 0;
 57        }
 58    }
 59}