diff --git a/README.md b/README.md index 26dba3f89..c09395d60 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# RSCG - 175 Examples of Roslyn Source Code Generators / 14 created by Microsoft / +# RSCG - 176 Examples of Roslyn Source Code Generators / 14 created by Microsoft / -## Latest Update : 2024-12-03 => 03 December 2024 +## Latest Update : 2024-12-04 => 04 December 2024 If you want to see examples with code, please click ***[List V2](https://ignatandrei.github.io/RSCG_Examples/v2/docs/List-of-RSCG)*** @@ -20,8 +20,30 @@ If you want to be notified each time I add a new RSCG example , please click htt ## Content -Those are the 175 Roslyn Source Code Generators that I have tested you can see and download source code example. +Those are the 176 Roslyn Source Code Generators that I have tested you can see and download source code example. ( including 14 from Microsoft ) +### 176. [Darp.BinaryObjects](https://ignatandrei.github.io/RSCG_Examples/v2/docs/Darp.BinaryObjects) , in the [Bitwise](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#bitwise) category + +Generated on : 2024-12-04 => 04 December 2024 + +
+ Expand + + + +Author: Ross Light GmbH + +A source generator to generate TryRead/Write Little/BigEndian methods for struct/class definitions for binary serialization. + +Nuget: [https://www.nuget.org/packages/Darp.BinaryObjects/](https://www.nuget.org/packages/Darp.BinaryObjects/) + + +Link: [https://ignatandrei.github.io/RSCG_Examples/v2/docs/Darp.BinaryObjects](https://ignatandrei.github.io/RSCG_Examples/v2/docs/Darp.BinaryObjects) + +Source: [https://github.com/rosslight/Darp.BinaryObjects](https://github.com/rosslight/Darp.BinaryObjects) + +
+ ### 175. [Dolly](https://ignatandrei.github.io/RSCG_Examples/v2/docs/Dolly) , in the [Clone](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#clone) category Generated on : 2024-12-03 => 03 December 2024 @@ -4202,231 +4224,224 @@ Why I have not tested : issue opened https://github.com/ignatandrei/RSCG_Examples/issues/new?title=https://github.com/OrgEleCho/EleCho.Internationalization&body=https://github.com/OrgEleCho/EleCho.Internationalization -25) [https://github.com/rosslight/Darp.BinaryObjects]( https://github.com/rosslight/Darp.BinaryObjects) , https://github.com/rosslight/Darp.BinaryObjects - -Why I have not tested : later - -https://github.com/ignatandrei/RSCG_Examples/issues/new?title=https://github.com/rosslight/Darp.BinaryObjects&body=https://github.com/rosslight/Darp.BinaryObjects - - -26) [https://github.com/Stepami/visitor-net]( https://github.com/Stepami/visitor-net) , https://github.com/Stepami/visitor-net +25) [https://github.com/Stepami/visitor-net]( https://github.com/Stepami/visitor-net) , https://github.com/Stepami/visitor-net Why I have not tested : later https://github.com/ignatandrei/RSCG_Examples/issues/new?title=https://github.com/Stepami/visitor-net&body=https://github.com/Stepami/visitor-net -27) [https://github.com/SzymonHalucha/Minerals.AutoCommands]( https://github.com/SzymonHalucha/Minerals.AutoCommands) , https://github.com/SzymonHalucha/Minerals.AutoCommands +26) [https://github.com/SzymonHalucha/Minerals.AutoCommands]( https://github.com/SzymonHalucha/Minerals.AutoCommands) , https://github.com/SzymonHalucha/Minerals.AutoCommands Why I have not tested : later https://github.com/ignatandrei/RSCG_Examples/issues/new?title=https://github.com/SzymonHalucha/Minerals.AutoCommands&body=https://github.com/SzymonHalucha/Minerals.AutoCommands -28) [Intellenum]( https://github.com/SteveDunn/Intellenum) , https://github.com/SteveDunn/Intellenum +27) [Intellenum]( https://github.com/SteveDunn/Intellenum) , https://github.com/SteveDunn/Intellenum Why I have not tested : not understand how to use https://github.com/ignatandrei/RSCG_Examples/issues/new?title=Intellenum&body=https://github.com/SteveDunn/Intellenum -29) [Jos.Enumeration,]( https://github.com/joseftw/jos.enumeration) , https://github.com/joseftw/jos.enumeration +28) [Jos.Enumeration,]( https://github.com/joseftw/jos.enumeration) , https://github.com/joseftw/jos.enumeration Why I have not tested : too complicated for me, need help https://github.com/ignatandrei/RSCG_Examples/issues/new?title=Jos.Enumeration,&body=https://github.com/joseftw/jos.enumeration -30) [laker]( https://github.com/Lakerfield/Lakerfield.Rpc) , https://github.com/Lakerfield/Lakerfield.Rpc +29) [laker]( https://github.com/Lakerfield/Lakerfield.Rpc) , https://github.com/Lakerfield/Lakerfield.Rpc Why I have not tested : later https://github.com/ignatandrei/RSCG_Examples/issues/new?title=laker&body=https://github.com/Lakerfield/Lakerfield.Rpc -31) [LoggingDecoratorGenerator]( https://github.com/DavidFineboym/LoggingDecoratorGenerator) , https://github.com/DavidFineboym/LoggingDecoratorGenerator +30) [LoggingDecoratorGenerator]( https://github.com/DavidFineboym/LoggingDecoratorGenerator) , https://github.com/DavidFineboym/LoggingDecoratorGenerator Why I have not tested : Microsoft have done same feature https://github.com/ignatandrei/RSCG_Examples/issues/new?title=LoggingDecoratorGenerator&body=https://github.com/DavidFineboym/LoggingDecoratorGenerator -32) [lucide-blazor]( https://github.com/brecht-vde/lucide-blazor/) , https://github.com/brecht-vde/lucide-blazor/ +31) [lucide-blazor]( https://github.com/brecht-vde/lucide-blazor/) , https://github.com/brecht-vde/lucide-blazor/ Why I have not tested : issue opened https://github.com/ignatandrei/RSCG_Examples/issues/new?title=lucide-blazor&body=https://github.com/brecht-vde/lucide-blazor/ -33) [ManagedDotnetProfiler]( https://github.com/kevingosse/ManagedDotnetProfiler) , https://github.com/kevingosse/ManagedDotnetProfiler +32) [ManagedDotnetProfiler]( https://github.com/kevingosse/ManagedDotnetProfiler) , https://github.com/kevingosse/ManagedDotnetProfiler Why I have not tested : too complicated for me, need help https://github.com/ignatandrei/RSCG_Examples/issues/new?title=ManagedDotnetProfiler&body=https://github.com/kevingosse/ManagedDotnetProfiler -34) [Maui.BindableProperty.Generator]( https://github.com/rrmanzano/maui-bindableproperty-generator) , https://github.com/rrmanzano/maui-bindableproperty-generator +33) [Maui.BindableProperty.Generator]( https://github.com/rrmanzano/maui-bindableproperty-generator) , https://github.com/rrmanzano/maui-bindableproperty-generator Why I have not tested : too complicated for me, need help https://github.com/ignatandrei/RSCG_Examples/issues/new?title=Maui.BindableProperty.Generator&body=https://github.com/rrmanzano/maui-bindableproperty-generator -35) [Minerals.AutoCQRS]( https://github.com/SzymonHalucha/Minerals.AutoCQRS) , https://github.com/SzymonHalucha/Minerals.AutoCQRS +34) [Minerals.AutoCQRS]( https://github.com/SzymonHalucha/Minerals.AutoCQRS) , https://github.com/SzymonHalucha/Minerals.AutoCQRS Why I have not tested : later https://github.com/ignatandrei/RSCG_Examples/issues/new?title=Minerals.AutoCQRS&body=https://github.com/SzymonHalucha/Minerals.AutoCQRS -36) [Minerals.AutoDomain]( https://github.com/SzymonHalucha/Minerals.AutoDomain) , https://github.com/SzymonHalucha/Minerals.AutoDomain +35) [Minerals.AutoDomain]( https://github.com/SzymonHalucha/Minerals.AutoDomain) , https://github.com/SzymonHalucha/Minerals.AutoDomain Why I have not tested : later https://github.com/ignatandrei/RSCG_Examples/issues/new?title=Minerals.AutoDomain&body=https://github.com/SzymonHalucha/Minerals.AutoDomain -37) [MvvmGen]( https://github.com/thomasclaudiushuber/mvvmgen) , https://github.com/thomasclaudiushuber/mvvmgen +36) [MvvmGen]( https://github.com/thomasclaudiushuber/mvvmgen) , https://github.com/thomasclaudiushuber/mvvmgen Why I have not tested : too complicated for me, need help https://github.com/ignatandrei/RSCG_Examples/issues/new?title=MvvmGen&body=https://github.com/thomasclaudiushuber/mvvmgen -38) [observable]( https://github.com/notanaverageman/Bindables) , https://github.com/notanaverageman/Bindables +37) [observable]( https://github.com/notanaverageman/Bindables) , https://github.com/notanaverageman/Bindables Why I have not tested : later https://github.com/ignatandrei/RSCG_Examples/issues/new?title=observable&body=https://github.com/notanaverageman/Bindables -39) [Overloader]( https://github.com/emptycoder/Overloader) , https://github.com/emptycoder/Overloader +38) [Overloader]( https://github.com/emptycoder/Overloader) , https://github.com/emptycoder/Overloader Why I have not tested : too complicated for me, need help https://github.com/ignatandrei/RSCG_Examples/issues/new?title=Overloader&body=https://github.com/emptycoder/Overloader -40) [PolySharp]( https://github.com/Sergio0694/PolySharp) , https://github.com/Sergio0694/PolySharp +39) [PolySharp]( https://github.com/Sergio0694/PolySharp) , https://github.com/Sergio0694/PolySharp Why I have not tested : too complicated for me, need help https://github.com/ignatandrei/RSCG_Examples/issues/new?title=PolySharp&body=https://github.com/Sergio0694/PolySharp -41) [Pure.DI]( https://github.com/DevTeam/Pure.DI) , https://github.com/DevTeam/Pure.DI +40) [Pure.DI]( https://github.com/DevTeam/Pure.DI) , https://github.com/DevTeam/Pure.DI Why I have not tested : too complicated for me, need help https://github.com/ignatandrei/RSCG_Examples/issues/new?title=Pure.DI&body=https://github.com/DevTeam/Pure.DI -42) [schema]( https://github.com/MeltyPlayer/Schema) , https://github.com/MeltyPlayer/Schema +41) [schema]( https://github.com/MeltyPlayer/Schema) , https://github.com/MeltyPlayer/Schema Why I have not tested : too complicated for me, need help https://github.com/ignatandrei/RSCG_Examples/issues/new?title=schema&body=https://github.com/MeltyPlayer/Schema -43) [SerdeDn]( https://github.com/serdedotnet/serde) , https://github.com/serdedotnet/serde +42) [SerdeDn]( https://github.com/serdedotnet/serde) , https://github.com/serdedotnet/serde Why I have not tested : serializer. Done by MSFT with System.Text.Json https://github.com/ignatandrei/RSCG_Examples/issues/new?title=SerdeDn&body=https://github.com/serdedotnet/serde -44) [SogePoco]( https://github.com/d-p-y/SogePoco) , https://github.com/d-p-y/SogePoco +43) [SogePoco]( https://github.com/d-p-y/SogePoco) , https://github.com/d-p-y/SogePoco Why I have not tested : too complicated for me, need help https://github.com/ignatandrei/RSCG_Examples/issues/new?title=SogePoco&body=https://github.com/d-p-y/SogePoco -45) [SourceCrafter.HttpServiceClientGenerator]( https://github.com/pedro-gilmora/SourceCrafter.HttpServiceClientGenerator/) , https://github.com/pedro-gilmora/SourceCrafter.HttpServiceClientGenerator/ +44) [SourceCrafter.HttpServiceClientGenerator]( https://github.com/pedro-gilmora/SourceCrafter.HttpServiceClientGenerator/) , https://github.com/pedro-gilmora/SourceCrafter.HttpServiceClientGenerator/ Why I have not tested : later https://github.com/ignatandrei/RSCG_Examples/issues/new?title=SourceCrafter.HttpServiceClientGenerator&body=https://github.com/pedro-gilmora/SourceCrafter.HttpServiceClientGenerator/ -46) [ST.NSwag.ServerSourceGenerator]( https://github.com/s-tarasov/ST.NSwag.ServerSourceGenerator) , https://github.com/s-tarasov/ST.NSwag.ServerSourceGenerator +45) [ST.NSwag.ServerSourceGenerator]( https://github.com/s-tarasov/ST.NSwag.ServerSourceGenerator) , https://github.com/s-tarasov/ST.NSwag.ServerSourceGenerator Why I have not tested : swagger,need help https://github.com/ignatandrei/RSCG_Examples/issues/new?title=ST.NSwag.ServerSourceGenerator&body=https://github.com/s-tarasov/ST.NSwag.ServerSourceGenerator -47) [StrongInject]( https://github.com/YairHalberstadt/stronginject/) , https://github.com/YairHalberstadt/stronginject/ +46) [StrongInject]( https://github.com/YairHalberstadt/stronginject/) , https://github.com/YairHalberstadt/stronginject/ Why I have not tested : too complicated for me, need help https://github.com/ignatandrei/RSCG_Examples/issues/new?title=StrongInject&body=https://github.com/YairHalberstadt/stronginject/ -48) [TeuJson]( https://github.com/Terria-K/TeuJson) , https://github.com/Terria-K/TeuJson +47) [TeuJson]( https://github.com/Terria-K/TeuJson) , https://github.com/Terria-K/TeuJson Why I have not tested : json a class, was done in System.Text.Json https://github.com/ignatandrei/RSCG_Examples/issues/new?title=TeuJson&body=https://github.com/Terria-K/TeuJson -49) [Tinyhand]( https://github.com/archi-Doc/Tinyhand) , https://github.com/archi-Doc/Tinyhand +48) [Tinyhand]( https://github.com/archi-Doc/Tinyhand) , https://github.com/archi-Doc/Tinyhand Why I have not tested : tried, need documentation https://github.com/ignatandrei/RSCG_Examples/issues/new?title=Tinyhand&body=https://github.com/archi-Doc/Tinyhand -50) [Tortuga.Shipwright]( https://github.com/TortugaResearch/Tortuga.Shipwright) , https://github.com/TortugaResearch/Tortuga.Shipwright +49) [Tortuga.Shipwright]( https://github.com/TortugaResearch/Tortuga.Shipwright) , https://github.com/TortugaResearch/Tortuga.Shipwright Why I have not tested : too complicated for me, need help https://github.com/ignatandrei/RSCG_Examples/issues/new?title=Tortuga.Shipwright&body=https://github.com/TortugaResearch/Tortuga.Shipwright -51) [TupleOverloadGenerator]( https://github.com/ProphetLamb/TupleOverloadGenerator) , https://github.com/ProphetLamb/TupleOverloadGenerator +50) [TupleOverloadGenerator]( https://github.com/ProphetLamb/TupleOverloadGenerator) , https://github.com/ProphetLamb/TupleOverloadGenerator Why I have not tested : too complicated for me, need help https://github.com/ignatandrei/RSCG_Examples/issues/new?title=TupleOverloadGenerator&body=https://github.com/ProphetLamb/TupleOverloadGenerator -52) [TypealizR]( https://github.com/earloc/TypealizR) , https://github.com/earloc/TypealizR +51) [TypealizR]( https://github.com/earloc/TypealizR) , https://github.com/earloc/TypealizR Why I have not tested : depends on Microsoft.Extensions.Localization https://github.com/ignatandrei/RSCG_Examples/issues/new?title=TypealizR&body=https://github.com/earloc/TypealizR -53) [UnitTestBlazor]( https://github.com/bUnit-dev/bUnit) , https://github.com/bUnit-dev/bUnit +52) [UnitTestBlazor]( https://github.com/bUnit-dev/bUnit) , https://github.com/bUnit-dev/bUnit Why I have not tested : issue opened https://github.com/ignatandrei/RSCG_Examples/issues/new?title=UnitTestBlazor&body=https://github.com/bUnit-dev/bUnit -54) [ValueLink]( https://github.com/archi-Doc/ValueLink) , https://github.com/archi-Doc/ValueLink +53) [ValueLink]( https://github.com/archi-Doc/ValueLink) , https://github.com/archi-Doc/ValueLink Why I have not tested : too complicated for me, need help https://github.com/ignatandrei/RSCG_Examples/issues/new?title=ValueLink&body=https://github.com/archi-Doc/ValueLink -55) [VisitorPatternGenerator]( https://github.com/hikarin522/VisitorPatternGenerator/) , https://github.com/hikarin522/VisitorPatternGenerator/ +54) [VisitorPatternGenerator]( https://github.com/hikarin522/VisitorPatternGenerator/) , https://github.com/hikarin522/VisitorPatternGenerator/ Why I have not tested : issue opened https://github.com/ignatandrei/RSCG_Examples/issues/new?title=VisitorPatternGenerator&body=https://github.com/hikarin522/VisitorPatternGenerator/ -56) [Visor]( https://github.com/Tinkoff/Visor) , https://github.com/Tinkoff/Visor +55) [Visor]( https://github.com/Tinkoff/Visor) , https://github.com/Tinkoff/Visor Why I have not tested : too complicated for me, need help https://github.com/ignatandrei/RSCG_Examples/issues/new?title=Visor&body=https://github.com/Tinkoff/Visor -57) [WrapperValueObject]( https://github.com/martinothamar/WrapperValueObject) , https://github.com/martinothamar/WrapperValueObject +56) [WrapperValueObject]( https://github.com/martinothamar/WrapperValueObject) , https://github.com/martinothamar/WrapperValueObject Why I have not tested : not maintained as in readme diff --git a/v2/Generator/all.csv b/v2/Generator/all.csv index 3ee5e1cea..ab14bf01d 100644 --- a/v2/Generator/all.csv +++ b/v2/Generator/all.csv @@ -174,3 +174,4 @@ Nr,Key,Source,Category 173,Microsoft.Windows.CsWin32, https://github.com/microsoft/CsWin32,WinAPI 174,Dapper.AOT, https://github.com/DapperLib/DapperAOT,Database 175,Dolly, https://github.com/AnderssonPeter/Dolly,Clone +176,Darp.BinaryObjects, https://github.com/rosslight/Darp.BinaryObjects,Bitwise diff --git a/v2/RSCGExamplesData/GeneratorDataRec.json b/v2/RSCGExamplesData/GeneratorDataRec.json index 98eaf2ecd..22cbddeb4 100644 --- a/v2/RSCGExamplesData/GeneratorDataRec.json +++ b/v2/RSCGExamplesData/GeneratorDataRec.json @@ -1053,5 +1053,11 @@ "Category": 29, "dtStart": "2024-12-03T00:00:00", "show": true + }, + { + "ID":"Darp.BinaryObjects", + "Category": 24, + "dtStart": "2024-12-04T00:00:00", + "show": true } ] \ No newline at end of file diff --git a/v2/RSCGExamplesData/NoExample.json b/v2/RSCGExamplesData/NoExample.json index b9dae2f30..93718a513 100644 --- a/v2/RSCGExamplesData/NoExample.json +++ b/v2/RSCGExamplesData/NoExample.json @@ -835,11 +835,6 @@ "name":"https://github.com/bjornhellander/TestInheritanceGenerator", "why":"later" }, - { - "ID":181, - "name":"https://github.com/rosslight/Darp.BinaryObjects", - "why":"later" - }, { "ID":182, "name":"https://github.com/AlexNav73/CoreCraft", diff --git a/v2/book/examples/Darp.BinaryObjects.html b/v2/book/examples/Darp.BinaryObjects.html new file mode 100644 index 000000000..71689bfa7 --- /dev/null +++ b/v2/book/examples/Darp.BinaryObjects.html @@ -0,0 +1,59 @@ + +

RSCG nr 176 : Darp.BinaryObjects

+ +

Info

+Nuget : https://www.nuget.org/packages/Darp.BinaryObjects/ + +

You can find more details at : https://github.com/rosslight/Darp.BinaryObjects

+ +

Author :Ross Light GmbH

+ +

Source : https://github.com/rosslight/Darp.BinaryObjects

+ +

About

+ +Serialize bits of data + +

+ How to use +

+

+ Add reference to the Darp.BinaryObjects in the csproj +

+ + +

This was for me the starting code

+ +
+ I have coded the file Program.cs +
+ +
+ +
+ I have coded the file BitStruct.cs +
+ +
+

And here are the generated files

+ +
+ The file generated is BinaryObjectsGenerator.g.cs +
+ + +

+ You can download the code and this page as pdf from + + https://ignatandrei.github.io/RSCG_Examples/v2/docs/Darp.BinaryObjects + +

+ + +

+ You can see the whole list at + + https://ignatandrei.github.io/RSCG_Examples/v2/docs/List-of-RSCG + +

+ diff --git a/v2/book/list.html b/v2/book/list.html index b8744556f..2e51c7298 100644 --- a/v2/book/list.html +++ b/v2/book/list.html @@ -17,7 +17,7 @@

-This is the list of 175 RSCG with examples => +This is the list of 176 RSCG with examples =>

@@ -726,6 +726,10 @@

+ + + +
175 Dolly
176Darp.BinaryObjects
diff --git a/v2/book/pandocHTML.yaml b/v2/book/pandocHTML.yaml index 4539c725a..80170ac34 100644 --- a/v2/book/pandocHTML.yaml +++ b/v2/book/pandocHTML.yaml @@ -189,6 +189,7 @@ input-files: - examples/Microsoft.Windows.CsWin32.html - examples/Dapper.AOT.html - examples/Dolly.html +- examples/Darp.BinaryObjects.html # or you may use input-file: with a single value # defaults: diff --git a/v2/rscg_examples/Darp.BinaryObjects/description.json b/v2/rscg_examples/Darp.BinaryObjects/description.json new file mode 100644 index 000000000..242cc6460 --- /dev/null +++ b/v2/rscg_examples/Darp.BinaryObjects/description.json @@ -0,0 +1,22 @@ +{ + "generator":{ + "name":"Darp.BinaryObjects", + "nuget":[ + "https://www.nuget.org/packages/Darp.BinaryObjects/" + ], + "link":"https://github.com/rosslight/Darp.BinaryObjects", + "author":"Ross Light GmbH", + "source":"https://github.com/rosslight/Darp.BinaryObjects" + }, + "data":{ + "goodFor":["Serialize bits of data"], + "csprojDemo":"BitsDemo.csproj", + "csFiles":["Program.cs","BitStruct.cs"], + "excludeDirectoryGenerated":[""], + "includeAdditionalFiles":[""] + }, + "links":{ + "blog":"", + "video":"" + } +} \ No newline at end of file diff --git a/v2/rscg_examples/Darp.BinaryObjects/nuget.txt b/v2/rscg_examples/Darp.BinaryObjects/nuget.txt new file mode 100644 index 000000000..6ff2ec094 --- /dev/null +++ b/v2/rscg_examples/Darp.BinaryObjects/nuget.txt @@ -0,0 +1 @@ +A source generator to generate TryRead/Write Little/BigEndian methods for struct/class definitions for binary serialization. \ No newline at end of file diff --git a/v2/rscg_examples/Darp.BinaryObjects/readme.txt b/v2/rscg_examples/Darp.BinaryObjects/readme.txt new file mode 100644 index 000000000..a364a74fd --- /dev/null +++ b/v2/rscg_examples/Darp.BinaryObjects/readme.txt @@ -0,0 +1,240 @@ +
+ +# Darp.BinaryObjects + +[![NuGet](https://img.shields.io/nuget/v/Darp.BinaryObjects.svg)](https://www.nuget.org/packages/Darp.BinaryObjects) +[![Downloads](https://img.shields.io/nuget/dt/Darp.BinaryObjects)](https://www.nuget.org/packages/Darp.BinaryObjects) + +![Dotnet Version](https://img.shields.io/badge/dotnet-net8.0%20%7C%20net9.0-blue) +![Language Version](https://img.shields.io/badge/c%23-11-blue) + +[![Tests](https://github.com/rosslight/Darp.BinaryObjects/actions/workflows/test_and_publish.yml/badge.svg)](https://github.com/rosslight/Darp.BinaryObjects/actions/workflows/test_and_publish.yml) +![License](https://img.shields.io/github/license/rosslight/Darp.BinaryObjects) + +### A source generator to generate TryRead/Write Little/BigEndian methods for struct/class definitions. + +> [!IMPORTANT] +> This package is under heavy development. Anything is subject to change. + +
+You should use the source generation when you want: + +- Serialization to a buffer of bytes +- Deserialization from a buffer already completely received +- Endianness during serialization +- Common interfaces for serialization are required which allow to implement more complex scenarios by hand without the generator +- Usage of something like BinaryPrimitives but for more complex types +- Can work with a minimum c# LanguageVersion of 11 and net8.0 / net9.0 + +If these requirements do not meet your expectations, check out those other wonderful projects + +- Several binary serializers. e.g. [MemoryPack](https://github.com/Cysharp/MemoryPack), [BinaryPack](https://github.com/Sergio0694/BinaryPack), ... + which are great if direct binary serialization is not needed +- Serialization libraries relying on reflection. e.g. [HyperSerializer](https://github.com/adam-dot-cohen/HyperSerializer) +- [StructPacker](https://github.com/RudolfKurkaMs/StructPacker) - not supporting allocation less packing/unpacking +- [BinarySerializer](https://github.com/jefffhaynes/BinarySerializer?tab=readme-ov-file) - Allows for binary serialization with a way larger feature set but more difficult to understand and relying on reflection + +## Supported properties + +Here is a list of the property types currently supported by the library: + +- [x] Unmanaged types: `bool`, `sbyte`, `byte`, `short`, `ushort`, `int`, `uint`, `long`, `ulong`, `char`, `float`, `double` +- [x] BinaryObjects implementing `IWritable` or `IReadable` +- [ ] Blittable types +- [x] Enums +- [ ] Other .NET types: `BitArray` + +For all of these types, it should be possible to define as array types: +- [x] Memory abstractions: `ReadOnlyMemory` +- [x] Arrays: `T[]` +- [x] Lists: `List` +- [x] Collections: `IEnumerable`, `IReadOnlyCollection`, `ICollection`, `IReadOnlyList`, `IList` + +To control these types there are attributes +- [x] `BinaryIgnore`: Ignore some members +- [x] `BinaryElementCount`: Sets the number of elements in an array +- [ ] `BinaryReadRemaining`: Reads the remaining into an array +- [ ] `BinaryLength`: Sets the length of a member + +Unplanned: +- Unmanaged types have no clearly defined length / endianness: ~~`nint`~~, ~~`nuint`~~, ~~`decimal`~~ +- Multidimensional arrays (e.g. `T[,]`, `T[,,]`, etc.) +- Jagged arrays (e.g. `T[][]`, etc.) +- Dictionaries: `Dictionary`, `IDictionary` and `IReadOnlyDictionary` +- Nullable value types: `Nullable` or `T?` + +## What is serialized? + +- Any `real`, user-defined member in a `class` or `struct` declaration +- Any `field` or `auto property` which is settable or has a parameter with matching type and name in the constructor + +- If there are multiple constructors defined the one with a `BinaryConstructorAttribute` is being used + +There are warnings if: +- The constructor cannot be resolved +- There are multiple constructors but none with a `BinaryConstructorAttribute` +- A member is readonly and does not have a matching constructor argument or is explicitly ignored + +## How it's supposed to work + +Let's pretend we have a series of bytes: + +```csharp +01020003040506 + +A: 01 +B: 0200 +Data: 03040506 +``` + +We now want to read an object from these bytes similar to how we would do with `BinaryPrimitives`: + +```csharp +[BinaryObject] +public readonly record struct SomeTestStruct(byte A, ushort B, ReadOnlyMemory Data); +``` + +Normally, you would have to write serialization methods for yourself. By adding the `BinaryObjectAttribute`, this is done automatically by the source generator. + + +## Usage + +```csharp +// Define your object +[BinaryObject] +partial record struct YourStruct(ushort A, byte B); + +// Read the struct from the buffer using either little or big endian format +var buffer = Convert.FromHexString("AABBCC"); +var success = YourStruct.TryReadLittleEndian(source: buffer, out var value); +var success2 = YourStruct.TryReadBigEndian(source: buffer, out var value2, out int bytesRead); + +// Get the actual size of the struct +var size = value.GetByteCount(); + +// Write the values back to a buffer +var writeBuffer = new byte[size]; +var success3 = value.TryWriteLittleEndian(destination: writeBuffer); +var success4 = value2.TryWriteLittleEndian(destination: writeBuffer, out int bytesWritten); +``` + +The code generated by the struct will attempt to maximize readability by still maintaining performance and as little allocations as possible. + +
+ Generated code + +```csharp +// +#nullable enable + +using BinaryHelpers = global::Darp.BinaryObjects.BinaryHelpers; +using NotNullWhenAttribute = global::System.Diagnostics.CodeAnalysis.NotNullWhenAttribute; + +namespace Your.Namespace; + +/// +/// Field Byte Length +/// 2 +/// 1 +/// --- 3 +/// +public partial record struct YourStruct : global::Darp.BinaryObjects.IWritable, global::Darp.BinaryObjects.ISpanReadable +{ + /// + [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public int GetByteCount() => 3; + + /// + public bool TryWriteLittleEndian(global::System.Span destination) => TryWriteLittleEndian(destination, out _); + /// + public bool TryWriteLittleEndian(global::System.Span destination, out int bytesWritten) + { + bytesWritten = 0; + + if (destination.Length < 3) + return false; + BinaryHelpers.WriteUInt16LittleEndian(destination[0..], this.A); + BinaryHelpers.WriteUInt8(destination[2..], this.B); + bytesWritten += 3; + + return true; + } + /// + public bool TryWriteBigEndian(global::System.Span destination) => TryWriteBigEndian(destination, out _); + /// + public bool TryWriteBigEndian(global::System.Span destination, out int bytesWritten) + { + bytesWritten = 0; + + if (destination.Length < 3) + return false; + BinaryHelpers.WriteUInt16BigEndian(destination[0..], this.A); + BinaryHelpers.WriteUInt8(destination[2..], this.B); + bytesWritten += 3; + + return true; + } + + /// + public static bool TryReadLittleEndian(global::System.ReadOnlySpan source, out YourStruct value) => TryReadLittleEndian(source, out value, out _); + /// + public static bool TryReadLittleEndian(global::System.ReadOnlySpan source, out YourStruct value, out int bytesRead) + { + bytesRead = 0; + value = default; + + if (source.Length < 3) + return false; + var ___readA = BinaryHelpers.ReadUInt16LittleEndian(source[0..]); + var ___readB = BinaryHelpers.ReadUInt8(source[2..]); + bytesRead += 3; + + value = new YourStruct(___readA, ___readB); + return true; + } + /// + public static bool TryReadBigEndian(global::System.ReadOnlySpan source, out YourStruct value) => TryReadBigEndian(source, out value, out _); + /// + public static bool TryReadBigEndian(global::System.ReadOnlySpan source, out YourStruct value, out int bytesRead) + { + bytesRead = 0; + value = default; + + if (source.Length < 3) + return false; + var ___readA = BinaryHelpers.ReadUInt16BigEndian(source[0..]); + var ___readB = BinaryHelpers.ReadUInt8(source[2..]); + bytesRead += 3; + + value = new YourStruct(___readA, ___readB); + return true; + } +} +``` +
+ +## Development + +After cloning the repository, you will find the following project structure: + +- `src/Darp.BinaryObjects` contains public APIs and Attributes +- `src/Darp.BinaryObjects.Generator` contains the actual source generator +- `test/Darp.BinaryObjects.Tests` contains unit tests ensuring the generated files actually build and read/write as expected +- `test/Darp.BInaryObjects.Generator.Tests` contains snapshot tests to ensure the source generator generates valid files + +### Code formatting + +This repository uses [CSharpier](https://csharpier.com/) (inspired by prettier) for code formatting. +CSharpier should be installed automatically when building the solution as a local dotnet tool. + +To run it, execute +```shell +dotnet csharpier . +``` + +If you want to format you code on save, check out available [Editor integration](https://csharpier.com/docs/Editors) for your IDE. + +### Testing + +Snapshot tests are done using [Verify](https://github.com/VerifyTests/Verify/). If you want to optimize running these tests in your local IDE, you might adjust some settings. +Please, check your local configuration in the [VerifyDocs](https://github.com/VerifyTests/Verify/blob/main/docs/wiz/readme.md) diff --git a/v2/rscg_examples/Darp.BinaryObjects/src/.tours/Darp.BinaryObjects.tour b/v2/rscg_examples/Darp.BinaryObjects/src/.tours/Darp.BinaryObjects.tour new file mode 100644 index 000000000..6f8ce3950 --- /dev/null +++ b/v2/rscg_examples/Darp.BinaryObjects/src/.tours/Darp.BinaryObjects.tour @@ -0,0 +1,36 @@ + +{ + "$schema": "https://aka.ms/codetour-schema", + "title": "Darp.BinaryObjects", + "steps": + [ + { + "file": "BitsDemo/BitsDemo.csproj", + "description": "First, we add Nuget [Darp.BinaryObjects](https://www.nuget.org/packages/Darp.BinaryObjects/) in csproj ", + "pattern": "Darp.BinaryObjects" + } + + ,{ + "file": "BitsDemo/BitStruct.cs", + "description": "File BitStruct.cs ", + "pattern": "this is the code" + } + + ,{ + "file": "BitsDemo/Program.cs", + "description": "File Program.cs \r\n>> dotnet run --project BitsDemo/BitsDemo.csproj ", + "pattern": "this is the code" + } + + + ,{ + "file": "BitsDemo/obj/GX/Darp.BinaryObjects.Generator/Darp.BinaryObjects.Generator.BinaryObjectsGenerator/BinaryObjectsGenerator.g.cs", + "description": "Generated File 1 from 1 : BinaryObjectsGenerator.g.cs ", + "line": 1 + } + + ], + + "ref": "main" + +} \ No newline at end of file diff --git a/v2/rscg_examples/Darp.BinaryObjects/src/BitsDemo.sln b/v2/rscg_examples/Darp.BinaryObjects/src/BitsDemo.sln new file mode 100644 index 000000000..684b96637 --- /dev/null +++ b/v2/rscg_examples/Darp.BinaryObjects/src/BitsDemo.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34728.123 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitsDemo", "BitsDemo\BitsDemo.csproj", "{0B307030-7104-490A-A57E-215067A88251}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0B307030-7104-490A-A57E-215067A88251}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0B307030-7104-490A-A57E-215067A88251}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0B307030-7104-490A-A57E-215067A88251}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0B307030-7104-490A-A57E-215067A88251}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {EDBF43BE-D199-4BC3-8A48-F270ACD097D9} + EndGlobalSection +EndGlobal diff --git a/v2/rscg_examples/Darp.BinaryObjects/src/BitsDemo/BitStruct.cs b/v2/rscg_examples/Darp.BinaryObjects/src/BitsDemo/BitStruct.cs new file mode 100644 index 000000000..a7e168974 --- /dev/null +++ b/v2/rscg_examples/Darp.BinaryObjects/src/BitsDemo/BitStruct.cs @@ -0,0 +1,10 @@ +using Darp.BinaryObjects; +using System.IO.Compression; + +namespace BitsDemo; + +[BinaryObject] +partial record zlib_header(byte cmf, byte flg) +{ + +} \ No newline at end of file diff --git a/v2/rscg_examples/Darp.BinaryObjects/src/BitsDemo/BitsDemo.csproj b/v2/rscg_examples/Darp.BinaryObjects/src/BitsDemo/BitsDemo.csproj new file mode 100644 index 000000000..eab5691c8 --- /dev/null +++ b/v2/rscg_examples/Darp.BinaryObjects/src/BitsDemo/BitsDemo.csproj @@ -0,0 +1,21 @@ + + + + Exe + net8.0 + enable + enable + + + + + true + $(BaseIntermediateOutputPath)\GX + + + + + + + + diff --git a/v2/rscg_examples/Darp.BinaryObjects/src/BitsDemo/Program.cs b/v2/rscg_examples/Darp.BinaryObjects/src/BitsDemo/Program.cs new file mode 100644 index 000000000..242aab6a1 --- /dev/null +++ b/v2/rscg_examples/Darp.BinaryObjects/src/BitsDemo/Program.cs @@ -0,0 +1,17 @@ +using BitsDemo; +using Darp.BinaryObjects; + +var z = new zlib_header(0x78, 0x9C); + +var size = z.GetByteCount(); + +// Write the values back to a buffer +var writeBuffer = new byte[size]; +if(z.TryWriteLittleEndian(writeBuffer)) +{ + Console.WriteLine("writing to buffer" ); + foreach (var item in writeBuffer) + { + Console.Write(item+" "); + } +} diff --git a/v2/rscg_examples/Darp.BinaryObjects/video.json b/v2/rscg_examples/Darp.BinaryObjects/video.json new file mode 100644 index 000000000..8aca6d57a --- /dev/null +++ b/v2/rscg_examples/Darp.BinaryObjects/video.json @@ -0,0 +1,39 @@ +{ + "scriptName": "Darp.BinaryObjects", + "steps": +[ + {"typeStep":"exec","arg":"clipchamp.exe launch"}, + {"typeStep":"text","arg": "Welcome to Roslyn Examples"}, + {"typeStep":"text","arg":"If you want to see more examples , see List Of RSCG"}, + {"typeStep":"browser","arg":"https://ignatandrei.github.io/RSCG_Examples/v2/docs/List-of-RSCG"}, + {"typeStep":"text","arg": "My name is Andrei Ignat and I am deeply fond of Roslyn Source Code Generator. "}, + +{"typeStep":"text","arg": "Today I will present Darp.BinaryObjects . Serialize bits of data ."}, +{"typeStep":"browser","arg":"https://www.nuget.org/packages/Darp.BinaryObjects/"}, +{"typeStep":"text","arg": "The whole example is here"}, +{"typeStep":"browser","arg":"https://ignatandrei.github.io/RSCG_Examples/v2/docs/Darp.BinaryObjects"}, +{"typeStep":"text","arg": "You can download the code from here"}, +{"typeStep":"browser","arg":"https://ignatandrei.github.io/RSCG_Examples/v2/docs/Darp.BinaryObjects#download-example-net--c-"}, +{"typeStep":"text","arg":"Here is the code downloaded "}, +{"typeStep":"exec","arg":"explorer.exe /select,D:\\gth\\RSCG_Examples\\v2\\rscg_examples\\Darp.BinaryObjects\\src\\BitsDemo.sln"}, +{"typeStep":"text","arg": "So , let's start the project with Visual Studio Code "}, +{"typeStep":"stepvscode","arg": "-n D:\\gth\\RSCG_Examples\\v2\\rscg_examples\\Darp.BinaryObjects\\src"}, + +{"typeStep":"text","arg": "To use it ,you will put the Nuget Darp.BinaryObjects into the csproj "}, + +{"typeStep":"stepvscode","arg": "-r -g D:\\gth\\RSCG_Examples\\v2\\rscg_examples\\Darp.BinaryObjects\\src\\BitsDemo\\BitsDemo.csproj"}, + +{"typeStep":"text","arg": "And now I will show you an example of using Darp.BinaryObjects"}, + +{"typeStep":"hide","arg": "now execute the tour in VSCode"}, +{"typeStep":"tour", "arg": "src/.tours/"}, +{"typeStep":"text","arg":" And I will execute the project"}, +{"typeStep":"showproj", "arg":"BitsDemo.csproj"}, +{"typeStep":"text","arg":" This concludes the project"}, +{"typeStep":"waitseconds","arg":"30"}, +{"typeStep":"text","arg": "Remember, you can download the code from here"}, +{"typeStep":"browser","arg":"https://ignatandrei.github.io/RSCG_Examples/v2/docs/Darp.BinaryObjects#download-example-net--c-", +SpeakTest=" "}, +{"typeStep":"waitseconds","arg":"30"}, +] +} diff --git a/v2/rscg_examples_site/docs/Categories/Bitwise.md b/v2/rscg_examples_site/docs/Categories/Bitwise.md index 33cfecee5..0a35f813c 100644 --- a/v2/rscg_examples_site/docs/Categories/Bitwise.md +++ b/v2/rscg_examples_site/docs/Categories/Bitwise.md @@ -1,6 +1,8 @@

Bitwise

-Number RSCG: 1 +Number RSCG: 2 1 [BitsKit](/docs/BitsKit) + + 2 [Darp.BinaryObjects](/docs/Darp.BinaryObjects) \ No newline at end of file diff --git a/v2/rscg_examples_site/docs/NoExamples.md b/v2/rscg_examples_site/docs/NoExamples.md index d5bf193f0..67d09a38a 100644 --- a/v2/rscg_examples_site/docs/NoExamples.md +++ b/v2/rscg_examples_site/docs/NoExamples.md @@ -298,387 +298,383 @@ Why I have not put example: old ISourceGenerator Why I have not put example: issue opened -74)https://github.com/rosslight/Darp.BinaryObjects https://github.com/rosslight/Darp.BinaryObjects +74)https://github.com/Stepami/visitor-net https://github.com/Stepami/visitor-net Why I have not put example: later -75)https://github.com/Stepami/visitor-net https://github.com/Stepami/visitor-net +75)https://github.com/SzymonHalucha/Minerals.AutoCommands https://github.com/SzymonHalucha/Minerals.AutoCommands Why I have not put example: later -76)https://github.com/SzymonHalucha/Minerals.AutoCommands https://github.com/SzymonHalucha/Minerals.AutoCommands - -Why I have not put example: later - -77)HubClientProxyGenerator https://www.nuget.org/packages/Microsoft.AspNetCore.SignalR.Client.SourceGenerator +76)HubClientProxyGenerator https://www.nuget.org/packages/Microsoft.AspNetCore.SignalR.Client.SourceGenerator Why I have not put example: not having nuget, but having IIncrementalGenerator -78)Imp.NET https://github.com/DouglasDwyer/Imp.NET +77)Imp.NET https://github.com/DouglasDwyer/Imp.NET Why I have not put example: old ISourceGenerator -79)Intellenum https://github.com/SteveDunn/Intellenum +78)Intellenum https://github.com/SteveDunn/Intellenum Why I have not put example: not understand how to use -80)InterfaceGenerator https://github.com/daver32/InterfaceGenerator +79)InterfaceGenerator https://github.com/daver32/InterfaceGenerator Why I have not put example: old ISourceGenerator -81)IoTHubClientGenerator https://github.com/alonf/IoTHubClientGenerator +80)IoTHubClientGenerator https://github.com/alonf/IoTHubClientGenerator Why I have not put example: old ISourceGenerator -82)Jos.Enumeration, https://github.com/joseftw/jos.enumeration +81)Jos.Enumeration, https://github.com/joseftw/jos.enumeration Why I have not put example: too complicated for me, need help -83)JsonByExampleGenerator https://github.com/hermanussen/JsonByExampleGenerator +82)JsonByExampleGenerator https://github.com/hermanussen/JsonByExampleGenerator Why I have not put example: old ISourceGenerator -84)JsonDeserializeResourceSourceGenerator https://github.com/musictopia2/JsonDeserializeResourceSourceGenerator +83)JsonDeserializeResourceSourceGenerator https://github.com/musictopia2/JsonDeserializeResourceSourceGenerator Why I have not put example: no readme -85)JsonMergePatch https://github.com/ladeak/JsonMergePatch +84)JsonMergePatch https://github.com/ladeak/JsonMergePatch Why I have not put example: old ISourceGenerator -86)JsonSerializerContextGenerator https://github.com/musictopia2/JsonSerializerContextGenerator +85)JsonSerializerContextGenerator https://github.com/musictopia2/JsonSerializerContextGenerator Why I have not put example: no readme -87)JsonSourceGenerator https://github.com/Pilchie/JsonSourceGenerator +86)JsonSourceGenerator https://github.com/Pilchie/JsonSourceGenerator Why I have not put example: not having nuget, but having IIncrementalGenerator -88)JsonSrcGen https://github.com/trampster/JsonSrcGen +87)JsonSrcGen https://github.com/trampster/JsonSrcGen Why I have not put example: old ISourceGenerator -89)kli.Localize https://github.com/kl1mm/localize +88)kli.Localize https://github.com/kl1mm/localize Why I have not put example: old ISourceGenerator -90)laker https://github.com/Lakerfield/Lakerfield.Rpc +89)laker https://github.com/Lakerfield/Lakerfield.Rpc Why I have not put example: later -91)lambdajection https://github.com/cythral/lambdajection +90)lambdajection https://github.com/cythral/lambdajection Why I have not put example: old ISourceGenerator -92)Lazysh https://github.com/B1Z0N/LazyshGen +91)Lazysh https://github.com/B1Z0N/LazyshGen Why I have not put example: old ISourceGenerator -93)LoggingDecoratorGenerator https://github.com/DavidFineboym/LoggingDecoratorGenerator +92)LoggingDecoratorGenerator https://github.com/DavidFineboym/LoggingDecoratorGenerator Why I have not put example: Microsoft have done same feature -94)lucide-blazor https://github.com/brecht-vde/lucide-blazor/ +93)lucide-blazor https://github.com/brecht-vde/lucide-blazor/ Why I have not put example: issue opened -95)ManagedDotnetProfiler https://github.com/kevingosse/ManagedDotnetProfiler +94)ManagedDotnetProfiler https://github.com/kevingosse/ManagedDotnetProfiler Why I have not put example: too complicated for me, need help -96)MapDataReader https://github.com/jitbit/MapDataReader +95)MapDataReader https://github.com/jitbit/MapDataReader Why I have not put example: old ISourceGenerator -97)MappingCloningExtensions https://github.com/musictopia2/MappingCloningExtensions +96)MappingCloningExtensions https://github.com/musictopia2/MappingCloningExtensions Why I have not put example: no readme -98)Maui.BindableProperty.Generator https://github.com/rrmanzano/maui-bindableproperty-generator +97)Maui.BindableProperty.Generator https://github.com/rrmanzano/maui-bindableproperty-generator Why I have not put example: too complicated for me, need help -99)MediatR https://github.com/Burgyn/MMLib.MediatR.Generators +98)MediatR https://github.com/Burgyn/MMLib.MediatR.Generators Why I have not put example: old ISourceGenerator -100)MemberAccessGenerator https://github.com/ufcpp/MemberAccessGenerator +99)MemberAccessGenerator https://github.com/ufcpp/MemberAccessGenerator Why I have not put example: old ISourceGenerator -101)MemoizeSourceGenerator https://github.com/Zoxive/MemoizeSourceGenerator +100)MemoizeSourceGenerator https://github.com/Zoxive/MemoizeSourceGenerator Why I have not put example: old ISourceGenerator -102)Minerals.AutoCQRS https://github.com/SzymonHalucha/Minerals.AutoCQRS +101)Minerals.AutoCQRS https://github.com/SzymonHalucha/Minerals.AutoCQRS Why I have not put example: later -103)Minerals.AutoDomain https://github.com/SzymonHalucha/Minerals.AutoDomain +102)Minerals.AutoDomain https://github.com/SzymonHalucha/Minerals.AutoDomain Why I have not put example: later -104)MiniRazor https://github.com/Tyrrrz/MiniRazor/ +103)MiniRazor https://github.com/Tyrrrz/MiniRazor/ Why I have not put example: archived -105)MockableStaticGenerator https://github.com/HamedFathi/MockableStaticGenerator +104)MockableStaticGenerator https://github.com/HamedFathi/MockableStaticGenerator Why I have not put example: old ISourceGenerator -106)MockGen https://github.com/thomas-girotto/MockGen +105)MockGen https://github.com/thomas-girotto/MockGen Why I have not put example: old ISourceGenerator -107)MockSourceGenerator https://github.com/hermanussen/MockSourceGenerator +106)MockSourceGenerator https://github.com/hermanussen/MockSourceGenerator Why I have not put example: old ISourceGenerator -108)MrMeeseeks.DIE https://github.com/Yeah69/MrMeeseeks.DIE +107)MrMeeseeks.DIE https://github.com/Yeah69/MrMeeseeks.DIE Why I have not put example: old ISourceGenerator -109)MrMeeseeks.ResXToViewModelGenerator https://github.com/Yeah69/MrMeeseeks.ResXToViewModelGenerator +108)MrMeeseeks.ResXToViewModelGenerator https://github.com/Yeah69/MrMeeseeks.ResXToViewModelGenerator Why I have not put example: old ISourceGenerator -110)MrMeeseeks.StaticDelegateGenerator https://github.com/Yeah69/MrMeeseeks.StaticDelegateGenerator +109)MrMeeseeks.StaticDelegateGenerator https://github.com/Yeah69/MrMeeseeks.StaticDelegateGenerator Why I have not put example: old ISourceGenerator -111)MrMeeseeks.Visitor https://github.com/Yeah69/MrMeeseeks.Visitor +110)MrMeeseeks.Visitor https://github.com/Yeah69/MrMeeseeks.Visitor Why I have not put example: old ISourceGenerator -112)MvvmGen https://github.com/thomasclaudiushuber/mvvmgen +111)MvvmGen https://github.com/thomasclaudiushuber/mvvmgen Why I have not put example: too complicated for me, need help -113)Neon.Roslyn https://www.nuget.org/packages/Neon.Roslyn +112)Neon.Roslyn https://www.nuget.org/packages/Neon.Roslyn Why I have not put example: old ISourceGenerator -114)net_automatic_interface https://github.com/codecentric/net_automatic_interface +113)net_automatic_interface https://github.com/codecentric/net_automatic_interface Why I have not put example: old ISourceGenerator -115)NSourceGenerators https://github.com/NeVeSpl/NSourceGenerators/ +114)NSourceGenerators https://github.com/NeVeSpl/NSourceGenerators/ Why I have not put example: old ISourceGenerator -116)observable https://github.com/notanaverageman/Bindables +115)observable https://github.com/notanaverageman/Bindables Why I have not put example: later -117)Overloader https://github.com/emptycoder/Overloader +116)Overloader https://github.com/emptycoder/Overloader Why I have not put example: too complicated for me, need help -118)Pipelines https://github.com/DumplingsDevs/Pipelines/ +117)Pipelines https://github.com/DumplingsDevs/Pipelines/ Why I have not put example: old ISourceGenerator -119)Plastic https://github.com/sang-hyeon/Plastic +118)Plastic https://github.com/sang-hyeon/Plastic Why I have not put example: old ISourceGenerator -120)PolySharp https://github.com/Sergio0694/PolySharp +119)PolySharp https://github.com/Sergio0694/PolySharp Why I have not put example: too complicated for me, need help -121)PrimaryConstructor https://github.com/chaowlert/PrimaryConstructor +120)PrimaryConstructor https://github.com/chaowlert/PrimaryConstructor Why I have not put example: old ISourceGenerator -122)PrimitiveStaticDataGenerator https://github.com/iiweis/PrimitiveStaticDataGenerator +121)PrimitiveStaticDataGenerator https://github.com/iiweis/PrimitiveStaticDataGenerator Why I have not put example: old ISourceGenerator -123)PrintMembersGenerator https://github.com/Youssef1313/PrintMembersGenerator +122)PrintMembersGenerator https://github.com/Youssef1313/PrintMembersGenerator Why I have not put example: old ISourceGenerator -124)ProxyInterfaceGenerator https://github.com/StefH/ProxyInterfaceSourceGenerator +123)ProxyInterfaceGenerator https://github.com/StefH/ProxyInterfaceSourceGenerator Why I have not put example: old ISourceGenerator -125)Pure.DI https://github.com/DevTeam/Pure.DI +124)Pure.DI https://github.com/DevTeam/Pure.DI Why I have not put example: too complicated for me, need help -126)PureHDF https://github.com/Apollo3zehn/PureHDF +125)PureHDF https://github.com/Apollo3zehn/PureHDF Why I have not put example: old ISourceGenerator -127)RazorPageRouteGenerator https://github.com/surgicalcoder/RazorPageRouteGenerator +126)RazorPageRouteGenerator https://github.com/surgicalcoder/RazorPageRouteGenerator Why I have not put example: old ISourceGenerator -128)ReForge.Union https://github.com/nalcorso/ReForge.Union +127)ReForge.Union https://github.com/nalcorso/ReForge.Union Why I have not put example: not having nuget, but having IIncrementalGenerator -129)RoslynWeave https://github.com/Jishun/RoslynWeave +128)RoslynWeave https://github.com/Jishun/RoslynWeave Why I have not put example: old ISourceGenerator -130)ScenarioTests https://github.com/koenbeuk/ScenarioTests +129)ScenarioTests https://github.com/koenbeuk/ScenarioTests Why I have not put example: old ISourceGenerator -131)schema https://github.com/MeltyPlayer/Schema +130)schema https://github.com/MeltyPlayer/Schema Why I have not put example: too complicated for me, need help -132)SerdeDn https://github.com/serdedotnet/serde +131)SerdeDn https://github.com/serdedotnet/serde Why I have not put example: serializer. Done by MSFT with System.Text.Json -133)SmallSharp https://github.com/devlooped/SmallSharp +132)SmallSharp https://github.com/devlooped/SmallSharp Why I have not put example: old ISourceGenerator -134)SmartAnnotations https://github.com/fiseni/SmartAnnotations +133)SmartAnnotations https://github.com/fiseni/SmartAnnotations Why I have not put example: old ISourceGenerator -135)SogePoco https://github.com/d-p-y/SogePoco +134)SogePoco https://github.com/d-p-y/SogePoco Why I have not put example: too complicated for me, need help -136)SourceApi https://github.com/alekshura/SourceApi +135)SourceApi https://github.com/alekshura/SourceApi Why I have not put example: old ISourceGenerator -137)SourceConfig https://github.com/alekshura/SourceConfig +136)SourceConfig https://github.com/alekshura/SourceConfig Why I have not put example: old ISourceGenerator -138)SourceCrafter.HttpServiceClientGenerator https://github.com/pedro-gilmora/SourceCrafter.HttpServiceClientGenerator/ +137)SourceCrafter.HttpServiceClientGenerator https://github.com/pedro-gilmora/SourceCrafter.HttpServiceClientGenerator/ Why I have not put example: later -139)SourceGeneratorQuery https://github.com/roeibajayo/SourceGeneratorQuery +138)SourceGeneratorQuery https://github.com/roeibajayo/SourceGeneratorQuery Why I have not put example: old ISourceGenerator -140)SourceInject https://github.com/giggio/sourceinject/ +139)SourceInject https://github.com/giggio/sourceinject/ Why I have not put example: old ISourceGenerator -141)SourceMapper https://github.com/alekshura/SourceMapper +140)SourceMapper https://github.com/alekshura/SourceMapper Why I have not put example: old ISourceGenerator -142)SourceMapper https://github.com/paiden/SourceMapper/ +141)SourceMapper https://github.com/paiden/SourceMapper/ Why I have not put example: old ISourceGenerator -143)SqlMarshal https://github.com/kant2002/SqlMarshal +142)SqlMarshal https://github.com/kant2002/SqlMarshal Why I have not put example: old ISourceGenerator -144)ST.NSwag.ServerSourceGenerator https://github.com/s-tarasov/ST.NSwag.ServerSourceGenerator +143)ST.NSwag.ServerSourceGenerator https://github.com/s-tarasov/ST.NSwag.ServerSourceGenerator Why I have not put example: swagger,need help -145)StackXML https://github.com/ZingBallyhoo/StackXML +144)StackXML https://github.com/ZingBallyhoo/StackXML Why I have not put example: old ISourceGenerator -146)StaticProxyGenerator https://github.com/robertturner/StaticProxyGenerator +145)StaticProxyGenerator https://github.com/robertturner/StaticProxyGenerator Why I have not put example: old ISourceGenerator -147)Strings.ResourceGenerator https://github.com/biggik/Strings.ResourceGenerator +146)Strings.ResourceGenerator https://github.com/biggik/Strings.ResourceGenerator Why I have not put example: old ISourceGenerator -148)StrongInject https://github.com/YairHalberstadt/stronginject/ +147)StrongInject https://github.com/YairHalberstadt/stronginject/ Why I have not put example: too complicated for me, need help -149)StronglyTypedEmbeddedResources https://github.com/surgicalcoder/StronglyTypedEmbeddedResources +148)StronglyTypedEmbeddedResources https://github.com/surgicalcoder/StronglyTypedEmbeddedResources Why I have not put example: old ISourceGenerator -150)StructPacker https://github.com/RudolfKurka/StructPacker +149)StructPacker https://github.com/RudolfKurka/StructPacker Why I have not put example: old ISourceGenerator -151)Svg https://github.com/wieslawsoltes/Svg.Skia +150)Svg https://github.com/wieslawsoltes/Svg.Skia Why I have not put example: old ISourceGenerator -152)tecli https://github.com/tyevco/TeCLI +151)tecli https://github.com/tyevco/TeCLI Why I have not put example: old ISourceGenerator -153)TeuJson https://github.com/Terria-K/TeuJson +152)TeuJson https://github.com/Terria-K/TeuJson Why I have not put example: json a class, was done in System.Text.Json -154)Thunderboltloc https://github.com/AlyElhaddad/ThunderboltIoc +153)Thunderboltloc https://github.com/AlyElhaddad/ThunderboltIoc Why I have not put example: old ISourceGenerator -155)Tinyhand https://github.com/archi-Doc/Tinyhand +154)Tinyhand https://github.com/archi-Doc/Tinyhand Why I have not put example: tried, need documentation -156)Tortuga.Shipwright https://github.com/TortugaResearch/Tortuga.Shipwright +155)Tortuga.Shipwright https://github.com/TortugaResearch/Tortuga.Shipwright Why I have not put example: too complicated for me, need help -157)ToString https://github.com/Burgyn/MMLib.ToString +156)ToString https://github.com/Burgyn/MMLib.ToString Why I have not put example: old ISourceGenerator -158)Transplator https://github.com/atifaziz/Transplator +157)Transplator https://github.com/atifaziz/Transplator Why I have not put example: old ISourceGenerator -159)TupleOverloadGenerator https://github.com/ProphetLamb/TupleOverloadGenerator +158)TupleOverloadGenerator https://github.com/ProphetLamb/TupleOverloadGenerator Why I have not put example: too complicated for me, need help -160)TxtToListGenerator https://github.com/musictopia2/TxtToListGenerator +159)TxtToListGenerator https://github.com/musictopia2/TxtToListGenerator Why I have not put example: no readme -161)TypealizR https://github.com/earloc/TypealizR +160)TypealizR https://github.com/earloc/TypealizR Why I have not put example: depends on Microsoft.Extensions.Localization -162)UnitTestBlazor https://github.com/bUnit-dev/bUnit +161)UnitTestBlazor https://github.com/bUnit-dev/bUnit Why I have not put example: issue opened -163)ValueChangedGenerator https://github.com/ufcpp/ValueChangedGenerator +162)ValueChangedGenerator https://github.com/ufcpp/ValueChangedGenerator Why I have not put example: old ISourceGenerator -164)ValueLink https://github.com/archi-Doc/ValueLink +163)ValueLink https://github.com/archi-Doc/ValueLink Why I have not put example: too complicated for me, need help -165)ValueObjectGenerator https://github.com/RyotaMurohoshi/ValueObjectGenerator +164)ValueObjectGenerator https://github.com/RyotaMurohoshi/ValueObjectGenerator Why I have not put example: old ISourceGenerator -166)VisitorPatternGenerator https://github.com/hikarin522/VisitorPatternGenerator/ +165)VisitorPatternGenerator https://github.com/hikarin522/VisitorPatternGenerator/ Why I have not put example: issue opened -167)Visor https://github.com/Tinkoff/Visor +166)Visor https://github.com/Tinkoff/Visor Why I have not put example: too complicated for me, need help -168)WrapperValueObject https://github.com/martinothamar/WrapperValueObject +167)WrapperValueObject https://github.com/martinothamar/WrapperValueObject Why I have not put example: not maintained as in readme -169)Xtz.StronglyTyped https://github.com/dev-experience/Xtz.StronglyTyped +168)Xtz.StronglyTyped https://github.com/dev-experience/Xtz.StronglyTyped Why I have not put example: old ISourceGenerator diff --git a/v2/rscg_examples_site/docs/RSCG-Examples/BitsKit.md b/v2/rscg_examples_site/docs/RSCG-Examples/BitsKit.md index 4951df3d2..ecc904c5f 100644 --- a/v2/rscg_examples_site/docs/RSCG-Examples/BitsKit.md +++ b/v2/rscg_examples_site/docs/RSCG-Examples/BitsKit.md @@ -472,5 +472,8 @@ namespace BitsDemo https://ignatandrei.github.io/RSCG_Examples/v2/docs/BitsKit -### In the same category (Bitwise) - 0 other generators +### In the same category (Bitwise) - 1 other generators + + +#### [Darp.BinaryObjects](/docs/Darp.BinaryObjects) diff --git a/v2/rscg_examples_site/docs/RSCG-Examples/Darp.BinaryObjects.md b/v2/rscg_examples_site/docs/RSCG-Examples/Darp.BinaryObjects.md new file mode 100644 index 000000000..1ea5f312c --- /dev/null +++ b/v2/rscg_examples_site/docs/RSCG-Examples/Darp.BinaryObjects.md @@ -0,0 +1,547 @@ +--- +sidebar_position: 1760 +title: 176 - Darp.BinaryObjects +description: Serialize bits of data +slug: /Darp.BinaryObjects +--- +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; +import TOCInline from '@theme/TOCInline'; + +# Darp.BinaryObjects by Ross Light GmbH + + + + +## Nuget / site data +[![Nuget](https://img.shields.io/nuget/dt/Darp.BinaryObjects?label=Darp.BinaryObjects)](https://www.nuget.org/packages/Darp.BinaryObjects/) +[![GitHub last commit](https://img.shields.io/github/last-commit/rosslight/Darp.BinaryObjects?label=updated)](https://github.com/rosslight/Darp.BinaryObjects) +![GitHub Repo stars](https://img.shields.io/github/stars/rosslight/Darp.BinaryObjects?style=social) + +## Details + +### Info +:::info + +Name: **Darp.BinaryObjects** + +A source generator to generate TryRead/Write Little/BigEndian methods for struct/class definitions for binary serialization. + +Author: Ross Light GmbH + +NuGet: +*https://www.nuget.org/packages/Darp.BinaryObjects/* + + +You can find more details at https://github.com/rosslight/Darp.BinaryObjects + +Source : https://github.com/rosslight/Darp.BinaryObjects + +::: + +### Original Readme +:::note + +
+ +# Darp.BinaryObjects + +[![NuGet](https://img.shields.io/nuget/v/Darp.BinaryObjects.svg)](https://www.nuget.org/packages/Darp.BinaryObjects) +[![Downloads](https://img.shields.io/nuget/dt/Darp.BinaryObjects)](https://www.nuget.org/packages/Darp.BinaryObjects) + +![Dotnet Version](https://img.shields.io/badge/dotnet-net8.0%20%7C%20net9.0-blue) +![Language Version](https://img.shields.io/badge/c%23-11-blue) + +[![Tests](https://github.com/rosslight/Darp.BinaryObjects/actions/workflows/test_and_publish.yml/badge.svg)](https://github.com/rosslight/Darp.BinaryObjects/actions/workflows/test_and_publish.yml) +![License](https://img.shields.io/github/license/rosslight/Darp.BinaryObjects) + +### A source generator to generate TryRead/Write Little/BigEndian methods for struct/class definitions. + +> [!IMPORTANT] +> This package is under heavy development. Anything is subject to change. + +
+You should use the source generation when you want: + +- Serialization to a buffer of bytes +- Deserialization from a buffer already completely received +- Endianness during serialization +- Common interfaces for serialization are required which allow to implement more complex scenarios by hand without the generator +- Usage of something like BinaryPrimitives but for more complex types +- Can work with a minimum c# LanguageVersion of 11 and net8.0 / net9.0 + +If these requirements do not meet your expectations, check out those other wonderful projects + +- Several binary serializers. e.g. [MemoryPack](https://github.com/Cysharp/MemoryPack), [BinaryPack](https://github.com/Sergio0694/BinaryPack), ... + which are great if direct binary serialization is not needed +- Serialization libraries relying on reflection. e.g. [HyperSerializer](https://github.com/adam-dot-cohen/HyperSerializer) +- [StructPacker](https://github.com/RudolfKurkaMs/StructPacker) - not supporting allocation less packing/unpacking +- [BinarySerializer](https://github.com/jefffhaynes/BinarySerializer?tab=readme-ov-file) - Allows for binary serialization with a way larger feature set but more difficult to understand and relying on reflection + +## Supported properties + +Here is a list of the property types currently supported by the library: + +- [x] Unmanaged types: `bool`, `sbyte`, `byte`, `short`, `ushort`, `int`, `uint`, `long`, `ulong`, `char`, `float`, `double` +- [x] BinaryObjects implementing `IWritable` or `IReadable` +- [ ] Blittable types +- [x] Enums +- [ ] Other .NET types: `BitArray` + +For all of these types, it should be possible to define as array types: +- [x] Memory abstractions: `ReadOnlyMemory` +- [x] Arrays: `T[]` +- [x] Lists: `List` +- [x] Collections: `IEnumerable`, `IReadOnlyCollection`, `ICollection`, `IReadOnlyList`, `IList` + +To control these types there are attributes +- [x] `BinaryIgnore`: Ignore some members +- [x] `BinaryElementCount`: Sets the number of elements in an array +- [ ] `BinaryReadRemaining`: Reads the remaining into an array +- [ ] `BinaryLength`: Sets the length of a member + +Unplanned: +- Unmanaged types have no clearly defined length / endianness: ~~`nint`~~, ~~`nuint`~~, ~~`decimal`~~ +- Multidimensional arrays (e.g. `T[,]`, `T[,,]`, etc.) +- Jagged arrays (e.g. `T[][]`, etc.) +- Dictionaries: `Dictionary`, `IDictionary` and `IReadOnlyDictionary` +- Nullable value types: `Nullable` or `T?` + +## What is serialized? + +- Any `real`, user-defined member in a `class` or `struct` declaration +- Any `field` or `auto property` which is settable or has a parameter with matching type and name in the constructor + +- If there are multiple constructors defined the one with a `BinaryConstructorAttribute` is being used + +There are warnings if: +- The constructor cannot be resolved +- There are multiple constructors but none with a `BinaryConstructorAttribute` +- A member is readonly and does not have a matching constructor argument or is explicitly ignored + +## How it's supposed to work + +Let's pretend we have a series of bytes: + +```csharp +01020003040506 + +A: 01 +B: 0200 +Data: 03040506 +``` + +We now want to read an object from these bytes similar to how we would do with `BinaryPrimitives`: + +```csharp +[BinaryObject] +public readonly record struct SomeTestStruct(byte A, ushort B, ReadOnlyMemory Data); +``` + +Normally, you would have to write serialization methods for yourself. By adding the `BinaryObjectAttribute`, this is done automatically by the source generator. + + +## Usage + +```csharp +// Define your object +[BinaryObject] +partial record struct YourStruct(ushort A, byte B); + +// Read the struct from the buffer using either little or big endian format +var buffer = Convert.FromHexString("AABBCC"); +var success = YourStruct.TryReadLittleEndian(source: buffer, out var value); +var success2 = YourStruct.TryReadBigEndian(source: buffer, out var value2, out int bytesRead); + +// Get the actual size of the struct +var size = value.GetByteCount(); + +// Write the values back to a buffer +var writeBuffer = new byte[size]; +var success3 = value.TryWriteLittleEndian(destination: writeBuffer); +var success4 = value2.TryWriteLittleEndian(destination: writeBuffer, out int bytesWritten); +``` + +The code generated by the struct will attempt to maximize readability by still maintaining performance and as little allocations as possible. + +
+ Generated code + +```csharp +// +#nullable enable + +using BinaryHelpers = global::Darp.BinaryObjects.BinaryHelpers; +using NotNullWhenAttribute = global::System.Diagnostics.CodeAnalysis.NotNullWhenAttribute; + +namespace Your.Namespace; + +/// +/// Field Byte Length +/// 2 +/// 1 +/// --- 3 +/// +public partial record struct YourStruct : global::Darp.BinaryObjects.IWritable, global::Darp.BinaryObjects.ISpanReadable +{ + /// + [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public int GetByteCount() => 3; + + /// + public bool TryWriteLittleEndian(global::System.Span destination) => TryWriteLittleEndian(destination, out _); + /// + public bool TryWriteLittleEndian(global::System.Span destination, out int bytesWritten) + { + bytesWritten = 0; + + if (destination.Length < 3) + return false; + BinaryHelpers.WriteUInt16LittleEndian(destination[0..], this.A); + BinaryHelpers.WriteUInt8(destination[2..], this.B); + bytesWritten += 3; + + return true; + } + /// + public bool TryWriteBigEndian(global::System.Span destination) => TryWriteBigEndian(destination, out _); + /// + public bool TryWriteBigEndian(global::System.Span destination, out int bytesWritten) + { + bytesWritten = 0; + + if (destination.Length < 3) + return false; + BinaryHelpers.WriteUInt16BigEndian(destination[0..], this.A); + BinaryHelpers.WriteUInt8(destination[2..], this.B); + bytesWritten += 3; + + return true; + } + + /// + public static bool TryReadLittleEndian(global::System.ReadOnlySpan source, out YourStruct value) => TryReadLittleEndian(source, out value, out _); + /// + public static bool TryReadLittleEndian(global::System.ReadOnlySpan source, out YourStruct value, out int bytesRead) + { + bytesRead = 0; + value = default; + + if (source.Length < 3) + return false; + var ___readA = BinaryHelpers.ReadUInt16LittleEndian(source[0..]); + var ___readB = BinaryHelpers.ReadUInt8(source[2..]); + bytesRead += 3; + + value = new YourStruct(___readA, ___readB); + return true; + } + /// + public static bool TryReadBigEndian(global::System.ReadOnlySpan source, out YourStruct value) => TryReadBigEndian(source, out value, out _); + /// + public static bool TryReadBigEndian(global::System.ReadOnlySpan source, out YourStruct value, out int bytesRead) + { + bytesRead = 0; + value = default; + + if (source.Length < 3) + return false; + var ___readA = BinaryHelpers.ReadUInt16BigEndian(source[0..]); + var ___readB = BinaryHelpers.ReadUInt8(source[2..]); + bytesRead += 3; + + value = new YourStruct(___readA, ___readB); + return true; + } +} +``` +
+ +## Development + +After cloning the repository, you will find the following project structure: + +- `src/Darp.BinaryObjects` contains public APIs and Attributes +- `src/Darp.BinaryObjects.Generator` contains the actual source generator +- `test/Darp.BinaryObjects.Tests` contains unit tests ensuring the generated files actually build and read/write as expected +- `test/Darp.BInaryObjects.Generator.Tests` contains snapshot tests to ensure the source generator generates valid files + +### Code formatting + +This repository uses [CSharpier](https://csharpier.com/) (inspired by prettier) for code formatting. +CSharpier should be installed automatically when building the solution as a local dotnet tool. + +To run it, execute +```shell +dotnet csharpier . +``` + +If you want to format you code on save, check out available [Editor integration](https://csharpier.com/docs/Editors) for your IDE. + +### Testing + +Snapshot tests are done using [Verify](https://github.com/VerifyTests/Verify/). If you want to optimize running these tests in your local IDE, you might adjust some settings. +Please, check your local configuration in the [VerifyDocs](https://github.com/VerifyTests/Verify/blob/main/docs/wiz/readme.md) + + +::: + +### About +:::note + +Serialize bits of data + + +::: + +## How to use + +### Example ( source csproj, source files ) + + + + + +This is the CSharp Project that references **Darp.BinaryObjects** +```xml showLineNumbers {18} + + + + Exe + net8.0 + enable + enable + + + + + true + $(BaseIntermediateOutputPath)\GX + + + + + + + + + +``` + + + + + + This is the use of **Darp.BinaryObjects** in *Program.cs* + +```csharp showLineNumbers +using BitsDemo; +using Darp.BinaryObjects; + +var z = new zlib_header(0x78, 0x9C); + +var size = z.GetByteCount(); + +// Write the values back to a buffer +var writeBuffer = new byte[size]; +if(z.TryWriteLittleEndian(writeBuffer)) +{ + Console.WriteLine("writing to buffer" ); + foreach (var item in writeBuffer) + { + Console.Write(item+" "); + } +} + +``` + + + + + This is the use of **Darp.BinaryObjects** in *BitStruct.cs* + +```csharp showLineNumbers +using Darp.BinaryObjects; +using System.IO.Compression; + +namespace BitsDemo; + +[BinaryObject] +partial record zlib_header(byte cmf, byte flg) +{ + +} +``` + + + + +### Generated Files + +Those are taken from $(BaseIntermediateOutputPath)\GX + + + + + + + +```csharp showLineNumbers +// +#nullable enable + +namespace BitsDemo +{ + /// + /// Field Byte Length + /// 1 + /// 1 + /// --- 2 + /// + partial record zlib_header : global::Darp.BinaryObjects.IWritable, global::Darp.BinaryObjects.ISpanReadable + { + /// + [global::System.Diagnostics.Contracts.Pure] + [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Darp.BinaryObjects.Generator", "0.4.0.0")] + public int GetByteCount() => 2; + + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Darp.BinaryObjects.Generator", "0.4.0.0")] + public bool TryWriteLittleEndian(global::System.Span destination) => TryWriteLittleEndian(destination, out _); + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Darp.BinaryObjects.Generator", "0.4.0.0")] + public bool TryWriteLittleEndian(global::System.Span destination, out int bytesWritten) + { + bytesWritten = 0; + + if (destination.Length < 2) + return false; + global::Darp.BinaryObjects.Generated.Utilities.WriteUInt8(destination[0..], this.cmf); + global::Darp.BinaryObjects.Generated.Utilities.WriteUInt8(destination[1..], this.flg); + bytesWritten += 2; + + return true; + } + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Darp.BinaryObjects.Generator", "0.4.0.0")] + public bool TryWriteBigEndian(global::System.Span destination) => TryWriteBigEndian(destination, out _); + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Darp.BinaryObjects.Generator", "0.4.0.0")] + public bool TryWriteBigEndian(global::System.Span destination, out int bytesWritten) + { + bytesWritten = 0; + + if (destination.Length < 2) + return false; + global::Darp.BinaryObjects.Generated.Utilities.WriteUInt8(destination[0..], this.cmf); + global::Darp.BinaryObjects.Generated.Utilities.WriteUInt8(destination[1..], this.flg); + bytesWritten += 2; + + return true; + } + + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Darp.BinaryObjects.Generator", "0.4.0.0")] + public static bool TryReadLittleEndian(global::System.ReadOnlySpan source, [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out zlib_header? value) => TryReadLittleEndian(source, out value, out _); + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Darp.BinaryObjects.Generator", "0.4.0.0")] + public static bool TryReadLittleEndian(global::System.ReadOnlySpan source, [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out zlib_header? value, out int bytesRead) + { + bytesRead = 0; + value = default; + + if (source.Length < 2) + return false; + var ___readcmf = global::Darp.BinaryObjects.Generated.Utilities.ReadUInt8(source[0..1]); + var ___readflg = global::Darp.BinaryObjects.Generated.Utilities.ReadUInt8(source[1..2]); + bytesRead += 2; + + value = new zlib_header(___readcmf, ___readflg); + return true; + } + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Darp.BinaryObjects.Generator", "0.4.0.0")] + public static bool TryReadBigEndian(global::System.ReadOnlySpan source, [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out zlib_header? value) => TryReadBigEndian(source, out value, out _); + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Darp.BinaryObjects.Generator", "0.4.0.0")] + public static bool TryReadBigEndian(global::System.ReadOnlySpan source, [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out zlib_header? value, out int bytesRead) + { + bytesRead = 0; + value = default; + + if (source.Length < 2) + return false; + var ___readcmf = global::Darp.BinaryObjects.Generated.Utilities.ReadUInt8(source[0..1]); + var ___readflg = global::Darp.BinaryObjects.Generated.Utilities.ReadUInt8(source[1..2]); + bytesRead += 2; + + value = new zlib_header(___readcmf, ___readflg); + return true; + } + } +} + +namespace Darp.BinaryObjects.Generated +{ + using Darp.BinaryObjects; + using System; + using System.Buffers.Binary; + using System.CodeDom.Compiler; + using System.Collections.Generic; + using System.Runtime.CompilerServices; + using System.Runtime.InteropServices; + + /// Helper methods used by generated BinaryObjects. + [GeneratedCodeAttribute("Darp.BinaryObjects.Generator", "0.4.0.0")] + file static class Utilities + { + /// Writes a byte to the destination + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void WriteUInt8(Span destination, byte value) + { + destination[0] = value; + } + /// Reads a byte from the given source + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static byte ReadUInt8(ReadOnlySpan source) + { + return source[0]; + } + } +} + +``` + + + + + + +## Usefull + +### Download Example (.NET C# ) + +:::tip + +[Download Example project Darp.BinaryObjects ](/sources/Darp.BinaryObjects.zip) + +::: + + +### Share Darp.BinaryObjects + + + +https://ignatandrei.github.io/RSCG_Examples/v2/docs/Darp.BinaryObjects + +### In the same category (Bitwise) - 1 other generators + + +#### [BitsKit](/docs/BitsKit) + diff --git a/v2/rscg_examples_site/docs/RSCG-Examples/index.md b/v2/rscg_examples_site/docs/RSCG-Examples/index.md index b623525e5..63422e25f 100644 --- a/v2/rscg_examples_site/docs/RSCG-Examples/index.md +++ b/v2/rscg_examples_site/docs/RSCG-Examples/index.md @@ -1,7 +1,7 @@ --- sidebar_position: 30 -title: 175 RSCG list by category -description: 175 RSCG list by category +title: 176 RSCG list by category +description: 176 RSCG list by category slug: /rscg-examples --- @@ -89,12 +89,17 @@ import DocCardList from '@theme/DocCardList'; ## Bitwise
- Expand Bitwise =>examples:1 + Expand Bitwise =>examples:2 [BitsKit](/docs/BitsKit) + + + +[Darp.BinaryObjects](/docs/Darp.BinaryObjects) +
@@ -1117,6 +1122,8 @@ flowchart LR; Bitwise--> BitsKit((BitsKit)) + Bitwise--> Darp.BinaryObjects((Darp.BinaryObjects)) + Blazor--> Blazorators((Blazorators)) Blazor--> GoLive.Generator.BlazorInterop((GoLive.Generator.BlazorInterop)) diff --git a/v2/rscg_examples_site/docs/about.md b/v2/rscg_examples_site/docs/about.md index 7bb96975b..8642696a3 100644 --- a/v2/rscg_examples_site/docs/about.md +++ b/v2/rscg_examples_site/docs/about.md @@ -6,7 +6,7 @@ title: About ## Content You will find here code examples -of 175 Roslyn Source Code Generator (RSCG) +of 176 Roslyn Source Code Generator (RSCG) that can be useful for you. That means, you will write more elegant and concise code - even if the generators code is not always nice to look. ## Are those examples ready for production? diff --git a/v2/rscg_examples_site/docs/indexRSCG.md b/v2/rscg_examples_site/docs/indexRSCG.md index fd99cccb6..532dbf56d 100644 --- a/v2/rscg_examples_site/docs/indexRSCG.md +++ b/v2/rscg_examples_site/docs/indexRSCG.md @@ -10,9 +10,9 @@ import useBaseUrl from '@docusaurus/useBaseUrl';