β Your star is the light at the end of our tunnel. Lead us out of the darkness by starring Byter on GitHub. Star me please, I beg you! π |
Get basic information about this project called Byter
Overview |
Byter 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. |
---|---|
Website |
Repository: github.com/alec1o/byter |
Official publisher
Nuget | .NET CLI | Netly |
---|---|---|
Install on Nuget |
```rb dotnet add package Byter --version 3.0.0 ``` |
Embedded, Since version 2.x.x |
Notable changes
v1.x.x | v2.x.x | v3.x.x |
---|---|---|
Stable | Stable | Stable |
Main (Reader & Writer) Types:
byte
bool
byte[]
short
ushort
int
uint
long
ulong
float
double
char
string
|
New (Reader & Writer) Types:
Float2 (Vector2)
Float3 (Vector3)
Float4 (Vector4 / Quaternion)
|
Bug Fix. (Reader & Writer)
Support: *Primitive New usage paradigms *Primitive *Primitive Types: bool
byte
char
short
ushort
int
uint
float
long
byte[]
ulong
double
string
*highlights enum*
sbyte*
DateTime*
decimal*
class*
struct*
array*
list*
BigInteger*
|
Used by. Netly v2 | Used by. Netly v3 | Used by. Netly v4 |
Integration and interaction example codes
v1.x.x v2.x.x |
π Writer### Constructor - ###### () : ``Writer``Create instance with empty internal buffer - ###### (``Writer`` writer) : ``Writer`` Create instance and copy buffer of (Writer) as internal buffer - ###### (ref ``Writer`` writer) : ``Writer`` Create instance and copy buffer of (ref Writer) as internal buffer ### Proprieties - ###### Length : ``int`` Return buffer length. ### Methods - ###### Write(T value) : ``void`` Write content in internal buffer - ###### GetBytes() : ``byte[]`` Return buffer from (Writer) instance as byte[]) - ###### GetList() : ``List Return buffer from (Writer) instance as List<byte> - ###### Clear(): ``void`` Clear internal buffer from (Writer) instance π Reader### Constructor - ###### (``byte[]`` buffer) : ``Reader``Create instance using (Byte[]) as internal buffer - ###### (``Writer`` writer) : ``Reader`` Create instance using (Writer) as internal buffer - ###### (ref ``Writer`` writer) : ``Reader`` Create instance using (ref Writer) as internal buffer ### Proprieties - ###### Success : ``bool`` Return true if deserialized successful. - ###### Position : ``int`` Return current read index. - ###### Length : ``int`` Return buffer length. ### Methods - ###### Seek(``int`` position) : ``void`` Move position (internal buffer index) - ###### Read<``T``>() : ``T`` Read content from iternal buffer. - ###### Read<``string``>(``Encoding`` encoding) : ``string`` Read custom encoding string. π Example- ###### Writer ```csharp using Byter; Writer w = new(); // write data w.Write("Powered by ALEC1O"); w.Write("η± ALEC1O ζδΎζ―ζ", Encoding.UTF32); w.Write((int)1000000);` // 1.000.000 w.Write((char)'A'); w.Write((long)-1000000000); // -100.0000.000 w.Write((byte[])[0, 1, 2, 3]); // Float(1|2|3) only available in version 2 w.Write(new Float2(-100F, 300F)); w.Write(new Float3(-100F, 300F, 600F)); w.Write(new Float4(-100F, 300F, 600F, 900F)); // get buffer byte[] buffer = w.GetBytes(); // example send buffer Magic.Send(buffer); ``` - ###### Reader ```csharp using Byter; // example receive buffer byte[] buffer = Magic.Receive(); // create instance Reader r = new() // read data string noticeInEnglish = r.Read |
---|---|
v3.x.x |
π Primitive### Constructor - ###### () : ``Primitive``Create instance with empty internal buffer - ###### (``byte[]`` buffer) : ``Primitive`` Create instance using (Byte[]) as internal buffer ### Proprieties - ###### Position : ``int`` Return internal reading index/position. - ###### IsValid : ``bool`` Return (true) if data was read successful. otherwise (false) - ###### Add : ``IPrimitiveAdd`` Object used to (read/get) content from internal (Primitive) buffer - ###### Get : ``IPrimitiveGet`` Object used to (write/add) content in internal (Primitive) buffer ### Methods - ###### GetBytes() : ``byte[]`` Return buffer from (Primitive) instance as byte[]) - ###### GetList() : ``List Return buffer from (Primitive) instance as List<byte> - ###### Reset(): ``void`` Clear internal buffer from (Primitive) instance π IPrimitiveAdd### Methods - ###### Bool(``bool`` value) ``void``(Write/Add) element typeof(bool) in internal buffer - ###### Byte(``byte`` value) ``void`` (Write/Add) element typeof(byte) in internal buffer - ###### SByte(``sbyte`` value) ``void`` (Write/Add) element typeof(sbyte) in internal buffer - ###### Char(``char`` value) ``void`` (Write/Add) element typeof(char) in internal buffer - ###### Short(``short`` value) ``void`` (Write/Add) element typeof(short) in internal buffer - ###### UShort(``ushort`` value) ``void`` (Write/Add) element typeof(ushort) in internal buffer - ###### Int(``int`` value) ``void`` (Write/Add) element typeof(int) in internal buffer - ###### UInt(``uint`` value) ``void`` (Write/Add) element typeof(uint) in internal buffer - ###### Float(``float`` value) ``void`` (Write/Add) element typeof(float) in internal buffer - ###### Enum<``T``>(``T`` value) ``void`` (Write/Add) element typeof(enum) in internal buffer - ###### Long(``long`` value) ``void`` (Write/Add) element typeof(long) in internal buffer - ###### ULong(``ulong`` value) ``void`` (Write/Add) element typeof(ulong) in internal buffer - ###### Double(``double`` value) ``void`` (Write/Add) element typeof(double) in internal buffer - ###### DateTime(``DateTime`` value) ``void`` (Write/Add) element typeof(DateTime) in internal buffer - ###### Decimal(``decimal`` value) ``void`` (Write/Add) element typeof(decimal) in internal buffer - ###### String(``string`` value) ``void`` (Write/Add) element typeof(string) in internal buffer - ###### Class<``T``>(``T`` value) ``void`` (Write/Add) element typeof(T) in internal buffer - ###### Struct<``T``>(``T`` value) ``void`` (Write/Add) element typeof(T) in internal buffer - ###### Array<``T``>(``T`` value) ``void`` (Write/Add) element typeof(T[]) in internal buffer - ###### List<``T``>(``List (Write/Add) element typeof(List (Write/Add) element typeof(BigInteger) in internal buffer - ###### Bytes(``byte[]`` value) ``void`` (Write/Add) element typeof(byte[]) in internal buffer π IPrimitiveGet### Methods - ###### Bool() ``bool``(Read/Get) element typeof(bool) from internal buffer - ###### Byte() ``byte`` (Read/Get) element typeof(byte) from internal buffer - ###### SByte() ``sbyte`` (Read/Get) element typeof(sbyte) from internal buffer - ###### Char() ``char`` (Read/Get) element typeof(char) from internal buffer - ###### Short() ``short`` (Read/Get) element typeof(short) from internal buffer - ###### UShort() ``ushort`` (Read/Get) element typeof(ushort) from internal buffer - ###### Int() ``int`` (Read/Get) element typeof(int) from internal buffer - ###### UInt() ``uint`` (Read/Get) element typeof(uint) from internal buffer - ###### Float() ``float`` (Read/Get) element typeof(float) from internal buffer - ###### Enum<``T``>() ``T`` (Read/Get) element typeof(enum) from internal buffer - ###### Long() ``long`` (Read/Get) element typeof(long) from internal buffer - ###### ULong() ``ulong`` (Read/Get) element typeof(ulong) from internal buffer - ###### Double() ``double`` (Read/Get) element typeof(double) from internal buffer - ###### DateTime() ``DateTime`` (Read/Get) element typeof(DateTime) from internal buffer - ###### Decimal() ``decimal`` (Read/Get) element typeof(decimal) from internal buffer - ###### String() ``string`` (Read/Get) element typeof(string) from internal buffer - ###### Class<``T``> () ``T`` (Read/Get) element typeof(T) from internal buffer - ###### Struct<``T``>() ``T`` (Read/Get) element typeof(T) from internal buffer - ###### Array<``T``>() ``T[]`` (Read/Get) element typeof(T[]) from internal buffer - ###### List<``T``>() ``List (Read/Get) element typeof(List (Read/Get) element typeof(BigInteger) from internal buffer - ###### Bytes() ``byte[]`` (Read/Get) element typeof(byte[]) from internal buffer π Example- ###### Add Element ```csharp using Byter; Primitive primitive = new(); // write elements primitive.Add.Class(myCharacterInfoClass); primitive.Add.Array(myCharacterArray); primitive.Add.List(myLogList); primitive.Add.Struct(myDeviceStruct); primitive.Add.DateTime(DateTime.UtcNow); primitive.Add.Enum(MyEnum.Option1); primitive.Add.Bytes(myImageBuffer); // send buffer byte[] buffer = primitive.GetBytes(); Magic.Send(buffer); // EXAMPLE! ``` - ###### Get Element ```csharp using Byter; // receive bugger byte[] buffer = Magic.Receive(); // EXAMPLE! Primitive primitive = new(buffer); // read elements var myCharacterInfoClass = primitive.Get.Class |
Byter overhead information
Type | Primitive (overhead + size = total) | Writer/Reader (overhead + size = total) |
---|---|---|
Bool | βοΈ (1 + 1 = 2 bytes) | βοΈ (2 + 1 = 3 bytes) |
Byte | βοΈ (1 + 1 = 2 bytes) | βοΈ (2 + 1 = 3 bytes) |
SByte | βοΈ (1 + 2 = 2 bytes) | π« |
Char | βοΈ (1 + 2 = 3 bytes) | βοΈ (2 + 2 = 4 bytes) |
Short | βοΈ (1 + 2 = 3 bytes) | βοΈ (2 + 2 = 4 bytes) |
UShort | βοΈ (1 + 2 = 3 bytes) | βοΈ (2 + 2 = 4 bytes) |
Int | βοΈ (1 + 4 = 5 bytes) | βοΈ (2 + 4 = 6 bytes) |
UInt | βοΈ (1 + 4 = 5 bytes) | βοΈ (2 + 4 = 6 bytes) |
Float | βοΈ (1 + 4 = 5 bytes) | βοΈ (2 + 4 = 6 bytes) |
Enum | βοΈ (1 + 4 = 5 bytes) | π« |
Long | βοΈ (1 + 8 = 9 bytes) | βοΈ (2 + 8 = 10 bytes) |
ULong | βοΈ (1 + 8 = 9 bytes) | βοΈ (2 + 8 = 10 bytes) |
Double | βοΈ (1 + 8 = 9 bytes) | βοΈ (2 + 8 = 10 bytes) |
DateTime | βοΈ (1 + 8 = 9 bytes) | π« |
Decimal | βοΈ (1 + 16 = 17 bytes) | π« |
String | βοΈ (5 + ? = +5 bytes) *UTF8 | βοΈ (6 + ? = +6 bytes) |
Class | βοΈ (2 + 0 = 2 bytes) | π« |
Struct | βοΈ (2 + 0 = 2 bytes) | π« |
Array | βοΈ (3 + ? = +3 bytes) *Max. 65535 | π« |
List | βοΈ (3 + ? = +3 bytes) *Max. 65535 | π« |
BigInteger | βοΈ (3 + ? = +3 bytes) | π« |
Bytes | βοΈ (5 + ? = +5 bytes) Max. 4.294.967.295 (~4billions) | βοΈ (6 + ? = +6 bytes) Max. 2.147.483.647 (~2billions) |
using Byter;
Global Default Encoding (source code spec)
// update global defaut encoding. Default is UTF8
StringExtension.Default = Encoding.Unicode; // Unicode is UTF16
Convert string to byte[]
// using global encoding (*UTF8)
byte[] username = "@alec1o".GetBytes();
// using UNICODE (*UTF16) encoding
byte[] message = "Hello π World π".GetBytes(Encoding.Unicode);
// using UTF32 encoding
string secreatWord = "I'm not human, I'm a concept.";
byte[] secreat = secreatWord.GetBytes(Encoding.UTF32);
Convert byte[] to string
// using global encoding (*UTF8)
string username = new byte[] { ... }.GetString();
// using UNICODE (*UTF16) encoding
string message = new byte[] { ... }.GetString(Encoding.Unicode);
// using UTF32 encoding
byte[] secreat = new byte[] { ... };
string secreatWord = secreat.GetString(Encoding.UTF32);
Capitalize string
string name = "alECio furanZE".ToCapitalize();
# Alecio Furanze
string title = "i'M noT humAn";
title = title.ToCapitalize();
# I'm Not Human
UpperCase string
string name = "alECio furanZE".ToUpperCase();
# ALECIO FURANZE
string title = "i'M noT humAn";
title = title.ToUpperCase();
# I'M NOT HUMAN
LowerCase string
string name = "ALEciO FUraNZE".ToLowerCase();
# alecio furanze
string title = "i'M Not huMAN";
title = title.ToLowerCase();
# i'm not human