Home

Awesome

<div align="right"> <table> <td aligh="right"> <p></p> <sup>⭐ Your star is the light at the end of our tunnel.<br> Lead us out of the darkness by starring <a href="https://github.com/alec1o/Byter">Byter on GitHub</a>.<br> Star me please, I beg you! πŸ’™</sup> </td> </table> </div> <br> <h1 align="center"><a href="https://github.com/alec1o/Byter">Byter</a></h1> <h6 align="center"><sub> powered by <a href="https://github.com/alec1o">ALEC1O</a><sub/> </h6> <div align="center"> <a href="#"> <img align="center" src="static/logo/Byter-logo-512/sprite_1.png" width="128px" alt="byter logo"> </a> </div>
Project

<sub>Get basic information about this project called Byter</sub>

<table> <tr> <th align="center" valign="center"><sub><strong>Overview</strong></sub></th> <td> <br> <sub><i><strong>Byter</strong></i> is a C# serialization library for primitive data types, including booleans, numbers, chars, enums, strings, DateTime, BigInteger, bytes, and complex types like classes, structs, arrays, and lists, supporting unlimited complexity and depth.</sub> <br> <br> </td> </tr> <tr> <th align="center" valign="center"><sub><strong>Website</strong></sub></th> <td> <br> <sub>Repository: <a href="https://github.com/alec1o/Byter"><i>github.com/alec1o/byter</i></a></sub><br> <br> </td> </tr> <tr> <th align="center" valign="center"><sub><strong>Contributions</strong></sub></th> <td> <br> <sub>

Thanks a lot <3 <br><br>

<div> <img src="https://github.com/vanhaodev.png" width="24" height="24"> <a href="https://github.com/vanhaodev">@vanhaodev</a> &nbsp; <img src="https://github.com/nvh2001.png" width="24" height="24" style="border-radius:50%"> <a href="https://github.com/nvh2001">@nvh2001</a> </div> </sup> <br> </td> </tr> </table> <br>
Installing

<sub>Official publisher</sub>

<table> <tr> <th valign="center" align="center"><sub>Nuget</sub></th> <th valign="center" align="center"><sub>.NET CLI</sub></th> <th valign="center" align="center"><sub>Netly</sub></th> </tr> <tr> <td valign="top" align="left"> <h6><sup>Install on <a href="https://www.nuget.org/packages/Byter">Nuget</a></sup></h6> </td> <td valign="top" align="left">
dotnet add package Byter --version 4.0.0
</td> <td valign="top" align="left"> <h6><sup>Embedded, <a href="https://github.com/alec1o/Netly">Since version 2.x.x</a></sup></h6> </td> </tr> </table> <br>
Versions

<sub>Notable changes</sub>

