Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class and No Head Support #8

Open
KFKMan opened this issue May 4, 2024 · 4 comments
Open

Class and No Head Support #8

KFKMan opened this issue May 4, 2024 · 4 comments
Labels
enhancement New feature or request wontfix This will not be worked on

Comments

@KFKMan
Copy link

KFKMan commented May 4, 2024

Can you add Class support?
With Two Types Of Reading;
1- With Prop Index (you can create a Attribute for that like Index(0) İndex(1))
2- With Head Data => With Prop Name or if class has no duplicate property type Reading With only property type

On Read Ended => Result class need to be returned.

.Result => Serialize/Deserialize Result
.IsSuccesfull => Simply check for any big error accoured if not check for Errors ant have element
.Errors => A dictionary like a <Property, Error> for giving which properties are not readed/writed.

And can you add Extension methods like ReadInt(), WriteInt(), ReadBool().... etc. This will help developers to detect problem.

@alec1o
Copy link
Owner

alec1o commented May 4, 2024

lol... bro you read my mind...
look version 3 example;
but byter will be very good in version 3;

I started develop version 3, hours before you send open this Issue and i had same thing on mind 🤣 I hope done this version 3 in this weeks. 7 day of development and tests, Will release soon because i wanna use this new feature to Netly

Writer Example

using Byter;

By b = new By();

List<DateTime> times = new List<DateTime>();
Video video = new Video();
Player player = new Player();

b.Add(times);
b.Add(video);
b.Add(plater);
byte[] MY_BUFFER = b.Buffer;

Reader Example

using Byter;

By b = new By(MY_BUFFER);

List<DateTime> times = b.Get<List<DateTime>>();
Video video = b.Get<video>();
Player player = b.Get<Player>();

if (b.IsValid == false)
{
     // error on parser
}

Encoding

using Byter;

string a = "ABC";
byte[] b = a.GetBytes(); // UTF8 is default;
byte[] c = a.GetBytes(Encoding.UTF32);
using Byter;

byte[] a =  new byte[] { 1, 2, 3, 4, 5, 6 };
byte[] b = a.GetString(); // UTF8 is default;
byte[] c = a.GetString(Encoding.UTF32);
// update default from utf8 to utf32 encoding
StringExtension.Default = Encoding.UTF32;

// string props
string example = "aLe";

string a = example.ToCapitalize(); // output: Ale
string a = example.ToLowerCase(); // output: ale
string a = example.ToUpperCase(); // output: ALE

Template

public class Video
{
    public string name;
    public int Likes;
    public DateTime UploadTime;
    public string[] Tags;
    public Metadata Meta;
}

public class Metadata
{
     public byte[] buffer;
     public Vector3 Something;
}

public class Player
{
   public long Id;
   public Vector3 position;
   public Quaternion rotation;
   public Vector3 scale;
   public bool running;
   puublic int HP;
}

Supported Types

// 1 byte
Null = TypesPrefix + 0,
Sbyte = TypesPrefix + 1,
Byte = TypesPrefix + 2,
Bool = TypesPrefix + 3,

// 2 bytes
Char = TypesPrefix + 4,
Short = TypesPrefix + 5,
Ushort = TypesPrefix + 6,

// 4 bytes
Uint = TypesPrefix + 7,
Int = TypesPrefix + 8,
Float = TypesPrefix + 9,
Enum = TypesPrefix + 10,

// 8 bytes
Long = TypesPrefix + 11,
Ulong = TypesPrefix + 12,
Double = TypesPrefix + 13,

// 16 bytes
Decimal = TypesPrefix + 14,

// dynamic
Bytes = TypesPrefix + 15,
String = TypesPrefix + 16,
BigInteger = TypesPrefix + 18,

// Symbols
Class = TypesPrefix + 19,
Struct = TypesPrefix + 20,
Array = TypesPrefix + 21,
DateTime = TypesPrefix + 22,
List = TypesPrefix + 23,

@KFKMan
Copy link
Author

KFKMan commented May 5, 2024

it's looks very good.
You can add Int names versions of Short, Long etc.

@alec1o
Copy link
Owner

alec1o commented May 5, 2024

Yes sir!
like code Below, write and read int, short, long... Encapsulated in class it work too.

By b = new By();

b.Add((int)100);
b.Add((long)100);
b.Add((short)400);
b.Add((decimal)500);

int i = b.Get<int>();
long l = b.Get<long>();
....

bool sucess = b.IsValid;

Now don't have logs or error handles.
Just (IsValid) it return false if some data is not get.


My recommendation you also can use dynamic read technical, I'll documents is soon. Supported with all Byter version, Looks like:

v1, v2 example:

Reader r = new Reader (<buffer>);

int v = r.Read<int>();
MyEnum t = (MyEnum)v;

if (t == MyEnum.ChatBuffer)
{
    string messageId = r.Read<string>();
    ....
}
else if (t == MyEnum.PositionBuffer)
{
    int playerId = r.Read<int>();
    ....
}

v3 will use By instead of Writer/Reader, but Writer and Reader will removed because each use different prefix and protocol, e.g Writer buffer isn't compatible with By.Get buffer.

By  r = new By (<buffer>);

int v = r.Get<int>();
MyEnum t = (MyEnum)v;

if (t == MyEnum.ChatBuffer)
{
    string messageId = r.Get<string>();
    ....
}
else if (t == MyEnum.PositionBuffer)
{
    int playerId = r.Get<int>();
    ....
}

Thankful for feedback in version 4 I'll implement your feature, it'll look like code Below

b.OnSucess(Type t, string message) =>
{
    // message: sucess in read <long> type. Buffer Index <32>. current element <4>
});

b.OnError((Type t, string message) =>
{
    // message: error in read <long> type. Buffer Index <32>. past element <3>
});

@alec1o alec1o added the enhancement New feature or request label Jul 1, 2024
@alec1o
Copy link
Owner

alec1o commented Jul 9, 2024

it's looks very good. You can add Int names versions of Short, Long etc.

@KFKMan the version 3 is released 🥇

@alec1o alec1o added the wontfix This will not be worked on label Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants