コード例 #1
0
        public static UnknownHeaderDescriptor Parse(ref ReadOnlySpan <byte> buffer)
        {
            UnknownHeaderDescriptor descriptor = default;

            descriptor.HeaderName = buffer.Slice(0, 4);

            ReadOnlySpan <byte> tempSpan = buffer.Slice(4);

            descriptor.HeadSize = ParseInt(ref tempSpan);
            descriptor.TagSize  = ParseInt(ref tempSpan);

            descriptor.Header = buffer.Slice(0, descriptor.HeadSize);
            descriptor.Tag    = buffer.Slice(descriptor.HeadSize, descriptor.TagSize - descriptor.HeadSize);

            buffer = buffer.Slice(descriptor.TagSize);

            return(descriptor);
        }
コード例 #2
0
        public static void ParseFile(ref ReadOnlySpan <byte> file,
                                     Action <MainFileDescriptor> mainFileDescriptorAction = null,
                                     FilePathDescriptorAction filePathDescriptorAction    = null,
                                     CueObjectDescriptorAction cueObjectDescriptorAction  = null,
                                     QuantizedTimeZonesDescriptorAction quantizedTimeZonesDescriptorAction = null,
                                     VbrSeekTableDescriptorAction vbrSeekTableDescriptorAction             = null,
                                     WaveDisplayDataDescriptorAction <ColoredWaveDataPoint> coloredWaveDisplayDataDescriptorAction       = null,
                                     WaveDisplayDataDescriptorAction <NonColoredWaveDataPoint> nonColoredWaveDisplayDataDescriptorAction = null,
                                     UnknownHeaderDescriptorAction unknownHeaderDescriptorAction = null)
        {
            while (!file.IsEmpty)
            {
                var type = PeekType(file);

                if (type.SequenceEqual(MainFileDescriptor.Tag.Span))
                {
                    MainFileDescriptor mainFileDescriptor = MainFileDescriptor.Parse(ref file);
                    mainFileDescriptorAction?.Invoke(mainFileDescriptor);
                }
                else if (type.SequenceEqual(FilePathDescriptor.Tag.Span))
                {
                    FilePathDescriptor filePathDescriptor = FilePathDescriptor.Parse(ref file);
                    filePathDescriptorAction?.Invoke(filePathDescriptor);
                }
                else if (type.SequenceEqual(CueObjectDescriptor.Tag.Span))
                {
                    CueObjectDescriptor cueObjectDescriptor = CueObjectDescriptor.Parse(ref file);
                    cueObjectDescriptorAction?.Invoke(cueObjectDescriptor);
                }
                else if (type.SequenceEqual(QuantizedTimeZonesDescriptor.Tag.Span))
                {
                    QuantizedTimeZonesDescriptor quantizedTimeZonesDescriptor = QuantizedTimeZonesDescriptor.Parse(ref file);
                    quantizedTimeZonesDescriptorAction?.Invoke(quantizedTimeZonesDescriptor);
                }
                else if (type.SequenceEqual(VbrSeekTableDescriptor.Tag.Span))
                {
                    VbrSeekTableDescriptor vbrSeekTableDescriptor = VbrSeekTableDescriptor.Parse(ref file);
                    vbrSeekTableDescriptorAction?.Invoke(vbrSeekTableDescriptor);
                }
                else if (type.StartsWith(WaveDisplayDataDescriptor <bool> .Tag.Span))
                {
                    if (WaveDisplayDataDescriptor <bool> .IsColored(type))
                    {
                        WaveDisplayDataDescriptor <ColoredWaveDataPoint> coloredWaveDisplayDataDescriptor = WaveDisplayDataDescriptor <ColoredWaveDataPoint> .Parse(ref file);

                        coloredWaveDisplayDataDescriptorAction?.Invoke(coloredWaveDisplayDataDescriptor);
                    }
                    else
                    {
                        WaveDisplayDataDescriptor <NonColoredWaveDataPoint> nonColoredWaveDisplayDataDescriptor = WaveDisplayDataDescriptor <NonColoredWaveDataPoint> .Parse(ref file);

                        nonColoredWaveDisplayDataDescriptorAction?.Invoke(nonColoredWaveDisplayDataDescriptor);
                    }
                }
                else
                {
                    UnknownHeaderDescriptor unknownHeaderDescriptor = UnknownHeaderDescriptor.Parse(ref file);
                    // Console.WriteLine("Unknown header: " + unknownHeaderDescriptor.GetHeaderName());
                    unknownHeaderDescriptorAction?.Invoke(unknownHeaderDescriptor);
                }
            }
        }