<table> <tr> <!-- title --> <th><sub>v1.x.x</sub></th> <th><sub>v2.x.x</sub></th> <th><sub>v3.x.x</sub></th> <th><sub>v4x.x</sub></th> </tr> <tr> <!-- status --> <td valign="center" align="center"><sup><sub><i>Stable</i></sub></sup></td> <td valign="center" align="center"><sup><sub><i>Stable</i></sub></sup></td> <td valign="center" align="center"><sup><sub><i>Stable</i></sub></sup></td> <td valign="center" align="center"><sup><sub><i>Stable</i></sub></sup></td> </tr> <tr> <!-- row #1 --> <td valign="top" align="left"> <sub> <i>Main (Reader & Writer)</i> Types: <br> &nbsp; <code>byte</code> &nbsp; <code>bool</code> &nbsp; <code>byte[]</code> <br> &nbsp; <code>short</code> &nbsp; <code>ushort</code> &nbsp; <code>int</code> <br> &nbsp; <code>uint</code> &nbsp; <code>long</code> &nbsp; <code>ulong</code> <br> &nbsp; <code>float</code> &nbsp; <code>double</code> &nbsp; <code>char</code> <br> &nbsp; <code>string</code> </sub> </td> <td valign="top" align="left"> <sub> New <i>(Reader & Writer)</i> Types: <br>&emsp;<code>Float2</code> (Vector2) <br>&emsp;<code>Float3</code> (Vector3) <br>&emsp;<code>Float4</code> (Vector4 / Quaternion) </sub> </td> <td valign="top" align="left"> <sub> Bug Fix. <i><strong>(Reader & Writer)</strong></i> <br><br>Support: <i><strong>*Primitive</strong></i> <br><br>New usage paradigms <i><strong>*Primitive</strong></i> <br><br>*Primitive Types: <br> &nbsp; <code>bool</code> &nbsp; <code>byte</code> <br> &nbsp; <code>char</code> &nbsp; <code>short</code> &nbsp; <code>ushort</code> <br> &nbsp; <code>int</code> &nbsp; <code>uint</code> &nbsp; <code>float</code> <br> &nbsp; <code>long</code> &nbsp; <code>byte[]</code> &nbsp; <code>ulong</code> &nbsp; <code>double</code> <br> &nbsp; <code>string</code> <br> &nbsp;&nbsp;&nbsp;<i>*highlights</i> <br> &nbsp; <code>enum*</code> &nbsp; <code>sbyte*</code> &nbsp; <code>DateTime*</code> <br> &nbsp; <code>decimal*</code> &nbsp; <code>class*</code> &nbsp; <code>struct*</code> <br> &nbsp; <code>array*</code> &nbsp; <code>list*</code> &nbsp; <code>BigInteger*</code> </sub> </td> <td valign="top" align="left"> <sub> Bug Fix. <i><strong>(Primitive & Extension)</strong></i> <br><br>Support: <i><strong>*Concat Bytes</strong></i> <br><br>Fix. <i>Compilation warning.</i> </sub> </td> </tr> <tr> <!-- row #2 --> <td valign="top" align="left"><sub>Used by. <a href="https://github.com/alec1o/Netly">Netly v2</a></sub></td> <td valign="top" align="left"><sub>Used by. <a href="https://github.com/alec1o/Netly">Netly v3</a></sub></td> <td valign="top" align="left"><sub>Used by. <a href="https://github.com/alec1o/Netly">Netly v4</a></sub> <sup><i>(under dev stage)</i></sup></td> <td valign="top" align="left"><sub>Used by. <a href="https://github.com/alec1o/Netly">Netly v4</a></sub></td> </tr> </table> <br>
Usage

<sub>Integration and interaction example codes</sub>

<table> <tr> <th align="center" valign="top"><sub><strong>v1.x.x<br>v2.x.x</strong></sub></th> <td> <details><summary>πŸ“„ <strong><sup><sub>Writer</sub></sup></strong></summary>

Constructor

Proprieties

Methods

</details> <details><summary>πŸ“„ <strong><sup><sub>Reader</sub></sup></strong></summary>

Constructor

Proprieties

Methods

</details> <details><summary>πŸ“„ <strong><sup><sub>Example</sub></sup></strong></summary> </details> </td> </tr> <tr><th></th></tr> <tr> <th align="center" valign="top"><sub><strong>v3.x.x</strong></sub></th> <td> <details><summary>πŸ“„ <strong><sup><sub>Primitive</sub></sup></strong></summary>

Constructor

Proprieties

Methods

</details> <details><summary>πŸ“„ <strong><sup><sub>IPrimitiveAdd</sub></sup></strong></summary>

Methods

</details> <details><summary>πŸ“„ <strong><sup><sub>IPrimitiveGet</sub></sup></strong></summary>

Methods

</details> <details><summary>πŸ“„ <strong><sup><sub>Example</sub></sup></strong></summary> </details> </td> </tr> </table> <br>
Overhead <sup><i>(supported types list)</i></sup>

<sub>Byter overhead information</sub>

<sub>Type</sub><sub>Primitive <i>(overhead + size = total)</i></sub><sub>Writer/Reader <i>(overhead + size = total)</i></sub>
<sub>Bool</sub>βœ”οΈ <i>(1 + 1 = 2 bytes)</i>βœ”οΈ <i>(2 + 1 = 3 bytes)</i>
<sub>Byte</sub>βœ”οΈ <i>(1 + 1 = 2 bytes)</i>βœ”οΈ <i>(2 + 1 = 3 bytes)</i>
<sub>SByte</sub>βœ”οΈ <i>(1 + 2 = 2 bytes)</i>🚫
<sub>Char</sub>βœ”οΈ <i>(1 + 2 = 3 bytes)</i>βœ”οΈ <i>(2 + 2 = 4 bytes)</i>
<sub>Short</sub>βœ”οΈ <i>(1 + 2 = 3 bytes)</i>βœ”οΈ <i>(2 + 2 = 4 bytes)</i>
<sub>UShort</sub>βœ”οΈ <i>(1 + 2 = 3 bytes)</i>βœ”οΈ <i>(2 + 2 = 4 bytes)</i>
<sub>Int</sub>βœ”οΈ <i>(1 + 4 = 5 bytes)</i>βœ”οΈ <i>(2 + 4 = 6 bytes)</i>
<sub>UInt</sub>βœ”οΈ <i>(1 + 4 = 5 bytes)</i>βœ”οΈ <i>(2 + 4 = 6 bytes)</i>
<sub>Float</sub>βœ”οΈ <i>(1 + 4 = 5 bytes)</i>βœ”οΈ <i>(2 + 4 = 6 bytes)</i>
<sub>Enum</sub>βœ”οΈ <i>(1 + 4 = 5 bytes)</i>🚫
<sub>Long</sub>βœ”οΈ <i>(1 + 8 = 9 bytes)</i>βœ”οΈ <i>(2 + 8 = 10 bytes)</i>
<sub>ULong</sub>βœ”οΈ <i>(1 + 8 = 9 bytes)</i>βœ”οΈ <i>(2 + 8 = 10 bytes)</i>
<sub>Double</sub>βœ”οΈ <i>(1 + 8 = 9 bytes)</i>βœ”οΈ <i>(2 + 8 = 10 bytes)</i>
<sub>DateTime</sub>βœ”οΈ <i>(1 + 8 = 9 bytes)</i>🚫
<sub>Decimal</sub>βœ”οΈ <i>(1 + 16 = 17 bytes)</i>🚫
<sub>String</sub>βœ”οΈ <i>(5 + ? = <sup>+</sup>5 bytes)</i> <sup>*UTF8</sup>βœ”οΈ <i>(6 + ? = <sup>+</sup>6 bytes)</i>
<sub>Class</sub>βœ”οΈ <i>(2 + 0 = 2 bytes)</i>🚫
<sub>Struct</sub>βœ”οΈ <i>(2 + 0 = 2 bytes)</i>🚫
<sub>Array</sub>βœ”οΈ <i>(3 + ? = <sup>+</sup>3 bytes)</i> <sup>*Max. 65535</sup>🚫
<sub>List</sub>βœ”οΈ <i>(3 + ? = <sup>+</sup>3 bytes)</i> <sup>*Max. 65535</sup>🚫
<sub>BigInteger</sub>βœ”οΈ <i>(3 + ? = <sup>+</sup>3 bytes)</i>🚫
<sub>Bytes</sub>βœ”οΈ <i>(5 + ? = <sup>+</sup>5 bytes)</i> <sup>*Max. 4.294.967.295 *(~4billions)</sup>βœ”οΈ <i>(6 + ? = <sup>+</sup>6 bytes)</i> <sup>*Max. 2.147.483.647 *(~2billions)</sup>
<br>

Encoding Extension

using Byter;
<details> <summary>Legacy Docs <i>(v1.x.x - v2.x.x)</i></summary>

Byter

Byter is a bytes serializer. It can serialize and deserialize from primitive type.

