-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.Formats.Nrbf
Milestone
Description
Background and motivation
With BinaryFormatter
depreciation transitioning off of usages requires looking at incoming data to see if it is valid Binary Format data. Knowing that it is allows fallback logic to be implemented.
Knowing this also is potentially useful for other filtering of incoming binary streams.
We're seeing numerous places where we need this in the WinForms stack and expect that our customers will need the same.
API Proposal
namespace System.Runtime.Serialization.Formatters.Binary;
public sealed class BinaryFormatter : IFormatter
{
public static bool HasValidBinaryFormatHeader(ReadOnlySpan<byte> data);
public static bool HasValidBinaryFormatHeader(byte[] data);
// Stream overload possible? Not all streams are seekable...
}
API Usage
void ProcessClipboardCsvData(ReadOnlySpan<byte> data)
{
if (BinaryFormatter.HasValidBinaryFormatHeader(data))
{
// Handle legacy data
return;
}
// Simple character stream, create string...
}
Alternative Designs
Could potentially invert the logic as it is remotely possible to match a non binary formatted stream. E.g. DoesNotHaveValid...
.
Risks
No specific known risks.
Metadata
Metadata
Assignees
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.Formats.Nrbf