public static FramingLayer Parse(ReadOnlySpan <byte> bytes, RootLayerVector rootLayerVector) { var vector = (FramingLayerVector)BinaryPrimitives.ReadUInt32BigEndian(bytes.Slice(sizeof(UInt16))); switch (rootLayerVector) { case RootLayerVector.VECTOR_ROOT_E131_DATA: switch (vector) { case FramingLayerVector.VECTOR_E131_DATA_PACKET: return(DataPacketFramingLayer.Parse(bytes)); } break; case RootLayerVector.VECTOR_ROOT_E131_EXTENDED: switch (vector) { case FramingLayerVector.VECTOR_E131_EXTENDED_SYNCHRONIZATION: return(SynchronizationPacketFramingLayer.Parse(bytes)); case FramingLayerVector.VECTOR_E131_EXTENDED_DISCOVERY: return(UniverseDiscoveryPacketFramingLayer.Parse(bytes)); } break; } return(null); }
public static UniverseDiscoveryPacketFramingLayer Parse(ReadOnlySpan <byte> bytes) { UniverseDiscoveryPacketFramingLayer framingLayer = new UniverseDiscoveryPacketFramingLayer(); var flagsAndLength = BinaryPrimitives.ReadUInt16BigEndian(bytes); bytes = bytes.Slice(sizeof(UInt16)); framingLayer.Vector = (FramingLayerVector)BinaryPrimitives.ReadUInt32BigEndian(bytes); if (framingLayer.Vector != FramingLayerVector.VECTOR_E131_EXTENDED_DISCOVERY) { return(null); } bytes = bytes.Slice(sizeof(UInt32)); var sourceNameBytes = bytes.Slice(0, 64); bytes = bytes.Slice(64); var endOfString = sourceNameBytes.IndexOf((byte)0); framingLayer.SourceName = Encoding.UTF8.GetString(sourceNameBytes.Slice(0, endOfString).ToArray()); return(framingLayer); }