Exemple #1
0
        public void When_WriteIsCalled_Then_TheDataIsCorrect()
        {
            UInt16 syncAddress    = 1023;
            byte   sequenceNumber = 135;

            var framingLayer = new SynchronizationPacketFramingLayer()
            {
                SynchronizationAddress = syncAddress,
                SequenceNumber         = sequenceNumber
            };

            var expectedBytes = GetSynchronizationPacketFramingLayer(sequenceNumber, syncAddress);

            using var owner = MemoryPool <byte> .Shared.Rent(SynchronizationPacketFramingLayer.Length);

            var actualBytes = owner.Memory.Span.Slice(0, SynchronizationPacketFramingLayer.Length);

            framingLayer.Write(actualBytes);
            Assert.Equal(expectedBytes.ToArray(), actualBytes.ToArray());
        }
Exemple #2
0
        public static Span <byte> GetSynchronizationPacket(byte[] CID, byte sequenceNumber)
        {
            var rootLayer = new RootLayer
            {
                CID    = CID,
                Vector = RootLayerVector.VECTOR_ROOT_E131_EXTENDED
            };

            var framingLayer = new SynchronizationPacketFramingLayer
            {
                SequenceNumber = sequenceNumber
            };

            int totalLength = SynchronizationPacketFramingLayer.Length + RootLayer.Length;

            using var owner = MemoryPool <byte> .Shared.Rent(totalLength);

            var bytes = owner.Memory.Span.Slice(0, totalLength);

            rootLayer.Write(bytes, (UInt16)(SynchronizationPacketFramingLayer.Length));
            framingLayer.Write(bytes.Slice(RootLayer.Length));

            return(bytes);
        }