コード例 #1
0
ファイル: SACNPacket.cs プロジェクト: RopyTan/kadmium-sacn
        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);
            }
        }
コード例 #2
0
        public static SynchronizationPacket Parse(ReadOnlySpan <byte> bytes, RootLayer rootLayer, SynchronizationPacketFramingLayer framingLayer)
        {
            SynchronizationPacket packet = new SynchronizationPacket
            {
                RootLayer    = rootLayer,
                FramingLayer = framingLayer
            };

            return(packet);
        }