Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update JpegSegmentPreamble to UTF-8 spans #376

Merged
merged 6 commits into from
Jan 27, 2024

Conversation

iamcarbon
Copy link
Collaborator

@drewnoakes Ready for review / feedback.

Note: The AdobeJpegReader compares the Preamble using a case-insensitive comparer in ReadJpegSegments, while it uses an ordinal comparer when reading segments. From what I can tell in the specifications, this should be exact, but I didn't want to change behavior here.

Copy link
Owner

@drewnoakes drewnoakes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some questions before merge.

The AdobeJpegReader compares the Preamble using a case-insensitive comparer in ReadJpegSegments, while it uses an ordinal comparer when reading segments. From what I can tell in the specifications, this should be exact, but I didn't want to change behavior here.

That sounds like a bug. My guess is it should be case-insensitive everywhere. Can run against the regression suite to see if we have any hits.

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net45</TargetFramework>
<TargetFramework>net48</TargetFramework>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What necessitated this?

@@ -90,7 +90,7 @@ public void Add(T value, params byte[][] parts)
}

/// <summary>Store the given value at the specified path.</summary>
internal void Add(T value, ReadOnlySpan<byte> part)
public void Add(T value, ReadOnlySpan<byte> part)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the byte[] overload still used?

Does this need to be added to the public API files?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a brand new member to avoid allocation, the params byte[] array overload still used.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a diagnostic here about the public member not being in the API files?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annoying, this analyzer randomly stops reporting for me in Visual Studio, and I have to catch these manually. Updated!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird. There should at least be a build warning, and CI should fail. I'll take a look some time.

Copy link
Owner

@drewnoakes drewnoakes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Adobe case is a shame. It's the only one that doesn't fit. What do you think about changing the interface to include a method that validates whether a given segments bytes are a match or not? Then the Adobe one could implement it's policy within that method. The dictionary in the PowerShell code would be swapped for iteration through known extractors, testing for a match.


private static ReadOnlySpan<byte> JpegSegmentPreambleBytes => "http://ns.adobe.com/xap/1.0/\0"u8;
private static ReadOnlySpan<byte> JpegSegmentPreambleExtensionBytes => "http://ns.adobe.com/xmp/extension/\0"u8;
public static ReadOnlySpan<byte> JpegSegmentPreamble=> "http://ns.adobe.com/xap/1.0/\0"u8;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public static ReadOnlySpan<byte> JpegSegmentPreamble=> "http://ns.adobe.com/xap/1.0/\0"u8;
public static ReadOnlySpan<byte> JpegSegmentPreamble => "http://ns.adobe.com/xap/1.0/\0"u8;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -90,7 +90,7 @@ public void Add(T value, params byte[][] parts)
}

/// <summary>Store the given value at the specified path.</summary>
internal void Add(T value, ReadOnlySpan<byte> part)
public void Add(T value, ReadOnlySpan<byte> part)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a diagnostic here about the public member not being in the API files?

Copy link
Owner

@drewnoakes drewnoakes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks!

@drewnoakes drewnoakes merged commit 32bf514 into drewnoakes:master Jan 27, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants