https://github.com/bonnyad9/bny.rawbytes
C# library for converting from and to binary data using attributes.
https://github.com/bonnyad9/bny.rawbytes
attributes binary-data csharp csharp-library library
Last synced: 10 months ago
JSON representation
C# library for converting from and to binary data using attributes.
- Host: GitHub
- URL: https://github.com/bonnyad9/bny.rawbytes
- Owner: BonnyAD9
- License: mit
- Created: 2022-08-24T17:26:07.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-01-26T21:47:43.000Z (over 3 years ago)
- Last Synced: 2025-03-03T07:17:18.256Z (about 1 year ago)
- Topics: attributes, binary-data, csharp, csharp-library, library
- Language: C#
- Homepage: https://bonnyad9.github.io/Bny.RawBytes/
- Size: 436 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Bny.RawBytes
C# library for converting from and to bytes. Without the boring repetition.
## In this repository
- **Bny.RawBytes:** the library
- **Bny.RawBytes.Tester:** unit tests
## How to use
### Code
```csharp
using Bny.RawBytes;
var arr = new byte[] { 0, 2, 0, 0, 0, 2, 0, 0 };
// convert bytes (arr) to BinaryTest, the default byte order will be big-endian
Console.WriteLine(Bytes.To(arr, Endianness.Big));
[BinaryObject] // mark this as binary object
class BinaryTest
{
// properties and fields with the BinaryMember attribute
// will be readed in the same order in which they are written in code
// or you can specify your own order with the Order property
// Width will be readed first and always in little endian byte order
[BinaryMember(endianness: Endianness.Little)]
public int Width { get; init; }
// Second will be readed height in the default byte order (big-endian in this case)
[BinaryMember]
public int Height { get; init; }
// members without the attribute are ignored
public int Size => Width * Height;
public override string ToString() => $"[{Size}({Width} * {Height})]";
}
```
### Output
```
[67108864(512 * 131072)]
```
## How to get it
- This library is available as [NuGet Package](https://www.nuget.org/packages/Bny.RawBytes/)
## Links
- **Author:** [BonnyAD9](https://github.com/BonnyAD9)
- **GitHub repository:** [Bny.RawBytes](https://github.com/BonnyAD9/Bny.RawBytes)
- **Documentation:** [Doxygen](https://bonnyad9.github.io/Bny.RawBytes/)
- **My Website:** [bonnyad9.github.io](https://bonnyad9.github.io/)
- **NuGetPackage:** [Bny.RawBytes](https://www.nuget.org/packages/Bny.RawBytes/)