From 0c3d5e8ec3b74244ec28496a4c7a505ce5b9211e Mon Sep 17 00:00:00 2001 From: Matt Janda Date: Fri, 26 Dec 2025 18:23:45 +0530 Subject: [PATCH 1/6] Upgrade pipeline and tests to .NET8 --- .github/workflows/build.yml | 2 +- .github/workflows/nuget.yml | 2 +- src/AutoByte.Tests/AutoByte.Tests.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b1d6ad4..6205e4c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,7 +30,7 @@ jobs: - name: Setup uses: actions/setup-dotnet@v1 with: - dotnet-version: 7.0.x + dotnet-version: 8.0.x source-url: https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json - name: Pack diff --git a/.github/workflows/nuget.yml b/.github/workflows/nuget.yml index f4a491f..43afbd6 100644 --- a/.github/workflows/nuget.yml +++ b/.github/workflows/nuget.yml @@ -27,7 +27,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v1 with: - dotnet-version: 7.0.x + dotnet-version: 8.0.x source-url: https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json - name: Pack diff --git a/src/AutoByte.Tests/AutoByte.Tests.csproj b/src/AutoByte.Tests/AutoByte.Tests.csproj index 9f0d529..d737b9c 100644 --- a/src/AutoByte.Tests/AutoByte.Tests.csproj +++ b/src/AutoByte.Tests/AutoByte.Tests.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 enable false true From 88bd1f7097dc66f06ca701ef29750041bcffacc6 Mon Sep 17 00:00:00 2001 From: Matt Janda Date: Fri, 26 Dec 2025 18:32:02 +0530 Subject: [PATCH 2/6] Add pascal string to byte slide with max length --- .../AutoByteSourceGenerator.cs | 1 - src/AutoByte.Tests/ByteSlide_Must.cs | 48 ++++++++++++++++++- src/AutoByte/ByteSlide.cs | 26 ++++++++++ 3 files changed, 73 insertions(+), 2 deletions(-) diff --git a/src/AutoByte.Generators/AutoByteSourceGenerator.cs b/src/AutoByte.Generators/AutoByteSourceGenerator.cs index f57de21..ed1ce0d 100644 --- a/src/AutoByte.Generators/AutoByteSourceGenerator.cs +++ b/src/AutoByte.Generators/AutoByteSourceGenerator.cs @@ -189,7 +189,6 @@ private string GetStringMethodName(IPropertySymbol property, AutoByteFieldAttrib } } - throw new Exception($"Propertry {property.Name} require AutoByteString attribute."); } diff --git a/src/AutoByte.Tests/ByteSlide_Must.cs b/src/AutoByte.Tests/ByteSlide_Must.cs index ec11161..3939666 100644 --- a/src/AutoByte.Tests/ByteSlide_Must.cs +++ b/src/AutoByte.Tests/ByteSlide_Must.cs @@ -141,7 +141,53 @@ public void GetPascalString_ReturnsExcpectedStrings() } + [Fact] + public void GetPascalString_WithMaxLength_ReturnsExpectedStrings_AndConsumesAllBytes() + { + // "Hello World" (11) + "Matt Janda" (10) + "" (0) + byte[] PASCAL_STRINGS = + { + 0x0B, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64, + 0x0A, 0x4D, 0x61, 0x74, 0x74, 0x20, 0x4A, 0x61, 0x6E, 0x64, 0x61, + 0x00 + }; + + var slide = new ByteSlide(PASCAL_STRINGS); + + // Full read (maxLength >= length) + Assert.Equal("Hello World", slide.GetPascalString(Encoding.ASCII, maxLength: 11)); + Assert.Equal("Matt Janda", slide.GetPascalString(Encoding.ASCII, maxLength: 10)); + Assert.Equal("", slide.GetPascalString(Encoding.ASCII, maxLength: 100)); + + Assert.Equal(0, slide.Length); + } + + [Fact] + public void GetPascalString_WithMaxLength_TruncatesButStillSkipsRemainingBytes() + { + // "Hello World" (11) + "Matt Janda" (10) + "" (0) + byte[] PASCAL_STRINGS = + { + 0x0B, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64, + 0x0A, 0x4D, 0x61, 0x74, 0x74, 0x20, 0x4A, 0x61, 0x6E, 0x64, 0x61, + 0x00 + }; + + var slide = new ByteSlide(PASCAL_STRINGS); + + // Truncate first string to 5 bytes => "Hello" + Assert.Equal("Hello", slide.GetPascalString(Encoding.ASCII, maxLength: 5)); + + // Must still be aligned to next Pascal string (i.e., remaining 6 bytes were skipped) + Assert.Equal("Matt Janda", slide.GetPascalString(Encoding.ASCII, maxLength: 10)); + + // Empty + Assert.Equal("", slide.GetPascalString(Encoding.ASCII, maxLength: 1)); + + Assert.Equal(0, slide.Length); + } + + - } } diff --git a/src/AutoByte/ByteSlide.cs b/src/AutoByte/ByteSlide.cs index bb82b32..bae5034 100644 --- a/src/AutoByte/ByteSlide.cs +++ b/src/AutoByte/ByteSlide.cs @@ -258,6 +258,32 @@ public string GetCString(Encoding encoding, int maxLength) public string GetPascalString(Encoding encoding) => encoding.GetString(Slide(GetByte())); + public string GetPascalString(Encoding encoding, int maxLength) + { + var length = GetByte(); + + if (length == 0) + { + return string.Empty; + } + + // Enforce maxLength (byte-based) + var effectiveLength = Math.Min(length, maxLength); + + // Read only what we're allowed to decode + var bytes = Slide(effectiveLength); + + // Skip remaining bytes if original length was larger + if (length > effectiveLength) + { + Slide(length - effectiveLength); + } + + return encoding.GetString(bytes); + } + + + /// /// Retrieves a byte array from the current pointer position and aligns the pointer to the specified value. From e0e8bc7f700e578904915d08e8a00ad5031b869b Mon Sep 17 00:00:00 2001 From: Matt Janda Date: Sat, 27 Dec 2025 22:18:46 +0530 Subject: [PATCH 3/6] Add file level namespace support --- .../AutoByteSourceGeneratorExtensions.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/AutoByte.Generators/AutoByteSourceGeneratorExtensions.cs b/src/AutoByte.Generators/AutoByteSourceGeneratorExtensions.cs index d2f3fbe..1750dbc 100644 --- a/src/AutoByte.Generators/AutoByteSourceGeneratorExtensions.cs +++ b/src/AutoByte.Generators/AutoByteSourceGeneratorExtensions.cs @@ -21,7 +21,7 @@ public static bool IsPartial(this ClassDeclarationSyntax classDeclaration) public static string GetNamespace(this BaseTypeDeclarationSyntax syntax) { - // Get the syntax node for the containing namespace declaration + // Get the syntax node for the containing namespace declaration (traditional namespace) SyntaxNode containingNamespace = syntax.AncestorsAndSelf() .OfType().FirstOrDefault(); @@ -31,6 +31,16 @@ public static string GetNamespace(this BaseTypeDeclarationSyntax syntax) return ((NamespaceDeclarationSyntax)containingNamespace).Name.ToString(); } + // Check for file-scoped namespace declaration (C# 10+) + SyntaxNode containingFileScopedNamespace = syntax.AncestorsAndSelf() + .OfType().FirstOrDefault(); + + if (containingFileScopedNamespace != null) + { + // Get the namespace name from the file-scoped namespace node + return ((FileScopedNamespaceDeclarationSyntax)containingFileScopedNamespace).Name.ToString(); + } + return null; } From 52738a77a477a29abf7cefee1b2afeb1888c55db Mon Sep 17 00:00:00 2001 From: Matt Janda Date: Sat, 27 Dec 2025 22:21:55 +0530 Subject: [PATCH 4/6] Create prerelease package --- .github/workflows/build.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6205e4c..491e0bb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,5 +40,6 @@ jobs: run: dotnet test - name: Push - if: github.ref == 'refs/heads/main' - run: dotnet nuget push "../bin/Release/*.nupkg" -k ${{ secrets.PACKAGE_REGISTRY_TOKEN }} -s https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json --skip-duplicate + # Create packages from every branch except pull requests + if: github.event_name == 'push' && contains(github.event.head_commit.message, 'prerelease') + run: dotnet nuget push "nuget/*.nupkg" -k ${{ secrets.NUGET_ORG_API_KEY }} -s https://api.nuget.org/v3/index.json --skip-duplicate \ No newline at end of file From 88e55ee8886f31f9e2de3e04f330cdde821297ff Mon Sep 17 00:00:00 2001 From: Matt Janda Date: Sat, 27 Dec 2025 22:23:40 +0530 Subject: [PATCH 5/6] Fix pack and create prerelease --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 491e0bb..c57fa3a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,7 +34,7 @@ jobs: source-url: https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json - name: Pack - run: dotnet pack -c:Release + run: dotnet pack -c:Release -o nuget - name: Test run: dotnet test From c0e8508808c6bf1bea27a08948ed2541322598c5 Mon Sep 17 00:00:00 2001 From: Matt Janda Date: Tue, 30 Dec 2025 18:45:53 +0530 Subject: [PATCH 6/6] Don't do pull request builds for now --- .github/workflows/build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c57fa3a..bd5d1bf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,9 +8,9 @@ env: on: push: - branches: '*' - pull_request: - branches: 'main' + branches: [ '*' ] +# pull_request: +# branches: [ 'main' ] defaults: run: