< Summary

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
WriteData(...)0%110100%
WriteData(...)0%110100%
Dispose()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        {
 8614            PooledWrappedComponent = pooledWrappedComponent;
 8615            MessageType = messageType;
 8616        }
 17
 18        public WriteData(CrdtMessageType messageType)
 19        {
 220            MessageType = messageType;
 221            PooledWrappedComponent = null;
 222        }
 23
 24        public void Dispose()
 25        {
 1026            PooledWrappedComponent?.Dispose();
 1027        }
 28    }
 29
 30    public record ComponentWriter
 31    {
 32        private readonly DualKeyValueSet<long, int, WriteData> outgoingMessages;
 33
 34        public ComponentWriter(DualKeyValueSet<long, int, WriteData> sceneOutgoingMessages)
 35        {
 36            outgoingMessages = sceneOutgoingMessages;
 37        }
 38
 39        public void Put(long entityId, int componentId, IPooledWrappedComponent component)
 40        {
 41            if (outgoingMessages.TryGetValue(entityId, componentId, out var storedData))
 42                storedData.Dispose();
 43
 44            outgoingMessages[entityId, componentId] = new WriteData(component, CrdtMessageType.PUT_COMPONENT);
 45        }
 46
 47        public void Remove(long entityId, int componentId)
 48        {
 49            if (outgoingMessages.TryGetValue(entityId, componentId, out var storedData))
 50                storedData.Dispose();
 51
 52            outgoingMessages[entityId, componentId] = new WriteData(CrdtMessageType.DELETE_COMPONENT);
 53        }
 54
 55        public void Append(long entityId, int componentId, IPooledWrappedComponent component)
 56        {
 57            if (outgoingMessages.TryGetValue(entityId, componentId, out var storedData))
 58                storedData.Dispose();
 59
 60            outgoingMessages[entityId, componentId] = new WriteData(component, CrdtMessageType.APPEND_COMPONENT);
 61        }
 62    }
 63}