Byter is very stable, super easy to learn, extremely fast and inexpensive (2 bytes or sizeof(char) of overhead per data written) and 100% written in C# and it's FREE!

<br><hr><br>

Install

<br><hr/>

Usage

Namespace

using Byter

Types

[
    `byte`,
    `bool`,
    `byte[]`,
    `short`,
    `ushort`,
    `int`,
    `uint`,
    `long`,
    `ulong`,
    `float`,
    `double`,
    `char`,
    `string`,
    `Float2`(Vector2),
    `Float3`(Vector3),
    `Float4`(Vector4 / Quaternion),
]
<hr/>

Writer

Constructor

_ = new Writer();                          // Create default instance
_ = new Writer(new Writer());              // Create instance and copy from existing Writer
_ = new Writer(ref new Writer());          // Create instance and copy from existing Writer (using ref)
<br>

Proprietary

<br/>

Methods

<hr>

Reader

Constructor

_ = new Reader(new Writer());               // Create instance and copy buffer from existing Writer
_ = new Reader(ref new Writer());           // Create instance and copy buffer from existing Writer (ref Writer)
_ = new Reader(new byte[] { 1, 1, 1, 1 });  // Create instance from buffer (bytes (byte[]))
<br/>

Proprietary

<br/>

Methods

<br/><hr/><br/>

Sample

using Byter;

// writing
Writer writer = new();

writer.Write(1000); // index
writer.Write("{JSON}"); // content
writer.Write(new byte[]{ 1, 1, 1, 1 }); // image

// geting buffer
byte[] buffer = writer.GetBytes();
writer.Dispose(); // Destroy Writer

// reading
Reader reader = new(buffer);

int index = reader.Read<int>();
string json = reader.Read<string>();
byte[] image = reader.Read<byte[]>();

// Check error
if (!reader.Success) // IS FALSE
{
    Console.WriteLine("*** ERROR ****");
    return;
}

// Check success
Console.WriteLine("*** SUCCESS ****");      

// Output
Console.WriteLine($"Index: {index}");           // output: 1000
Console.WriteLine($"JSON : {json }");           // output: JSON
Console.WriteLine($"Image: {image.Length}");    // output: 4
Console.WriteLine($"Status: {reader.Success}"); // output: True

// Making error
float delay = reader.Read<float>();
                                                                                            /*
WARNING:                
if you reverse the reading order or try to read more data than added (Reader.Succes = False),
Remembering does not return exception when trying to read data that does not exist it just
returns the default construction, and (Reader.Success) will be assigned (False)             */

if (reader.Success)  // IS FALSE, THE IS NOT WRITED IN BUFFER
    Console.WriteLine($"Delay: {delay}");
else                // IS TRUE, THE DELAY NOT EXIST
    Console.WriteLine($"Delay not exist");

// Output of status
Console.WriteLine($"Status: {reader.Success}"); // output: False

reader.Dispose(); // Destroy Reader

<br/><hr/><br/>

Install using git submodule

# Install - recommend a stable branch e.g. "1.x" or use a fork repository, --depth clone last sources
git submodule add --name byter --depth 1 --branch main "https://github.com/alec1o/byter" vendor/byter

# Rebuilding - Download repository and link it in file location, must add this step in dotnet.yaml if using
git submodule update --init

# Update submodule - Update and load new repository updates
git submodule update --remote

# PATH
# |__ vendor
# |   |__ byter
# |      |__ src
# |        |__ Byter.csproj
# |
# |__ app
# |   |__ app.csproj
# |
# |__ app.sln
# |__ .git
# |__ .gitignore
# |__ .gitmodules

# .NET link on .sln
cd <PATH>
dotnet sln add vendor/byter/src/Byter.csproj

# .NET link on .csproj
cd app/
dotnet add reference ../vendor/byter/src/Byter.csproj

# Rebuild dependencies to be linked in the project
dotnet restore
</details> <br>