< Summary

Class:DCL.ECS7.ComponentWriter
Assembly:ECS7Plugin.ComponentWriter
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/ComponentWriter/ComponentWriter.cs
Covered lines:15
Uncovered lines:0
Coverable lines:15
Total lines:63
Line coverage:100% (15 of 15)
Covered branches:0
Total branches:0
Covered methods:4
Total methods:4
Method coverage:100% (4 of 4)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ComponentWriter(...)0%110100%
Put(...)0%220100%
Remove(...)0%220100%
Append(...)0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/ComponentWriter/ComponentWriter.cs

#LineLine coverage
 1using DCL.CRDT;
 2using DCL.ECS7.ComponentWrapper;
 3using System;
 4
 5namespace DCL.ECS7
 6{
 7    public readonly struct WriteData : IDisposable
 8    {
 9        public readonly IPooledWrappedComponent PooledWrappedComponent;
 10        public readonly CrdtMessageType MessageType;
 11
 12        public WriteData(IPooledWrappedComponent pooledWrappedComponent, CrdtMessageType messageType)
 13        {
 14            PooledWrappedComponent = pooledWrappedComponent;
 15            MessageType = messageType;
 16        }
 17
 18        public WriteData(CrdtMessageType messageType)
 19        {
 20            MessageType = messageType;
 21            PooledWrappedComponent = null;
 22        }
 23
 24        public void Dispose()
 25        {
 26            PooledWrappedComponent?.Dispose();
 27        }
 28    }
 29
 30    public record ComponentWriter
 31    {
 32        private readonly DualKeyValueSet<long, int, WriteData> outgoingMessages;
 33
 5634        public ComponentWriter(DualKeyValueSet<long, int, WriteData> sceneOutgoingMessages)
 35        {
 5636            outgoingMessages = sceneOutgoingMessages;
 5637        }
 38
 39        public void Put(long entityId, int componentId, IPooledWrappedComponent component)
 40        {
 7541            if (outgoingMessages.TryGetValue(entityId, componentId, out var storedData))
 442                storedData.Dispose();
 43
 7544            outgoingMessages[entityId, componentId] = new WriteData(component, CrdtMessageType.PUT_COMPONENT);
 7545        }
 46
 47        public void Remove(long entityId, int componentId)
 48        {
 249            if (outgoingMessages.TryGetValue(entityId, componentId, out var storedData))
 150                storedData.Dispose();
 51
 252            outgoingMessages[entityId, componentId] = new WriteData(CrdtMessageType.DELETE_COMPONENT);
 253        }
 54
 55        public void Append(long entityId, int componentId, IPooledWrappedComponent component)
 56        {
 1157            if (outgoingMessages.TryGetValue(entityId, componentId, out var storedData))
 558                storedData.Dispose();
 59
 1160            outgoingMessages[entityId, componentId] = new WriteData(component, CrdtMessageType.APPEND_COMPONENT);
 1161        }
 62    }
 63}