public static SacnPacket Parse(ReadOnlySpan <byte> bytes) { RootLayer rootLayer = RootLayer.Parse(bytes); if (rootLayer == null) { return(null); } bytes = bytes.Slice(RootLayer.Length); FramingLayer framingLayer = FramingLayer.Parse(bytes, rootLayer.Vector); switch (framingLayer) { case DataPacketFramingLayer dataLayer: bytes = bytes.Slice(DataPacketFramingLayer.Length); return(DataPacket.Parse(bytes, rootLayer, dataLayer)); case SynchronizationPacketFramingLayer syncLayer: bytes = bytes.Slice(SynchronizationPacketFramingLayer.Length); return(SynchronizationPacket.Parse(bytes, rootLayer, syncLayer)); case UniverseDiscoveryPacketFramingLayer discoveryLayer: bytes = bytes.Slice(UniverseDiscoveryPacketFramingLayer.Length); return(UniverseDiscoveryPacket.Parse(bytes, rootLayer, discoveryLayer)); default: return(null); } }
public static Span <byte> GetUniverseDiscoveryPacket(byte[] CID, string sourceName, byte page, byte lastPage, UInt16[] universes) { var rootLayer = new RootLayer { CID = CID, Vector = RootLayerVector.VECTOR_ROOT_E131_EXTENDED }; var framingLayer = new UniverseDiscoveryPacketFramingLayer { SourceName = sourceName }; var universeDiscoveryLayer = new UniverseDiscoveryLayer { Page = page, LastPage = lastPage, Universes = universes }; int totalLength = RootLayer.Length + UniverseDiscoveryPacketFramingLayer.Length + universeDiscoveryLayer.Length; using var owner = MemoryPool <byte> .Shared.Rent(totalLength); var bytes = owner.Memory.Span.Slice(0, totalLength); rootLayer.Write(bytes, (UInt16)(SynchronizationPacketFramingLayer.Length + universeDiscoveryLayer.Length)); framingLayer.Write(bytes.Slice(RootLayer.Length), universeDiscoveryLayer.Length); universeDiscoveryLayer.Write(bytes.Slice(RootLayer.Length + UniverseDiscoveryPacketFramingLayer.Length)); return(bytes); }
public void Given_TheSequenceIdentifierIsWrong_When_ParseIsCalled_Then_NullIsReturned() { var expectedVector = RootLayerVector.VECTOR_ROOT_E131_DATA; var expectedFlags = RootLayer.FLAGS; var expectedLength = RootLayer.Length - 16; var bytes = new List <byte> { 0x00, 0x10, // preamble size 0x00, 0x00, // postamble size }; bytes.AddRange(new byte[] { 0x41, 0x53, 0x43, 0x2d, 0x45, 0x31, 0x2e, 0x31, 0x37, 0x00, 0x00, 0x32 }); bytes.AddRange(new byte[] { (byte)(expectedFlags << 4), (byte)expectedLength, // flags and length 0x00, 0x00, 0x00, (byte)expectedVector, // vector }); var expectedCid = new List <byte> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; bytes.AddRange(expectedCid); Assert.Null(RootLayer.Parse(bytes.ToArray())); }
public static Span <byte> GetDataPacket(byte[] CID, string sourceName, UInt16 universe, byte[] properties) { var rootLayer = new RootLayer { CID = CID, Vector = RootLayerVector.VECTOR_ROOT_E131_DATA }; var framingLayer = new DataPacketFramingLayer { SourceName = sourceName, Universe = universe }; var dmpLayer = new DMPLayer { PropertyValues = properties }; int totalLength = dmpLayer.Length + DataPacketFramingLayer.Length + RootLayer.Length; using var owner = MemoryPool <byte> .Shared.Rent(totalLength); var bytes = owner.Memory.Span.Slice(0, totalLength); rootLayer.Write(bytes, (UInt16)(DataPacketFramingLayer.Length + dmpLayer.Length)); framingLayer.Write(bytes.Slice(RootLayer.Length), dmpLayer.Length); dmpLayer.Write(bytes.Slice(RootLayer.Length + DataPacketFramingLayer.Length)); return(bytes); }
public SynchronizationPacket() { RootLayer = new RootLayer { Vector = RootLayerVector.VECTOR_ROOT_E131_EXTENDED }; FramingLayer = new SynchronizationPacketFramingLayer(); }
public DataPacket() { RootLayer = new RootLayer { Vector = RootLayerVector.VECTOR_ROOT_E131_DATA }; FramingLayer = new DataPacketFramingLayer(); DMPLayer = new DMPLayer(); }
public UniverseDiscoveryPacket() { RootLayer = new RootLayer { Vector = RootLayerVector.VECTOR_ROOT_E131_EXTENDED }; FramingLayer = new UniverseDiscoveryPacketFramingLayer(); UniverseDiscoveryLayer = new UniverseDiscoveryLayer(); }
protected override void Draw() { GraphicsDevice.Clear(ClearColor); if (RootLayer != null) { RootLayer.Render(GraphicsDevice); } }
public static SynchronizationPacket Parse(ReadOnlySpan <byte> bytes, RootLayer rootLayer, SynchronizationPacketFramingLayer framingLayer) { SynchronizationPacket packet = new SynchronizationPacket { RootLayer = rootLayer, FramingLayer = framingLayer }; return(packet); }
public static DataPacket Parse(ReadOnlySpan <byte> bytes, RootLayer rootLayer, DataPacketFramingLayer framingLayer) { DataPacket dataPacket = new DataPacket { RootLayer = rootLayer, FramingLayer = framingLayer, DMPLayer = DMPLayer.Parse(bytes) }; return(dataPacket); }
public static UniverseDiscoveryPacket Parse(ReadOnlySpan <byte> bytes, RootLayer rootLayer, UniverseDiscoveryPacketFramingLayer framingLayer) { UniverseDiscoveryPacket dataPacket = new UniverseDiscoveryPacket { RootLayer = rootLayer, FramingLayer = framingLayer, UniverseDiscoveryLayer = UniverseDiscoveryLayer.Parse(bytes) }; return(dataPacket); }
public void Given_TheDataIsValid_When_ParseIsCalled_Then_TheLayerParsesCorrectly() { var expectedCid = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; var expectedVector = RootLayerVector.VECTOR_ROOT_E131_DATA; var bytes = GetRootLayer(expectedCid, expectedVector); var rootLayer = RootLayer.Parse(bytes.ToArray()); Assert.Equal(expectedVector, rootLayer.Vector); Assert.Equal(expectedCid, rootLayer.CID); }
public void Given_ThePacketIsAValidUniverseDiscoveryPacket_When_ParseIsCalled_Then_ThePacketIsParsedCorrectly() { byte[] CID = Enumerable.Range(1, 12).Select(x => (byte)x).ToArray(); var rootLayer = new RootLayer { CID = CID, Vector = RootLayerVector.VECTOR_ROOT_E131_EXTENDED }; string sourceName = "Source name"; var framingLayer = new UniverseDiscoveryPacketFramingLayer { SourceName = sourceName }; UInt16[] universes = Enumerable.Range(200, 1000) .Select(x => (UInt16)x) .ToArray(); var discoveryLayer = new UniverseDiscoveryLayer { Universes = universes, Page = 25, LastPage = 25 }; int totalLength = discoveryLayer.Length + UniverseDiscoveryPacketFramingLayer.Length + RootLayer.Length; using var owner = MemoryPool <byte> .Shared.Rent(totalLength); var bytes = owner.Memory.Span.Slice(0, totalLength); rootLayer.Write(bytes, (UInt16)(UniverseDiscoveryPacketFramingLayer.Length + discoveryLayer.Length)); framingLayer.Write(bytes.Slice(RootLayer.Length), discoveryLayer.Length); discoveryLayer.Write(bytes.Slice(RootLayer.Length + UniverseDiscoveryPacketFramingLayer.Length)); var packet = SacnPacket.Parse(bytes); Assert.NotNull(packet); Assert.IsType <UniverseDiscoveryPacket>(packet); }
public void When_WriteIsCalled_Then_TheDataIsCorrect() { var expectedCid = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; var expectedVector = RootLayerVector.VECTOR_ROOT_E131_DATA; var expectedBytes = GetRootLayer(expectedCid, expectedVector); RootLayer rootLayer = new RootLayer() { CID = expectedCid, Vector = RootLayerVector.VECTOR_ROOT_E131_DATA }; using var owner = MemoryPool <byte> .Shared.Rent(RootLayer.Length); var actualBytes = owner.Memory.Span.Slice(0, RootLayer.Length); rootLayer.Write(actualBytes, 0); Assert.Equal(expectedBytes, actualBytes.ToArray()); }
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); }
public override void Write(Span <byte> bytes) { RootLayer.Write(bytes, (UInt16)(DataPacketFramingLayer.Length + DMPLayer.Length)); FramingLayer.Write(bytes.Slice(RootLayer.Length), (UInt16)(DMPLayer.Length)); DMPLayer.Write(bytes.Slice(RootLayer.Length + DataPacketFramingLayer.Length)); }
public override void Write(Span <byte> bytes) { RootLayer.Write(bytes, SynchronizationPacketFramingLayer.Length); FramingLayer.Write(bytes.Slice(RootLayer.Length)); }
public override void Write(Span <byte> bytes) { RootLayer.Write(bytes, (UInt16)(UniverseDiscoveryPacketFramingLayer.Length + UniverseDiscoveryLayer.Length)); FramingLayer.Write(bytes.Slice(RootLayer.Length), UniverseDiscoveryLayer.Length); UniverseDiscoveryLayer.Write(bytes.Slice(RootLayer.Length + UniverseDiscoveryPacketFramingLayer.Length)); }