From 941dc279815c4c15ad3cb945bbe76298140fa480 Mon Sep 17 00:00:00 2001 From: Haga R Date: Sat, 20 Jan 2024 03:10:42 +0100 Subject: [PATCH] Remove unused code --- .../Pcapng/Merge/PcapBlockWriter.cs | 20 ++++++++----------- .../Pcapng/Merge/SleepyStream.cs | 10 +--------- .../Pcapng/Merge/SleepyStreamBlockReader.cs | 7 +------ .../Pcapng/Structs/IfMacAddressOption.cs | 10 ---------- .../Pcapng/Structs/StringOptionBlock.cs | 9 --------- .../Pcapng/Structs/TsResolOption.cs | 10 ---------- 6 files changed, 10 insertions(+), 56 deletions(-) diff --git a/src/Fluxzy.Core.Pcap/Pcapng/Merge/PcapBlockWriter.cs b/src/Fluxzy.Core.Pcap/Pcapng/Merge/PcapBlockWriter.cs index 18acf2906..6d0ca6134 100644 --- a/src/Fluxzy.Core.Pcap/Pcapng/Merge/PcapBlockWriter.cs +++ b/src/Fluxzy.Core.Pcap/Pcapng/Merge/PcapBlockWriter.cs @@ -42,14 +42,15 @@ private PcapngStreamWriter InternalCreateWriter() return result; } - public void Write(ref DataBlock content) + private void InternalWrite(ReadOnlySpan data) { - if (_writer == null) - { - _writer = InternalCreateWriter(); - } + _writer ??= InternalCreateWriter(); + _outStream.Write(data); + } - _outStream.Write(content.Data.Span); + public void Write(ref DataBlock content) + { + InternalWrite(content.Data.Span); } public bool NotifyNewBlock(uint blockType, ReadOnlySpan buffer) @@ -81,12 +82,7 @@ public bool NotifyNewBlock(uint blockType, ReadOnlySpan buffer) || blockType == InterfaceDescriptionBlock.BlockTypeValue ) { - if (_writer == null) - { - _writer = InternalCreateWriter(); - } - - _outStream.Write(buffer); + InternalWrite(buffer); } return true; diff --git a/src/Fluxzy.Core.Pcap/Pcapng/Merge/SleepyStream.cs b/src/Fluxzy.Core.Pcap/Pcapng/Merge/SleepyStream.cs index 459aff832..3bed261f8 100644 --- a/src/Fluxzy.Core.Pcap/Pcapng/Merge/SleepyStream.cs +++ b/src/Fluxzy.Core.Pcap/Pcapng/Merge/SleepyStream.cs @@ -7,7 +7,7 @@ namespace Fluxzy.Core.Pcap.Pcapng.Merge /// It saves the last offset read and allows closing the file descriptor /// in between reads. /// - internal class SleepyStream : IDisposable, IAsyncDisposable + internal class SleepyStream : IDisposable { private readonly Func _streamFactory; private long _offset; @@ -89,13 +89,5 @@ public void Dispose() { _pendingStream?.Dispose(); } - - public async ValueTask DisposeAsync() - { - if (_pendingStream != null) - { - await _pendingStream.DisposeAsync(); - } - } } } diff --git a/src/Fluxzy.Core.Pcap/Pcapng/Merge/SleepyStreamBlockReader.cs b/src/Fluxzy.Core.Pcap/Pcapng/Merge/SleepyStreamBlockReader.cs index c831a6df5..da6365277 100644 --- a/src/Fluxzy.Core.Pcap/Pcapng/Merge/SleepyStreamBlockReader.cs +++ b/src/Fluxzy.Core.Pcap/Pcapng/Merge/SleepyStreamBlockReader.cs @@ -2,7 +2,7 @@ namespace Fluxzy.Core.Pcap.Pcapng.Merge { - internal abstract class SleepyStreamBlockReader : IBlockReader, IAsyncDisposable + internal abstract class SleepyStreamBlockReader : IBlockReader { private readonly SleepyStream _sleepyStream; private Option _nextBlockOption = new(); @@ -96,11 +96,6 @@ public void Dispose() { _sleepyStream.Dispose(); } - - public async ValueTask DisposeAsync() - { - await _sleepyStream.DisposeAsync(); - } } diff --git a/src/Fluxzy.Core.Pcap/Pcapng/Structs/IfMacAddressOption.cs b/src/Fluxzy.Core.Pcap/Pcapng/Structs/IfMacAddressOption.cs index 6d3c0897e..0b316935f 100644 --- a/src/Fluxzy.Core.Pcap/Pcapng/Structs/IfMacAddressOption.cs +++ b/src/Fluxzy.Core.Pcap/Pcapng/Structs/IfMacAddressOption.cs @@ -31,15 +31,5 @@ public int Write(Span buffer) return OnWireLength; } - - public static IfMacAddressOption Parse(ReadOnlySpan buffer) - { - return new IfMacAddressOption(buffer.Slice(4, 6).ToArray()); - } - - public static int DirectWrite(Span buffer) - { - return new IfMacAddressOption().Write(buffer); - } } } \ No newline at end of file diff --git a/src/Fluxzy.Core.Pcap/Pcapng/Structs/StringOptionBlock.cs b/src/Fluxzy.Core.Pcap/Pcapng/Structs/StringOptionBlock.cs index 248da9fee..88dfb05cd 100644 --- a/src/Fluxzy.Core.Pcap/Pcapng/Structs/StringOptionBlock.cs +++ b/src/Fluxzy.Core.Pcap/Pcapng/Structs/StringOptionBlock.cs @@ -51,14 +51,5 @@ public int Write(Span buffer) return OnWireLength; } - - public static StringOptionBlock Parse(ReadOnlySpan buffer) - { - var optionLength = BinaryPrimitives.ReadUInt16LittleEndian(buffer.Slice(2)); - var valueBuffer = buffer.Slice(4, optionLength); - string value = Encoding.UTF8.GetString(valueBuffer); - - return new StringOptionBlock(BinaryPrimitives.ReadUInt16LittleEndian(buffer), value); - } } } \ No newline at end of file diff --git a/src/Fluxzy.Core.Pcap/Pcapng/Structs/TsResolOption.cs b/src/Fluxzy.Core.Pcap/Pcapng/Structs/TsResolOption.cs index 07993f329..8dc2ea360 100644 --- a/src/Fluxzy.Core.Pcap/Pcapng/Structs/TsResolOption.cs +++ b/src/Fluxzy.Core.Pcap/Pcapng/Structs/TsResolOption.cs @@ -30,15 +30,5 @@ public int Write(Span buffer) return 8; } - - public static TsResolOption Parse(ReadOnlySpan buffer) - { - return new TsResolOption(buffer[4]); - } - - public static int DirectWrite(Span buffer) - { - return new TsResolOption().Write(buffer); - } } }