Skip to content

Conversation

@iSazonov
Copy link
Collaborator

@iSazonov iSazonov commented Sep 27, 2018

PR Summary

  1. Add new Offset and Count parameters. Resolve Format-Hex should have Count and Offset parameters #3383.
  2. Modify ByteCollection class to support offsets up to UInt64.MaxValue size.
  3. Hide/obsolete Raw parameter because the behavior is by default. Related Can we hide obsolete or internal-use-only helper parameters from syntax diagrams? #7868.
  4. Optimize conversion to bytes to reduce allocations for large input data.

Additional comments

  1. For review: Now Offset parameter does a shift in output byte stream. Since we accept objects as input we could consider Offset as "skip the Offset-count objects from input (array/pipeline)" although Skip parameter is more suitable for this (or Select-Object -Skip) and this is contrary to the behavior for input streams (Path parameter or FileInfo input object).

  2. I don't consider a scenario "get last count bytes". As a minimum, the PR should not block this enhancement.

  3. New ReFS file system support files up to UInt64.MaxValue. So ByteCollection is modified to support UInt64.MaxValue too.
    On the other hand current .Net Core limitation is Int64.MaxValue for file size/offset. In result we have to use Int64 type for Offset and Count parameters.

/cc @rkeithhill @mklement0 @adamdriscoll

PR Checklist

@iSazonov iSazonov added the Review - Committee The PR/Issue needs a review from the PowerShell Committee label Sep 27, 2018
@iSazonov iSazonov added the Documentation Needed in this repo Documentation is needed in this repo label Sep 27, 2018
Copy link
Collaborator

Choose a reason for hiding this comment

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

Redundant from at the end of the sentence.

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.

Copy link
Collaborator

@rkeithhill rkeithhill Sep 28, 2018

Choose a reason for hiding this comment

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

👍

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice!

@iSazonov iSazonov changed the title WIP: Add new Offset and Count parameters to Format-Hex and refactor the cmdlet Add new Offset and Count parameters to Format-Hex and refactor the cmdlet Sep 28, 2018
@SteveL-MSFT SteveL-MSFT added Committee-Reviewed PS-Committee has reviewed this and made a decision and removed Review - Committee The PR/Issue needs a review from the PowerShell Committee labels Oct 3, 2018
@SteveL-MSFT
Copy link
Member

@PowerShell/powershell-committee reviewed this and ok with the proposed changes

@iSazonov
Copy link
Collaborator Author

iSazonov commented Oct 4, 2018

Doc Issue created.

Copy link
Member

Choose a reason for hiding this comment

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

Is this not a breaking change?

Copy link
Member

Choose a reason for hiding this comment

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

@PowerShell/powershell-committee discussed this and formatting changes have not been considered breaking changes. The extra zeros are acceptable.

@iSazonov
Copy link
Collaborator Author

@SteveL-MSFT @TravisEz13 Could you please review the PR?

case Int32 iInt32:
inputBytes = BitConverter.GetBytes(iInt32);
break;
case Int32[] inputInt32s:
Copy link
Member

Choose a reason for hiding this comment

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

NIT: variable naming is inconsistent with line 257, perhaps just use i32 and i32s? Same below for int64

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.

/// <param name="inputBytes">Bytes for the hexadecimial representaion.</param>
/// <param name="path">File path.</param>
/// <param name="offset">Offset in the file.</param>
private void ConvertToHexidecimal(Span<byte> inputBytes, string path, Int64 offset)
Copy link
Member

Choose a reason for hiding this comment

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

Since this method does the actual WriteObject(), perhaps rename as WriteHexidecimal()?

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.

StringBuilder asciiEnd = new StringBuilder(BytesPerLine);

// '+1' comes from 'result.Append(nextLine.ToString() + " " + asciiEnd.ToString());' below.
StringBuilder result = new StringBuilder(nextLine.Capacity+asciiEnd.Capacity+1);
Copy link
Member

Choose a reason for hiding this comment

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

NIT: have whitespace between operators: nextLine.Capacity + asciiEnd.Capacity + 1

Copy link
Collaborator Author

@iSazonov iSazonov Oct 15, 2018

Choose a reason for hiding this comment

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

Fixed.

{ Format-Hex -Path $inputFile4 -Count 0 } | Should -Throw -ErrorId "ParameterArgumentValidationError,Microsoft.PowerShell.Commands.FormatHex"
}

It "Offset should be >= 0" {
Copy link
Member

Choose a reason for hiding this comment

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

May be interesting to read from end of file, but is out of scope of this PR :)

Copy link
Member

@SteveL-MSFT SteveL-MSFT left a comment

Choose a reason for hiding this comment

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

LGTM

@iSazonov iSazonov merged commit 745e305 into PowerShell:master Oct 18, 2018
@iSazonov iSazonov deleted the format-hex-offset branch October 18, 2018 05:04
@iSazonov iSazonov mentioned this pull request Oct 19, 2018
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Committee-Reviewed PS-Committee has reviewed this and made a decision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Format-Hex should have Count and Offset parameters

5 participants